#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(const Tree &tree){ return tree.nleaves(); } 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; } int main(){ const vector axioms=importAxioms({ // "([1]*[2])>([2]*[1])", // "(([1]*[2])*[3])=([1]*([2]*[3]))", // "([1]*([1]*[2]))=[1]", // "(([2]*[1])*[1])=[1]", // "[1]=([1]*[1])", // "(([1]*[2])*[3])=(([2]*[3])*[1])", "[1]=[2]", }); const Tree t_from("(1*2)"),t_to("(2*1)"); 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)<