src/Pure/conjunction.ML
author wenzelm
Sun, 19 May 2024 18:43:45 +0200
changeset 80181 aa92c0f96036
parent 79339 8eb7e325f40d
permissions -rw-r--r--
provide scala-3.4.2, but do not activate it: scala-3.3.x is LTS version;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/conjunction.ML
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     3
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     4
Meta-level conjunction.
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     5
*)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     6
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     7
signature CONJUNCTION =
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     8
sig
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
     9
  val conjunction: cterm
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    10
  val mk_conjunction: cterm * cterm -> cterm
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    11
  val mk_conjunction_balanced: cterm list -> cterm
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    12
  val dest_conjunction: cterm -> cterm * cterm
30823
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    13
  val dest_conjunctions: cterm -> cterm list
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    14
  val cong: thm -> thm -> thm
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    15
  val convs: (cterm -> thm) -> cterm -> thm
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    16
  val conjunctionD1: thm
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    17
  val conjunctionD2: thm
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    18
  val conjunctionI: thm
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    19
  val intr: thm -> thm -> thm
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    20
  val intr_balanced: thm list -> thm
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    21
  val elim: thm -> thm * thm
60623
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
    22
  val elim_conjunctions: thm -> thm list
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    23
  val elim_balanced: int -> thm -> thm list
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    24
  val curry_balanced: int -> thm -> thm
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    25
  val uncurry_balanced: int -> thm -> thm
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    26
end;
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    27
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    28
structure Conjunction: CONJUNCTION =
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    29
struct
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    30
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    31
(** abstract syntax **)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    32
62876
507c90523113 clarified modules -- simplified bootstrap;
wenzelm
parents: 60825
diff changeset
    33
fun certify t = Thm.global_cterm_of (Context.the_global_context ()) t;
33384
1b5ba4e6a953 modernized structure Simple_Syntax;
wenzelm
parents: 33277
diff changeset
    34
val read_prop = certify o Simple_Syntax.read_prop;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    35
26485
b90d1fc201de certify wrt. dynamic context;
wenzelm
parents: 26424
diff changeset
    36
val true_prop = certify Logic.true_prop;
b90d1fc201de certify wrt. dynamic context;
wenzelm
parents: 26424
diff changeset
    37
val conjunction = certify Logic.conjunction;
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    38
46497
89ccf66aa73d renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents: 43329
diff changeset
    39
fun mk_conjunction (A, B) = Thm.apply (Thm.apply conjunction A) B;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    40
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    41
fun mk_conjunction_balanced [] = true_prop
32765
3032c0308019 modernized Balanced_Tree;
wenzelm
parents: 30823
diff changeset
    42
  | mk_conjunction_balanced ts = Balanced_Tree.make mk_conjunction ts;
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    43
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    44
fun dest_conjunction ct =
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    45
  (case Thm.term_of ct of
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 24976
diff changeset
    46
    (Const ("Pure.conjunction", _) $ _ $ _) => Thm.dest_binop ct
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    47
  | _ => raise TERM ("dest_conjunction", [Thm.term_of ct]));
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    48
30823
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    49
fun dest_conjunctions ct =
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    50
  (case try dest_conjunction ct of
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    51
    NONE => [ct]
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    52
  | SOME (A, B) => dest_conjunctions A @ dest_conjunctions B);
eb99b9134f2e added dest_conjunctions (cf. Logic.dest_conjunctions);
wenzelm
parents: 29606
diff changeset
    53
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    54
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    55
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    56
(** derived rules **)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    57
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    58
(* conversion *)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    59
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    60
val cong = Thm.combination o Thm.combination (Thm.reflexive conjunction);
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    61
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    62
fun convs cv ct =
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    63
  (case try dest_conjunction ct of
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    64
    NONE => cv ct
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
    65
  | SOME (A, B) => cong (convs cv A) (convs cv B));
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    66
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    67
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    68
(* intro/elim *)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    69
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    70
local
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    71
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60623
diff changeset
    72
val A = read_prop "A" and vA = (("A", 0), propT);
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60623
diff changeset
    73
val B = read_prop "B" and vB = (("B", 0), propT);
24241
424cb8b5e5b4 SimpleSyntax.read_prop;
wenzelm
parents: 23535
diff changeset
    74
val C = read_prop "C";
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 64556
diff changeset
    75
val ABC = read_prop "A \<Longrightarrow> B \<Longrightarrow> C";
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28674
diff changeset
    76
val A_B = read_prop "A &&& B";
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    77
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 24976
diff changeset
    78
val conjunction_def =
62876
507c90523113 clarified modules -- simplified bootstrap;
wenzelm
parents: 60825
diff changeset
    79
  Thm.unvarify_axiom (Context.the_global_context ()) "Pure.conjunction_def";
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    80
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    81
fun conjunctionD which =
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    82
  Drule.implies_intr_list [A, B] (Thm.assume (which (A, B))) COMP
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26485
diff changeset
    83
  Thm.forall_elim_vars 0 (Thm.equal_elim conjunction_def (Thm.assume A_B));
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    84
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    85
in
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    86
56436
30ccec1e82fb more source positions;
wenzelm
parents: 46497
diff changeset
    87
val conjunctionD1 =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62876
diff changeset
    88
  Drule.store_standard_thm (Binding.make ("conjunctionD1", \<^here>)) (conjunctionD #1);
56436
30ccec1e82fb more source positions;
wenzelm
parents: 46497
diff changeset
    89
30ccec1e82fb more source positions;
wenzelm
parents: 46497
diff changeset
    90
val conjunctionD2 =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62876
diff changeset
    91
  Drule.store_standard_thm (Binding.make ("conjunctionD2", \<^here>)) (conjunctionD #2);
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
    92
33277
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    93
val conjunctionI =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62876
diff changeset
    94
  Drule.store_standard_thm (Binding.make ("conjunctionI", \<^here>))
33277
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    95
    (Drule.implies_intr_list [A, B]
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    96
      (Thm.equal_elim
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    97
        (Thm.symmetric conjunction_def)
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    98
        (Thm.forall_intr C (Thm.implies_intr ABC
1bdc3c732fdd Drule.store: proper binding;
wenzelm
parents: 32765
diff changeset
    99
          (Drule.implies_elim_list (Thm.assume ABC) [Thm.assume A, Thm.assume B])))));
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   100
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   101
20508
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   102
fun intr tha thb =
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   103
  Thm.implies_elim
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   104
    (Thm.implies_elim
77879
wenzelm
parents: 74282
diff changeset
   105
      (Thm.instantiate (TVars.empty, Vars.make2 (vA, Thm.cprop_of tha) (vB, Thm.cprop_of thb))
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 67721
diff changeset
   106
        conjunctionI)
20508
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   107
    tha)
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   108
  thb;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   109
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   110
fun elim th =
20508
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   111
  let
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   112
    val (A, B) = dest_conjunction (Thm.cprop_of th)
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   113
      handle TERM (msg, _) => raise THM (msg, 0, [th]);
77879
wenzelm
parents: 74282
diff changeset
   114
    val inst = Thm.instantiate (TVars.empty, Vars.make2 (vA, A) (vB, B));
20508
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   115
  in
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   116
   (Thm.implies_elim (inst conjunctionD1) th,
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   117
    Thm.implies_elim (inst conjunctionD2) th)
8182d961c7cc intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
wenzelm
parents: 20260
diff changeset
   118
  end;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   119
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   120
end;
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   121
60623
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
   122
fun elim_conjunctions th =
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
   123
  (case try elim th of
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
   124
    NONE => [th]
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
   125
  | SOME (th1, th2) => elim_conjunctions th1 @ elim_conjunctions th2);
be39fe6c5620 support for subgoal focus command;
wenzelm
parents: 59621
diff changeset
   126
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   127
23535
58147e5bd070 removed obsolete mk_conjunction_list, intr/elim_list;
wenzelm
parents: 23422
diff changeset
   128
(* balanced conjuncts *)
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   129
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   130
fun intr_balanced [] = asm_rl
32765
3032c0308019 modernized Balanced_Tree;
wenzelm
parents: 30823
diff changeset
   131
  | intr_balanced ths = Balanced_Tree.make (uncurry intr) ths;
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   132
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   133
fun elim_balanced 0 _ = []
32765
3032c0308019 modernized Balanced_Tree;
wenzelm
parents: 30823
diff changeset
   134
  | elim_balanced n th = Balanced_Tree.dest elim n th;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   135
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   136
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   137
(* currying *)
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   138
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   139
local
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   140
62876
507c90523113 clarified modules -- simplified bootstrap;
wenzelm
parents: 60825
diff changeset
   141
val bootstrap_thy = Context.the_global_context ();
60815
c93a83472eab clarified context;
wenzelm
parents: 60642
diff changeset
   142
c93a83472eab clarified context;
wenzelm
parents: 60642
diff changeset
   143
fun conjs n =
c93a83472eab clarified context;
wenzelm
parents: 60642
diff changeset
   144
  let
c93a83472eab clarified context;
wenzelm
parents: 60642
diff changeset
   145
    val As =
c93a83472eab clarified context;
wenzelm
parents: 60642
diff changeset
   146
      map (fn A => Thm.global_cterm_of bootstrap_thy (Free (A, propT)))
79339
8eb7e325f40d minor performance tuning: shorter names;
wenzelm
parents: 79338
diff changeset
   147
        (Name.invent Name.context "" n);
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   148
  in (As, mk_conjunction_balanced As) end;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   149
24241
424cb8b5e5b4 SimpleSyntax.read_prop;
wenzelm
parents: 23535
diff changeset
   150
val B = read_prop "B";
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   151
79338
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   152
fun gen_rule idx rule =
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   153
  let val frees = Names.build (rule |> Thm.fold_terms {hyps = true} Names.add_free_names)
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   154
  in rule |> Thm.generalize (Names.empty, frees) idx end;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   155
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   156
(*
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 64556
diff changeset
   157
  A1 &&& ... &&& An \<Longrightarrow> B
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   158
  -----------------------
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 64556
diff changeset
   159
  A1 \<Longrightarrow> ... \<Longrightarrow> An \<Longrightarrow> B
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   160
*)
79338
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   161
fun curry_balanced_rule idx n =
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   162
  let
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   163
    val (As, C) = conjs n;
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   164
    val D = Drule.mk_implies (C, B);
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   165
  in
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   166
    Thm.implies_elim (Thm.assume D) (intr_balanced (map Thm.assume As))
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   167
    |> Drule.implies_intr_list (D :: As)
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   168
    |> gen_rule idx
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   169
  end;
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   170
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   171
(*
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 64556
diff changeset
   172
  A1 \<Longrightarrow> ... \<Longrightarrow> An \<Longrightarrow> B
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   173
  -----------------------
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 64556
diff changeset
   174
  A1 &&& ... &&& An \<Longrightarrow> B
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   175
*)
79338
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   176
fun uncurry_balanced_rule idx n =
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   177
  let
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   178
    val (As, C) = conjs n;
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   179
    val D = Drule.list_implies (As, B);
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   180
  in
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   181
    Drule.implies_elim_list (Thm.assume D) (elim_balanced n (Thm.assume C))
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   182
    |> Drule.implies_intr_list [D, C]
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   183
    |> gen_rule idx
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   184
  end;
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   185
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   186
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   187
(* static vs. dynamic rules *)
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   188
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   189
fun make_rules make = (make, Vector.tabulate (10, fn i => make 0 (i + 2)));
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   190
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   191
fun apply_rule (make, rules) n thm =
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   192
  if n < 2 then thm
23422
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   193
  else
4a368c087f58 balanced conjunctions;
wenzelm
parents: 21565
diff changeset
   194
    let
79338
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   195
      val idx = Thm.maxidx_of thm + 1;
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   196
      val rule =
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   197
        (case try Vector.sub (rules, n - 2) of
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   198
          SOME rule => Thm.incr_indexes idx rule
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   199
        | NONE => make idx n);
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   200
    in Thm.adjust_maxidx_thm ~1 (thm COMP rule) end;
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   201
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   202
in
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   203
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   204
val curry_balanced = apply_rule (make_rules curry_balanced_rule);
b3b0950ef24e minor performance tuning: static vs. dynamic rules;
wenzelm
parents: 79337
diff changeset
   205
val uncurry_balanced = apply_rule (make_rules uncurry_balanced_rule);
19416
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   206
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   207
end;
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   208
4198e7698f6a Meta-level conjunction.
wenzelm
parents:
diff changeset
   209
end;