src/Provers/project_rule.ML
author wenzelm
Thu Dec 22 00:29:17 2005 +0100 (2005-12-22)
changeset 18483 c3027c8df1bf
child 19874 cc4b2b882e4c
permissions -rw-r--r--
Transform mutual rule into projection.
wenzelm@18483
     1
(*  Title:      Provers/project_rule.ML
wenzelm@18483
     2
    ID:         $Id$
wenzelm@18483
     3
    Author:     Makarius
wenzelm@18483
     4
wenzelm@18483
     5
Transform mutual rule:
wenzelm@18483
     6
  HH ==> (x1:A1 --> P1 x1) & ... & (xn:An --> Pn xn)
wenzelm@18483
     7
into projection:
wenzelm@18483
     8
  xi:Ai ==> HH ==> Pi xi
wenzelm@18483
     9
*)
wenzelm@18483
    10
wenzelm@18483
    11
signature PROJECT_RULE_DATA =
wenzelm@18483
    12
sig
wenzelm@18483
    13
  val conjunct1: thm
wenzelm@18483
    14
  val conjunct2: thm
wenzelm@18483
    15
  val mp: thm
wenzelm@18483
    16
end;
wenzelm@18483
    17
wenzelm@18483
    18
signature PROJECT_RULE =
wenzelm@18483
    19
sig
wenzelm@18483
    20
  val project: thm -> int -> thm
wenzelm@18483
    21
  val projections: thm -> thm list
wenzelm@18483
    22
end;
wenzelm@18483
    23
wenzelm@18483
    24
functor ProjectRuleFun(Data: PROJECT_RULE_DATA): PROJECT_RULE =
wenzelm@18483
    25
struct
wenzelm@18483
    26
wenzelm@18483
    27
fun conj1 th = th RS Data.conjunct1;
wenzelm@18483
    28
fun conj2 th = th RS Data.conjunct2;
wenzelm@18483
    29
fun imp th = th RS Data.mp;
wenzelm@18483
    30
wenzelm@18483
    31
val freeze = Drule.zero_var_indexes #> Drule.freeze_all;
wenzelm@18483
    32
wenzelm@18483
    33
fun project rule i =
wenzelm@18483
    34
  let
wenzelm@18483
    35
    fun proj 1 th = the_default th (try conj1 th)
wenzelm@18483
    36
      | proj k th = proj (k - 1) (conj2 th);
wenzelm@18483
    37
    fun prems k th =
wenzelm@18483
    38
      (case try imp th of
wenzelm@18483
    39
        NONE => (k, th)
wenzelm@18483
    40
      | SOME th' => prems (k + 1) th');
wenzelm@18483
    41
  in
wenzelm@18483
    42
    rule
wenzelm@18483
    43
    |> freeze
wenzelm@18483
    44
    |> proj i
wenzelm@18483
    45
    |> prems 0 |-> (fn k =>
wenzelm@18483
    46
      Thm.permute_prems 0 (~ k)
wenzelm@18483
    47
      #> Drule.standard'
wenzelm@18483
    48
      #> RuleCases.save rule
wenzelm@18483
    49
      #> RuleCases.add_consumes k)
wenzelm@18483
    50
  end;
wenzelm@18483
    51
wenzelm@18483
    52
fun projections rule =
wenzelm@18483
    53
  let
wenzelm@18483
    54
    fun projs k th =
wenzelm@18483
    55
      (case try conj2 th of
wenzelm@18483
    56
        NONE => k
wenzelm@18483
    57
      | SOME th' => projs (k + 1) th');
wenzelm@18483
    58
    val n = projs 1 (freeze rule);
wenzelm@18483
    59
  in map (project rule) (1 upto n) end;
wenzelm@18483
    60
wenzelm@18483
    61
end;