src/Pure/thm.ML
changeset 32032 a6a6e8031c14
parent 32027 9dd548810ed1
child 32035 8e77b6a250d5
equal deleted inserted replaced
32031:e2e6b0691264 32032:a6a6e8031c14
  1245 fun assumption i state =
  1245 fun assumption i state =
  1246   let
  1246   let
  1247     val Thm (der, {thy_ref, maxidx, shyps, hyps, prop, ...}) = state;
  1247     val Thm (der, {thy_ref, maxidx, shyps, hyps, prop, ...}) = state;
  1248     val thy = Theory.deref thy_ref;
  1248     val thy = Theory.deref thy_ref;
  1249     val (tpairs, Bs, Bi, C) = dest_state (state, i);
  1249     val (tpairs, Bs, Bi, C) = dest_state (state, i);
  1250     fun newth n (env as Envir.Envir {maxidx, ...}, tpairs) =
  1250     fun newth n (env, tpairs) =
  1251       Thm (deriv_rule1
  1251       Thm (deriv_rule1
  1252           ((if Envir.is_empty env then I else (Pt.norm_proof' env)) o
  1252           ((if Envir.is_empty env then I else (Pt.norm_proof' env)) o
  1253             Pt.assumption_proof Bs Bi n) der,
  1253             Pt.assumption_proof Bs Bi n) der,
  1254        {tags = [],
  1254        {tags = [],
  1255         maxidx = maxidx,
  1255         maxidx = Envir.maxidx_of env,
  1256         shyps = Envir.insert_sorts env shyps,
  1256         shyps = Envir.insert_sorts env shyps,
  1257         hyps = hyps,
  1257         hyps = hyps,
  1258         tpairs =
  1258         tpairs =
  1259           if Envir.is_empty env then tpairs
  1259           if Envir.is_empty env then tpairs
  1260           else map (pairself (Envir.norm_term env)) tpairs,
  1260           else map (pairself (Envir.norm_term env)) tpairs,
  1463   | strip_assums2 BB = BB;
  1463   | strip_assums2 BB = BB;
  1464 
  1464 
  1465 
  1465 
  1466 (*Faster normalization: skip assumptions that were lifted over*)
  1466 (*Faster normalization: skip assumptions that were lifted over*)
  1467 fun norm_term_skip env 0 t = Envir.norm_term env t
  1467 fun norm_term_skip env 0 t = Envir.norm_term env t
  1468   | norm_term_skip env n (Const("all",_)$Abs(a,T,t)) =
  1468   | norm_term_skip env n (Const ("all", _) $ Abs (a, T, t)) =
  1469         let val Envir.Envir{iTs, ...} = env
  1469       let
  1470             val T' = Envir.typ_subst_TVars iTs T
  1470         val T' = Envir.typ_subst_TVars (Envir.type_env env) T
  1471             (*Must instantiate types of parameters because they are flattened;
  1471         (*Must instantiate types of parameters because they are flattened;
  1472               this could be a NEW parameter*)
  1472           this could be a NEW parameter*)
  1473         in Term.all T' $ Abs(a, T', norm_term_skip env n t)  end
  1473       in Term.all T' $ Abs (a, T', norm_term_skip env n t) end
  1474   | norm_term_skip env n (Const("==>", _) $ A $ B) =
  1474   | norm_term_skip env n (Const ("==>", _) $ A $ B) =
  1475         Logic.mk_implies (A, norm_term_skip env (n-1) B)
  1475       Logic.mk_implies (A, norm_term_skip env (n - 1) B)
  1476   | norm_term_skip env n t = error"norm_term_skip: too few assumptions??";
  1476   | norm_term_skip env n t = error "norm_term_skip: too few assumptions??";
  1477 
  1477 
  1478 
  1478 
  1479 (*Composition of object rule r=(A1...Am/B) with proof state s=(B1...Bn/C)
  1479 (*Composition of object rule r=(A1...Am/B) with proof state s=(B1...Bn/C)
  1480   Unifies B with Bi, replacing subgoal i    (1 <= i <= n)
  1480   Unifies B with Bi, replacing subgoal i    (1 <= i <= n)
  1481   If match then forbid instantiations in proof state
  1481   If match then forbid instantiations in proof state
  1493              tpairs=rtpairs, prop=rprop,...}) = orule
  1493              tpairs=rtpairs, prop=rprop,...}) = orule
  1494          (*How many hyps to skip over during normalization*)
  1494          (*How many hyps to skip over during normalization*)
  1495      and nlift = Logic.count_prems (strip_all_body Bi) + (if eres_flg then ~1 else 0)
  1495      and nlift = Logic.count_prems (strip_all_body Bi) + (if eres_flg then ~1 else 0)
  1496      val thy = Theory.deref (merge_thys2 state orule);
  1496      val thy = Theory.deref (merge_thys2 state orule);
  1497      (** Add new theorem with prop = '[| Bs; As |] ==> C' to thq **)
  1497      (** Add new theorem with prop = '[| Bs; As |] ==> C' to thq **)
  1498      fun addth A (As, oldAs, rder', n) ((env as Envir.Envir {maxidx, ...}, tpairs), thq) =
  1498      fun addth A (As, oldAs, rder', n) ((env, tpairs), thq) =
  1499        let val normt = Envir.norm_term env;
  1499        let val normt = Envir.norm_term env;
  1500            (*perform minimal copying here by examining env*)
  1500            (*perform minimal copying here by examining env*)
  1501            val (ntpairs, normp) =
  1501            val (ntpairs, normp) =
  1502              if Envir.is_empty env then (tpairs, (Bs @ As, C))
  1502              if Envir.is_empty env then (tpairs, (Bs @ As, C))
  1503              else
  1503              else
  1518                        (fn f => fn der => f (Pt.norm_proof' env der))
  1518                        (fn f => fn der => f (Pt.norm_proof' env der))
  1519                      else
  1519                      else
  1520                        curry op oo (Pt.norm_proof' env))
  1520                        curry op oo (Pt.norm_proof' env))
  1521                     (Pt.bicompose_proof flatten Bs oldAs As A n (nlift+1))) rder' sder,
  1521                     (Pt.bicompose_proof flatten Bs oldAs As A n (nlift+1))) rder' sder,
  1522                 {tags = [],
  1522                 {tags = [],
  1523                  maxidx = maxidx,
  1523                  maxidx = Envir.maxidx_of env,
  1524                  shyps = Envir.insert_sorts env (Sorts.union rshyps sshyps),
  1524                  shyps = Envir.insert_sorts env (Sorts.union rshyps sshyps),
  1525                  hyps = union_hyps rhyps shyps,
  1525                  hyps = union_hyps rhyps shyps,
  1526                  tpairs = ntpairs,
  1526                  tpairs = ntpairs,
  1527                  prop = Logic.list_implies normp,
  1527                  prop = Logic.list_implies normp,
  1528                  thy_ref = Theory.check_thy thy})
  1528                  thy_ref = Theory.check_thy thy})