src/Pure/thm.ML
changeset 18486 bf8637d9d53b
parent 18418 bf448d999b7e
child 18501 915105af2e80
equal deleted inserted replaced
18485:5959295f82d3 18486:bf8637d9d53b
   122   val assumption: int -> thm -> thm Seq.seq
   122   val assumption: int -> thm -> thm Seq.seq
   123   val eq_assumption: int -> thm -> thm
   123   val eq_assumption: int -> thm -> thm
   124   val rotate_rule: int -> int -> thm -> thm
   124   val rotate_rule: int -> int -> thm -> thm
   125   val permute_prems: int -> int -> thm -> thm
   125   val permute_prems: int -> int -> thm -> thm
   126   val rename_params_rule: string list * int -> thm -> thm
   126   val rename_params_rule: string list * int -> thm -> thm
       
   127   val bicompose_no_flatten: bool -> bool * thm * int -> int -> thm -> thm Seq.seq
   127   val bicompose: bool -> bool * thm * int -> int -> thm -> thm Seq.seq
   128   val bicompose: bool -> bool * thm * int -> int -> thm -> thm Seq.seq
   128   val biresolution: bool -> (bool * thm) list -> int -> thm -> thm Seq.seq
   129   val biresolution: bool -> (bool * thm) list -> int -> thm -> thm Seq.seq
   129   val invoke_oracle: theory -> xstring -> theory * Object.T -> thm
   130   val invoke_oracle: theory -> xstring -> theory * Object.T -> thm
   130   val invoke_oracle_i: theory -> string -> theory * Object.T -> thm
   131   val invoke_oracle_i: theory -> string -> theory * Object.T -> thm
   131 end;
   132 end;
  1374   nsubgoal is the number of new subgoals (written m above).
  1375   nsubgoal is the number of new subgoals (written m above).
  1375   Curried so that resolution calls dest_state only once.
  1376   Curried so that resolution calls dest_state only once.
  1376 *)
  1377 *)
  1377 local exception COMPOSE
  1378 local exception COMPOSE
  1378 in
  1379 in
  1379 fun bicompose_aux match (state, (stpairs, Bs, Bi, C), lifted)
  1380 fun bicompose_aux flatten match (state, (stpairs, Bs, Bi, C), lifted)
  1380                         (eres_flg, orule, nsubgoal) =
  1381                         (eres_flg, orule, nsubgoal) =
  1381  let val Thm{der=sder, maxidx=smax, shyps=sshyps, hyps=shyps, ...} = state
  1382  let val Thm{der=sder, maxidx=smax, shyps=sshyps, hyps=shyps, ...} = state
  1382      and Thm{der=rder, maxidx=rmax, shyps=rshyps, hyps=rhyps,
  1383      and Thm{der=rder, maxidx=rmax, shyps=rshyps, hyps=rhyps,
  1383              tpairs=rtpairs, prop=rprop,...} = orule
  1384              tpairs=rtpairs, prop=rprop,...} = orule
  1384          (*How many hyps to skip over during normalization*)
  1385          (*How many hyps to skip over during normalization*)
  1409                    ((if Envir.is_empty env then I
  1410                    ((if Envir.is_empty env then I
  1410                      else if Envir.above (smax, env) then
  1411                      else if Envir.above (smax, env) then
  1411                        (fn f => fn der => f (Pt.norm_proof' env der))
  1412                        (fn f => fn der => f (Pt.norm_proof' env der))
  1412                      else
  1413                      else
  1413                        curry op oo (Pt.norm_proof' env))
  1414                        curry op oo (Pt.norm_proof' env))
  1414                     (Pt.bicompose_proof Bs oldAs As A n)) rder' sder,
  1415                     (Pt.bicompose_proof flatten Bs oldAs As A n)) rder' sder,
  1415                  maxidx = maxidx,
  1416                  maxidx = maxidx,
  1416                  shyps = may_insert_env_sorts thy env (Sorts.union rshyps sshyps),
  1417                  shyps = may_insert_env_sorts thy env (Sorts.union rshyps sshyps),
  1417                  hyps = union_hyps rhyps shyps,
  1418                  hyps = union_hyps rhyps shyps,
  1418                  tpairs = ntpairs,
  1419                  tpairs = ntpairs,
  1419                  prop = Logic.list_implies normp}
  1420                  prop = Logic.list_implies normp}
  1425        let val (As1, rder') =
  1426        let val (As1, rder') =
  1426          if !Logic.auto_rename orelse not lifted then (As0, rder)
  1427          if !Logic.auto_rename orelse not lifted then (As0, rder)
  1427          else (map (rename_bvars(dpairs,tpairs,B)) As0,
  1428          else (map (rename_bvars(dpairs,tpairs,B)) As0,
  1428            Pt.infer_derivs' (Pt.map_proof_terms
  1429            Pt.infer_derivs' (Pt.map_proof_terms
  1429              (rename_bvars (dpairs, tpairs, Bound 0)) I) rder);
  1430              (rename_bvars (dpairs, tpairs, Bound 0)) I) rder);
  1430        in (map (Logic.flatten_params n) As1, As1, rder', n)
  1431        in (map (if flatten then (Logic.flatten_params n) else I) As1, As1, rder', n)
  1431           handle TERM _ =>
  1432           handle TERM _ =>
  1432           raise THM("bicompose: 1st premise", 0, [orule])
  1433           raise THM("bicompose: 1st premise", 0, [orule])
  1433        end;
  1434        end;
  1434      val env = Envir.empty(Int.max(rmax,smax));
  1435      val env = Envir.empty(Int.max(rmax,smax));
  1435      val BBi = if lifted then strip_assums2(B,Bi) else (B,Bi);
  1436      val BBi = if lifted then strip_assums2(B,Bi) else (B,Bi);
  1453  in  if eres_flg then eres(rev rAs)
  1454  in  if eres_flg then eres(rev rAs)
  1454      else res(Seq.pull(Unify.unifiers(thy, env, dpairs)))
  1455      else res(Seq.pull(Unify.unifiers(thy, env, dpairs)))
  1455  end;
  1456  end;
  1456 end;
  1457 end;
  1457 
  1458 
  1458 
  1459 fun bicompose0 flatten match arg i state =
  1459 fun bicompose match arg i state =
  1460     bicompose_aux flatten match (state, dest_state(state,i), false) arg;
  1460     bicompose_aux match (state, dest_state(state,i), false) arg;
  1461 
       
  1462 val bicompose_no_flatten = bicompose0 false;
       
  1463 val bicompose = bicompose0 true;
  1461 
  1464 
  1462 (*Quick test whether rule is resolvable with the subgoal with hyps Hs
  1465 (*Quick test whether rule is resolvable with the subgoal with hyps Hs
  1463   and conclusion B.  If eres_flg then checks 1st premise of rule also*)
  1466   and conclusion B.  If eres_flg then checks 1st premise of rule also*)
  1464 fun could_bires (Hs, B, eres_flg, rule) =
  1467 fun could_bires (Hs, B, eres_flg, rule) =
  1465     let fun could_reshyp (A1::_) = exists (fn H => could_unify (A1, H)) Hs
  1468     let fun could_reshyp (A1::_) = exists (fn H => could_unify (A1, H)) Hs
  1473 fun biresolution match brules i state =
  1476 fun biresolution match brules i state =
  1474     let val (stpairs, Bs, Bi, C) = dest_state(state,i);
  1477     let val (stpairs, Bs, Bi, C) = dest_state(state,i);
  1475         val lift = lift_rule (cprem_of state i);
  1478         val lift = lift_rule (cprem_of state i);
  1476         val B = Logic.strip_assums_concl Bi;
  1479         val B = Logic.strip_assums_concl Bi;
  1477         val Hs = Logic.strip_assums_hyp Bi;
  1480         val Hs = Logic.strip_assums_hyp Bi;
  1478         val comp = bicompose_aux match (state, (stpairs, Bs, Bi, C), true);
  1481         val comp = bicompose_aux true match (state, (stpairs, Bs, Bi, C), true);
  1479         fun res [] = Seq.empty
  1482         fun res [] = Seq.empty
  1480           | res ((eres_flg, rule)::brules) =
  1483           | res ((eres_flg, rule)::brules) =
  1481               if !Pattern.trace_unify_fail orelse
  1484               if !Pattern.trace_unify_fail orelse
  1482                  could_bires (Hs, B, eres_flg, rule)
  1485                  could_bires (Hs, B, eres_flg, rule)
  1483               then Seq.make (*delay processing remainder till needed*)
  1486               then Seq.make (*delay processing remainder till needed*)