Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file hrs.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136(** This module provides a function to translate a signature to the HRS format
used in the confluence competition.
@see <http://project-coco.uibk.ac.at/problems/hrs.php>. *)open!LplibopenLplib.BaseopenLplib.ExtraopenTimedopenCoreopenTermopenPrint(** [print_sym ppf s] outputs the fully qualified name of [s] to [ppf]. The
name is prefixed by ["c_"], and modules are separated with ["_"], not
["."]. *)letprint_sym:sympp=funppfs->letprint_path=List.ppFormat.pp_print_string"_"inoutppf"c_%a_%s"print_paths.sym_paths.sym_name(** [print_patt ppf p] outputs TPDB format corresponding to the pattern [p],
to [ppf]. *)letprint_term:bool->termpp=funlhs->letrecppppft=matchunfoldtwith(* Forbidden cases. *)|Meta(_,_)->assertfalse|TRef(_)->assertfalse|TEnv(_,_)->assertfalse|Wild->assertfalse|Kind->assertfalse(* Printing of atoms. *)|Vari(x)->outppf"%a"pp_varx|Type->outppf"TYPE"|Symb(s)->print_symppfs|Patt(i,n,ts)->ifts=[||]thenoutppf"$%s"nelseppppf(Array.fold_left(funtu->mk_Appl(t,u))(mk_Patt(i,n,[||]))ts)|Appl(t,u)->outppf"app(%a,%a)"pptppu|Abst(a,t)->let(x,t)=Bindlib.unbindtiniflhsthenoutppf"lam(m_typ,\\%a.%a)"pp_varxpptelseoutppf"lam(%a,\\%a.%a)"ppapp_varxppt|Prod(a,b)->let(x,b)=Bindlib.unbindbinoutppf"pi(%a,\\%a.%a)"ppapp_varxppb|LLet(_,t,u)->ppppf(Bindlib.substut)inpp(** [print_rule ppf lhs rhs] outputs the rule declaration [lhs]->[rhs]
to [ppf] *)letprint_rule:Format.formatter->term->term->unit=funppflhsrhs->(* gets pattern and binded variable names *)letadd_var_names:StrSet.t->term->StrSet.t=funnst->letnames=Stdlib.refnsinletfnt=matchtwith|Patt(_,n,_)->Stdlib.(names:=StrSet.add("$"^n)!names)|Abst(_,b)->let(x,_)=Bindlib.unbindbinStdlib.(names:=StrSet.add(Bindlib.name_ofx)!names)|_->()inLibTerm.iterfnt;Stdlib.(!names)inletnames=add_var_namesStrSet.emptylhsinletnames=add_var_namesnamesrhsinifnot(StrSet.is_emptynames)thenbeginletprint_nameppfx=outppf" %s : term\n"xinletpp_strsetppf=StrSet.iter(print_nameppf)inoutppf"(VAR\n%a)\n"pp_strsetnamesend;(* Print the rewriting rule. *)outppf"(RULES %a"(print_termtrue)lhs;outppf"\n -> %a)\n"(print_termfalse)rhs(** [print_sym_rule ppf s r] outputs the rule declaration corresponding [r]
(on the symbol [s]), to [ppf]. *)letprint_sym_rule:Format.formatter->sym->rule->unit=funppfsr->letlhs=add_args(mk_Symbs)r.lhsinletrhs=LibTerm.term_of_rhsrinprint_ruleppflhsrhs(** [to_HRS ppf sign] outputs a TPDB representation of the rewriting system of
the signature [sign] to [ppf]. *)letto_HRS:Format.formatter->Sign.t->unit=funppfsign->(* Get all the dependencies (every needed symbols and rewriting rules). *)letdeps=Sign.dependenciessignin(* Function to iterate over every symbols. *)letiter_symbols:(sym->unit)->unit=funfn->letnot_on_ghosts_(s,_)=ifnot(Unif_rule.is_ghosts)thenfnsinletiter_symbolssign=StrMap.iternot_on_ghostsSign.(!(sign.sign_symbols))inList.iter(fun(_,sign)->iter_symbolssign)depsin(* Print the prelude. *)letprelude=["(FUN";" lam : term -> (term -> term) -> term";" app : term -> term -> term";" pi : term -> (term -> term) -> term";" type : term";")";"";"(COMMENT beta-reduction)";"(VAR";" v_x : term";" m_typ : term";" m_B : term";" m_F : term -> term";")";"(RULES app(lam(m_typ,\\v_x. m_F v_x), m_B) -> m_F(m_B))";"";"(COMMENT TYPE keyword)";"(FUN TYPE : term)"]inList.iter(outppf"%s\n")prelude;(* Print the symbol declarations. *)outppf"\n(COMMENT symbols)\n";letprint_symbols=outppf"(FUN %a : term)\n"print_symsiniter_symbolsprint_symbol;(* Print the rewriting rules. *)outppf"\n(COMMENT rewriting rules)\n";letprint_ruless=match!(s.sym_def)with|Some(d)->print_ruleppf(mk_Symbs)d|None->List.iter(print_sym_ruleppfs)!(s.sym_rules)initer_symbolsprint_rules