196 | ZBox of serial |
196 | ZBox of serial |
197 | ZThm of {theory_name: string, thm_name: Thm_Name.T * Position.T, serial: int}; |
197 | ZThm of {theory_name: string, thm_name: Thm_Name.T * Position.T, serial: int}; |
198 |
198 |
199 datatype zproof = |
199 datatype zproof = |
200 ZDummy (*dummy proof*) |
200 ZDummy (*dummy proof*) |
201 | ZConstp of zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
201 | ZConstp of (zproof_name * zterm) * (ztyp ZTVars.table * zterm ZVars.table) |
202 | ZBoundp of int |
202 | ZBoundp of int |
203 | ZAbst of string * ztyp * zproof |
203 | ZAbst of string * ztyp * zproof |
204 | ZAbsp of string * zterm * zproof |
204 | ZAbsp of string * zterm * zproof |
205 | ZAppt of zproof * zterm |
205 | ZAppt of zproof * zterm |
206 | ZAppp of zproof * zproof |
206 | ZAppp of zproof * zproof |
215 sig |
215 sig |
216 datatype ztyp = datatype ztyp |
216 datatype ztyp = datatype ztyp |
217 datatype zterm = datatype zterm |
217 datatype zterm = datatype zterm |
218 datatype zproof = datatype zproof |
218 datatype zproof = datatype zproof |
219 exception ZTERM of string * ztyp list * zterm list * zproof list |
219 exception ZTERM of string * ztyp list * zterm list * zproof list |
220 type zproof_const = zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
220 type zproof_const = (zproof_name * zterm) * (ztyp ZTVars.table * zterm ZVars.table) |
221 val fold_tvars: (indexname * sort -> 'a -> 'a) -> ztyp -> 'a -> 'a |
221 val fold_tvars: (indexname * sort -> 'a -> 'a) -> ztyp -> 'a -> 'a |
222 val fold_aterms: (zterm -> 'a -> 'a) -> zterm -> 'a -> 'a |
222 val fold_aterms: (zterm -> 'a -> 'a) -> zterm -> 'a -> 'a |
223 val fold_types: (ztyp -> 'a -> 'a) -> zterm -> 'a -> 'a |
223 val fold_types: (ztyp -> 'a -> 'a) -> zterm -> 'a -> 'a |
224 val ztyp_ord: ztyp ord |
224 val ztyp_ord: ztyp ord |
225 val fast_zterm_ord: zterm ord |
225 val fast_zterm_ord: zterm ord |
474 (* fold types/terms within proof *) |
474 (* fold types/terms within proof *) |
475 |
475 |
476 fun fold_proof {hyps} typ term = |
476 fun fold_proof {hyps} typ term = |
477 let |
477 let |
478 fun proof ZDummy = I |
478 fun proof ZDummy = I |
479 | proof (ZConstp (_, _, instT, inst)) = |
479 | proof (ZConstp (_, (instT, inst))) = |
480 ZTVars.fold (typ o #2) instT #> ZVars.fold (term o #2) inst |
480 ZTVars.fold (typ o #2) instT #> ZVars.fold (term o #2) inst |
481 | proof (ZBoundp _) = I |
481 | proof (ZBoundp _) = I |
482 | proof (ZAbst (_, T, p)) = typ T #> proof p |
482 | proof (ZAbst (_, T, p)) = typ T #> proof p |
483 | proof (ZAbsp (_, t, p)) = term t #> proof p |
483 | proof (ZAbsp (_, t, p)) = term t #> proof p |
484 | proof (ZAppt (p, t)) = proof p #> term t |
484 | proof (ZAppt (p, t)) = proof p #> term t |
532 in if ! changed then (instT', inst') else raise Same.SAME end; |
532 in if ! changed then (instT', inst') else raise Same.SAME end; |
533 |
533 |
534 fun map_proof_same {hyps} typ term = |
534 fun map_proof_same {hyps} typ term = |
535 let |
535 let |
536 fun proof ZDummy = raise Same.SAME |
536 fun proof ZDummy = raise Same.SAME |
537 | proof (ZConstp (a, A, instT, inst)) = |
537 | proof (ZConstp (a, (instT, inst))) = |
538 let val (instT', inst') = map_insts_same typ term (instT, inst) |
538 ZConstp (a, map_insts_same typ term (instT, inst)) |
539 in ZConstp (a, A, instT', inst') end |
|
540 | proof (ZBoundp _) = raise Same.SAME |
539 | proof (ZBoundp _) = raise Same.SAME |
541 | proof (ZAbst (a, T, p)) = |
540 | proof (ZAbst (a, T, p)) = |
542 (ZAbst (a, typ T, Same.commit proof p) |
541 (ZAbst (a, typ T, Same.commit proof p) |
543 handle Same.SAME => ZAbst (a, T, proof p)) |
542 handle Same.SAME => ZAbst (a, T, proof p)) |
544 | proof (ZAbsp (a, t, p)) = |
543 | proof (ZAbsp (a, t, p)) = |
787 |
786 |
788 (** proof construction **) |
787 (** proof construction **) |
789 |
788 |
790 (* constants *) |
789 (* constants *) |
791 |
790 |
792 type zproof_const = zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table; |
791 type zproof_const = (zproof_name * zterm) * (ztyp ZTVars.table * zterm ZVars.table); |
793 |
792 |
794 fun zproof_const a A : zproof_const = |
793 fun zproof_const (a, A) : zproof_const = |
795 let |
794 let |
796 val instT = |
795 val instT = |
797 ZTVars.build (A |> (fold_types o fold_tvars) (fn v => fn tab => |
796 ZTVars.build (A |> (fold_types o fold_tvars) (fn v => fn tab => |
798 if ZTVars.defined tab v then tab else ZTVars.update (v, ZTVar v) tab)); |
797 if ZTVars.defined tab v then tab else ZTVars.update (v, ZTVar v) tab)); |
799 val inst = |
798 val inst = |
800 ZVars.build (A |> fold_aterms (fn t => fn tab => |
799 ZVars.build (A |> fold_aterms (fn t => fn tab => |
801 (case t of |
800 (case t of |
802 ZVar v => if ZVars.defined tab v then tab else ZVars.update (v, t) tab |
801 ZVar v => if ZVars.defined tab v then tab else ZVars.update (v, t) tab |
803 | _ => tab))); |
802 | _ => tab))); |
804 in (a, A, instT, inst) end; |
803 in ((a, A), (instT, inst)) end; |
805 |
804 |
806 fun make_const_proof (f, g) (a, A, instT, inst) = |
805 fun make_const_proof (f, g) (a, insts) = |
807 let |
806 let |
808 val typ = subst_type_same (Same.function (fn ((x, _), _) => try f x)); |
807 val typ = subst_type_same (Same.function (fn ((x, _), _) => try f x)); |
809 val term = Same.function (fn ZVar ((x, _), _) => try g x | _ => NONE); |
808 val term = Same.function (fn ZVar ((x, _), _) => try g x | _ => NONE); |
810 val (instT', inst') = Same.commit (map_insts_same typ term) (instT, inst); |
809 in ZConstp (a, Same.commit (map_insts_same typ term) insts) end; |
811 in ZConstp (a, A, instT', inst') end; |
|
812 |
810 |
813 |
811 |
814 (* closed proof boxes *) |
812 (* closed proof boxes *) |
815 |
813 |
816 type zbox = serial * (zterm * zproof); |
814 type zbox = serial * (zterm * zproof); |
888 val prf' = beta_norm_prooft (close_proof prems (unconstrain_proof prf)); |
886 val prf' = beta_norm_prooft (close_proof prems (unconstrain_proof prf)); |
889 |
887 |
890 val i = serial (); |
888 val i = serial (); |
891 val zbox: zbox = (i, (prop', prf')); |
889 val zbox: zbox = (i, (prop', prf')); |
892 |
890 |
893 val const = constrain_proof (ZConstp (zproof_const (zproof_name i) prop')); |
891 val const = constrain_proof (ZConstp (zproof_const (zproof_name i, prop'))); |
894 val args1 = |
892 val args1 = |
895 outer_constraints |> map (fn (T, c) => |
893 outer_constraints |> map (fn (T, c) => |
896 ZClassp (ztyp_of (if unconstrain then unconstrain_typ T else T), c)); |
894 ZClassp (ztyp_of (if unconstrain then unconstrain_typ T else T), c)); |
897 val args2 = if unconstrain then map ZHyp hyps' else map (ZHyp o zterm) hyps; |
895 val args2 = if unconstrain then map ZHyp hyps' else map (ZHyp o zterm) hyps; |
898 in (zbox, ZAppps (ZAppps (const, args1), args2)) end; |
896 in (zbox, ZAppps (ZAppps (const, args1), args2)) end; |
915 |
913 |
916 |
914 |
917 (* basic logic *) |
915 (* basic logic *) |
918 |
916 |
919 fun axiom_proof thy name A = |
917 fun axiom_proof thy name A = |
920 ZConstp (zproof_const (ZAxiom name) (zterm_of thy A)); |
918 ZConstp (zproof_const (ZAxiom name, zterm_of thy A)); |
921 |
919 |
922 fun oracle_proof thy name A = |
920 fun oracle_proof thy name A = |
923 ZConstp (zproof_const (ZOracle name) (zterm_of thy A)); |
921 ZConstp (zproof_const (ZOracle name, zterm_of thy A)); |
924 |
922 |
925 fun assume_proof thy A = |
923 fun assume_proof thy A = |
926 ZHyp (zterm_of thy A); |
924 ZHyp (zterm_of thy A); |
927 |
925 |
928 fun trivial_proof thy A = |
926 fun trivial_proof thy A = |
996 let val ZConstp c = axiom_proof thy0 (Sign.full_name thy0 b) t in c end); |
994 let val ZConstp c = axiom_proof thy0 (Sign.full_name thy0 b) t in c end); |
997 |
995 |
998 in |
996 in |
999 |
997 |
1000 val is_reflexive_proof = |
998 val is_reflexive_proof = |
1001 fn ZConstp (ZAxiom "Pure.reflexive", _, _, _) => true | _ => false; |
999 fn ZConstp ((ZAxiom "Pure.reflexive", _), _) => true | _ => false; |
1002 |
1000 |
1003 fun reflexive_proof thy T t = |
1001 fun reflexive_proof thy T t = |
1004 let |
1002 let |
1005 val {ztyp, zterm} = zterm_cache thy; |
1003 val {ztyp, zterm} = zterm_cache thy; |
1006 val A = ztyp T; |
1004 val A = ztyp T; |
1200 (ZAppt (proof Ts lev p, Same.commit (term Ts lev) t) |
1198 (ZAppt (proof Ts lev p, Same.commit (term Ts lev) t) |
1201 handle Same.SAME => ZAppt (p, term Ts lev t)) |
1199 handle Same.SAME => ZAppt (p, term Ts lev t)) |
1202 | proof Ts lev (ZAppp (p, q)) = |
1200 | proof Ts lev (ZAppp (p, q)) = |
1203 (ZAppp (proof Ts lev p, Same.commit (proof Ts lev) q) |
1201 (ZAppp (proof Ts lev p, Same.commit (proof Ts lev) q) |
1204 handle Same.SAME => ZAppp (p, proof Ts lev q)) |
1202 handle Same.SAME => ZAppp (p, proof Ts lev q)) |
1205 | proof Ts lev (ZConstp (a, A, instT, inst)) = |
1203 | proof Ts lev (ZConstp (a, insts)) = |
1206 let val (instT', insts') = map_insts_same typ (term Ts lev) (instT, inst) |
1204 ZConstp (a, map_insts_same typ (term Ts lev) insts) |
1207 in ZConstp (a, A, instT', insts') end |
|
1208 | proof _ _ (ZClassp (T, c)) = ZClassp (typ T, c) |
1205 | proof _ _ (ZClassp (T, c)) = ZClassp (typ T, c) |
1209 | proof _ _ _ = raise Same.SAME; |
1206 | proof _ _ _ = raise Same.SAME; |
1210 |
1207 |
1211 val k = length prems; |
1208 val k = length prems; |
1212 |
1209 |