-type sort = Prop | Univ;;
-
-let floc = HExtlib.dummy_floc;;
-
-
-let paramod_timeout = ref 600;;
-let depth = ref 10;;
-
-let universe = "Univ" ;;
-let prop = "Prop";;
-
-let kw = [
- "and","myand"
-];;
-
-let mk_ident s =
- PT.Ident ((try List.assoc s kw with Not_found -> s),None)
-;;
-
-let rec collect_arities_from_term = function
- | A.Constant name -> [name,(0,Univ)]
- | A.Variable name -> [name,(0,Univ)]
- | A.Function (name,l) ->
- (name,(List.length l,Univ))::
- List.flatten (List.map collect_arities_from_term l)
-;;
-
-let rec collect_fv_from_term = function
- | A.Constant name -> []
- | A.Variable name -> [name]
- | A.Function (_,l) ->
- List.flatten (List.map collect_fv_from_term l)
-;;
-
-let collect_arities_from_atom a =
- let aux = function
- | A.Proposition name -> [name,(0,Prop)]
- | A.Predicate (name,args) ->
- (name,(List.length args,Prop)) ::
- (List.flatten (List.map collect_arities_from_term args))
- | A.True -> []
- | A.False -> []
- | A.Eq (t1,t2) ->
- collect_arities_from_term t1 @ collect_arities_from_term t2
- | A.NotEq (t1,t2) ->
- collect_arities_from_term t1 @ collect_arities_from_term t2
- in
- HExtlib.list_uniq (List.sort compare (List.flatten (List.map aux a)))
-;;
-
-let collect_fv_from_atom a =
- let aux = function
- | A.Proposition name -> [name]
- | A.Predicate (name,args) ->
- name :: List.flatten (List.map collect_fv_from_term args)
- | A.True -> []
- | A.False -> []
- | A.Eq (t1,t2) -> collect_fv_from_term t1 @ collect_fv_from_term t2
- | A.NotEq (t1,t2) -> collect_fv_from_term t1 @ collect_fv_from_term t2
- in
- let rec aux2 = function
- | [] -> []
- | hd::tl -> aux hd @ aux2 tl
- in
- HExtlib.list_uniq (List.sort compare (aux2 a))
-;;
-
-let rec collect_fv_from_formulae = function
- | A.Disjunction (a,b) ->
- collect_fv_from_formulae a @ collect_fv_from_formulae b
- | A.NegAtom a
- | A.Atom a -> collect_fv_from_atom [a]
-;;
-
-let rec convert_term = function
- | A.Variable x -> mk_ident x
- | A.Constant x -> mk_ident x
- | A.Function (name, args) ->
- PT.Appl (mk_ident name :: List.map convert_term args)
-;;
-
-let rec atom_of_formula neg pos = function
- | A.Disjunction (a,b) ->
- let neg, pos = atom_of_formula neg pos a in
- atom_of_formula neg pos b
- | A.NegAtom a -> a::neg, pos
- | A.Atom (A.NotEq (a,b)) -> (A.Eq (a,b) :: neg), pos
- | A.Atom a -> neg, a::pos
-;;
-
-let atom_of_formula f =
- let neg, pos = atom_of_formula [] [] f in
- neg @ pos
-;;
-
-let rec mk_arrow component tail = function
- | 0 -> begin
- match tail with
- | Prop -> mk_ident prop
- | Univ -> mk_ident universe
- end
- | n ->
- PT.Binder
- (`Forall,
- ((mk_ident "_"),Some (mk_ident component)),
- mk_arrow component tail (n-1))
-;;
-
-let build_ctx_for_arities univesally arities t =
- let binder = if univesally then `Forall else `Exists in
- let rec aux = function
- | [] -> t
- | (name,(nargs,sort))::tl ->
- PT.Binder
- (binder,
- (mk_ident name,Some (mk_arrow universe sort nargs)),
- aux tl)
- in
- aux arities
-;;
-
-let convert_atom universally a =
- let aux = function
- | A.Proposition p -> mk_ident p
- | A.Predicate (name,params) ->
- PT.Appl ((mk_ident name) :: (List.map convert_term params))
- | A.True -> mk_ident "True"
- | A.False -> mk_ident "False"
- | A.Eq (l,r)
- | A.NotEq (l,r) -> (* removes the negation *)
- PT.Appl [mk_ident "eq";mk_ident universe;convert_term l;convert_term r]
- in
- let rec aux2 = function
- | [] -> assert false
- | [x] -> aux x
- | he::tl ->
- if universally then
- PT.Binder (`Forall, (mk_ident "_", Some (aux he)), aux2 tl)
- else
- PT.Appl [mk_ident "And";aux he;aux2 tl]
- in
- let arities = collect_arities_from_atom a in
- let fv = collect_fv_from_atom a in
- build_ctx_for_arities universally
- (List.filter
- (function (x,(0,Univ)) -> List.mem x fv | _-> false)
- arities)
- (aux2 a)
-;;
-
-let collect_arities atom ctx =
- let atoms = atom@(List.flatten (List.map atom_of_formula ctx)) in
- collect_arities_from_atom atoms
-;;
-
-let collect_arities_from_formulae f =
- let rec collect_arities_from_formulae = function
- | A.Disjunction (a,b) ->
- collect_arities_from_formulae a @ collect_arities_from_formulae b
- | A.NegAtom a
- | A.Atom a -> collect_arities_from_atom [a]
- in
- HExtlib.list_uniq (List.sort compare (collect_arities_from_formulae f))
-;;
-
-let is_formulae_1eq_negated f =
- let atom = atom_of_formula f in
- match atom with
- | [A.NotEq (l,r)] -> true
- | _ -> false
-;;
-
-let collect_fv_1stord_from_formulae f =
- let arities = collect_arities_from_formulae f in
- let fv = collect_fv_from_formulae f in
- List.map fst
- (List.filter (function (x,(0,Univ)) -> List.mem x fv | _-> false) arities)
-;;
-
-let rec convert_formula fv no_arities context f =
- let atom = atom_of_formula f in
- let t = convert_atom (fv = []) atom in
- let rec build_ctx n = function
- | [] -> t
- | hp::tl ->
- PT.Binder
- (`Forall,
- (mk_ident ("H" ^ string_of_int n),
- Some (convert_formula [] true [] hp)),
- build_ctx (n+1) tl)
- in
- let arities = if no_arities then [] else collect_arities atom context in
- build_ctx_for_arities true arities (build_ctx 0 context)
-;;
-
-let check_if_atom_is_negative = function
- | A.True -> false
- | A.False -> true
- | A.Proposition _ -> false
- | A.Predicate _ -> false
- | A.Eq _ -> false
- | A.NotEq _ -> true
-;;
-
-let rec check_if_formula_is_negative = function
- | A.Disjunction (a,b) ->
- check_if_formula_is_negative a && check_if_formula_is_negative b
- | A.NegAtom a -> not (check_if_atom_is_negative a)
- | A.Atom a -> check_if_atom_is_negative a
-;;
-
-let ng_generate_tactics fv ueq_case context arities =
- [ GA.Executable(floc,GA.NTactic(floc,
- [GA.NIntro (floc,"Univ") ; GA.NDot(floc)])) ]
- @
- (HExtlib.list_mapi
- (fun (name,_) _->
- GA.Executable(floc,GA.NTactic(floc,
- [GA.NIntro (floc,(try List.assoc name kw with Not_found -> name));
- GA.NDot(floc)])))
- arities)
- @
- (HExtlib.list_mapi
- (fun _ i->
- GA.Executable(floc,GA.NTactic(floc,
- [GA.NIntro (floc,"H"^string_of_int i);GA.NDot(floc)])))
- context)
- @
-(if fv <> [] then
- (List.flatten
- (List.map
- (fun _ ->
- [GA.Executable(floc,GA.NTactic(floc,
- [GA.NApply (floc,
- PT.Appl [mk_ident "ex_intro";PT.Implicit;PT.Implicit;
- PT.Implicit;PT.Implicit]);GA.NBranch floc]));
- GA.Executable(floc,GA.NTactic(floc,
- [GA.NPos (floc,[2])]))])
- fv))
- else [])@
- [GA.Executable(floc,GA.NTactic(floc, [
- if (*ueq_case*) true then
- GA.NAuto (floc,(
- HExtlib.list_mapi
- (fun _ i ->
- mk_ident ("H" ^ string_of_int i))
- context
- ,[]))
- else
- GA.NAuto (floc,([],[
- "depth",string_of_int 5;
- "width",string_of_int 5;
- "size",string_of_int 20;
- "timeout",string_of_int 10;
- ]))
- ;
- GA.NSemicolon(floc)]));
-(*
- GA.Executable(floc,GA.NTactic(floc, Some (GA.Try(floc,
- GA.Assumption floc)), GA.Dot(floc)))
-*)
- ]@
-(if fv <> [] then
- (List.flatten
- (List.map
- (fun _ ->
- [GA.Executable(floc,GA.NTactic(floc, [GA.NShift floc;
- GA.NSkip floc; GA.NMerge floc]))])
- fv))
- else [])@
- [GA.Executable(floc,GA.NTactic(floc,[GA.NTry(floc, GA.NAssumption(floc));
- GA.NSemicolon(floc)]))]@
- [GA.Executable(floc,GA.NCommand(floc, GA.NQed(floc)))]