src/Pure/proofterm.ML
changeset 70458 9e2173eb23eb
parent 70454 fa933b98d64d
child 70492 c65ccd813f4d
equal deleted inserted replaced
70457:a8b5d668bf13 70458:9e2173eb23eb
   129   val combination: term -> term -> term -> term -> typ -> proof -> proof -> proof
   129   val combination: term -> term -> term -> term -> typ -> proof -> proof -> proof
   130   val equal_intr: term -> term -> proof -> proof -> proof
   130   val equal_intr: term -> term -> proof -> proof -> proof
   131   val equal_elim: term -> term -> proof -> proof -> proof
   131   val equal_elim: term -> term -> proof -> proof -> proof
   132   val strip_shyps_proof: Sorts.algebra -> (typ * sort) list -> (typ * sort) list ->
   132   val strip_shyps_proof: Sorts.algebra -> (typ * sort) list -> (typ * sort) list ->
   133     sort list -> proof -> proof
   133     sort list -> proof -> proof
   134   val classrel_proof: theory -> class * class -> proof
   134   val of_sort_proof: Sorts.algebra ->
   135   val arity_proof: theory -> string * sort list * class -> proof
   135     (class * class -> proof) ->
   136   val of_sort_proof: theory -> (typ * class -> proof) -> typ * sort -> proof list
   136     (string * class list list * class -> proof) ->
   137   val install_axclass_proofs:
   137     (typ * class -> proof) -> typ * sort -> proof list
   138    {classrel_proof: theory -> class * class -> proof,
       
   139     arity_proof: theory -> string * sort list * class -> proof} -> theory -> theory
       
   140   val axm_proof: string -> term -> proof
   138   val axm_proof: string -> term -> proof
   141   val oracle_proof: string -> term -> oracle * proof
   139   val oracle_proof: string -> term -> oracle * proof
   142   val shrink_proof: proof -> proof
   140   val shrink_proof: proof -> proof
   143 
   141 
   144   (*rewriting on proof terms*)
   142   (*rewriting on proof terms*)
   157   val prop_of: proof -> term
   155   val prop_of: proof -> term
   158   val expand_proof: theory -> (string * term option) list -> proof -> proof
   156   val expand_proof: theory -> (string * term option) list -> proof -> proof
   159 
   157 
   160   val proof_serial: unit -> proof_serial
   158   val proof_serial: unit -> proof_serial
   161   val fulfill_norm_proof: theory -> (serial * proof_body) list -> proof_body -> proof_body
   159   val fulfill_norm_proof: theory -> (serial * proof_body) list -> proof_body -> proof_body
   162   val thm_proof: theory -> string -> sort list -> term list -> term ->
   160   val thm_proof: theory -> (class * class -> proof) ->
       
   161     (string * class list list * class -> proof) -> string -> sort list -> term list -> term ->
   163     (serial * proof_body future) list -> proof_body -> pthm * proof
   162     (serial * proof_body future) list -> proof_body -> pthm * proof
   164   val unconstrain_thm_proof: theory -> sort list -> term ->
   163   val unconstrain_thm_proof: theory -> (class * class -> proof) ->
       
   164     (string * class list list * class -> proof) -> sort list -> term ->
   165     (serial * proof_body future) list -> proof_body -> pthm * proof
   165     (serial * proof_body future) list -> proof_body -> pthm * proof
   166   val get_name: sort list -> term list -> term -> proof -> string
   166   val get_name: sort list -> term list -> term -> proof -> string
   167 end
   167 end
   168 
   168 
   169 structure Proofterm : PROOFTERM =
   169 structure Proofterm : PROOFTERM =
  1051         (case get_first (get (Type.sort_of_atyp T)) replacements of
  1051         (case get_first (get (Type.sort_of_atyp T)) replacements of
  1052           SOME T' => T'
  1052           SOME T' => T'
  1053         | NONE => raise Fail "strip_shyps_proof: bad type variable in proof term");
  1053         | NONE => raise Fail "strip_shyps_proof: bad type variable in proof term");
  1054   in Same.commit (map_proof_types_same (Term_Subst.map_atypsT_same replace)) prf end;
  1054   in Same.commit (map_proof_types_same (Term_Subst.map_atypsT_same replace)) prf end;
  1055 
  1055 
  1056 
  1056 fun of_sort_proof algebra classrel_proof arity_proof hyps =
  1057 local
  1057   Sorts.of_sort_derivation algebra
  1058 
  1058    {class_relation = fn _ => fn _ => fn (prf, c1) => fn c2 =>
  1059 type axclass_proofs =
  1059       if c1 = c2 then prf else classrel_proof (c1, c2) %% prf,
  1060  {classrel_proof: theory -> class * class -> proof,
  1060     type_constructor = fn (a, _) => fn dom => fn c =>
  1061   arity_proof: theory -> string * sort list * class -> proof};
       
  1062 
       
  1063 structure Axclass_Proofs = Theory_Data
       
  1064 (
       
  1065   type T = axclass_proofs option;
       
  1066   val empty = NONE;
       
  1067   val extend = I;
       
  1068   val merge = merge_options;
       
  1069 );
       
  1070 
       
  1071 fun the_axclass_proofs which thy x =
       
  1072   (case Axclass_Proofs.get thy of
       
  1073     NONE => raise Fail "Axclass proof operations not installed"
       
  1074   | SOME proofs => which proofs thy x);
       
  1075 
       
  1076 in
       
  1077 
       
  1078 val classrel_proof = the_axclass_proofs #classrel_proof;
       
  1079 val arity_proof = the_axclass_proofs #arity_proof;
       
  1080 
       
  1081 fun install_axclass_proofs proofs =
       
  1082   Axclass_Proofs.map
       
  1083     (fn NONE => SOME proofs
       
  1084       | SOME _ => raise Fail "Axclass proof operations already installed");
       
  1085 
       
  1086 end;
       
  1087 
       
  1088 
       
  1089 local
       
  1090 
       
  1091 fun canonical_instance typs =
       
  1092   let
       
  1093     val names = Name.invent Name.context Name.aT (length typs);
       
  1094     val instT = map2 (fn a => fn T => (((a, 0), []), Type.strip_sorts T)) names typs;
       
  1095   in instantiate (instT, []) end;
       
  1096 
       
  1097 in
       
  1098 
       
  1099 fun of_sort_proof thy hyps =
       
  1100   Sorts.of_sort_derivation (Sign.classes_of thy)
       
  1101    {class_relation = fn typ => fn _ => fn (prf, c1) => fn c2 =>
       
  1102       if c1 = c2 then prf
       
  1103       else canonical_instance [typ] (classrel_proof thy (c1, c2)) %% prf,
       
  1104     type_constructor = fn (a, typs) => fn dom => fn c =>
       
  1105       let val Ss = map (map snd) dom and prfs = maps (map fst) dom
  1061       let val Ss = map (map snd) dom and prfs = maps (map fst) dom
  1106       in proof_combP (canonical_instance typs (arity_proof thy (a, Ss, c)), prfs) end,
  1062       in proof_combP (arity_proof (a, Ss, c), prfs) end,
  1107     type_variable = fn typ => map (fn c => (hyps (typ, c), c)) (Type.sort_of_atyp typ)};
  1063     type_variable = fn typ => map (fn c => (hyps (typ, c), c)) (Type.sort_of_atyp typ)};
  1108 
       
  1109 end;
       
  1110 
  1064 
  1111 
  1065 
  1112 
  1066 
  1113 (** axioms and theorems **)
  1067 (** axioms and theorems **)
  1114 
  1068 
  2004 
  1958 
  2005 val proof_serial = Counter.make ();
  1959 val proof_serial = Counter.make ();
  2006 
  1960 
  2007 local
  1961 local
  2008 
  1962 
  2009 fun unconstrainT_prf thy (ucontext: Logic.unconstrain_context) =
  1963 fun unconstrainT_proof algebra classrel_proof arity_proof (ucontext: Logic.unconstrain_context) =
  2010   let
  1964   let
  2011     fun hyp_map hyp =
  1965     fun hyp_map hyp =
  2012       (case AList.lookup (op =) (#constraints ucontext) hyp of
  1966       (case AList.lookup (op =) (#constraints ucontext) hyp of
  2013         SOME t => Hyp t
  1967         SOME t => Hyp t
  2014       | NONE => raise Fail "unconstrainT_prf: missing constraint");
  1968       | NONE => raise Fail "unconstrainT_proof: missing constraint");
  2015 
  1969 
  2016     val typ = Term_Subst.map_atypsT_same (Type.strip_sorts o #atyp_map ucontext);
  1970     val typ = Term_Subst.map_atypsT_same (Type.strip_sorts o #atyp_map ucontext);
  2017     fun ofclass (ty, c) =
  1971     fun ofclass (ty, c) =
  2018       let val ty' = Term.map_atyps (#atyp_map ucontext) ty;
  1972       let val ty' = Term.map_atyps (#atyp_map ucontext) ty;
  2019       in the_single (of_sort_proof thy hyp_map (ty', [c])) end;
  1973       in the_single (of_sort_proof algebra classrel_proof arity_proof  hyp_map (ty', [c])) end;
  2020   in
  1974   in
  2021     Same.commit (map_proof_same (Term_Subst.map_types_same typ) typ ofclass)
  1975     Same.commit (map_proof_same (Term_Subst.map_types_same typ) typ ofclass)
  2022     #> fold_rev (implies_intr_proof o snd) (#constraints ucontext)
  1976     #> fold_rev (implies_intr_proof o snd) (#constraints ucontext)
  2023   end;
  1977   end;
  2024 
  1978 
  2060 
  2014 
  2061 fun prune proof =
  2015 fun prune proof =
  2062   if Options.default_bool "prune_proofs" then MinProof
  2016   if Options.default_bool "prune_proofs" then MinProof
  2063   else proof;
  2017   else proof;
  2064 
  2018 
  2065 fun prepare_thm_proof unconstrain thy name shyps hyps concl promises body =
  2019 fun prepare_thm_proof unconstrain thy classrel_proof arity_proof
  2066   let
  2020     name shyps hyps concl promises body =
  2067 (*
  2021   let
  2068     val FIXME =
       
  2069       Output.physical_stderr ("pthm " ^ quote name ^ " " ^ Position.here (Position.thread_data ()) ^ "\n");
       
  2070 *)
       
  2071 
       
  2072     val named = name <> "";
  2022     val named = name <> "";
  2073 
  2023 
  2074     val prop = Logic.list_implies (hyps, concl);
  2024     val prop = Logic.list_implies (hyps, concl);
  2075     val args = prop_args prop;
  2025     val args = prop_args prop;
  2076 
  2026 
  2086     val open_proof = not named ? clean_proof thy;
  2036     val open_proof = not named ? clean_proof thy;
  2087 
  2037 
  2088     fun new_prf () =
  2038     fun new_prf () =
  2089       let
  2039       let
  2090         val i = proof_serial ();
  2040         val i = proof_serial ();
  2091         val postproc = map_proof_of (unconstrainT_prf thy ucontext) #> named ? publish i;
  2041         val unconstrainT =
       
  2042           unconstrainT_proof (Sign.classes_of thy) classrel_proof arity_proof ucontext;
       
  2043         val postproc = map_proof_of unconstrainT #> named ? publish i;
  2092       in (i, fulfill_proof_future thy promises postproc body0) end;
  2044       in (i, fulfill_proof_future thy promises postproc body0) end;
  2093 
  2045 
  2094     val (i, body') =
  2046     val (i, body') =
  2095       (*non-deterministic, depends on unknown promises*)
  2047       (*non-deterministic, depends on unknown promises*)
  2096       (case strip_combt (fst (strip_combP prf)) of
  2048       (case strip_combt (fst (strip_combP prf)) of
  2113 
  2065 
  2114 in
  2066 in
  2115 
  2067 
  2116 val thm_proof = prepare_thm_proof false;
  2068 val thm_proof = prepare_thm_proof false;
  2117 
  2069 
  2118 fun unconstrain_thm_proof thy shyps concl promises body =
  2070 fun unconstrain_thm_proof thy classrel_proof arity_proof shyps concl promises body =
  2119   prepare_thm_proof true thy "" shyps [] concl promises body;
  2071   prepare_thm_proof true thy classrel_proof arity_proof "" shyps [] concl promises body;
  2120 
  2072 
  2121 end;
  2073 end;
  2122 
  2074 
  2123 
  2075 
  2124 (* approximative PThm name *)
  2076 (* approximative PThm name *)