Module("term/share",[Imports([Import("collection/list/set"),Import("strategy/general/unification"),Import("term/common")]),Strategies([SDef("share",[DefaultVarDec("mkvar"),DefaultVarDec("always"),DefaultVarDec("mklet")],Seq(Call(SVar("graph"),[CallNoArgs(SVar("mkvar"))]),Call(SVar("inline-graph"),[CallNoArgs(SVar("always")),CallNoArgs(SVar("mklet"))])))]),Strategies([SDef("edge",[DefaultVarDec("mkvar")],Call(SVar("split"),[Seq(CallNoArgs(SVar("address")),CallNoArgs(SVar("mkvar"))),All(Seq(CallNoArgs(SVar("address")),CallNoArgs(SVar("mkvar"))))])),SDef("list-edge",[DefaultVarDec("mkvar")],Call(SVar("split"),[Seq(CallNoArgs(SVar("address")),CallNoArgs(SVar("mkvar"))),Call(SVar("map"),[Seq(CallNoArgs(SVar("address")),CallNoArgs(SVar("mkvar")))])])),SDef("graph",[DefaultVarDec("mkvar")],Rec("x",LChoice(Seq(CallNoArgs(SVar("is-list")),Seq(Call(SVar("split"),[Call(SVar("list-edge"),[CallNoArgs(SVar("mkvar"))]),Seq(Call(SVar("map"),[CallNoArgs(SVar("x"))]),CallNoArgs(SVar("unions")))]),CallNoArgs(SVar("MkCons")))),Seq(Call(SVar("split"),[Call(SVar("edge"),[CallNoArgs(SVar("mkvar"))]),Seq(LRule(RuleNoCond(NoAnnoList(Explode(Wld,Var("xs"))),Var("xs"))),Seq(Call(SVar("map"),[CallNoArgs(SVar("x"))]),CallNoArgs(SVar("unions"))))]),CallNoArgs(SVar("MkCons"))))))]),Signature([Constructors([OpDecl("GraphLet",FunType([ConstType(Sort("List",[Sort("Product",[SortList([SortNoArgs("Int"),SortNoArgs("Term")])])])),ConstType(SortNoArgs("Term"))],ConstType(SortNoArgs("Term"))))])]),Strategies([SDef("inline-graph",[DefaultVarDec("always"),DefaultVarDec("mklet")],Seq(LRule(RuleNoCond(NoAnnoList(ListTail([NoAnnoList(Tuple([Var("a"),Var("t")]))],Var("graph"))),NoAnnoList(Op("GraphLet",[Var("graph"),Var("t")])))),Seq(Call(SVar("repeat"),[LChoice(Seq(CallNoArgs(SVar("term-share-inline")),Choice(Call(SVar("GraphLet"),[ListCong([TupleCong(Id,[CallNoArgs(SVar("always"))])],Id),Id]),CallNoArgs(SVar("term-share-dead")))),LChoice(CallNoArgs(SVar("term-share-dead")),Call(SVar("term-share-dont-inline"),[CallNoArgs(SVar("mklet"))])))]),LRule(RuleNoCond(NoAnnoList(Op("GraphLet",[NoAnnoList(List([])),Var("t")])),Var("t"))))))]),Rules([RDefNoArgs("term-share-inline",Rule(NoAnnoList(Op("GraphLet",[NoAnnoList(ListTail([NoAnnoList(Tuple([Var("a"),Var("skel")]))],Var("graph"))),Var("t")])),NoAnnoList(Op("GraphLet",[NoAnnoList(ListTail([NoAnnoList(Tuple([Var("a"),Var("skel")]))],Var("graph"))),Var("t'")])),AM(BA(Call(SVar("oncetd"),[SRule(RuleNoCond(Var("a"),Var("skel")))]),Var("t")),Var("t'")))),RDefNoArgs("term-share-dead",Rule(NoAnnoList(Op("GraphLet",[NoAnnoList(ListTail([NoAnnoList(Tuple([Var("a"),Var("skel")]))],Var("graph"))),Var("t")])),NoAnnoList(Op("GraphLet",[Var("graph"),Var("t")])),BA(Not(CallNoArgs(SVar("is-subterm"))),NoAnnoList(Tuple([Var("a"),Var("t")]))))),RDef("term-share-dont-inline",[DefaultVarDec("mklet")],RuleNoCond(NoAnnoList(Op("GraphLet",[NoAnnoList(ListTail([NoAnnoList(Tuple([Var("a"),Var("skel")]))],Var("graph"))),Var("t")])),NoAnnoList(Op("GraphLet",[Var("graph"),App(CallNoArgs(SVar("mklet")),NoAnnoList(Tuple([Var("a"),Var("skel"),Var("t")])))]))))])])
