Skip to content

Commit 18d7f61

Browse files
authored
Add proof production (egraphs-good#115)
* making progress on interface * fix up interface again * minor docs stuff * undo searchmatch struct * unions are delayed until rebuild * refactor much into explain file * rework justification structure * big get_ast refactor * add checking (not passing yet) * modified rebuilding to maintain congruence before analysis pending * tests passing! * implement proof production (untested) * explanation class * make math examples call with justification * printing explanation trees * various bugs * make proof checker * tests passing * remove confusing comment * change api for apply_one * fix subtle bug in lambda example * fix up congruence for analysis * some cleanup * new structure which is better for caching * Revert "new structure which is better for caching" This reverts commit 31df99a. * caching works elegantly! * run formatting * disable test for proof production * add test pass for proof generation * rename union_roots back to union * some progress on docs * more small progress on docs * document tree and flattened formats minimally * starting on nits * a bunch of nits * fix up rebuilding with analysis and tests * a better solution to the analysis problem * docs for string representation * fix format of example explanations * rename to get_ast * disallow calling explanation when feature not enabled * format * stray prints * don't clone asts when you don't need them * fix up conditional compilation * fmt * improve rebuilding with Max * change rule names to arc * use cow for the patternasts and thus ascend to a new level of rust development * simplify unification api greatly * add let binding to printing explanations * add documentation for let binding * make apply_one perform the union to clean up interface * remove Cow when not needed * make explain an option * fix up diff_power_harder * nits * add to changelog * apply_one for pattern faster when explanations off * simplify analysis rebuilding slightly * re-implement pattern apply_matches * oops * add disabling explanations * fix up disabling * working on explanations tutorial * continue working on tutorial * more work on tutorial * tutorial rough draft ready * also generate sexps * change simplify_const back oops * move analysis docs to rightful place
1 parent 8d68c87 commit 18d7f61

21 files changed

+1864
-240
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@
55
## [Unreleased] - ReleaseDate
66

77
### Added
8+
- The egraph now has an `EGraph::with_explanations_enabled` mode that allows for
9+
explaining why two terms are equivalent in the egraph.
10+
In explanations mode, all unions must be done through `union_instantiations` in order
11+
to justify the union.
12+
Calling `explain_equivalence` returns an `Explanation`
13+
which has both a `FlatExplanation` form and a
14+
`TreeExplanation` form.
815
- The `BackoffScheduler` is now more flexible.
916
- `EGraph::pre_union` allows inspection of unions, which can be useful for debugging.
1017
- The dot printer is now more flexible.
1118

1219
### Changed
20+
- All unions are now delayed until rebuilding, so `EGraph::rebuild` be called to observe effects.
21+
- The `apply_one` function on appliers now needs to perform unions.
22+
- The congruence closure algorithm now keeps the egraph congruent before
23+
doing any analysis (calling `make`). It does this by interleaving rebuilding
24+
and doing analysis.
1325
- `EGraph::add_expr` now proceeds linearly through the given `RecExpr`, which
1426
should be faster and include _all_ e-nodes from the expression.
1527
- `Rewrite` now has public `searcher` and `applier` fields and no `long_name`.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ all: test nits bench
44
test:
55
cargo build --release
66
cargo test --release
7+
# don't run examples in proof-production mode
8+
EGG_TEST_EXPLANATIONS=true cargo test --lib --bins --tests --benches --release
9+
710

811
.PHONY: nits
912
nits:
@@ -14,9 +17,14 @@ nits:
1417
cargo deadlinks
1518

1619
cargo clippy --tests
20+
EGG_TEST_EXPLANATIONS=true cargo clippy --tests
1721
cargo clippy --tests --features "serde-1"
1822
cargo clippy --tests --features "reports"
1923

2024
.PHONY: bench
2125
bench:
2226
cargo bench | ./scripts/filter-iai-output.py
27+
28+
.PHONY: bench_explanations
29+
bench_explanations:
30+
EGG_TEST_EXPLANATIONS=true cargo bench | ./scripts/filter-iai-output.py

scripts/filter-iai-output.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
ratios = []
1313

1414
for line in fileinput.input():
15-
if match := BENCH_NAME.match(line):
15+
match = BENCH_NAME.match(line)
16+
if match:
1617
name = match[1]
17-
if match := EST_CYCLES.match(line):
18+
match = EST_CYCLES.match(line)
19+
if match:
1820
if not printed_headers:
1921
printed_headers = True
2022
print(f'{"name":25} {"cycles":>10} {"diff":>10}')

src/eclass.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct EClass<L, D> {
1313
pub nodes: Vec<L>,
1414
/// The analysis data associated with this eclass.
1515
pub data: D,
16+
/// The parent enodes and their original Ids.
1617
pub(crate) parents: Vec<(L, Id)>,
1718
}
1819

0 commit comments

Comments
 (0)