src/Pure/proofterm.ML
changeset 70502 b053c9ed0b0a
parent 70501 23c4f264250c
child 70510 5b35d46c994f
equal deleted inserted replaced
70501:23c4f264250c 70502:b053c9ed0b0a
   198 and proof_body = PBody of
   198 and proof_body = PBody of
   199   {oracles: (string * term) Ord_List.T,
   199   {oracles: (string * term) Ord_List.T,
   200    thms: (proof_serial * thm_node) Ord_List.T,
   200    thms: (proof_serial * thm_node) Ord_List.T,
   201    proof: proof}
   201    proof: proof}
   202 and thm_body =
   202 and thm_body =
   203   Thm_Body of {open_proof: proof -> proof, body: proof_body future}
   203   Thm_Body of {export_proof: unit lazy, open_proof: proof -> proof, body: proof_body future}
   204 and thm_node =
   204 and thm_node =
   205   Thm_Node of {name: string, prop: term, body: proof_body future, consolidate: unit lazy};
   205   Thm_Node of {name: string, prop: term, body: proof_body future, consolidate: unit lazy};
   206 
   206 
   207 type oracle = string * term;
   207 type oracle = string * term;
   208 type pthm = proof_serial * thm_node;
   208 type pthm = proof_serial * thm_node;
   214   PBody {oracles = oracles, thms = thms, proof = f proof};
   214   PBody {oracles = oracles, thms = thms, proof = f proof};
   215 
   215 
   216 fun thm_header serial pos name prop types : thm_header =
   216 fun thm_header serial pos name prop types : thm_header =
   217   {serial = serial, pos = pos, name = name, prop = prop, types = types};
   217   {serial = serial, pos = pos, name = name, prop = prop, types = types};
   218 
   218 
   219 fun thm_body body = Thm_Body {open_proof = I, body = Future.value body};
   219 val no_export_proof = Lazy.value ();
       
   220 
       
   221 fun thm_body body =
       
   222   Thm_Body {export_proof = no_export_proof, open_proof = I, body = Future.value body};
       
   223 fun thm_body_export_proof (Thm_Body {export_proof, ...}) = export_proof;
   220 fun thm_body_proof_raw (Thm_Body {body, ...}) = join_proof body;
   224 fun thm_body_proof_raw (Thm_Body {body, ...}) = join_proof body;
   221 fun thm_body_proof_open (Thm_Body {open_proof, body}) = open_proof (join_proof body);
   225 fun thm_body_proof_open (Thm_Body {open_proof, body, ...}) = open_proof (join_proof body);
   222 
   226 
   223 fun rep_thm_node (Thm_Node args) = args;
   227 fun rep_thm_node (Thm_Node args) = args;
   224 val thm_node_name = #name o rep_thm_node;
   228 val thm_node_name = #name o rep_thm_node;
   225 val thm_node_prop = #prop o rep_thm_node;
   229 val thm_node_prop = #prop o rep_thm_node;
   226 val thm_node_body = #body o rep_thm_node;
   230 val thm_node_body = #body o rep_thm_node;
   328       thms = Ord_List.make thm_ord thms,
   332       thms = Ord_List.make thm_ord thms,
   329       proof = prf}
   333       proof = prf}
   330   end;
   334   end;
   331 
   335 
   332 fun no_proof_body proof = PBody {oracles = [], thms = [], proof = proof};
   336 fun no_proof_body proof = PBody {oracles = [], thms = [], proof = proof};
   333 val no_thm_body = Thm_Body {open_proof = I, body = Future.value (no_proof_body MinProof)};
   337 val no_thm_body = thm_body (no_proof_body MinProof);
   334 
   338 
   335 fun no_thm_proofs (Abst (x, T, prf)) = Abst (x, T, no_thm_proofs prf)
   339 fun no_thm_proofs (Abst (x, T, prf)) = Abst (x, T, no_thm_proofs prf)
   336   | no_thm_proofs (AbsP (x, t, prf)) = AbsP (x, t, no_thm_proofs prf)
   340   | no_thm_proofs (AbsP (x, t, prf)) = AbsP (x, t, no_thm_proofs prf)
   337   | no_thm_proofs (prf % t) = no_thm_proofs prf % t
   341   | no_thm_proofs (prf % t) = no_thm_proofs prf % t
   338   | no_thm_proofs (prf1 %% prf2) = no_thm_proofs prf1 %% no_thm_proofs prf2
   342   | no_thm_proofs (prf1 %% prf2) = no_thm_proofs prf1 %% no_thm_proofs prf2
   341 
   345 
   342 fun no_body_proofs (Abst (x, T, prf)) = Abst (x, T, no_body_proofs prf)
   346 fun no_body_proofs (Abst (x, T, prf)) = Abst (x, T, no_body_proofs prf)
   343   | no_body_proofs (AbsP (x, t, prf)) = AbsP (x, t, no_body_proofs prf)
   347   | no_body_proofs (AbsP (x, t, prf)) = AbsP (x, t, no_body_proofs prf)
   344   | no_body_proofs (prf % t) = no_body_proofs prf % t
   348   | no_body_proofs (prf % t) = no_body_proofs prf % t
   345   | no_body_proofs (prf1 %% prf2) = no_body_proofs prf1 %% no_body_proofs prf2
   349   | no_body_proofs (prf1 %% prf2) = no_body_proofs prf1 %% no_body_proofs prf2
   346   | no_body_proofs (PThm (header, Thm_Body {open_proof, body})) =
   350   | no_body_proofs (PThm (header, Thm_Body {export_proof, open_proof, body})) =
   347       PThm (header, Thm_Body {open_proof = open_proof, body = Future.value (no_proof_body (join_proof body))})
   351       let
       
   352         val body' = Future.value (no_proof_body (join_proof body));
       
   353         val thm_body' = Thm_Body {export_proof = export_proof, open_proof = open_proof, body = body'};
       
   354       in PThm (header, thm_body') end
   348   | no_body_proofs a = a;
   355   | no_body_proofs a = a;
   349 
   356 
   350 
   357 
   351 
   358 
   352 (** XML data representation **)
   359 (** XML data representation **)
   366   fn a %% b => ([], pair proof proof (a, b)),
   373   fn a %% b => ([], pair proof proof (a, b)),
   367   fn Hyp a => ([], term a),
   374   fn Hyp a => ([], term a),
   368   fn PAxm (a, b, c) => ([a], pair term (option (list typ)) (b, c)),
   375   fn PAxm (a, b, c) => ([a], pair term (option (list typ)) (b, c)),
   369   fn OfClass (a, b) => ([b], typ a),
   376   fn OfClass (a, b) => ([b], typ a),
   370   fn Oracle (a, b, c) => ([a], pair term (option (list typ)) (b, c)),
   377   fn Oracle (a, b, c) => ([a], pair term (option (list typ)) (b, c)),
   371   fn PThm ({serial, pos, name, prop, types}, Thm_Body {open_proof, body}) =>
   378   fn PThm ({serial, pos, name, prop, types}, Thm_Body {open_proof, body, ...}) =>
   372     ([int_atom serial, name],
   379     ([int_atom serial, name],
   373       pair (list properties) (pair term (pair (option (list typ)) proof_body))
   380       pair (list properties) (pair term (pair (option (list typ)) proof_body))
   374         (map Position.properties_of pos, (prop, (types, map_proof_of open_proof (Future.join body)))))]
   381         (map Position.properties_of pos, (prop, (types, map_proof_of open_proof (Future.join body)))))]
   375 and proof_body (PBody {oracles, thms, proof = prf}) =
   382 and proof_body (PBody {oracles, thms, proof = prf}) =
   376   triple (list (pair string term)) (list pthm) proof (oracles, thms, prf)
   383   triple (list (pair string term)) (list pthm) proof (oracles, thms, prf)
  2016       executable = false,
  2023       executable = false,
  2017       compress = true,
  2024       compress = true,
  2018       strict = false}
  2025       strict = false}
  2019   end;
  2026   end;
  2020 
  2027 
  2021 fun export_proof_boxes thy proof =
  2028 fun export_proof_boxes proof =
  2022   let
  2029   let
  2023     fun export_boxes (AbsP (_, _, prf)) = export_boxes prf
  2030     fun export_boxes (AbsP (_, _, prf)) = export_boxes prf
  2024       | export_boxes (Abst (_, _, prf)) = export_boxes prf
  2031       | export_boxes (Abst (_, _, prf)) = export_boxes prf
  2025       | export_boxes (prf1 %% prf2) = export_boxes prf1 #> export_boxes prf2
  2032       | export_boxes (prf1 %% prf2) = export_boxes prf1 #> export_boxes prf2
  2026       | export_boxes (prf % _) = export_boxes prf
  2033       | export_boxes (prf % _) = export_boxes prf
  2027       | export_boxes (PThm ({serial = i, name = "", prop, ...}, thm_body)) =
  2034       | export_boxes (PThm ({serial = i, name = "", ...}, thm_body)) =
  2028           (fn seen =>
  2035           (fn boxes =>
  2029             if Inttab.defined seen i then seen
  2036             if Inttab.defined boxes i then boxes
  2030             else
  2037             else
  2031               let
  2038               let
  2032                 val proof = thm_body_proof_open thm_body;
  2039                 val prf = thm_body_proof_raw thm_body;
  2033                 val _ = export_proof thy i prop proof;
  2040                 val boxes' = Inttab.update (i, thm_body_export_proof thm_body) boxes;
  2034                 val boxes' = Inttab.update (i, ()) seen;
  2041               in export_boxes prf boxes' end)
  2035               in export_boxes proof boxes' end)
       
  2036       | export_boxes _ = I;
  2042       | export_boxes _ = I;
  2037   in (proof, Inttab.empty) |-> export_boxes |> ignore end;
  2043     val boxes = (proof, Inttab.empty) |-> export_boxes |> Inttab.dest;
       
  2044   in List.app (Lazy.force o #2) boxes end;
       
  2045 
       
  2046 fun export_enabled () = Options.default_bool "export_proofs";
  2038 
  2047 
  2039 fun export thy i prop prf =
  2048 fun export thy i prop prf =
  2040   if Options.default_bool "export_proofs" then
  2049   if export_enabled () then (export_proof_boxes prf; export_proof thy i prop prf) else ();
  2041     (export_proof_boxes thy prf; export_proof thy i prop prf)
       
  2042   else ();
       
  2043 
  2050 
  2044 fun prune proof =
  2051 fun prune proof =
  2045   if Options.default_bool "prune_proofs" then MinProof
  2052   if Options.default_bool "prune_proofs" then MinProof
  2046   else proof;
  2053   else proof;
  2047 
  2054 
  2080             let val Thm_Body {body = body', ...} = thm_body';
  2087             let val Thm_Body {body = body', ...} = thm_body';
  2081             in (i, body' |> (a = "" andalso named) ? Future.map (publish i)) end
  2088             in (i, body' |> (a = "" andalso named) ? Future.map (publish i)) end
  2082           else new_prf ()
  2089           else new_prf ()
  2083       | _ => new_prf ());
  2090       | _ => new_prf ());
  2084 
  2091 
       
  2092     val export_proof =
       
  2093       if named orelse not (export_enabled ()) then no_export_proof
       
  2094       else Lazy.lazy (fn () => join_proof body' |> open_proof |> export_proof thy i prop1);
       
  2095 
  2085     val pthm = (i, make_thm_node name prop1 body');
  2096     val pthm = (i, make_thm_node name prop1 body');
  2086 
  2097 
  2087     val header = thm_header i ([pos, Position.thread_data ()]) name prop1 NONE;
  2098     val header = thm_header i ([pos, Position.thread_data ()]) name prop1 NONE;
  2088     val head = PThm (header, Thm_Body {open_proof = open_proof, body = body'});
  2099     val thm_body = Thm_Body {export_proof = export_proof, open_proof = open_proof, body = body'};
       
  2100     val head = PThm (header, thm_body);
  2089     val proof =
  2101     val proof =
  2090       if unconstrain then
  2102       if unconstrain then
  2091         proof_combt' (head, (map o Option.map o Term.map_types) (#map_atyps ucontext) args)
  2103         proof_combt' (head, (map o Option.map o Term.map_types) (#map_atyps ucontext) args)
  2092       else
  2104       else
  2093         proof_combP (proof_combt' (head, args),
  2105         proof_combP (proof_combt' (head, args),