src/Pure/thm.ML
changeset 70822 22e2f5acc0b4
parent 70814 a6644dfe8e26
child 70824 7000868c6098
equal deleted inserted replaced
70821:37062fe19175 70822:22e2f5acc0b4
  1826   let
  1826   let
  1827     val Thm (der, {cert, maxidx, constraints, shyps, hyps, ...}) = state;
  1827     val Thm (der, {cert, maxidx, constraints, shyps, hyps, ...}) = state;
  1828     val (context, cert') = make_context_certificate [state] opt_ctxt cert;
  1828     val (context, cert') = make_context_certificate [state] opt_ctxt cert;
  1829     val (tpairs, Bs, Bi, C) = dest_state (state, i);
  1829     val (tpairs, Bs, Bi, C) = dest_state (state, i);
  1830     fun newth n (env, tpairs) =
  1830     fun newth n (env, tpairs) =
  1831       Thm (deriv_rule1
  1831       let
  1832           ((if Envir.is_empty env then I else Proofterm.norm_proof' env) o
  1832         val normt = Envir.norm_term env;
  1833             Proofterm.assumption_proof Bs Bi n) der,
  1833         fun assumption_proof prf =
  1834        {tags = [],
  1834           Proofterm.assumption_proof (map normt Bs) (normt Bi) n prf
  1835         maxidx = Envir.maxidx_of env,
  1835           |> not (Envir.is_empty env) ? Proofterm.norm_proof' env;
  1836         constraints = insert_constraints_env (Context.certificate_theory cert') env constraints,
  1836       in
  1837         shyps = Envir.insert_sorts env shyps,
  1837         Thm (deriv_rule1 assumption_proof der,
  1838         hyps = hyps,
  1838          {tags = [],
  1839         tpairs =
  1839           maxidx = Envir.maxidx_of env,
  1840           if Envir.is_empty env then tpairs
  1840           constraints = insert_constraints_env (Context.certificate_theory cert') env constraints,
  1841           else map (apply2 (Envir.norm_term env)) tpairs,
  1841           shyps = Envir.insert_sorts env shyps,
  1842         prop =
  1842           hyps = hyps,
  1843           if Envir.is_empty env then (*avoid wasted normalizations*)
  1843           tpairs = if Envir.is_empty env then tpairs else map (apply2 normt) tpairs,
  1844             Logic.list_implies (Bs, C)
  1844           prop =
  1845           else (*normalize the new rule fully*)
  1845             if Envir.is_empty env then Logic.list_implies (Bs, C) (*avoid wasted normalizations*)
  1846             Envir.norm_term env (Logic.list_implies (Bs, C)),
  1846             else normt (Logic.list_implies (Bs, C)) (*normalize the new rule fully*),
  1847         cert = cert'});
  1847           cert = cert'})
       
  1848       end;
  1848 
  1849 
  1849     val (close, asms, concl) = Logic.assum_problems (~1, Bi);
  1850     val (close, asms, concl) = Logic.assum_problems (~1, Bi);
  1850     val concl' = close concl;
  1851     val concl' = close concl;
  1851     fun addprfs [] _ = Seq.empty
  1852     fun addprfs [] _ = Seq.empty
  1852       | addprfs (asm :: rest) n = Seq.make (fn () => Seq.pull
  1853       | addprfs (asm :: rest) n = Seq.make (fn () => Seq.pull
  1896       else if 0 < m andalso m < n then
  1897       else if 0 < m andalso m < n then
  1897         let val (ps, qs) = chop m asms
  1898         let val (ps, qs) = chop m asms
  1898         in Logic.list_all (params, Logic.list_implies (qs @ ps, concl)) end
  1899         in Logic.list_all (params, Logic.list_implies (qs @ ps, concl)) end
  1899       else raise THM ("rotate_rule", k, [state]);
  1900       else raise THM ("rotate_rule", k, [state]);
  1900   in
  1901   in
  1901     Thm (deriv_rule1 (Proofterm.rotate_proof Bs Bi m) der,
  1902     Thm (deriv_rule1 (Proofterm.rotate_proof Bs Bi' params asms m) der,
  1902      {cert = cert,
  1903      {cert = cert,
  1903       tags = [],
  1904       tags = [],
  1904       maxidx = maxidx,
  1905       maxidx = maxidx,
  1905       constraints = constraints,
  1906       constraints = constraints,
  1906       shyps = shyps,
  1907       shyps = shyps,
  1921     val moved_prems = List.drop (prems, j)
  1922     val moved_prems = List.drop (prems, j)
  1922     and fixed_prems = List.take (prems, j)
  1923     and fixed_prems = List.take (prems, j)
  1923       handle General.Subscript => raise THM ("permute_prems: j", j, [rl]);
  1924       handle General.Subscript => raise THM ("permute_prems: j", j, [rl]);
  1924     val n_j = length moved_prems;
  1925     val n_j = length moved_prems;
  1925     val m = if k < 0 then n_j + k else k;
  1926     val m = if k < 0 then n_j + k else k;
  1926     val prop' =
  1927     val (prems', prop') =
  1927       if 0 = m orelse m = n_j then prop
  1928       if 0 = m orelse m = n_j then (prems, prop)
  1928       else if 0 < m andalso m < n_j then
  1929       else if 0 < m andalso m < n_j then
  1929         let val (ps, qs) = chop m moved_prems
  1930         let
  1930         in Logic.list_implies (fixed_prems @ qs @ ps, concl) end
  1931           val (ps, qs) = chop m moved_prems;
       
  1932           val prems' = fixed_prems @ qs @ ps;
       
  1933         in (prems', Logic.list_implies (prems', concl)) end
  1931       else raise THM ("permute_prems: k", k, [rl]);
  1934       else raise THM ("permute_prems: k", k, [rl]);
  1932   in
  1935   in
  1933     Thm (deriv_rule1 (Proofterm.permute_prems_proof prems j m) der,
  1936     Thm (deriv_rule1 (Proofterm.permute_prems_proof prems' j m) der,
  1934      {cert = cert,
  1937      {cert = cert,
  1935       tags = [],
  1938       tags = [],
  1936       maxidx = maxidx,
  1939       maxidx = maxidx,
  1937       constraints = constraints,
  1940       constraints = constraints,
  1938       shyps = shyps,
  1941       shyps = shyps,
  2077                   (ntps, (map normt (Bs @ As), normt C))
  2080                   (ntps, (map normt (Bs @ As), normt C))
  2078              end
  2081              end
  2079            val constraints' =
  2082            val constraints' =
  2080              union_constraints constraints1 constraints2
  2083              union_constraints constraints1 constraints2
  2081              |> insert_constraints_env (Context.certificate_theory cert) env;
  2084              |> insert_constraints_env (Context.certificate_theory cert) env;
       
  2085            fun bicompose_proof prf1 prf2 =
       
  2086              Proofterm.bicompose_proof flatten (map normt Bs) (map normt As) A oldAs n (nlift+1)
       
  2087                prf1 prf2
  2082            val th =
  2088            val th =
  2083              Thm (deriv_rule2
  2089              Thm (deriv_rule2
  2084                    ((if Envir.is_empty env then I
  2090                    ((if Envir.is_empty env then I
  2085                      else if Envir.above env smax then
  2091                      else if Envir.above env smax then
  2086                        (fn f => fn der => f (Proofterm.norm_proof' env der))
  2092                        (fn f => fn der => f (Proofterm.norm_proof' env der))
  2087                      else
  2093                      else
  2088                        curry op oo (Proofterm.norm_proof' env))
  2094                        curry op oo (Proofterm.norm_proof' env)) bicompose_proof) rder' sder,
  2089                     (Proofterm.bicompose_proof flatten Bs oldAs As A n (nlift+1))) rder' sder,
       
  2090                 {tags = [],
  2095                 {tags = [],
  2091                  maxidx = Envir.maxidx_of env,
  2096                  maxidx = Envir.maxidx_of env,
  2092                  constraints = constraints',
  2097                  constraints = constraints',
  2093                  shyps = Envir.insert_sorts env (Sorts.union shyps1 shyps2),
  2098                  shyps = Envir.insert_sorts env (Sorts.union shyps1 shyps2),
  2094                  hyps = union_hyps hyps1 hyps2,
  2099                  hyps = union_hyps hyps1 hyps2,