-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.rs
42 lines (33 loc) · 1.33 KB
/
math.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use egglog::EGraph;
use ruler::enumo;
#[test]
fn math_eval() {
let mut egraph = EGraph::default();
egraph
.parse_and_run_program(
Some("egglog/math.egg".to_string()),
include_str!("egglog/math-old.egg"),
)
.unwrap();
// begin by enumerating the language
let unary_fns = enumo::Workload::new(&["(Abs)"]);
let binary_fns = enumo::Workload::new(&["(Add)", "(Sub)", "(Mul)", "(Div)"]);
let pred_binary_fns = enumo::Workload::new(&["(Eq)", "(Neq)"]);
let atoms = enumo::Workload::new(&["(Num 0)", "(Num 1)", "(Var quoteaquote)"]);
let term_productions = enumo::Workload::new(&["(MathOp2 mathop x y)", "(PredOp2 predop x y)"])
.plug("mathop", &binary_fns)
.plug("predop", &pred_binary_fns);
let terms_depth_1 = term_productions.plug("x", &atoms).plug("y", &atoms);
let mut prog: String = String::new();
for term in terms_depth_1.force() {
let term_str = term.to_string().replace("quote", "\"");
prog = format!("{}\n{}", prog, term_str);
}
prog += "\n(run 20)\n";
let extracts = egraph.parse_and_run_program(None, &prog).unwrap();
for extract in extracts {
println!("{}", extract);
}
let serialized = egraph.serialize(egglog::SerializeConfig::default());
serialized.to_json_file("math.svg").unwrap();
}