src/Pure/zterm.ML
author wenzelm
Mon, 11 Dec 2023 11:46:12 +0100
changeset 79237 f97fe7ad62a7
parent 79234 4a1a25bdf81d
child 79259 46d16fc4bc15
permissions -rw-r--r--
proper ZTerm.lift_proof (amending 4a1a25bdf81d);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/zterm.ML
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     3
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     4
Tight representation of types / terms / proof terms, notably for proof recording.
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     5
*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
     6
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
     7
(*** global ***)
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
     8
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
     9
(* types and terms *)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    10
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    11
datatype ztyp =
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    12
    ZTVar of indexname * sort      (*free: index ~1*)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    13
  | ZFun of ztyp * ztyp
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    14
  | ZProp
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    15
  | ZItself of ztyp
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    16
  | ZType0 of string               (*type constant*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    17
  | ZType1 of string * ztyp        (*type constructor: 1 argument*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    18
  | ZType of string * ztyp list    (*type constructor: >= 2 arguments*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    19
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    20
datatype zterm =
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    21
    ZVar of indexname * ztyp       (*free: index ~1*)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    22
  | ZBound of int
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    23
  | ZConst0 of string              (*monomorphic constant*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    24
  | ZConst1 of string * ztyp       (*polymorphic constant: 1 type argument*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    25
  | ZConst of string * ztyp list   (*polymorphic constant: >= 2 type arguments*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    26
  | ZAbs of string * ztyp * zterm
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    27
  | ZApp of zterm * zterm
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    28
  | ZClass of ztyp * class         (*OFCLASS proposition*)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    29
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    30
structure ZTerm =
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    31
struct
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    32
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    33
(* fold *)
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    34
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    35
fun fold_tvars f (ZTVar v) = f v
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    36
  | fold_tvars f (ZFun (T, U)) = fold_tvars f T #> fold_tvars f U
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    37
  | fold_tvars f (ZItself T) = fold_tvars f T
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    38
  | fold_tvars f (ZType1 (_, T)) = fold_tvars f T
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    39
  | fold_tvars f (ZType (_, Ts)) = fold (fold_tvars f) Ts
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    40
  | fold_tvars _ _ = I;
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    41
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    42
fun fold_aterms f (ZApp (t, u)) = fold_aterms f t #> fold_aterms f u
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    43
  | fold_aterms f (ZAbs (_, _, t)) = fold_aterms f t
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    44
  | fold_aterms f a = f a;
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    45
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    46
fun fold_types f (ZVar (_, T)) = f T
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    47
  | fold_types f (ZConst1 (_, T)) = f T
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    48
  | fold_types f (ZConst (_, As)) = fold f As
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    49
  | fold_types f (ZAbs (_, T, b)) = f T #> fold_types f b
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    50
  | fold_types f (ZApp (t, u)) = fold_types f t #> fold_types f u
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    51
  | fold_types f (ZClass (T, _)) = f T
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    52
  | fold_types _ _ = I;
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    53
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    54
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    55
(* ordering *)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    56
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    57
local
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    58
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    59
fun cons_nr (ZTVar _) = 0
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    60
  | cons_nr (ZFun _) = 1
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    61
  | cons_nr ZProp = 2
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    62
  | cons_nr (ZItself _) = 3
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    63
  | cons_nr (ZType0 _) = 4
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    64
  | cons_nr (ZType1 _) = 5
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    65
  | cons_nr (ZType _) = 6;
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    66
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    67
val fast_indexname_ord = Term_Ord.fast_indexname_ord;
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    68
val sort_ord = Term_Ord.sort_ord;
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    69
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    70
in
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    71
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    72
fun ztyp_ord TU =
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    73
  if pointer_eq TU then EQUAL
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    74
  else
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    75
    (case TU of
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    76
      (ZTVar (a, A), ZTVar (b, B)) =>
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
    77
        (case fast_indexname_ord (a, b) of EQUAL => sort_ord (A, B) | ord => ord)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    78
    | (ZFun (T, T'), ZFun (U, U')) =>
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    79
        (case ztyp_ord (T, U) of EQUAL => ztyp_ord (T', U') | ord => ord)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    80
    | (ZProp, ZProp) => EQUAL
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    81
    | (ZItself T, ZItself U) => ztyp_ord (T, U)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    82
    | (ZType0 a, ZType0 b) => fast_string_ord (a, b)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    83
    | (ZType1 (a, T), ZType1 (b, U)) =>
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    84
        (case fast_string_ord (a, b) of EQUAL => ztyp_ord (T, U) | ord => ord)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    85
    | (ZType (a, Ts), ZType (b, Us)) =>
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    86
        (case fast_string_ord (a, b) of EQUAL => dict_ord ztyp_ord (Ts, Us) | ord => ord)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    87
    | (T, U) => int_ord (cons_nr T, cons_nr U));
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    88
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    89
end;
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    90
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    91
end;
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
    92
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    93
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    94
(* term items *)
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    95
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
    96
structure ZTypes = Table(type key = ztyp val ord = ZTerm.ztyp_ord);
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
    97
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    98
structure ZTVars:
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
    99
sig
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   100
  include TERM_ITEMS
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   101
  val add_tvarsT: ztyp -> set -> set
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   102
  val add_tvars: zterm -> set -> set
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   103
end =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   104
struct
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   105
  open TVars;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   106
  val add_tvarsT = ZTerm.fold_tvars add_set;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   107
  val add_tvars = ZTerm.fold_types add_tvarsT;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   108
end;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   109
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   110
structure ZVars:
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   111
sig
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   112
  include TERM_ITEMS
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   113
  val add_vars: zterm -> set -> set
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   114
end =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   115
struct
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   116
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   117
structure Term_Items = Term_Items
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   118
(
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   119
  type key = indexname * ztyp;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   120
  val ord = pointer_eq_ord (prod_ord Term_Ord.fast_indexname_ord ZTerm.ztyp_ord);
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   121
);
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   122
open Term_Items;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   123
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   124
val add_vars = ZTerm.fold_aterms (fn ZVar v => add_set v | _ => I);
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   125
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   126
end;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   127
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   128
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   129
(* proofs *)
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   130
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   131
datatype zproof_name =
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   132
    ZAxiom of string
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   133
  | ZOracle of string
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   134
  | ZBox of serial;
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   135
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   136
datatype zproof =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   137
    ZDummy                         (*dummy proof*)
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   138
  | ZConstp of zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   139
  | ZBoundp of int
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   140
  | ZHyp of zterm
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   141
  | ZAbst of string * ztyp * zproof
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   142
  | ZAbsp of string * zterm * zproof
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   143
  | ZAppt of zproof * zterm
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   144
  | ZAppp of zproof * zproof
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   145
  | ZClassp of ztyp * class;       (*OFCLASS proof from sorts algebra*)
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   146
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   147
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   148
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   149
(*** local ***)
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   150
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   151
signature ZTERM =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   152
sig
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   153
  datatype ztyp = datatype ztyp
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   154
  datatype zterm = datatype zterm
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   155
  datatype zproof = datatype zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   156
  val fold_tvars: (indexname * sort -> 'a -> 'a) -> ztyp -> 'a -> 'a
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   157
  val fold_aterms: (zterm -> 'a -> 'a) -> zterm -> 'a -> 'a
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   158
  val fold_types: (ztyp -> 'a -> 'a) -> zterm -> 'a -> 'a
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   159
  val ztyp_ord: ztyp * ztyp -> order
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   160
  val aconv_zterm: zterm * zterm -> bool
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   161
  val ZAbsts: (string * ztyp) list -> zproof -> zproof
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   162
  val ZAbsps: zterm list -> zproof -> zproof
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   163
  val ZAppts: zproof * zterm list -> zproof
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   164
  val ZAppps: zproof * zproof list -> zproof
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   165
  val fold_proof_terms: (zterm -> 'a -> 'a) -> zproof -> 'a -> 'a
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   166
  val exists_proof_terms: (zterm -> bool) -> zproof -> bool
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   167
  val incr_bv_same: int -> int -> zterm Same.operation
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   168
  val incr_bv: int -> int -> zterm -> zterm
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   169
  val incr_boundvars: int -> zterm -> zterm
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   170
  val ztyp_of: typ -> ztyp
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   171
  val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp}
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   172
  val zterm_of: theory -> term -> zterm
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   173
  val typ_of: ztyp -> typ
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   174
  val term_of: theory -> zterm -> term
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   175
  val could_beta_contract: zterm -> bool
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   176
  val norm_type: Type.tyenv -> ztyp -> ztyp
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   177
  val norm_term: theory -> Envir.env -> zterm -> zterm
79205
a159cb82afe7 more operations;
wenzelm
parents: 79204
diff changeset
   178
  val norm_proof: theory -> Envir.env -> zproof -> zproof
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   179
  val dummy_proof: 'a -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   180
  val todo_proof: 'a -> zproof
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   181
  val axiom_proof:  theory -> string -> term -> zproof
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   182
  val oracle_proof:  theory -> string -> term -> zproof
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   183
  val assume_proof: theory -> term -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   184
  val trivial_proof: theory -> term -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   185
  val implies_intr_proof: theory -> term -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   186
  val forall_intr_proof: theory -> typ -> string * term -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   187
  val forall_elim_proof: theory -> term -> zproof -> zproof
79128
b6f5d4392388 more zproofs;
wenzelm
parents: 79126
diff changeset
   188
  val of_class_proof: typ * class -> zproof
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   189
  val reflexive_proof: theory -> typ -> term -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   190
  val symmetric_proof: theory -> typ -> term -> term -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   191
  val transitive_proof: theory -> typ -> term -> term -> term -> zproof -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   192
  val equal_intr_proof: theory -> term -> term -> zproof -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   193
  val equal_elim_proof: theory -> term -> term -> zproof -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   194
  val abstract_rule_proof: theory -> typ -> typ -> string * term -> term -> term -> zproof -> zproof
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   195
  val combination_proof: theory -> typ -> typ -> term -> term -> term -> term ->
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   196
    zproof -> zproof -> zproof
79133
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   197
  val generalize_proof: Names.set * Names.set -> int -> zproof -> zproof
79149
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   198
  val instantiate_proof: theory ->
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   199
    ((indexname * sort) * typ) list * ((indexname * typ) * term) list -> zproof -> zproof
79135
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   200
  val varifyT_proof: ((string * sort) * (indexname * sort)) list -> zproof -> zproof
79152
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   201
  val legacy_freezeT_proof: term -> zproof -> zproof
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   202
  val rotate_proof: theory -> term list -> term -> (string * typ) list ->
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   203
    term list -> int -> zproof -> zproof
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   204
  val permute_prems_proof: theory -> term list -> int -> int -> zproof -> zproof
79234
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   205
  val incr_indexes_proof: int -> zproof -> zproof
79237
f97fe7ad62a7 proper ZTerm.lift_proof (amending 4a1a25bdf81d);
wenzelm
parents: 79234
diff changeset
   206
  val lift_proof: theory -> term -> int -> term list -> zproof -> zproof
79211
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   207
  val assumption_proof: theory -> Envir.env -> term list -> term -> int -> zproof -> zproof
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   208
end;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   209
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   210
structure ZTerm: ZTERM =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   211
struct
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   212
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   213
datatype ztyp = datatype ztyp;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   214
datatype zterm = datatype zterm;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   215
datatype zproof = datatype zproof;
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   216
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   217
open ZTerm;
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   218
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   219
fun aconv_zterm (tm1, tm2) =
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   220
  pointer_eq (tm1, tm2) orelse
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   221
    (case (tm1, tm2) of
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   222
      (ZApp (t1, u1), ZApp (t2, u2)) => aconv_zterm (t1, t2) andalso aconv_zterm (u1, u2)
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   223
    | (ZAbs (_, T1, t1), ZAbs (_, T2, t2)) => aconv_zterm (t1, t2) andalso T1 = T2
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   224
    | (a1, a2) => a1 = a2);
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   225
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   226
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   227
(* derived operations *)
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   228
79234
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   229
val ZFuns = Library.foldr ZFun;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   230
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   231
val ZAbsts = fold_rev (fn (x, T) => fn prf => ZAbst (x, T, prf));
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   232
val ZAbsps = fold_rev (fn t => fn prf => ZAbsp ("H", t, prf));
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   233
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   234
val ZAppts = Library.foldl ZAppt;
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   235
val ZAppps = Library.foldl ZAppp;
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   236
79234
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   237
fun combound (t, n, k) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   238
  if k > 0 then ZApp (combound (t, n + 1, k - 1), ZBound n) else t;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   239
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   240
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   241
(* fold *)
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   242
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   243
fun fold_proof_terms f =
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   244
  let
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   245
    fun proof (ZConstp (_, _, _, inst)) = ZVars.fold (f o #2) inst
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   246
      | proof (ZHyp t) = f t
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   247
      | proof (ZAbst (_, _, p)) = proof p
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   248
      | proof (ZAbsp (_, t, p)) = f t #> proof p
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   249
      | proof (ZAppt (p, t)) = proof p #> f t
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   250
      | proof (ZAppp (p, q)) = proof p #> proof q
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   251
      | proof _ = I;
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   252
  in proof end;
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   253
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   254
local exception Found in
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   255
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   256
fun exists_proof_terms P prf =
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   257
  (fold_proof_terms (fn t => fn () => if P t then raise Found else ()) prf (); true)
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   258
    handle Found => true;
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   259
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   260
end;
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   261
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   262
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   263
(* substitution of bound variables *)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   264
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   265
fun incr_bv_same inc =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   266
  if inc = 0 then fn _ => Same.same
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   267
  else
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   268
    let
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   269
      fun term lev (ZBound i) = if i >= lev then ZBound (i + inc) else raise Same.SAME
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   270
        | term lev (ZAbs (a, T, t)) = ZAbs (a, T, term (lev + 1) t)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   271
        | term lev (ZApp (t, u)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   272
            (ZApp (term lev t, Same.commit (term lev) u) handle Same.SAME =>
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   273
              ZApp (t, term lev u))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   274
        | term _ _ = raise Same.SAME;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   275
    in term end;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   276
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   277
fun incr_bv inc lev = Same.commit (incr_bv_same inc lev);
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   278
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   279
fun incr_boundvars inc = incr_bv inc 0;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   280
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   281
fun subst_bound arg body =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   282
  let
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   283
    fun term lev (ZBound i) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   284
          if i < lev then raise Same.SAME   (*var is locally bound*)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   285
          else if i = lev then incr_boundvars lev arg
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   286
          else ZBound (i - 1)   (*loose: change it*)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   287
      | term lev (ZAbs (a, T, t)) = ZAbs (a, T, term (lev + 1) t)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   288
      | term lev (ZApp (t, u)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   289
          (ZApp (term lev t, Same.commit (term lev) u)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   290
            handle Same.SAME => ZApp (t, term lev u))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   291
      | term _ _ = raise Same.SAME;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   292
  in Same.commit (term 0) body end;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   293
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   294
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   295
(* direct substitution *)
79132
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   296
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   297
fun subst_type_same tvar =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   298
  let
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   299
    fun typ (ZTVar x) = tvar x
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   300
      | typ (ZFun (T, U)) = (ZFun (typ T, Same.commit typ U) handle Same.SAME => ZFun (T, typ U))
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   301
      | typ ZProp = raise Same.SAME
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   302
      | typ (ZItself T) = ZItself (typ T)
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   303
      | typ (ZType0 _) = raise Same.SAME
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   304
      | typ (ZType1 (a, T)) = ZType1 (a, typ T)
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   305
      | typ (ZType (a, Ts)) = ZType (a, Same.map typ Ts);
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   306
  in typ end;
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   307
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   308
fun subst_term_same typ var =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   309
  let
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   310
    fun term (ZVar (x, T)) =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   311
          let val (T', same) = Same.commit_id typ T in
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   312
            (case Same.catch var (x, T') of
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   313
              NONE => if same then raise Same.SAME else ZVar (x, T')
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   314
            | SOME t' => t')
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   315
          end
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   316
      | term (ZBound _) = raise Same.SAME
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   317
      | term (ZConst0 _) = raise Same.SAME
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   318
      | term (ZConst1 (a, T)) = ZConst1 (a, typ T)
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   319
      | term (ZConst (a, Ts)) = ZConst (a, Same.map typ Ts)
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   320
      | term (ZAbs (a, T, t)) =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   321
          (ZAbs (a, typ T, Same.commit term t) handle Same.SAME => ZAbs (a, T, term t))
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   322
      | term (ZApp (t, u)) =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   323
          (ZApp (term t, Same.commit term u) handle Same.SAME => ZApp (t, term u))
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   324
      | term (ZClass (T, c)) = ZClass (typ T, c);
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   325
  in term end;
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   326
79145
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   327
fun map_insts_same typ term (instT, inst) =
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   328
  let
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   329
    val changed = Unsynchronized.ref false;
79146
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   330
    fun apply f x =
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   331
      (case Same.catch f x of
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   332
        NONE => NONE
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   333
      | some => (changed := true; some));
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   334
79145
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   335
    val instT' =
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   336
      (instT, instT) |-> ZTVars.fold (fn (v, T) =>
79146
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   337
        (case apply typ T of
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   338
          NONE => I
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   339
        | SOME T' => ZTVars.update (v, T')));
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   340
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   341
    val vars' =
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   342
      (inst, ZVars.empty) |-> ZVars.fold (fn ((v, T), _) =>
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   343
        (case apply typ T of
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   344
          NONE => I
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   345
        | SOME T' => ZVars.add ((v, T), (v, T'))));
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   346
79145
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   347
    val inst' =
79146
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   348
      if ZVars.is_empty vars' then
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   349
        (inst, inst) |-> ZVars.fold (fn (v, t) =>
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   350
          (case apply term t of
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   351
            NONE => I
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   352
          | SOME t' => ZVars.update (v, t')))
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   353
      else
79145
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   354
        ZVars.dest inst
79146
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   355
        |> map (fn (v, t) => (the_default v (ZVars.lookup vars' v), the_default t (apply term t)))
feb94ac5df41 more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents: 79145
diff changeset
   356
        |> ZVars.make_strict;
79145
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   357
  in if ! changed then (instT', inst') else raise Same.SAME end;
a9c55fef42b0 tuned signature;
wenzelm
parents: 79144
diff changeset
   358
79132
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   359
fun map_proof_same typ term =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   360
  let
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   361
    fun proof ZDummy = raise Same.SAME
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   362
      | proof (ZConstp (a, A, instT, inst)) =
79148
99201e7b1d94 proper treatment of ZConstP: term represents body of closure;
wenzelm
parents: 79147
diff changeset
   363
          let val (instT', inst') = map_insts_same typ term (instT, inst)
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   364
          in ZConstp (a, A, instT', inst') end
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   365
      | proof (ZBoundp _) = raise Same.SAME
79132
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   366
      | proof (ZHyp h) = ZHyp (term h)
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   367
      | proof (ZAbst (a, T, p)) =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   368
          (ZAbst (a, typ T, Same.commit proof p) handle Same.SAME => ZAbst (a, T, proof p))
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   369
      | proof (ZAbsp (a, t, p)) =
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   370
          (ZAbsp (a, term t, Same.commit proof p) handle Same.SAME => ZAbsp (a, t, proof p))
79132
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   371
      | proof (ZAppt (p, t)) =
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   372
          (ZAppt (proof p, Same.commit term t) handle Same.SAME => ZAppt (p, term t))
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   373
      | proof (ZAppp (p, q)) =
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   374
          (ZAppp (proof p, Same.commit proof q) handle Same.SAME => ZAppp (p, proof q))
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   375
      | proof (ZClassp (T, c)) = ZClassp (typ T, c);
79132
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   376
  in proof end;
6d3322477cfd more operations;
wenzelm
parents: 79128
diff changeset
   377
79144
wenzelm
parents: 79136
diff changeset
   378
fun map_proof_types_same typ =
wenzelm
parents: 79136
diff changeset
   379
  map_proof_same typ (subst_term_same typ Same.same);
wenzelm
parents: 79136
diff changeset
   380
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   381
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   382
(* convert ztyp / zterm vs. regular typ / term *)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   383
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   384
fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   385
  | ztyp_of (TVar v) = ZTVar v
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   386
  | ztyp_of (Type ("fun", [T, U])) = ZFun (ztyp_of T, ztyp_of U)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   387
  | ztyp_of (Type (c, [])) = if c = "prop" then ZProp else ZType0 c
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   388
  | ztyp_of (Type (c, [T])) = if c = "itself" then ZItself (ztyp_of T) else ZType1 (c, ztyp_of T)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   389
  | ztyp_of (Type (c, ts)) = ZType (c, map ztyp_of ts);
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   390
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   391
fun ztyp_cache () = Typtab.unsynchronized_cache ztyp_of;
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   392
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   393
fun zterm_cache thy =
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   394
  let
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   395
    val typargs = Consts.typargs (Sign.consts_of thy);
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   396
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   397
    val ztyp = ztyp_cache ();
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   398
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   399
    fun zterm (Free (x, T)) = ZVar ((x, ~1), ztyp T)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   400
      | zterm (Var (xi, T)) = ZVar (xi, ztyp T)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   401
      | zterm (Bound i) = ZBound i
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   402
      | zterm (Const (c, T)) =
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   403
          (case typargs (c, T) of
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   404
            [] => ZConst0 c
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   405
          | [T] => ZConst1 (c, ztyp T)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   406
          | Ts => ZConst (c, map ztyp Ts))
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   407
      | zterm (Abs (a, T, b)) = ZAbs (a, ztyp T, zterm b)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   408
      | zterm ((t as Const (c, _)) $ (u as Const ("Pure.type", _))) =
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   409
          if String.isSuffix Logic.class_suffix c then
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   410
            ZClass (ztyp (Logic.dest_type u), Logic.class_of_const c)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   411
          else ZApp (zterm t, zterm u)
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   412
      | zterm (t $ u) = ZApp (zterm t, zterm u);
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   413
  in {ztyp = ztyp, zterm = zterm} end;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   414
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   415
val zterm_of = #zterm o zterm_cache;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   416
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   417
fun typ_of (ZTVar ((a, ~1), S)) = TFree (a, S)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   418
  | typ_of (ZTVar v) = TVar v
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   419
  | typ_of (ZFun (T, U)) = typ_of T --> typ_of U
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   420
  | typ_of ZProp = propT
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   421
  | typ_of (ZItself T) = Term.itselfT (typ_of T)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   422
  | typ_of (ZType0 c) = Type (c, [])
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   423
  | typ_of (ZType1 (c, T)) = Type (c, [typ_of T])
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   424
  | typ_of (ZType (c, Ts)) = Type (c, map typ_of Ts);
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   425
79201
wenzelm
parents: 79200
diff changeset
   426
fun typ_cache () = ZTypes.unsynchronized_cache typ_of;
wenzelm
parents: 79200
diff changeset
   427
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   428
fun term_of thy =
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   429
  let
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   430
    val instance = Consts.instance (Sign.consts_of thy);
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   431
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   432
    fun const (c, Ts) = Const (c, instance (c, Ts));
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   433
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   434
    fun term (ZVar ((x, ~1), T)) = Free (x, typ_of T)
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   435
      | term (ZVar (xi, T)) = Var (xi, typ_of T)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   436
      | term (ZBound i) = Bound i
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   437
      | term (ZConst0 c) = const (c, [])
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   438
      | term (ZConst1 (c, T)) = const (c, [typ_of T])
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   439
      | term (ZConst (c, Ts)) = const (c, map typ_of Ts)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   440
      | term (ZAbs (a, T, b)) = Abs (a, typ_of T, term b)
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   441
      | term (ZApp (t, u)) = term t $ term u
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   442
      | term (ZClass (T, c)) = Logic.mk_of_class (typ_of T, c);
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   443
  in term end;
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   444
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   445
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   446
(* beta normalization wrt. environment *)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   447
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   448
fun could_beta_contract (ZApp (ZAbs _, _)) = true
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   449
  | could_beta_contract (ZApp (t, u)) = could_beta_contract t orelse could_beta_contract u
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   450
  | could_beta_contract (ZAbs (_, _, b)) = could_beta_contract b
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   451
  | could_beta_contract _ = false;
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   452
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   453
fun norm_type_same ztyp tyenv =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   454
  if Vartab.is_empty tyenv then Same.same
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   455
  else
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   456
    let
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   457
      fun norm (ZTVar v) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   458
            (case Type.lookup tyenv v of
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   459
              SOME U => Same.commit norm (ztyp U)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   460
            | NONE => raise Same.SAME)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   461
        | norm (ZFun (T, U)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   462
            (ZFun (norm T, Same.commit norm U)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   463
              handle Same.SAME => ZFun (T, norm U))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   464
        | norm ZProp = raise Same.SAME
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   465
        | norm (ZItself T) = ZItself (norm T)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   466
        | norm (ZType0 _) = raise Same.SAME
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   467
        | norm (ZType1 (a, T)) = ZType1 (a, norm T)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   468
        | norm (ZType (a, Ts)) = ZType (a, Same.map norm Ts);
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   469
    in norm end;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   470
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   471
fun norm_term_same {ztyp, zterm, typ} (envir as Envir.Envir {tyenv, tenv, ...}) tm =
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   472
  if Envir.is_empty envir andalso not (could_beta_contract tm) then raise Same.SAME
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   473
  else
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   474
    let
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   475
      val lookup =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   476
        if Vartab.is_empty tenv then K NONE
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   477
        else ZVars.unsynchronized_cache (apsnd typ #> Envir.lookup envir #> Option.map zterm);
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   478
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   479
      val normT = norm_type_same ztyp tyenv;
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   480
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   481
      fun norm (ZVar (xi, T)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   482
            (case lookup (xi, T) of
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   483
              SOME u => Same.commit norm u
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   484
            | NONE => ZVar (xi, normT T))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   485
        | norm (ZBound _) = raise Same.SAME
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   486
        | norm (ZConst0 _) = raise Same.SAME
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   487
        | norm (ZConst1 (a, T)) = ZConst1 (a, normT T)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   488
        | norm (ZConst (a, Ts)) = ZConst (a, Same.map normT Ts)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   489
        | norm (ZAbs (a, T, t)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   490
            (ZAbs (a, normT T, Same.commit norm t)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   491
              handle Same.SAME => ZAbs (a, T, norm t))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   492
        | norm (ZApp (ZAbs (_, _, body), t)) = Same.commit norm (subst_bound t body)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   493
        | norm (ZApp (f, t)) =
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   494
            ((case norm f of
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   495
               ZAbs (_, _, body) => Same.commit norm (subst_bound t body)
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   496
             | nf => ZApp (nf, Same.commit norm t))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   497
            handle Same.SAME => ZApp (f, norm t))
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   498
        | norm _ = raise Same.SAME;
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   499
    in norm tm end;
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   500
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   501
fun norm_proof_same (cache as {ztyp, ...}) (envir as Envir.Envir {tyenv, ...}) prf =
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   502
  if Envir.is_empty envir andalso not (exists_proof_terms could_beta_contract prf) then
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   503
    raise Same.SAME
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   504
  else map_proof_same (norm_type_same ztyp tyenv) (norm_term_same cache envir) prf;
79210
5ed6f16a5f7c clarified signature: support shared cache;
wenzelm
parents: 79205
diff changeset
   505
5ed6f16a5f7c clarified signature: support shared cache;
wenzelm
parents: 79205
diff changeset
   506
fun norm_cache thy =
79205
a159cb82afe7 more operations;
wenzelm
parents: 79204
diff changeset
   507
  let
79226
0b87e04d0b68 tuned signature;
wenzelm
parents: 79214
diff changeset
   508
    val {ztyp, zterm} = zterm_cache thy;
79205
a159cb82afe7 more operations;
wenzelm
parents: 79204
diff changeset
   509
    val typ = typ_cache ();
a159cb82afe7 more operations;
wenzelm
parents: 79204
diff changeset
   510
  in {ztyp = ztyp, zterm = zterm, typ = typ} end;
a159cb82afe7 more operations;
wenzelm
parents: 79204
diff changeset
   511
79214
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   512
fun norm_type tyenv = Same.commit (norm_type_same (ztyp_cache ()) tyenv);
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   513
fun norm_term thy envir = Same.commit (norm_term_same (norm_cache thy) envir);
61af3e917597 more operations;
wenzelm
parents: 79212
diff changeset
   514
fun norm_proof thy envir = Same.commit (norm_proof_same (norm_cache thy) envir);
79200
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   515
f6bbe80f5f41 more operations;
wenzelm
parents: 79163
diff changeset
   516
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   517
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   518
(** proof construction **)
79113
5109e4b2a292 pro-forma support for optional zproof: no proper content yet;
wenzelm
parents: 79098
diff changeset
   519
5109e4b2a292 pro-forma support for optional zproof: no proper content yet;
wenzelm
parents: 79098
diff changeset
   520
fun dummy_proof _ = ZDummy;
5109e4b2a292 pro-forma support for optional zproof: no proper content yet;
wenzelm
parents: 79098
diff changeset
   521
val todo_proof = dummy_proof;
5109e4b2a292 pro-forma support for optional zproof: no proper content yet;
wenzelm
parents: 79098
diff changeset
   522
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   523
79161
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   524
(* constants *)
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   525
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   526
fun const_proof thy a A =
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   527
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   528
    val t = zterm_of thy A;
79154
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   529
    val instT =
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   530
      ZTVars.build (t |> (fold_types o fold_tvars) (fn v => fn tab =>
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   531
        if ZTVars.defined tab v then tab else ZTVars.update (v, ZTVar v) tab));
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   532
    val inst =
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   533
      ZVars.build (t |> fold_aterms (fn a => fn tab =>
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   534
        (case a of
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   535
          ZVar v => if ZVars.defined tab v then tab else ZVars.update (v, a) tab
e47db1e15a22 minor performance tuning;
wenzelm
parents: 79153
diff changeset
   536
        | _ => tab)));
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   537
  in ZConstp (a, t, instT, inst) end;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   538
79161
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   539
fun map_const_proof (f, g) prf =
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   540
  (case prf of
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   541
    ZConstp (a, A, instT, inst) =>
79161
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   542
      let
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   543
        val instT' = ZTVars.map (fn ((x, _), _) => fn y => the_default y (try f x)) instT;
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   544
        val inst' = ZVars.map (fn ((x, _), _) => fn y => the_default y (try g x)) inst;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   545
      in ZConstp (a, A, instT', inst') end
79161
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   546
  | _ => prf);
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   547
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   548
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   549
(* basic logic *)
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   550
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   551
fun axiom_proof thy name =
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   552
  const_proof thy (ZAxiom name);
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   553
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   554
fun oracle_proof thy name =
3f532c76d0ad tuned structure;
wenzelm
parents: 79160
diff changeset
   555
  const_proof thy (ZOracle name);
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   556
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   557
fun assume_proof thy A =
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   558
  ZHyp (zterm_of thy A);
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   559
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   560
fun trivial_proof thy A =
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   561
  ZAbsp ("H", zterm_of thy A, ZBoundp 0);
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   562
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   563
fun implies_intr_proof thy A prf =
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   564
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   565
    val h = zterm_of thy A;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   566
    fun proof i (ZHyp t) = if aconv_zterm (h, t) then ZBoundp i else raise Same.SAME
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   567
      | proof i (ZAbst (x, T, p)) = ZAbst (x, T, proof i p)
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   568
      | proof i (ZAbsp (x, t, p)) = ZAbsp (x, t, proof (i + 1) p)
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   569
      | proof i (ZAppt (p, t)) = ZAppt (proof i p, t)
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   570
      | proof i (ZAppp (p, q)) =
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   571
          (ZAppp (proof i p, Same.commit (proof i) q) handle Same.SAME =>
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   572
            ZAppp (p, proof i q))
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   573
      | proof _ _ = raise Same.SAME;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   574
  in ZAbsp ("H", h, Same.commit (proof 0) prf) end;
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   575
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   576
fun forall_intr_proof thy T (a, x) prf =
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   577
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   578
    val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   579
    val Z = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   580
    val z = zterm x;
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   581
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   582
    fun term i b =
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   583
      if aconv_zterm (b, z) then ZBound i
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   584
      else
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   585
        (case b of
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   586
          ZAbs (x, T, t) => ZAbs (x, T, term (i + 1) t)
79156
3b272da1d165 minor performance tuning;
wenzelm
parents: 79155
diff changeset
   587
        | ZApp (t, u) =>
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   588
            (ZApp (term i t, Same.commit (term i) u) handle Same.SAME =>
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   589
              ZApp (t, term i u))
79156
3b272da1d165 minor performance tuning;
wenzelm
parents: 79155
diff changeset
   590
        | _ => raise Same.SAME);
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   591
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   592
    fun proof i (ZAbst (x, T, prf)) = ZAbst (x, T, proof (i + 1) prf)
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   593
      | proof i (ZAbsp (x, t, prf)) =
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   594
          (ZAbsp (x, term i t, Same.commit (proof i) prf) handle Same.SAME =>
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   595
            ZAbsp (x, t, proof i prf))
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   596
      | proof i (ZAppt (p, t)) =
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   597
          (ZAppt (proof i p, Same.commit (term i) t) handle Same.SAME =>
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   598
            ZAppt (p, term i t))
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   599
      | proof i (ZAppp (p, q)) =
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   600
          (ZAppp (proof i p, Same.commit (proof i) q) handle Same.SAME =>
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   601
            ZAppp (p, proof i q))
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   602
      | proof _ _ = raise Same.SAME;
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   603
79157
00962876301c tuned names;
wenzelm
parents: 79156
diff changeset
   604
  in ZAbst (a, Z, Same.commit (proof 0) prf) end;
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   605
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   606
fun forall_elim_proof thy t p = ZAppt (p, zterm_of thy t);
79119
cf29db6c95e1 more zterm operations;
wenzelm
parents: 79114
diff changeset
   607
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   608
fun of_class_proof (T, c) = ZClassp (ztyp_of T, c);
79128
b6f5d4392388 more zproofs;
wenzelm
parents: 79126
diff changeset
   609
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   610
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   611
(* equality *)
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   612
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   613
local
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   614
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   615
val thy0 =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   616
  Context.the_global_context ()
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   617
  |> Sign.add_types_global [(Binding.name "fun", 2, NoSyn), (Binding.name "prop", 0, NoSyn)]
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   618
  |> Sign.local_path
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   619
  |> Sign.add_consts
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   620
   [(Binding.name "all", (Term.aT [] --> propT) --> propT, NoSyn),
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   621
    (Binding.name "imp", propT --> propT --> propT, NoSyn),
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   622
    (Binding.name "eq", Term.aT [] --> Term.aT [] --> propT, NoSyn)];
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   623
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   624
val [reflexive_axiom, symmetric_axiom, transitive_axiom, equal_intr_axiom, equal_elim_axiom,
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   625
  abstract_rule_axiom, combination_axiom] =
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   626
    Theory.equality_axioms |> map (fn (b, t) => axiom_proof thy0 (Sign.full_name thy0 b) t);
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   627
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   628
in
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   629
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   630
val is_reflexive_proof =
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   631
  fn ZConstp (ZAxiom "Pure.reflexive", _, _, _) => true | _ => false;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   632
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   633
fun reflexive_proof thy T t =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   634
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   635
    val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   636
    val A = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   637
    val x = zterm t;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   638
  in map_const_proof (fn "'a" => A, fn "x" => x) reflexive_axiom end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   639
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   640
fun symmetric_proof thy T t u prf =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   641
  if is_reflexive_proof prf then prf
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   642
  else
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   643
    let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   644
      val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   645
      val A = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   646
      val x = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   647
      val y = zterm u;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   648
      val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y) symmetric_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   649
    in ZAppp (ax, prf) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   650
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   651
fun transitive_proof thy T t u v prf1 prf2 =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   652
  if is_reflexive_proof prf1 then prf2
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   653
  else if is_reflexive_proof prf2 then prf1
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   654
  else
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   655
    let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   656
      val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   657
      val A = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   658
      val x = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   659
      val y = zterm u;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   660
      val z = zterm v;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   661
      val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y | "z" => z) transitive_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   662
    in ZAppp (ZAppp (ax, prf1), prf2) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   663
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   664
fun equal_intr_proof thy t u prf1 prf2 =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   665
  let
79160
wenzelm
parents: 79158
diff changeset
   666
    val {zterm, ...} = zterm_cache thy;
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   667
    val A = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   668
    val B = zterm u;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   669
    val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_intr_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   670
  in ZAppp (ZAppp (ax, prf1), prf2) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   671
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   672
fun equal_elim_proof thy t u prf1 prf2 =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   673
  let
79160
wenzelm
parents: 79158
diff changeset
   674
    val {zterm, ...} = zterm_cache thy;
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   675
    val A = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   676
    val B = zterm u;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   677
    val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_elim_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   678
  in ZAppp (ZAppp (ax, prf1), prf2) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   679
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   680
fun abstract_rule_proof thy T U x t u prf =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   681
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   682
    val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   683
    val A = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   684
    val B = ztyp U;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   685
    val f = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   686
    val g = zterm u;
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   687
    val ax =
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   688
      map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f | "g" => g)
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   689
        abstract_rule_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   690
  in ZAppp (ax, forall_intr_proof thy T x prf) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   691
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   692
fun combination_proof thy T U f g t u prf1 prf2 =
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   693
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   694
    val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   695
    val A = ztyp T;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   696
    val B = ztyp U;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   697
    val f' = zterm f;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   698
    val g' = zterm g;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   699
    val x = zterm t;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   700
    val y = zterm u;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   701
    val ax =
79126
bdb33a2d4167 clarified const_proof vs. zproof_name;
wenzelm
parents: 79124
diff changeset
   702
      map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f' | "g" => g' | "x" => x | "y" => y)
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   703
        combination_axiom;
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   704
  in ZAppp (ZAppp (ax, prf1), prf2) end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   705
79098
d8940e5bbb25 tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff changeset
   706
end;
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   707
79133
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   708
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   709
(* substitution *)
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   710
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   711
fun generalize_proof (tfrees, frees) idx prf =
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   712
  let
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   713
    val typ =
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   714
      if Names.is_empty tfrees then Same.same else
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   715
        ZTypes.unsynchronized_cache
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   716
          (subst_type_same (fn ((a, i), S) =>
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   717
            if i = ~1 andalso Names.defined tfrees a then ZTVar ((a, idx), S)
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   718
            else raise Same.SAME));
79136
wenzelm
parents: 79135
diff changeset
   719
    val term =
79147
bfe5c20074e4 proper substitution of types within term;
wenzelm
parents: 79146
diff changeset
   720
      subst_term_same typ (fn ((x, i), T) =>
bfe5c20074e4 proper substitution of types within term;
wenzelm
parents: 79146
diff changeset
   721
        if i = ~1 andalso Names.defined frees x then ZVar ((x, idx), T)
bfe5c20074e4 proper substitution of types within term;
wenzelm
parents: 79146
diff changeset
   722
        else raise Same.SAME);
79136
wenzelm
parents: 79135
diff changeset
   723
  in Same.commit (map_proof_same typ term) prf end;
79133
cfe995369655 more zproofs;
wenzelm
parents: 79132
diff changeset
   724
79149
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   725
fun instantiate_proof thy (Ts, ts) prf =
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   726
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   727
    val {ztyp, zterm} = zterm_cache thy;
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   728
    val instT = ZTVars.build (Ts |> fold (fn (v, T) => ZTVars.add (v, ztyp T)));
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   729
    val inst = ZVars.build (ts |> fold (fn ((v, T), t) => ZVars.add ((v, ztyp T), zterm t)));
79149
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   730
    val typ =
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   731
      if ZTVars.is_empty instT then Same.same
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   732
      else ZTypes.unsynchronized_cache (subst_type_same (Same.function (ZTVars.lookup instT)));
79149
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   733
    val term = subst_term_same typ (Same.function (ZVars.lookup inst));
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   734
  in Same.commit (map_proof_same typ term) prf end;
810679c5ed3c more zproofs;
wenzelm
parents: 79148
diff changeset
   735
79135
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   736
fun varifyT_proof names prf =
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   737
  if null names then prf
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   738
  else
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   739
    let
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   740
      val tab = ZTVars.build (names |> fold (fn ((a, S), b) => ZTVars.add (((a, ~1), S), b)));
79136
wenzelm
parents: 79135
diff changeset
   741
      val typ =
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   742
        ZTypes.unsynchronized_cache (subst_type_same (fn v =>
79136
wenzelm
parents: 79135
diff changeset
   743
          (case ZTVars.lookup tab v of
wenzelm
parents: 79135
diff changeset
   744
            NONE => raise Same.SAME
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   745
          | SOME w => ZTVar w)));
79144
wenzelm
parents: 79136
diff changeset
   746
    in Same.commit (map_proof_types_same typ) prf end;
79135
db2dc7634d62 more zproofs;
wenzelm
parents: 79133
diff changeset
   747
79152
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   748
fun legacy_freezeT_proof t prf =
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   749
  (case Type.legacy_freezeT t of
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   750
    NONE => prf
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   751
  | SOME f =>
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   752
      let
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   753
        val tvar = ztyp_of o Same.function f;
79163
9ddcaca41ed2 more operations;
wenzelm
parents: 79161
diff changeset
   754
        val typ = ZTypes.unsynchronized_cache (subst_type_same tvar);
79152
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   755
      in Same.commit (map_proof_types_same typ) prf end);
4189e10f1524 more zproofs;
wenzelm
parents: 79150
diff changeset
   756
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   757
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   758
(* permutations *)
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   759
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   760
fun rotate_proof thy Bs Bi' params asms m prf =
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   761
  let
79158
3c7ab17380a8 performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents: 79157
diff changeset
   762
    val {ztyp, zterm} = zterm_cache thy;
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   763
    val i = length asms;
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   764
    val j = length Bs;
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   765
  in
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   766
    ZAbsps (map zterm Bs @ [zterm Bi']) (ZAppps (prf, map ZBoundp
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   767
      (j downto 1) @ [ZAbsts (map (apsnd ztyp) params) (ZAbsps (map zterm asms)
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   768
        (ZAppps (ZAppts (ZBoundp i, map ZBound ((length params - 1) downto 0)),
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   769
          map ZBoundp (((i-m-1) downto 0) @ ((i-1) downto (i-m))))))]))
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   770
  end;
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   771
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   772
fun permute_prems_proof thy prems' j k prf =
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   773
  let
79160
wenzelm
parents: 79158
diff changeset
   774
    val {zterm, ...} = zterm_cache thy;
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   775
    val n = length prems';
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   776
  in
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   777
    ZAbsps (map zterm prems')
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   778
      (ZAppps (prf, map ZBoundp ((n-1 downto n-j) @ (k-1 downto 0) @ (n-j-1 downto k))))
79155
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   779
  end;
53288743c2f0 more zproofs;
wenzelm
parents: 79154
diff changeset
   780
79211
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   781
79234
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   782
(* lifting *)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   783
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   784
fun incr_tvar_same inc =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   785
  if inc = 0 then Same.same
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   786
  else
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   787
    let fun tvar ((a, i), S) = if i >= 0 then ZTVar ((a, i + inc), S) else raise Same.SAME
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   788
    in ZTypes.unsynchronized_cache (subst_type_same tvar) end;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   789
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   790
fun incr_indexes_proof inc prf =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   791
  let
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   792
    val typ = incr_tvar_same inc;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   793
    fun var ((x, i), T) = if i >= 0 then ZVar ((x, i + inc), T) else raise Same.SAME;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   794
    val term = subst_term_same typ var;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   795
  in Same.commit (map_proof_same typ term) prf end;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   796
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   797
fun lift_proof thy gprop inc prems prf =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   798
  let
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   799
    val {ztyp, zterm} = zterm_cache thy;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   800
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   801
    val typ = incr_tvar_same inc;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   802
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   803
    fun term Ts lev =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   804
      if null Ts andalso inc = 0 then Same.same
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   805
      else
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   806
        let
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   807
          val n = length Ts;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   808
          fun incr lev (ZVar ((x, i), T)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   809
                if i >= 0 then combound (ZVar ((x, i + inc), ZFuns (Ts, Same.commit typ T)), lev, n)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   810
                else raise Same.SAME
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   811
            | incr _ (ZBound _) = raise Same.SAME
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   812
            | incr _ (ZConst0 _) = raise Same.SAME
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   813
            | incr _ (ZConst1 (c, T)) = ZConst1 (c, typ T)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   814
            | incr _ (ZConst (c, Ts)) = ZConst (c, Same.map typ Ts)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   815
            | incr lev (ZAbs (x, T, t)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   816
                (ZAbs (x, typ T, Same.commit (incr (lev + 1)) t)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   817
                  handle Same.SAME => ZAbs (x, T, incr (lev + 1) t))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   818
            | incr lev (ZApp (t, u)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   819
                (ZApp (incr lev t, Same.commit (incr lev) u)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   820
                  handle Same.SAME => ZApp (t, incr lev u))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   821
            | incr _ (ZClass (T, c)) = ZClass (typ T, c);
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   822
        in incr lev end;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   823
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   824
    fun proof Ts lev (ZAbst (a, T, p)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   825
          (ZAbst (a, typ T, Same.commit (proof Ts (lev + 1)) p)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   826
            handle Same.SAME => ZAbst (a, T, proof Ts (lev + 1) p))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   827
      | proof Ts lev (ZAbsp (a, t, p)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   828
          (ZAbsp (a, term Ts lev t, Same.commit (proof Ts lev) p)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   829
            handle Same.SAME => ZAbsp (a, t, proof Ts lev p))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   830
      | proof Ts lev (ZAppt (p, t)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   831
          (ZAppt (proof Ts lev p, Same.commit (term Ts lev) t)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   832
            handle Same.SAME => ZAppt (p, term Ts lev t))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   833
      | proof Ts lev (ZAppp (p, q)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   834
          (ZAppp (proof Ts lev p, Same.commit (proof Ts lev) q)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   835
            handle Same.SAME => ZAppp (p, proof Ts lev q))
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   836
      | proof Ts lev (ZConstp (a, A, instT, inst)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   837
          let val (instT', insts') = map_insts_same typ (term Ts lev) (instT, inst)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   838
          in ZConstp (a, A, instT', insts') end
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   839
      | proof _ _ (ZClassp (T, c)) = ZClassp (typ T, c)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   840
      | proof _ _ _ = raise Same.SAME;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   841
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   842
    val k = length prems;
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   843
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   844
    fun mk_app b (i, j, p) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   845
      if b then (i - 1, j, ZAppp (p, ZBoundp i)) else (i, j - 1, ZAppt (p, ZBound j));
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   846
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   847
    fun lift Ts bs i j (Const ("Pure.imp", _) $ A $ B) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   848
          ZAbsp ("H", Same.commit (term Ts 0) (zterm A), lift Ts (true :: bs) (i + 1) j B)
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   849
      | lift Ts bs i j (Const ("Pure.all", _) $ Abs (a, T, t)) =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   850
          let val T' = ztyp T
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   851
          in ZAbst (a, T', lift (T' :: Ts) (false :: bs) i (j + 1) t) end
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   852
      | lift Ts bs i j _ =
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   853
          ZAppps (Same.commit (proof (rev Ts) 0) prf,
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   854
            map (fn k => (#3 (fold_rev mk_app bs (i - 1, j - 1, ZBoundp k)))) (i + k - 1 downto i));
79237
f97fe7ad62a7 proper ZTerm.lift_proof (amending 4a1a25bdf81d);
wenzelm
parents: 79234
diff changeset
   855
  in ZAbsps (map zterm prems) (lift [] [] 0 0 gprop) end;
79234
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   856
4a1a25bdf81d more zproofs;
wenzelm
parents: 79226
diff changeset
   857
79211
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   858
(* higher-order resolution *)
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   859
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   860
fun mk_asm_prf C i m =
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   861
  let
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   862
    fun imp _ i 0 = ZBoundp i
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   863
      | imp (ZApp (ZApp (ZConst0 "Pure.imp", A), B)) i m = ZAbsp ("H", A, imp B (i + 1) (m - 1))
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   864
      | imp _ i _ = ZBoundp i;
79211
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   865
    fun all (ZApp (ZConst1 ("Pure.all", _), ZAbs (a, T, t))) = ZAbst (a, T, all t)
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   866
      | all t = imp t (~ i) m
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   867
  in all C end;
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   868
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   869
fun assumption_proof thy envir Bs Bi n prf =
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   870
  let
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   871
    val cache as {zterm, ...} = norm_cache thy;
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   872
    val normt = zterm #> Same.commit (norm_term_same cache envir);
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   873
  in
79212
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   874
    ZAbsps (map normt Bs)
601aa36071ba clarified signature;
wenzelm
parents: 79211
diff changeset
   875
      (ZAppps (prf, map ZBoundp (length Bs - 1 downto 0) @ [mk_asm_prf (normt Bi) n ~1]))
79211
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   876
    |> Same.commit (norm_proof_same cache envir)
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   877
  end;
35ead2206eb1 more zproofs;
wenzelm
parents: 79210
diff changeset
   878
79124
89d4a8f52738 more zproofs;
wenzelm
parents: 79119
diff changeset
   879
end;