Theorem TheoryArith::canonRec(const Expr& e) { if (isLeaf(e)) return reflexivityRule(e); int ar = e.arity(); if (ar > 0) { vector<Theorem> newChildrenThm; vector<unsigned> changed; for(int k = 0; k < ar; ++k) { // Recursively canonize the kids Theorem thm = canonRec(e[k]); if (thm.getLHS() != thm.getRHS()) { newChildrenThm.push_back(thm); changed.push_back(k); } } if(changed.size() > 0) { return canonThm(substitutivityRule(e, changed, newChildrenThm)); } } return canon(e); }
Theorem TheoryArith::canonSimp(const Expr& e) { DebugAssert(canonRec(e).getRHS() == e, "canonSimp expects input to be canonized"); int ar = e.arity(); if (isLeaf(e)) return find(e); if (ar > 0) { vector<Theorem> newChildrenThm; vector<unsigned> changed; Theorem thm; for (int k = 0; k < ar; ++k) { thm = canonSimp(e[k]); if (thm.getLHS() != thm.getRHS()) { newChildrenThm.push_back(thm); changed.push_back(k); } } if(changed.size() > 0) { thm = canonThm(substitutivityRule(e, changed, newChildrenThm)); return transitivityRule(thm, find(thm.getRHS())); } else return find(e); } return find(e); }