···27482748 }
27492749 }
2750275027512751- // Maximize ( -branching_factor, references ).
27512751+ // We want to picke the variable that has the smallest branching factor
27522752+ // possible, this tends to yield smaller, shallower decision trees.
27532753+ // So, for example, we will pick a list (branching factor of 2 `[]` and
27542754+ // `[_, ..]`) over an integer (infinitely many choices).
27522755 //
27532753- // - branching_factor: prefer the split that creates the FEWEST switch arms.
27542754- // Fewer children tends to yield smaller, shallower decision trees.
27552755- //
27562756- // - references: break ties by choosing the subject that appears in the most
27572757- // clauses (i.e. a test that will pay off for more rows).
27562756+ // In case two variables are tied we break the tie by choosing the subject
27572757+ // that appears in the most clauses (i.e. a test that will pay off for more
27582758+ // rows).
27582759 //
27592760 // Both parts mirror standard guidance for good match trees (small branching
27602760- // factor; prioritize columns that are widely useful).
27612761- //
27612761+ // factor; prioritize columns that are widely useful):
27622762 // https://www.cs.tufts.edu/~nr/cs257/archive/luc-maranget/jun08.pdf
27632763 first_branch
27642764 .checks
27652765 .iter()
27662766- .max_by_key(|check| {
27672767- let mode = check.var.branch_mode(env);
27682768- let branching_factor = mode.branching_factor();
27662766+ .min_by_key(|check| {
27672767+ let branching_factor = check.var.branch_mode(env).branching_factor();
27692768 let references = var_references.get(&check.var.id).cloned().unwrap_or(0);
2770276927712771- (usize::MAX - branching_factor, references)
27702770+ // Notice how we're using `-references`: we want to favour the one
27712771+ // that has the most references, so the one were `-references` is
27722772+ // the smallest.
27732773+ (branching_factor, -references)
27722774 })
27732775 .cloned()
27742776}
···1919 let t;
2020 let b;
2121 let c;
2222- let $ = x[1][2];
2323- if ($ === 2) {
2424- let $1 = x[3];
2525- if ($1 === 1) {
2222+ let $ = x[3];
2323+ if ($ === 1) {
2424+ let $1 = x[1][2];
2525+ if ($1 === 2) {
2626 a = x[0];
2727 t = x[1];
2828 b = x[1][0];