src/Pure/IsaPlanner/isand.ML
changeset 15570 8d8c70b41bab
parent 15531 08c8dad8e399
child 15574 b1d1b5bfc464
equal deleted inserted replaced
15569:1b3115d1a8df 15570:8d8c70b41bab
   106       val premts = Thm.prems_of th;
   106       val premts = Thm.prems_of th;
   107     
   107     
   108       fun allify_prem_var (vt as (n,ty),t)  = 
   108       fun allify_prem_var (vt as (n,ty),t)  = 
   109           (Term.all ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t)))
   109           (Term.all ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t)))
   110 
   110 
   111       fun allify_prem Ts p = foldr allify_prem_var (Ts, p)
   111       fun allify_prem Ts p = Library.foldr allify_prem_var (Ts, p)
   112 
   112 
   113       val cTs = map (ctermify o Free) Ts
   113       val cTs = map (ctermify o Free) Ts
   114       val cterm_asms = map (ctermify o allify_prem Ts) premts
   114       val cterm_asms = map (ctermify o allify_prem Ts) premts
   115       val allifyied_asm_thms = map (Drule.forall_elim_list cTs o Thm.assume) cterm_asms
   115       val allifyied_asm_thms = map (Drule.forall_elim_list cTs o Thm.assume) cterm_asms
   116     in 
   116     in 
   117       (foldl (fn (x,y) => y COMP x) (th, allifyied_asm_thms), cterm_asms)
   117       (Library.foldl (fn (x,y) => y COMP x) (th, allifyied_asm_thms), cterm_asms)
   118     end;
   118     end;
   119 
   119 
   120 fun allify_conditions' Ts th = 
   120 fun allify_conditions' Ts th = 
   121     allify_conditions (Thm.cterm_of (Thm.sign_of_thm th)) Ts th;
   121     allify_conditions (Thm.cterm_of (Thm.sign_of_thm th)) Ts th;
   122 
   122 
   130       val vars = map Term.dest_Var (Term.term_vars prop)
   130       val vars = map Term.dest_Var (Term.term_vars prop)
   131 
   131 
   132       val names = Term.add_term_names (prop, [])
   132       val names = Term.add_term_names (prop, [])
   133 
   133 
   134       val (insts,names2) = 
   134       val (insts,names2) = 
   135           foldl (fn ((insts,names),v as ((n,i),ty)) => 
   135           Library.foldl (fn ((insts,names),v as ((n,i),ty)) => 
   136                     let val n2 = Term.variant names n in
   136                     let val n2 = Term.variant names n in
   137                       ((ctermify (Var v), ctermify (Free(n2,ty))) :: insts, 
   137                       ((ctermify (Var v), ctermify (Free(n2,ty))) :: insts, 
   138                        n2 :: names)
   138                        n2 :: names)
   139                     end)
   139                     end)
   140                 (([],names), vars)
   140                 (([],names), vars)
   165     let val vt = #t (Thm.rep_cterm v)
   165     let val vt = #t (Thm.rep_cterm v)
   166       val (n,ty) = Term.dest_Free vt
   166       val (n,ty) = Term.dest_Free vt
   167     in (Term.all ty) $ (Abs(n,ty,Term.abstract_over (vt, t))) end;
   167     in (Term.all ty) $ (Abs(n,ty,Term.abstract_over (vt, t))) end;
   168 
   168 
   169 fun allify_for_sg_term ctermify vs t =
   169 fun allify_for_sg_term ctermify vs t =
   170     let val t_alls = foldr allify_term (vs,t);
   170     let val t_alls = Library.foldr allify_term (vs,t);
   171         val ct_alls = ctermify t_alls; 
   171         val ct_alls = ctermify t_alls; 
   172     in 
   172     in 
   173       (ct_alls, Drule.forall_elim_list vs (Thm.assume ct_alls))
   173       (ct_alls, Drule.forall_elim_list vs (Thm.assume ct_alls))
   174     end;
   174     end;
   175 (* lookup type of a free var name from a list *)
   175 (* lookup type of a free var name from a list *)
   187 
   187 
   188       val sgs = prems_of newth;
   188       val sgs = prems_of newth;
   189       val (sgallcts, sgthms) = 
   189       val (sgallcts, sgthms) = 
   190           Library.split_list (map (allify_for_sg_term ctermify vs) sgs);
   190           Library.split_list (map (allify_for_sg_term ctermify vs) sgs);
   191       val minimal_newth = 
   191       val minimal_newth = 
   192           (foldl (fn ( newth', sgthm) => 
   192           (Library.foldl (fn ( newth', sgthm) => 
   193                           Drule.compose_single (sgthm, 1, newth'))
   193                           Drule.compose_single (sgthm, 1, newth'))
   194                       (newth, sgthms));
   194                       (newth, sgthms));
   195       val allified_newth = 
   195       val allified_newth = 
   196           minimal_newth 
   196           minimal_newth 
   197             |> Drule.implies_intr_list hprems
   197             |> Drule.implies_intr_list hprems
   227       val sgs = prems_of th;
   227       val sgs = prems_of th;
   228       val (sgallcts, sgthms) = 
   228       val (sgallcts, sgthms) = 
   229           Library.split_list (map (allify_for_sg_term ctermify cfrees) sgs);
   229           Library.split_list (map (allify_for_sg_term ctermify cfrees) sgs);
   230 
   230 
   231       val minimal_th = 
   231       val minimal_th = 
   232           (foldl (fn ( th', sgthm) => 
   232           (Library.foldl (fn ( th', sgthm) => 
   233                           Drule.compose_single (sgthm, 1, th'))
   233                           Drule.compose_single (sgthm, 1, th'))
   234                       (th, sgthms)) RS Drule.rev_triv_goal;
   234                       (th, sgthms)) RS Drule.rev_triv_goal;
   235 
   235 
   236       val allified_th = 
   236       val allified_th = 
   237           minimal_th 
   237           minimal_th 
   254       val solth' = 
   254       val solth' = 
   255           solth |> Drule.implies_intr_list hcprems
   255           solth |> Drule.implies_intr_list hcprems
   256                 |> Drule.forall_intr_list cfvs
   256                 |> Drule.forall_intr_list cfvs
   257     in Drule.compose_single (solth', i, gth) end;
   257     in Drule.compose_single (solth', i, gth) end;
   258 
   258 
   259 val export_solutions = foldr (uncurry export_solution);
   259 val export_solutions = Library.foldr (uncurry export_solution);
   260 
   260 
   261 
   261 
   262 (* fix parameters of a subgoal "i", as free variables, and create an
   262 (* fix parameters of a subgoal "i", as free variables, and create an
   263 exporting function that will use the result of this proved goal to
   263 exporting function that will use the result of this proved goal to
   264 show the goal in the original theorem. 
   264 show the goal in the original theorem.