Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file Test_prop.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217(* This file is free software, part of Zipperposition. See file "license" for more details. *)openLogtkmoduleTI=InnerTermmoduleT=TermmoduleFmt=CCFormatmoduleRW=Rewriteletsection=Util.Section.(make"test_prop")letstat_narrow=Util.mk_stat"test_prop.narrow.calls"letstat_narrow_fail=Util.mk_stat"test_prop.narrow.fails"letstat_narrow_ok=Util.mk_stat"test_prop.narrow.ok"letstat_narrow_step_term=Util.mk_stat"test_prop.narrow.steps_term"letstat_narrow_step_lit=Util.mk_stat"test_prop.narrow.steps_lit"letprof_narrow=ZProf.make"test_prop.narrow"typeterm=T.ttypelit=Literal.ttypeclause=Literals.ttypeform=clauselisttypevar=Type.tHVar.ttyperes=|R_ok|R_failofSubst.t(* counter-example *)type'at_view=|T_ZofZ.t|T_QofQ.t|T_boolofbool|T_cstorofID.t*'alist(* cstor application *)|T_appofID.t*'alist(* other application *)|T_fun_appof'a*'alist|T_builtinofBuiltin.t*'alist|T_funofType.t*'a|T_varofvar(* TODO: β reduction *)lett_view(t:term):termt_view=matchT.viewtwith|T.AppBuiltin(Builtin.Intn,[])->T_Zn|T.AppBuiltin(Builtin.Ratn,[])->T_Qn|T.AppBuiltin(Builtin.True,[])->T_booltrue|T.AppBuiltin(Builtin.False,[])->T_boolfalse|T.AppBuiltin(b,l)->T_builtin(b,l)|T.Varv->T_varv|T.ConstidwhenInd_ty.is_constructorid->T_cstor(id,[])|T.Constid->T_app(id,[])|T.Fun(arg,bod)->T_fun(arg,bod)|T.App(f,l)->beginmatchT.viewfwith|T.ConstidwhenInd_ty.is_constructorid->T_cstor(id,l)|T.Constid->T_app(id,l)|_->T_fun_app(f,l)end|T.DB_->assertfalseletpp_formout(f:form):unit=letpp_c=Literals.ppinbeginmatchfwith|[c]->pp_coutc|_->Fmt.fprintfout"∧{@[%a@]}"(Util.pp_list~sep:","pp_c)fendmoduleNarrow:sigvaldefault_limit:intvalcheck_form:limit:int->form->resend=structletdefault_limit=10(* pseudo-substitution that is accumulated *)typesubst_acc=T.tT.VarMap.tletsubst_of_acc(s:subst_acc):Subst.t=T.VarMap.to_lists|>List.map(fun(v,t)->(v,0),(t,1))|>Subst.FO.of_list'?init:Noneletcomposerenaming(subst:Subst.t)(s1:subst_accScoped.t):subst_acc=lets1,sc1=s1inT.VarMap.map(funt->Subst.FO.applyrenamingsubst(t,sc1))s1letform_is_false(f:form):bool=List.existsLiterals.is_absurdf(* free variables of the form *)letvars_of_form(f:form):varlist=Iter.of_listf|>Iter.flat_mapLiterals.Seq.vars|>T.VarSet.of_iter|>T.VarSet.to_list(* perform term narrowing in [f] *)letnarrow_term(acc:subst_acc)(f:form):(subst_acc*form)Iter.t=letsc_rule=1inletsc_c=0in(* find the various pairs (rule,subst) that can apply *)letsubst_rule_l=Iter.of_listf|>Iter.flat_mapLiterals.Seq.terms|>Iter.flat_mapT.Seq.subterms|>Iter.flat_map(funt->RW.Term.narrow_term~scope_rules:sc_rule(t,sc_c))|>Iter.to_rev_list|>CCList.sort_uniq~cmp:CCOrd.(pairRW.Term.Rule.compareUnif_subst.compare)in(* now do one step for each *)beginIter.of_listsubst_rule_l|>Iter.map(fun(rule,us)->letrenaming=Subst.Renaming.create()inletsubst=Unif_subst.substusinletc_guard=Literals.of_unif_substrenamingusin(* evaluate new formula by substituting and evaluating *)letf'=f|>List.map(funlits->CCArray.appendc_guard(Literals.apply_substrenamingsubst(lits,sc_c)))|>Libzipperposition.Cut_form.normalize_formin(* make new formula *)Util.incr_statstat_narrow_step_term;Util.debugf~section5"(@[<2>test_prop.narrow_term@ :from %a@ :to %a@ :rule %a@ :subst %a@])"(funk->kpp_formfpp_formf'RW.Term.Rule.ppruleSubst.ppsubst);letnew_acc=composerenamingsubst(acc,sc_c)innew_acc,f')end(* perform lit narrowing in [f] *)letnarrow_lit(acc:subst_acc)(f:form):(subst_acc*form)Iter.t=letsc_rule=1inletsc_c=0in(* find the various pairs (rule,subst) that can apply *)letsubst_rule_l=Iter.of_listf|>Iter.flat_mapIter.of_array|>Iter.flat_map(funlit->RW.Lit.narrow_lit~scope_rules:sc_rule(lit,sc_c))|>Iter.to_rev_list|>CCList.sort_uniq~cmp:CCOrd.(tripleRW.Lit.Rule.compareUnif_subst.compare(listcompare))in(* now do one step for each *)beginIter.of_listsubst_rule_l|>Iter.map(fun(rule,us,_)->letrenaming=Subst.Renaming.create()inletsubst=Unif_subst.substusinletc_guard=Literals.of_unif_substrenamingusin(* evaluate new formula by substituting and evaluating *)letf'=f|>List.map(funlits->CCArray.appendc_guard(Literals.apply_substrenamingsubst(lits,sc_c)))|>Libzipperposition.Cut_form.normalize_formin(* make new formula *)Util.incr_statstat_narrow_step_lit;Util.debugf~section5"(@[<2>test_prop.narrow_lit@ :from %a@ :to %a@ :rule %a@ :subst %a@])"(funk->kpp_formfpp_formf'RW.Lit.Rule.ppruleSubst.ppsubst);letnew_acc=composerenamingsubst(acc,sc_c)innew_acc,f')endexceptionFound_unsatofSubst.tletcheck_form~limit(f:form)=Util.incr_statstat_narrow;letq=Queue.create()inletacc0=vars_of_formf|>List.map(funv->v,T.varv)|>T.VarMap.of_listinQueue.push(acc0,f)q;letn=reflimitintrywhile!n>0&¬(Queue.is_emptyq)dodecrn;letsubst,f=Queue.popqinletnew_f_l=Iter.append(narrow_termsubstf)(narrow_litsubstf)inIter.iter(fun(acc,f')->ifform_is_falsef'then(letsubst=subst_of_accaccinraise(Found_unsatsubst););Queue.push(acc,f')q)new_f_l;done;R_okwithFound_unsatsubst->R_failsubstendletdefault_limit=Narrow.default_limitletcheck_form?(limit=Narrow.default_limit)(f:form):res=ZProf.with_profprof_narrow(Narrow.check_form~limit)f(* [t] head symbol is a function that is not a constructor *)letstarts_with_fun(t:T.t):bool=matchT.headtwith|None->false|Someid->not(Ind_ty.is_constructorid)