src/Pure/zterm.ML
changeset 79273 d1e5f6d1ddca
parent 79272 899f37f6d218
child 79275 8368160d3c65
equal deleted inserted replaced
79272:899f37f6d218 79273:d1e5f6d1ddca
   234   val fold_proof_terms: (zterm -> 'a -> 'a) -> zproof -> 'a -> 'a
   234   val fold_proof_terms: (zterm -> 'a -> 'a) -> zproof -> 'a -> 'a
   235   val exists_proof_terms: (zterm -> bool) -> zproof -> bool
   235   val exists_proof_terms: (zterm -> bool) -> zproof -> bool
   236   val incr_bv_same: int -> int -> zterm Same.operation
   236   val incr_bv_same: int -> int -> zterm Same.operation
   237   val incr_bv: int -> int -> zterm -> zterm
   237   val incr_bv: int -> int -> zterm -> zterm
   238   val incr_boundvars: int -> zterm -> zterm
   238   val incr_boundvars: int -> zterm -> zterm
   239   val map_proof_same: ztyp Same.operation -> zterm Same.operation -> zproof Same.operation
   239   val map_proof: ztyp Same.operation -> zterm Same.operation -> zproof -> zproof
   240   val map_proof_types_same: ztyp Same.operation -> zproof Same.operation
   240   val map_proof_types: ztyp Same.operation -> zproof -> zproof
   241   val ztyp_of: typ -> ztyp
   241   val ztyp_of: typ -> ztyp
   242   val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp}
   242   val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp}
   243   val zterm_of: theory -> term -> zterm
   243   val zterm_of: theory -> term -> zterm
   244   val typ_of: ztyp -> typ
   244   val typ_of: ztyp -> typ
   245   val term_of: theory -> zterm -> term
   245   val term_of: theory -> zterm -> term
   454       | proof (ZAppp (p, q)) =
   454       | proof (ZAppp (p, q)) =
   455           (ZAppp (proof p, Same.commit proof q) handle Same.SAME => ZAppp (p, proof q))
   455           (ZAppp (proof p, Same.commit proof q) handle Same.SAME => ZAppp (p, proof q))
   456       | proof (ZClassp (T, c)) = ZClassp (typ T, c);
   456       | proof (ZClassp (T, c)) = ZClassp (typ T, c);
   457   in proof end;
   457   in proof end;
   458 
   458 
   459 fun map_proof_types_same typ =
   459 fun map_proof typ term = Same.commit (map_proof_same typ term);
   460   map_proof_same typ (subst_term_same typ Same.same);
   460 fun map_proof_types typ = map_proof typ (subst_term_same typ Same.same);
   461 
   461 
   462 
   462 
   463 (* convert ztyp / zterm vs. regular typ / term *)
   463 (* convert ztyp / zterm vs. regular typ / term *)
   464 
   464 
   465 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S)
   465 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S)
   617           val inst_term =
   617           val inst_term =
   618             ZVars.build (visible |> (fold o Term.fold_aterms) (fn Var v => add_var v | _ => I))
   618             ZVars.build (visible |> (fold o Term.fold_aterms) (fn Var v => add_var v | _ => I))
   619             |> instantiate_term_same inst_typ;
   619             |> instantiate_term_same inst_typ;
   620 
   620 
   621           val norm_term = Same.compose beta_norm_same inst_term;
   621           val norm_term = Same.compose beta_norm_same inst_term;
   622         in Same.commit (map_proof_same inst_typ norm_term) prf end
   622         in map_proof inst_typ norm_term prf end
   623   end;
   623   end;
   624 
   624 
   625 fun norm_cache thy =
   625 fun norm_cache thy =
   626   let
   626   let
   627     val {ztyp, zterm} = zterm_cache thy;
   627     val {ztyp, zterm} = zterm_cache thy;
   882             else raise Same.SAME));
   882             else raise Same.SAME));
   883     val term =
   883     val term =
   884       subst_term_same typ (fn ((x, i), T) =>
   884       subst_term_same typ (fn ((x, i), T) =>
   885         if i = ~1 andalso Names.defined frees x then ZVar ((x, idx), T)
   885         if i = ~1 andalso Names.defined frees x then ZVar ((x, idx), T)
   886         else raise Same.SAME);
   886         else raise Same.SAME);
   887   in Same.commit (map_proof_same typ term) prf end;
   887   in map_proof typ term prf end;
   888 
   888 
   889 fun instantiate_proof thy (Ts, ts) prf =
   889 fun instantiate_proof thy (Ts, ts) prf =
   890   let
   890   let
   891     val {ztyp, zterm} = zterm_cache thy;
   891     val {ztyp, zterm} = zterm_cache thy;
   892     val instT = ZTVars.build (Ts |> fold (fn (v, T) => ZTVars.add (v, ztyp T)));
   892     val instT = ZTVars.build (Ts |> fold (fn (v, T) => ZTVars.add (v, ztyp T)));
   893     val inst = ZVars.build (ts |> fold (fn ((v, T), t) => ZVars.add ((v, ztyp T), zterm t)));
   893     val inst = ZVars.build (ts |> fold (fn ((v, T), t) => ZVars.add ((v, ztyp T), zterm t)));
   894     val typ = instantiate_type_same instT;
   894     val typ = instantiate_type_same instT;
   895     val term = instantiate_term_same typ inst;
   895     val term = instantiate_term_same typ inst;
   896   in Same.commit (map_proof_same typ term) prf end;
   896   in map_proof typ term prf end;
   897 
   897 
   898 fun varifyT_proof names prf =
   898 fun varifyT_proof names prf =
   899   if null names then prf
   899   if null names then prf
   900   else
   900   else
   901     let
   901     let
   903       val typ =
   903       val typ =
   904         ZTypes.unsynchronized_cache (subst_type_same (fn v =>
   904         ZTypes.unsynchronized_cache (subst_type_same (fn v =>
   905           (case ZTVars.lookup tab v of
   905           (case ZTVars.lookup tab v of
   906             NONE => raise Same.SAME
   906             NONE => raise Same.SAME
   907           | SOME w => ZTVar w)));
   907           | SOME w => ZTVar w)));
   908     in Same.commit (map_proof_types_same typ) prf end;
   908     in map_proof_types typ prf end;
   909 
   909 
   910 fun legacy_freezeT_proof t prf =
   910 fun legacy_freezeT_proof t prf =
   911   (case Type.legacy_freezeT t of
   911   (case Type.legacy_freezeT t of
   912     NONE => prf
   912     NONE => prf
   913   | SOME f =>
   913   | SOME f =>
   914       let
   914       let
   915         val tvar = ztyp_of o Same.function f;
   915         val tvar = ztyp_of o Same.function f;
   916         val typ = ZTypes.unsynchronized_cache (subst_type_same tvar);
   916         val typ = ZTypes.unsynchronized_cache (subst_type_same tvar);
   917       in Same.commit (map_proof_types_same typ) prf end);
   917       in map_proof_types typ prf end);
   918 
   918 
   919 
   919 
   920 (* permutations *)
   920 (* permutations *)
   921 
   921 
   922 fun rotate_proof thy Bs Bi' params asms m prf =
   922 fun rotate_proof thy Bs Bi' params asms m prf =
   952 fun incr_indexes_proof inc prf =
   952 fun incr_indexes_proof inc prf =
   953   let
   953   let
   954     val typ = incr_tvar_same inc;
   954     val typ = incr_tvar_same inc;
   955     fun var ((x, i), T) = if i >= 0 then ZVar ((x, i + inc), T) else raise Same.SAME;
   955     fun var ((x, i), T) = if i >= 0 then ZVar ((x, i + inc), T) else raise Same.SAME;
   956     val term = subst_term_same typ var;
   956     val term = subst_term_same typ var;
   957   in Same.commit (map_proof_same typ term) prf end;
   957   in map_proof typ term prf end;
   958 
   958 
   959 fun lift_proof thy gprop inc prems prf =
   959 fun lift_proof thy gprop inc prems prf =
   960   let
   960   let
   961     val {ztyp, zterm} = zterm_cache thy;
   961     val {ztyp, zterm} = zterm_cache thy;
   962 
   962