src/Provers/project_rule.ML
author wenzelm
Sun, 11 Jan 2009 21:49:59 +0100
changeset 29450 ac7f67be7f1f
parent 22568 ed7aa5a350ef
permissions -rw-r--r--
tuned categories;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     1
(*  Title:      Provers/project_rule.ML
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     4
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     5
Transform mutual rule:
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     6
  HH ==> (x1:A1 --> P1 x1) & ... & (xn:An --> Pn xn)
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     7
into projection:
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     8
  xi:Ai ==> HH ==> Pi xi
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
     9
*)
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    10
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    11
signature PROJECT_RULE_DATA =
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    12
sig
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    13
  val conjunct1: thm
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    14
  val conjunct2: thm
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    15
  val mp: thm
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    16
end;
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    17
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    18
signature PROJECT_RULE =
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    19
sig
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    20
  val project: Proof.context -> int -> thm -> thm
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    21
  val projects: Proof.context -> int list -> thm -> thm list
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    22
  val projections: Proof.context -> thm -> thm list
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    23
end;
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    24
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    25
functor ProjectRuleFun(Data: PROJECT_RULE_DATA): PROJECT_RULE =
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    26
struct
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    27
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    28
fun conj1 th = th RS Data.conjunct1;
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    29
fun conj2 th = th RS Data.conjunct2;
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    30
fun imp th = th RS Data.mp;
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    31
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    32
fun projects ctxt is raw_rule =
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    33
  let
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    34
    fun proj 1 th = the_default th (try conj1 th)
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    35
      | proj k th = proj (k - 1) (conj2 th);
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    36
    fun prems k th =
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    37
      (case try imp th of
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    38
        NONE => (k, th)
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    39
      | SOME th' => prems (k + 1) th');
22568
ed7aa5a350ef renamed Variable.import to import_thms (avoid clash with Alice keywords);
wenzelm
parents: 20218
diff changeset
    40
    val ((_, [rule]), ctxt') = Variable.import_thms true [raw_rule] ctxt;
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    41
    fun result i =
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    42
      rule
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    43
      |> proj i
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    44
      |> prems 0 |-> (fn k =>
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    45
        Thm.permute_prems 0 (~ k)
19905
7f480338b66e ProofContext.export: singleton;
wenzelm
parents: 19897
diff changeset
    46
        #> singleton (Variable.export ctxt' ctxt)
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    47
        #> Drule.zero_var_indexes
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    48
        #> RuleCases.save raw_rule
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    49
        #> RuleCases.add_consumes k);
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    50
  in map result is end;
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    51
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    52
fun project ctxt i th = hd (projects ctxt [i] th);
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    53
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    54
fun projections ctxt raw_rule =
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    55
  let
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    56
    fun projs k th =
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    57
      (case try conj2 th of
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    58
        NONE => k
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    59
      | SOME th' => projs (k + 1) th');
22568
ed7aa5a350ef renamed Variable.import to import_thms (avoid clash with Alice keywords);
wenzelm
parents: 20218
diff changeset
    60
    val ((_, [rule]), _) = Variable.import_thms true [raw_rule] ctxt;
19874
cc4b2b882e4c ProjectRule now context dependent;
wenzelm
parents: 18483
diff changeset
    61
  in projects ctxt (1 upto projs 1 rule) raw_rule end;
18483
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    62
c3027c8df1bf Transform mutual rule into projection.
wenzelm
parents:
diff changeset
    63
end;