src/Pure/drule.ML
changeset 19878 51ae6677dd5f
parent 19861 620d90091788
child 19906 c23a0e65b285
equal deleted inserted replaced
19877:705ba8232952 19878:51ae6677dd5f
    56   val read_instantiate_sg: theory -> (string*string)list -> thm -> thm
    56   val read_instantiate_sg: theory -> (string*string)list -> thm -> thm
    57   val read_instantiate: (string*string)list -> thm -> thm
    57   val read_instantiate: (string*string)list -> thm -> thm
    58   val cterm_instantiate: (cterm*cterm)list -> thm -> thm
    58   val cterm_instantiate: (cterm*cterm)list -> thm -> thm
    59   val eq_thm_thy: thm * thm -> bool
    59   val eq_thm_thy: thm * thm -> bool
    60   val eq_thm_prop: thm * thm -> bool
    60   val eq_thm_prop: thm * thm -> bool
    61   val weak_eq_thm: thm * thm -> bool
    61   val equiv_thm: thm * thm -> bool
    62   val size_of_thm: thm -> int
    62   val size_of_thm: thm -> int
    63   val reflexive_thm: thm
    63   val reflexive_thm: thm
    64   val symmetric_thm: thm
    64   val symmetric_thm: thm
    65   val transitive_thm: thm
    65   val transitive_thm: thm
    66   val symmetric_fun: thm -> thm
    66   val symmetric_fun: thm -> thm
   114   val goals_conv: (int -> bool) -> (cterm -> thm) -> cterm -> thm
   114   val goals_conv: (int -> bool) -> (cterm -> thm) -> cterm -> thm
   115   val fconv_rule: (cterm -> thm) -> thm -> thm
   115   val fconv_rule: (cterm -> thm) -> thm -> thm
   116   val norm_hhf_eq: thm
   116   val norm_hhf_eq: thm
   117   val is_norm_hhf: term -> bool
   117   val is_norm_hhf: term -> bool
   118   val norm_hhf: theory -> term -> term
   118   val norm_hhf: theory -> term -> term
       
   119   val unvarify: thm -> thm
   119   val protect: cterm -> cterm
   120   val protect: cterm -> cterm
   120   val protectI: thm
   121   val protectI: thm
   121   val protectD: thm
   122   val protectD: thm
   122   val protect_cong: thm
   123   val protect_cong: thm
   123   val implies_intr_protected: cterm list -> thm -> thm
   124   val implies_intr_protected: cterm list -> thm -> thm
   134   val sort_triv: theory -> typ * sort -> thm list
   135   val sort_triv: theory -> typ * sort -> thm list
   135   val unconstrainTs: thm -> thm
   136   val unconstrainTs: thm -> thm
   136   val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a
   137   val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a
   137   val rename_bvars: (string * string) list -> thm -> thm
   138   val rename_bvars: (string * string) list -> thm -> thm
   138   val rename_bvars': string option list -> thm -> thm
   139   val rename_bvars': string option list -> thm -> thm
   139   val unvarifyT: thm -> thm
       
   140   val unvarify: thm -> thm
       
   141   val tvars_intr_list: string list -> thm -> (string * (indexname * sort)) list * thm
   140   val tvars_intr_list: string list -> thm -> (string * (indexname * sort)) list * thm
   142   val incr_indexes: thm -> thm -> thm
   141   val incr_indexes: thm -> thm -> thm
   143   val incr_indexes2: thm -> thm -> thm -> thm
   142   val incr_indexes2: thm -> thm -> thm -> thm
   144   val remdups_rl: thm
   143   val remdups_rl: thm
   145   val multi_resolve: thm list -> thm -> thm Seq.seq
   144   val multi_resolve: thm list -> thm -> thm Seq.seq
   469 (*Convert all Vars in a theorem to Frees.  Also return a function for
   468 (*Convert all Vars in a theorem to Frees.  Also return a function for
   470   reversing that operation.  DOES NOT WORK FOR TYPE VARIABLES.
   469   reversing that operation.  DOES NOT WORK FOR TYPE VARIABLES.
   471   Similar code in type/freeze_thaw*)
   470   Similar code in type/freeze_thaw*)
   472 
   471 
   473 fun freeze_thaw_robust th =
   472 fun freeze_thaw_robust th =
   474  let val fth = freezeT th
   473  let val fth = Thm.freezeT th
   475      val {prop, tpairs, thy, ...} = rep_thm fth
   474      val {prop, tpairs, thy, ...} = rep_thm fth
   476  in
   475  in
   477    case foldr add_term_vars [] (prop :: Thm.terms_of_tpairs tpairs) of
   476    case foldr add_term_vars [] (prop :: Thm.terms_of_tpairs tpairs) of
   478        [] => (fth, fn i => fn x => x)   (*No vars: nothing to do!*)
   477        [] => (fth, fn i => fn x => x)   (*No vars: nothing to do!*)
   479      | vars =>
   478      | vars =>
   491 
   490 
   492 (*Basic version of the function above. No option to rename Vars apart in thaw.
   491 (*Basic version of the function above. No option to rename Vars apart in thaw.
   493   The Frees created from Vars have nice names. FIXME: does not check for 
   492   The Frees created from Vars have nice names. FIXME: does not check for 
   494   clashes with variables in the assumptions, so delete and use freeze_thaw_robust instead?*)
   493   clashes with variables in the assumptions, so delete and use freeze_thaw_robust instead?*)
   495 fun freeze_thaw th =
   494 fun freeze_thaw th =
   496  let val fth = freezeT th
   495  let val fth = Thm.freezeT th
   497      val {prop, tpairs, thy, ...} = rep_thm fth
   496      val {prop, tpairs, thy, ...} = rep_thm fth
   498  in
   497  in
   499    case foldr add_term_vars [] (prop :: Thm.terms_of_tpairs tpairs) of
   498    case foldr add_term_vars [] (prop :: Thm.terms_of_tpairs tpairs) of
   500        [] => (fth, fn x => x)
   499        [] => (fth, fn x => x)
   501      | vars =>
   500      | vars =>
   602 (*maintain lists of theorems --- preserving canonical order*)
   601 (*maintain lists of theorems --- preserving canonical order*)
   603 val del_rule = remove eq_thm_prop;
   602 val del_rule = remove eq_thm_prop;
   604 fun add_rule th = cons th o del_rule th;
   603 fun add_rule th = cons th o del_rule th;
   605 val merge_rules = Library.merge eq_thm_prop;
   604 val merge_rules = Library.merge eq_thm_prop;
   606 
   605 
   607 (*weak_eq_thm: ignores variable renaming and (some) type variable renaming*)
   606 (*pattern equivalence*)
   608 val weak_eq_thm = Thm.eq_thm o pairself (forall_intr_vars o freezeT);
   607 fun equiv_thm ths =
       
   608   Pattern.equiv (Theory.merge (pairself Thm.theory_of_thm ths)) (pairself Thm.full_prop_of ths);
   609 
   609 
   610 
   610 
   611 (*** Meta-Rewriting Rules ***)
   611 (*** Meta-Rewriting Rules ***)
   612 
   612 
   613 fun read_prop s = read_cterm ProtoPure.thy (s, propT);
   613 fun read_prop s = read_cterm ProtoPure.thy (s, propT);
   940 
   940 
   941 (*Calling equal_abs_elim with multiple terms*)
   941 (*Calling equal_abs_elim with multiple terms*)
   942 fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) th (rev cts);
   942 fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) th (rev cts);
   943 
   943 
   944 
   944 
       
   945 (* global schematic variables *)
       
   946 
       
   947 fun unvarify th =
       
   948   let
       
   949     val thy = Thm.theory_of_thm th;
       
   950     val cert = Thm.cterm_of thy;
       
   951     val certT = Thm.ctyp_of thy;
       
   952 
       
   953     val prop = Thm.full_prop_of th;
       
   954     val _ = map Logic.unvarify (prop :: Thm.hyps_of th)
       
   955       handle TERM (msg, _) => raise THM (msg, 0, [th]);
       
   956 
       
   957     val instT0 = rev (Term.add_tvars prop []) |> map (fn v as ((a, _), S) => (v, TFree (a, S)));
       
   958     val instT = map (fn (v, T) => (certT (TVar v), certT T)) instT0;
       
   959     val inst = rev (Term.add_vars prop []) |> map (fn ((a, i), T) =>
       
   960       let val T' = Term.instantiateT instT0 T
       
   961       in (cert (Var ((a, i), T')), cert (Free ((a, T')))) end);
       
   962   in Thm.instantiate (instT, inst) th end;
       
   963 
       
   964 
   945 (** protected propositions and embedded terms **)
   965 (** protected propositions and embedded terms **)
   946 
   966 
   947 local
   967 local
   948   val A = cert (Free ("A", propT));
   968   val A = cert (Free ("A", propT));
   949   val prop_def = #1 (freeze_thaw ProtoPure.prop_def);
   969   val prop_def = unvarify ProtoPure.prop_def;
   950   val term_def = #1 (freeze_thaw ProtoPure.term_def);
   970   val term_def = unvarify ProtoPure.term_def;
   951 in
   971 in
   952   val protect = Thm.capply (cert Logic.protectC);
   972   val protect = Thm.capply (cert Logic.protectC);
   953   val protectI = store_thm "protectI" (PureThy.kind_rule PureThy.internalK (standard
   973   val protectI = store_thm "protectI" (PureThy.kind_rule PureThy.internalK (standard
   954       (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A))));
   974       (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A))));
   955   val protectD = store_thm "protectD" (PureThy.kind_rule PureThy.internalK (standard
   975   val protectD = store_thm "protectD" (PureThy.kind_rule PureThy.internalK (standard
  1059       ([], prop') => equal_elim (reflexive (cterm_of thy prop')) thm
  1079       ([], prop') => equal_elim (reflexive (cterm_of thy prop')) thm
  1060     | _ => error "More names than abstractions in theorem"
  1080     | _ => error "More names than abstractions in theorem"
  1061   end;
  1081   end;
  1062 
  1082 
  1063 
  1083 
  1064 
       
  1065 (* unvarify(T) *)
       
  1066 
       
  1067 (*assume thm in standard form, i.e. no frees, 0 var indexes*)
       
  1068 
       
  1069 fun unvarifyT thm =
       
  1070   let
       
  1071     val cT = Thm.ctyp_of (Thm.theory_of_thm thm);
       
  1072     val tfrees = map (fn ((x, _), S) => SOME (cT (TFree (x, S)))) (tvars_of thm);
       
  1073   in instantiate' tfrees [] thm end;
       
  1074 
       
  1075 fun unvarify raw_thm =
       
  1076   let
       
  1077     val thm = unvarifyT raw_thm;
       
  1078     val ct = Thm.cterm_of (Thm.theory_of_thm thm);
       
  1079     val frees = map (fn ((x, _), T) => SOME (ct (Free (x, T)))) (vars_of thm);
       
  1080   in instantiate' [] frees thm end;
       
  1081 
       
  1082 
       
  1083 (* tvars_intr_list *)
  1084 (* tvars_intr_list *)
  1084 
  1085 
  1085 fun tvars_intr_list tfrees thm =
  1086 fun tvars_intr_list tfrees thm =
  1086   apfst (map (fn ((s, S), ixn) => (s, (ixn, S)))) (Thm.varifyT'
  1087   apfst (map (fn ((s, S), ixn) => (s, (ixn, S)))) (Thm.varifyT'
  1087     (gen_rems (op = o apfst fst) (tfrees_of thm, tfrees)) thm);
  1088     (gen_rems (op = o apfst fst) (tfrees_of thm, tfrees)) thm);