#include #include #include #include #include #include #include "tree.h" using namespace std; struct Axiom{ Tree from,to; }; ostream& operator<<(ostream &os,const Axiom &ax){ return os< "< &dst,const string &expr){ size_t idx=expr.find('='); bool twoway=true; if(idx==string::npos){ idx=expr.find('>'); assert(idx!=string::npos); twoway=false; } assert(expr.find('=',idx+1)==string::npos); assert(expr.find('>',idx+1)==string::npos); string from=expr.substr(0,idx),to=expr.substr(idx+1); dst.push_back({Tree(from),Tree(to)}); if(twoway)dst.push_back({Tree(to),Tree(from)}); } vector importAxioms(const vector &list){ vector axioms; for(const string &str : list){ parseAxiom(axioms,str); } return axioms; } using Heuristic = int (*)(const Tree&); int heuristic_nleaves(const Tree &tree){return tree.nleaves();} int heuristic_height(const Tree &tree){return tree.height();} template struct AscendingCompare{ bool operator()(const Tree &a,const Tree &b) const { return F(a)>F(b); } }; template vector* deduceEq(const vector &axioms,const Tree &startTree,const Tree &target){ priority_queue,AscendingCompare> pqu; map parentMap; pqu.push(startTree); Tree current; while(true){ if(pqu.size()==0)return nullptr; current=pqu.top(); pqu.pop(); // cerr<<"current = "< *v=new vector(); Tree *t=¤t; while(true){ // cerr<<"*t = "<<*t<push_back(*t); auto it=parentMap.find(*t); if(it==parentMap.end())break; t=&it->second; } return v; } void test_func(){ Tree from("([2]*([2]*1))"),to("10"); Tree subj("(([1]*1)*[1])"); /*unordered_set temps=to.collectTemporaries(); for(Variable v : temps){ cout< res=subj.replace(from,to); for(const Tree &t : res){ cout< axioms=importAxioms({ // "([1]*[2])>([2]*[1])", // Commutativity // "(([1]*[2])*[3])=([1]*([2]*[3]))", // Associativity // "([1]*([1]*[2]))=[1]", // Onno's 1=2 axioms // "(([2]*[1])*[1])=[1]", // "[1]=([1]*[1])", // "(([1]*[2])*[3])=(([2]*[3])*[1])", // "[1]=[2]", "[1]=([1]*([1]*([1]*[2])))", // Daan's 1=2 axioms "(([2]*[1])*[1])=[1]", }); const Tree t_from("1"),t_to("2"); for(const Axiom &ax : axioms)cout< *res=deduceEq(axioms,t_from,t_to); if(res==nullptr){ cout<<"No deduction"<size()-1;i>=0;i--){ cout<at(i)<