QuotMain.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 26 Nov 2009 21:16:59 +0100
changeset 404 d676974e3c89
parent 403 4771198ecfd8
child 405 8bc7428745ad
permissions -rw-r--r--
more tuning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotMain
6
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     2
imports QuotScript QuotList Prove
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
     3
uses ("quotient_info.ML") 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
     4
     ("quotient.ML")
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
     5
     ("quotient_def.ML")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    17
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    20
  ABS::"'a \<Rightarrow> 'b"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    21
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    25
  REP::"'b \<Rightarrow> 'a"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    26
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    29
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  then have "R x (Eps (R x))" by (rule someI)
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    34
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    39
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    40
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    41
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    43
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    53
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    59
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    65
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    71
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    72
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    73
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    74
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    75
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    76
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    86
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    87
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    88
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    89
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    90
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    91
  have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    92
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    93
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    94
  ultimately show "R a c" unfolding TRANS_def by blast
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    95
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    96
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    97
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    98
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    99
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   100
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   101
  have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   102
  then show "R b a" using ab unfolding SYM_def by blast
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   103
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   104
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   105
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   106
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   107
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   108
  shows "R a b = R c d"
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   109
using ac bd
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   110
by (blast intro: R_trans R_sym)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   111
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   112
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   113
  shows "R (REP a) (REP b) \<equiv> (a = b)"
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   114
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   115
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   116
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   117
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   118
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   119
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   120
      where eqs: "Rep a = R x" "Rep b = R y" by blast
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   121
    from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   122
    then have "R x (Eps (R y))" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   123
    then have "R (Eps (R y)) x" using R_sym by blast
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   124
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   125
    then have "R x y" using R_sym by blast
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   126
    then have "ABS x = ABS y" using thm11 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   127
    then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   128
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   129
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   130
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   131
    have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   132
    then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   133
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   134
  then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   135
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   136
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   141
(* the auxiliary data for the quotient types *)
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
   142
use "quotient_info.ML"
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   143
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   144
declare [[map list = (map, LIST_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   145
declare [[map * = (prod_fun, prod_rel)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   146
declare [[map "fun" = (fun_map, FUN_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   147
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   148
ML {* maps_lookup @{theory} "List.list" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   149
ML {* maps_lookup @{theory} "*" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   150
ML {* maps_lookup @{theory} "fun" *}
174
09048a951dca moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   151
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   152
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   153
(* definition of the quotient types *)
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   154
(* FIXME: should be called quotient_typ.ML *)
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   155
use "quotient.ML"
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   156
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   157
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   158
(* lifting of constants *)
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   159
use "quotient_def.ML"
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   160
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   161
(* TODO: Consider defining it with an "if"; sth like:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   162
   Babs p m = \<lambda>x. if x \<in> p then m x else undefined
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   163
*)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   164
definition
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   165
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   166
where
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   167
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   168
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   169
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   170
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   171
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   172
lemma atomize_eqv[atomize]:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   173
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   174
proof
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   175
  assume "A \<equiv> B"
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   176
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   177
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   178
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   179
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   180
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   181
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   182
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   183
    then show "A = B" using * by simp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   184
  next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   185
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   186
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   187
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   188
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   189
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   190
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   191
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   192
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   193
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   194
let
221
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 219
diff changeset
   195
  val thm' = Thm.freezeT (forall_intr_vars thm)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   196
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   197
in
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   198
  @{thm equal_elim_rule1} OF [thm'', thm']
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   199
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   200
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   201
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   202
section {* infrastructure about id *}
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   203
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   204
(* Need to have a meta-equality *)
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   205
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   206
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   207
by (simp add: id_def)
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   208
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   209
(* TODO: can be also obtained with: *)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   210
ML {* symmetric (eq_reflection OF @{thms id_def}) *}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   211
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   212
lemma prod_fun_id: "prod_fun id id \<equiv> id"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   213
by (rule eq_reflection) (simp add: prod_fun_def)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   214
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   215
lemma map_id: "map id \<equiv> id"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   216
apply (rule eq_reflection)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   217
apply (rule ext)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   218
apply (rule_tac list="x" in list.induct)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   219
apply (simp_all)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   220
done
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   221
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   222
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   223
fun simp_ids lthy thm =
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   224
let 
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   225
  val thms = @{thms eq_reflection[OF FUN_MAP_I] 
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   226
                    eq_reflection[OF id_apply] 
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   227
                    id_def_sym prod_fun_id map_id} 
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   228
in
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   229
  MetaSimplifier.rewrite_rule thms thm
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   230
end
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   231
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   232
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   233
section {* Does the same as 'subst' in a given theorem *}
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   234
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   235
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   236
fun eqsubst_thm ctxt thms thm =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   237
  let
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   238
    val goalstate = Goal.init (Thm.cprop_of thm)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   239
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   240
      NONE => error "eqsubst_thm"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   241
    | SOME th => cprem_of th 1
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   242
    val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   243
    val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a');
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   244
    val cgoal = cterm_of (ProofContext.theory_of ctxt) goal
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   245
    val rt = Goal.prove_internal [] cgoal (fn _ => tac);
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   246
  in
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   247
    @{thm equal_elim_rule1} OF [rt, thm]
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   248
  end
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   249
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   250
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   251
section {*  Infrastructure about definitions *}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   252
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   253
(* expects atomized definitions *)
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   254
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   255
fun add_lower_defs_aux lthy thm =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   256
  let
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   257
    val e1 = @{thm fun_cong} OF [thm];
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   258
    val f = eqsubst_thm lthy @{thms fun_map.simps} e1;
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   259
    val g = simp_ids lthy f
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   260
  in
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   261
    (simp_ids lthy thm) :: (add_lower_defs_aux lthy g)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   262
  end
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   263
  handle _ => [simp_ids lthy thm]
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   264
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   265
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   266
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   267
fun add_lower_defs lthy def =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   268
  let
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   269
    val def_pre_sym = symmetric def
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   270
    val def_atom = atomize_thm def_pre_sym
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   271
    val defs_all = add_lower_defs_aux lthy def_atom
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   272
  in
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   273
    map Thm.varifyT defs_all
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   274
  end
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   275
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   276
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   277
section {* Infrastructure for collecting theorems for calling lifting *}
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   278
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   279
ML {*
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   280
fun lookup_quot_data lthy qty =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   281
  let
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   282
    val qty_name = fst (dest_Type qty)
314
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 311
diff changeset
   283
    val SOME quotdata = quotdata_lookup lthy qty_name
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   284
                  (* cu: Changed the lookup\<dots>not sure whether this works *)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   285
    (* TODO: Should no longer be needed *)
257
68bd5c2a1b96 Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 255
diff changeset
   286
    val rty = Logic.unvarifyT (#rtyp quotdata)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   287
    val rel = #rel quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   288
    val rel_eqv = #equiv_thm quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   289
    val rel_refl_pre = @{thm EQUIV_REFL} OF [rel_eqv]
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   290
    val rel_refl = @{thm spec} OF [MetaSimplifier.rewrite_rule [@{thm REFL_def}] rel_refl_pre]
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   291
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   292
    (rty, rel, rel_refl, rel_eqv)
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   293
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   294
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   295
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   296
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   297
fun lookup_quot_thms lthy qty_name =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   298
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   299
    val thy = ProofContext.theory_of lthy;
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   300
    val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   301
    val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
   302
    val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   303
    val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name)
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   304
  in
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
   305
    (trans2, reps_same, absrep, quot)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   306
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   307
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   308
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   309
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   310
fun lookup_quot_consts defs =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   311
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   312
    fun dest_term (a $ b) = (a, b);
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   313
    val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   314
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   315
    map (fst o dest_Const o snd o dest_term) def_terms
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   316
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   317
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   318
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   319
section {* Regularization *} 
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   320
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   321
(*
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   322
Regularizing an rtrm means:
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   323
 - quantifiers over a type that needs lifting are replaced by
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   324
   bounded quantifiers, for example:
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   325
      \<forall>x. P     \<Longrightarrow>     \<forall>x \<in> (Respects R). P  /  All (Respects R) P
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   326
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   327
   the relation R is given by the rty and qty;
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   328
 
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   329
 - abstractions over a type that needs lifting are replaced
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   330
   by bounded abstractions:
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   331
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   332
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   333
 - equalities over the type being lifted are replaced by
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   334
   corresponding relations:
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   335
      A = B     \<Longrightarrow>     A \<approx> B
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   336
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   337
   example with more complicated types of A, B:
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   338
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   339
*)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   340
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   341
ML {*
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   342
(* builds the relation that is the argument of respects *)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   343
fun mk_resp_arg lthy (rty, qty) =
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
   344
let
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
   345
  val thy = ProofContext.theory_of lthy
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   346
in  
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   347
  if rty = qty
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   348
  then HOLogic.eq_const rty
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   349
  else
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   350
    case (rty, qty) of
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   351
      (Type (s, tys), Type (s', tys')) =>
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   352
       if s = s' 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   353
       then let
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   354
              val SOME map_info = maps_lookup thy s
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   355
              val args = map (mk_resp_arg lthy) (tys ~~ tys')
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   356
            in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   357
              list_comb (Const (#relfun map_info, dummyT), args) 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   358
            end  
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   359
       else let  
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   360
              val SOME qinfo = quotdata_lookup_thy thy s'
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   361
              (* FIXME: check in this case that the rty and qty *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   362
              (* FIXME: correspond to each other *)
353
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
   363
              val (s, _) = dest_Const (#rel qinfo)
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
   364
              (* FIXME: the relation should only be the string       *)
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
   365
              (* FIXME: and the type needs to be calculated as below *) 
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   366
            in
353
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
   367
              Const (s, rty --> rty --> @{typ bool})
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   368
            end
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   369
      | _ => HOLogic.eq_const dummyT 
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
   370
             (* FIXME: check that the types correspond to each other? *)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   371
end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   372
*}
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
   373
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   374
ML {*
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   375
val mk_babs = Const (@{const_name "Babs"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   376
val mk_ball = Const (@{const_name "Ball"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   377
val mk_bex  = Const (@{const_name "Bex"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   378
val mk_resp = Const (@{const_name Respects}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   379
*}
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   380
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
   381
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   382
(* - applies f to the subterm of an abstraction,   *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   383
(*   otherwise to the given term,                  *)
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
   384
(* - used by REGULARIZE, therefore abstracted      *)
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   385
(*   variables do not have to be treated specially *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   386
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   387
fun apply_subt f trm1 trm2 =
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   388
  case (trm1, trm2) of
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   389
    (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   390
  | _ => f trm1 trm2
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   391
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   392
(* the major type of All and Ex quantifiers *)
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
   393
fun qnt_typ ty = domain_type (domain_type ty)  
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   394
*}
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
   395
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   396
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   397
(* produces a regularized version of rtm      *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   398
(* - the result is still not completely typed *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   399
(* - does not need any special treatment of   *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   400
(*   bound variables                          *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   401
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   402
fun REGULARIZE_trm lthy rtrm qtrm =
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   403
  case (rtrm, qtrm) of
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
   404
    (Abs (x, ty, t), Abs (x', ty', t')) =>
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   405
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   406
         val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   407
       in     
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
   408
         if ty = ty'
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
   409
         then Abs (x, ty, subtrm)
326
e755a5da14c8 my first version of repabs injection
Christian Urban <urbanc@in.tum.de>
parents: 325
diff changeset
   410
         else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   411
       end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   412
  | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   413
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   414
         val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   415
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   416
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   417
         then Const (@{const_name "All"}, ty) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   418
         else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   419
       end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   420
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   421
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   422
         val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   423
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   424
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   425
         then Const (@{const_name "Ex"}, ty) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   426
         else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   427
       end
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
   428
    (* FIXME: Should = only be replaced, when fully applied? *) 
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
   429
    (* Then there must be a 2nd argument                     *)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   430
  | (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   431
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   432
         val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   433
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   434
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   435
         then Const (@{const_name "op ="}, ty) $ subtrm
349
f507f088de73 domain_type in regularizing equality
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 348
diff changeset
   436
         else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   437
       end 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   438
  | (t1 $ t2, t1' $ t2') =>
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   439
       (REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2')
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   440
  | (Free (x, ty), Free (x', ty')) =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   441
       if x = x' 
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   442
       then rtrm     (* FIXME: check whether types corresponds *)
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
   443
       else raise (LIFT_MATCH "regularize (frees)")
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   444
  | (Bound i, Bound i') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   445
       if i = i' 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   446
       then rtrm 
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
   447
       else raise (LIFT_MATCH "regularize (bounds)")
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   448
  | (Const (s, ty), Const (s', ty')) =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   449
       if s = s' andalso ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   450
       then rtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   451
       else rtrm (* FIXME: check correspondence according to definitions *) 
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
   452
  | (rt, qt) => 
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
   453
       raise (LIFT_MATCH "regularize (default)")
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   454
*}
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   455
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   456
(*
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   457
To prove that the raw theorem implies the regularised one, 
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   458
we try in order:
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   459
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   460
 - Reflexivity of the relation
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   461
 - Assumption
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   462
 - Elimnating quantifiers on both sides of toplevel implication
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   463
 - Simplifying implications on both sides of toplevel implication
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   464
 - Ball (Respects ?E) ?P = All ?P
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   465
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   466
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   467
*)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   468
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   469
lemma universal_twice:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   470
  assumes *: "\<And>x. (P x \<longrightarrow> Q x)"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   471
  shows "(\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   472
using * by auto
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   473
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   474
lemma implication_twice:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   475
  assumes a: "c \<longrightarrow> a"
390
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   476
  assumes b: "b \<longrightarrow> d"
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   477
  shows "(a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   478
using a b by auto
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   479
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   480
(* version of REGULARIZE_tac including debugging information *)
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   481
ML {*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   482
fun my_print_tac ctxt s thm =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   483
let
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   484
  val prems_str = prems_of thm
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   485
                  |> map (Syntax.string_of_term ctxt)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   486
                  |> cat_lines
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   487
  val _ = tracing (s ^ "\n" ^ prems_str)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   488
in
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   489
  Seq.single thm
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   490
end
400
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   491
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   492
fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))]
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   493
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   494
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   495
ML {*
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   496
fun regularize_tac ctxt rel_eqv rel_refl =
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   497
  (ObjectLogic.full_atomize_tac) THEN'
400
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   498
  REPEAT_ALL_NEW (FIRST'
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   499
   [(K (print_tac "start")) THEN' (K no_tac),
390
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   500
    DT ctxt "1" (rtac rel_refl),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   501
    DT ctxt "2" atac,
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   502
    DT ctxt "3" (rtac @{thm universal_twice}),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   503
    DT ctxt "4" (rtac @{thm impI} THEN' atac),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   504
    DT ctxt "5" (rtac @{thm implication_twice}),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   505
    DT ctxt "6" (EqSubst.eqsubst_tac ctxt [0]
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   506
      [(@{thm equiv_res_forall} OF [rel_eqv]),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   507
       (@{thm equiv_res_exists} OF [rel_eqv])]),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   508
    (* For a = b \<longrightarrow> a \<approx> b *)
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   509
    DT ctxt "7" (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   510
    DT ctxt "8" (rtac @{thm RIGHT_RES_FORALL_REGULAR})
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   511
  ]);
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   512
*}
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   513
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   514
lemma move_forall: 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   515
  "(\<And>y. (\<forall>x\<in>P. A x y) \<longrightarrow> (\<forall>x. B x y)) \<Longrightarrow> ((\<forall>x\<in>P. \<forall>y. A x y) \<longrightarrow> (\<forall>x. \<forall>y. B x y))"
400
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   516
by auto
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   517
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   518
lemma move_exists: 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   519
  "((\<exists>y. \<exists>x. A x y) \<longrightarrow> (\<exists>y. \<exists>x\<in>P. B x y)) \<Longrightarrow> ((\<exists>x. \<exists>y. A x y) \<longrightarrow> (\<exists>x\<in>P. \<exists>y. B x y))"
400
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   520
by auto
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   521
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   522
lemma [mono]: 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   523
  "(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (Ex P) \<longrightarrow> (Ex Q)"
400
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   524
by blast
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   525
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   526
lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   527
by auto
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   528
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   529
lemma ball_respects_refl:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   530
  fixes P Q::"'a \<Rightarrow> bool"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   531
  and x::"'a"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   532
  assumes a: "EQUIV R2"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   533
  and     b: "\<And>f. Q (f x) \<longrightarrow> P (f x)"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   534
  shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. Q (f x)) \<longrightarrow> All (\<lambda>f. P (f x)))"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   535
apply(rule impI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   536
apply(rule allI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   537
apply(drule_tac x="\<lambda>y. f x" in bspec)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   538
apply(simp add: Respects_def IN_RESPECTS)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   539
apply(rule impI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   540
using a EQUIV_REFL_SYM_TRANS[of "R2"]
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   541
apply(simp add: REFL_def)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   542
using b
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   543
apply(simp)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   544
done
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   545
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   546
lemma bex_respects_refl:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   547
  fixes P Q::"'a \<Rightarrow> bool"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   548
  and x::"'a"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   549
  assumes a: "EQUIV R2"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   550
  and     b: "\<And>f. P (f x) \<longrightarrow> Q (f x)"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   551
  shows   "(Ex (\<lambda>f. P (f x))) \<longrightarrow> (Bex (Respects (R1 ===> R2)) (\<lambda>f. Q (f x)))"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   552
apply(rule impI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   553
apply(erule exE)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   554
thm bexI
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   555
apply(rule_tac x="\<lambda>y. f x" in bexI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   556
using b
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   557
apply(simp)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   558
apply(simp add: Respects_def IN_RESPECTS)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   559
apply(rule impI)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   560
using a EQUIV_REFL_SYM_TRANS[of "R2"]
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   561
apply(simp add: REFL_def)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   562
done
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   563
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   564
(* FIXME: OPTION_EQUIV, PAIR_EQUIV, ... *)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   565
ML {*
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   566
fun equiv_tac rel_eqvs =
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   567
  REPEAT_ALL_NEW(FIRST' [
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   568
    FIRST' (map rtac rel_eqvs),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   569
    rtac @{thm IDENTITY_EQUIV},
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   570
    rtac @{thm LIST_EQUIV}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   571
  ])
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   572
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   573
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   574
ML {*
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   575
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   576
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   577
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   578
ML {*
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   579
fun regularize_tac ctxt rel_eqvs rel_refl =
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   580
  let
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   581
    val subs1 = map (fn x => @{thm equiv_res_forall} OF [x]) rel_eqvs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   582
    val subs2 = map (fn x => @{thm equiv_res_exists} OF [x]) rel_eqvs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   583
    val subs = map (fn x => @{thm eq_reflection} OF [x]) (subs1 @ subs2)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   584
  in
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   585
  (ObjectLogic.full_atomize_tac) THEN'
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   586
  (simp_tac ((Simplifier.context ctxt empty_ss) addsimps subs))
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   587
  THEN'
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   588
  REPEAT_ALL_NEW (FIRST' [
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   589
    (rtac @{thm RIGHT_RES_FORALL_REGULAR}),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   590
    (rtac @{thm LEFT_RES_EXISTS_REGULAR}),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   591
    (resolve_tac (Inductive.get_monos ctxt)),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   592
    (rtac @{thm ball_respects_refl} THEN' (RANGE [SOLVES' (equiv_tac rel_eqvs)])),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   593
    (rtac @{thm bex_respects_refl} THEN' (RANGE [SOLVES' (equiv_tac rel_eqvs)])),
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   594
    rtac @{thm move_forall},
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   595
    rtac @{thm move_exists},
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   596
    (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   597
  ])
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   598
  end
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 398
diff changeset
   599
*}
390
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   600
1dd6a21cdd1c test with monos
Christian Urban <urbanc@in.tum.de>
parents: 388
diff changeset
   601
section {* Injections of REP and ABSes *}
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
   602
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   603
(*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   604
Injecting REPABS means:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   605
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   606
  For abstractions:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   607
  * If the type of the abstraction doesn't need lifting we recurse.
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   608
  * If it does we add RepAbs around the whole term and check if the
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   609
    variable needs lifting.
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   610
    * If it doesn't then we recurse
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   611
    * If it does we recurse and put 'RepAbs' around all occurences
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   612
      of the variable in the obtained subterm. This in combination
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   613
      with the RepAbs above will let us change the type of the
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   614
      abstraction with rewriting.
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   615
  For applications:
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   616
  * If the term is 'Respects' applied to anything we leave it unchanged
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   617
  * If the term needs lifting and the head is a constant that we know
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   618
    how to lift, we put a RepAbs and recurse
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   619
  * If the term needs lifting and the head is a free applied to subterms
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   620
    (if it is not applied we treated it in Abs branch) then we
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   621
    put RepAbs and recurse
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   622
  * Otherwise just recurse.
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   623
*)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   624
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   625
ML {*
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   626
fun mk_repabs lthy (T, T') trm = 
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   627
  Quotient_Def.get_fun repF lthy (T, T') 
354
2eb6d527dfe4 addded a tactic, which sets up the three goals of the `algorithm'
Christian Urban <urbanc@in.tum.de>
parents: 353
diff changeset
   628
    $ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   629
*}
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   630
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   631
ML {*
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   632
(* bound variables need to be treated properly,  *)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   633
(* as the type of subterms need to be calculated *)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   634
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   635
fun inj_REPABS lthy (rtrm, qtrm) =
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   636
let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   637
  val rty = fastype_of rtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   638
  val qty = fastype_of qtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   639
in
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   640
  case (rtrm, qtrm) of
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   641
    (Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   642
       Const (@{const_name "Ball"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   643
  | (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   644
       Const (@{const_name "Bex"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   645
  | (Const (@{const_name "Babs"}, T) $ r $ t, t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   646
       Const (@{const_name "Babs"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   647
  | (Abs (x, T, t), Abs (x', T', t')) =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   648
      let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   649
        val (y, s) = Term.dest_abs (x, T, t)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   650
        val (_, s') = Term.dest_abs (x', T', t')
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   651
        val yvar = Free (y, T)
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   652
        val result = lambda yvar (inj_REPABS lthy (s, s'))
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   653
      in
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   654
        if rty = qty 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   655
        then result
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   656
        else mk_repabs lthy (rty, qty) result
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   657
      end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   658
  | _ =>
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   659
      (* FIXME / TODO: this is a case that needs to be looked at          *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   660
      (* - variables get a rep-abs insde and outside an application       *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   661
      (* - constants only get a rep-abs on the outside of the application *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   662
      (* - applications get a rep-abs insde and outside an application    *)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   663
      let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   664
        val (rhead, rargs) = strip_comb rtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   665
        val (qhead, qargs) = strip_comb qtrm
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   666
        val rargs' = map (inj_REPABS lthy) (rargs ~~ qargs)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   667
      in
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   668
        if rty = qty
355
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   669
        then
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   670
          case (rhead, qhead) of
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   671
            (Free (_, T), Free (_, T')) =>
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   672
              if T = T' then list_comb (rhead, rargs')
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   673
              else list_comb (mk_repabs lthy (T, T') rhead, rargs')
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   674
          | _ => list_comb (rhead, rargs')
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   675
        else
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   676
          case (rhead, qhead, length rargs') of
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   677
            (Const _, Const _, 0) => mk_repabs lthy (rty, qty) rhead
355
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
   678
          | (Free (_, T), Free (_, T'), 0) => mk_repabs lthy (T, T') rhead
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   679
          | (Const _, Const _, _) =>  mk_repabs lthy (rty, qty) (list_comb (rhead, rargs')) 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   680
          | (Free (x, T), Free (x', T'), _) => 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   681
               mk_repabs lthy (rty, qty) (list_comb (mk_repabs lthy (T, T') rhead, rargs'))
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   682
          | (Abs _, Abs _, _ ) =>
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
   683
               mk_repabs lthy (rty, qty) (list_comb (inj_REPABS lthy (rhead, qhead), rargs')) 
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
   684
          | _ => raise (LIFT_MATCH "injection")
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   685
      end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   686
end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   687
*}
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
   688
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   689
section {* RepAbs Injection Tactic *}
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   690
(*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   691
To prove that the regularised theorem implies the abs/rep injected, we first
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   692
atomize it and then try:
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   693
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   694
 1) theorems 'trans2' from the appropriate QUOT_TYPE
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   695
 2) remove lambdas from both sides (LAMBDA_RES_TAC)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   696
 3) remove Ball/Bex from the right hand side
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   697
 4) use user-supplied RSP theorems
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   698
 5) remove rep_abs from the right side
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   699
 6) reflexivity of equality
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   700
 7) split applications of lifted type (apply_rsp)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   701
 8) split applications of non-lifted type (cong_tac)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   702
 9) apply extentionality
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   703
10) reflexivity of the relation
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   704
11) assumption
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   705
    (Lambdas under respects may have left us some assumptions)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   706
12) proving obvious higher order equalities by simplifying fun_rel
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   707
    (not sure if it is still needed?)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   708
13) unfolding lambda on one side
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   709
14) simplifying (= ===> =) for simpler respectfullness
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   710
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   711
*)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   712
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   713
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   714
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   715
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   716
    val pat = Drule.strip_imp_concl (cprop_of thm)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   717
    val insts = Thm.match (pat, concl)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   718
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   719
    rtac (Drule.instantiate insts thm) 1
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   720
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   721
  handle _ => no_tac)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   722
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   723
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   724
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   725
fun CHANGED' tac = (fn i => CHANGED (tac i))
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   726
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   727
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   728
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   729
fun quotient_tac quot_thm =
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   730
let
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   731
  val simps = @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] 
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   732
                     id_def_sym prod_fun_id map_id}
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   733
in
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   734
  REPEAT_ALL_NEW (FIRST' [
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   735
    rtac @{thm FUN_QUOTIENT},
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   736
    rtac quot_thm,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   737
    rtac @{thm IDENTITY_QUOTIENT},
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   738
    (* For functional identity quotients, (op = ---> op =) *)
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   739
    CHANGED' (simp_tac (HOL_ss addsimps simps))
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   740
  ])
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   741
end
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   742
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   743
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   744
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   745
fun LAMBDA_RES_TAC ctxt i st =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   746
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   747
    (_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   748
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   749
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   750
  | _ => fn _ => no_tac) i st
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   751
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   752
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   753
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   754
fun WEAK_LAMBDA_RES_TAC ctxt i st =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   755
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   756
    (_ $ (_ $ _ $ (Abs(_, _, _)))) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   757
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   758
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   759
  | (_ $ (_ $ (Abs(_, _, _)) $ _)) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   760
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   761
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   762
  | _ => fn _ => no_tac) i st
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   763
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   764
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   765
ML {* (* Legacy *)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   766
fun needs_lift (rty as Type (rty_s, _)) ty =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   767
  case ty of
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   768
    Type (s, tys) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   769
      (s = rty_s) orelse (exists (needs_lift rty) tys)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   770
  | _ => false
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   771
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   772
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   773
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   774
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   775
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   776
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   777
    val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl;
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   778
    val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP});
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   779
    val insts = Thm.match (pat, concl)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   780
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   781
    if needs_lift rty (type_of f) then
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   782
      rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   783
    else no_tac
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   784
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   785
  handle _ => no_tac)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   786
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   787
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   788
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   789
val ball_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   790
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   791
    val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   792
                 (Const (@{const_name Ball}, _) $ _)) = term_of concl
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   793
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   794
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   795
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   796
    THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   797
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   798
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   799
  handle _ => no_tac)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   800
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   801
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   802
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   803
val bex_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   804
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   805
    val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   806
                 (Const (@{const_name Bex}, _) $ _)) = term_of concl
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   807
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   808
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   809
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   810
    THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN'
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   811
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   812
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   813
  handle _ => no_tac)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   814
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   815
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   816
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   817
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   818
  (FIRST' [
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   819
    rtac trans_thm,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   820
    LAMBDA_RES_TAC ctxt,
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   821
    rtac @{thm RES_FORALL_RSP},
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   822
    ball_rsp_tac ctxt,
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   823
    rtac @{thm RES_EXISTS_RSP},
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   824
    bex_rsp_tac ctxt,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   825
    FIRST' (map rtac rsp_thms),
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   826
    rtac refl,
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   827
    (instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   828
         (RANGE [SOLVES' (quotient_tac quot_thm)])),
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   829
    (APPLY_RSP_TAC rty ctxt THEN' 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
   830
         (RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)])),
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   831
    Cong_Tac.cong_tac @{thm cong},
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   832
    rtac @{thm ext},
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   833
    rtac reflex_thm,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   834
    atac,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   835
    SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   836
    WEAK_LAMBDA_RES_TAC ctxt,
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   837
    CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   838
    ])
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   839
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   840
398
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   841
(*
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   842
To prove that the regularised theorem implies the abs/rep injected, 
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   843
we try:
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   844
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   845
 1) theorems 'trans2' from the appropriate QUOT_TYPE
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   846
 2) remove lambdas from both sides (LAMBDA_RES_TAC)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   847
 3) remove Ball/Bex from the right hand side
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   848
 4) use user-supplied RSP theorems
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   849
 5) remove rep_abs from the right side
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   850
 6) reflexivity of equality
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   851
 7) split applications of lifted type (apply_rsp)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   852
 8) split applications of non-lifted type (cong_tac)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   853
 9) apply extentionality
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   854
10) reflexivity of the relation
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   855
11) assumption
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   856
    (Lambdas under respects may have left us some assumptions)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   857
12) proving obvious higher order equalities by simplifying fun_rel
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   858
    (not sure if it is still needed?)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   859
13) unfolding lambda on one side
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   860
14) simplifying (= ===> =) for simpler respectfulness
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   861
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   862
*)
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   863
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   864
ML {*
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   865
fun r_mk_comb_tac' ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   866
  REPEAT_ALL_NEW (FIRST' [
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   867
    (K (print_tac "start")) THEN' (K no_tac), 
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   868
    DT ctxt "1" (rtac trans_thm),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   869
    DT ctxt "2" (LAMBDA_RES_TAC ctxt),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   870
    DT ctxt "3" (rtac @{thm RES_FORALL_RSP}),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   871
    DT ctxt "4" (ball_rsp_tac ctxt),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   872
    DT ctxt "5" (rtac @{thm RES_EXISTS_RSP}),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   873
    DT ctxt "6" (bex_rsp_tac ctxt),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   874
    DT ctxt "7" (FIRST' (map rtac rsp_thms)),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   875
    DT ctxt "8" (rtac refl),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   876
    DT ctxt "9" ((instantiate_tac @{thm REP_ABS_RSP(1)} ctxt 
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   877
                  THEN' (RANGE [SOLVES' (quotient_tac quot_thm)]))),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   878
    DT ctxt "A" ((APPLY_RSP_TAC rty ctxt THEN' 
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   879
                (RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)]))),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   880
    DT ctxt "B" (Cong_Tac.cong_tac @{thm cong}),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   881
    DT ctxt "C" (rtac @{thm ext}),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   882
    DT ctxt "D" (rtac reflex_thm),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   883
    DT ctxt "E" (atac),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   884
    DT ctxt "F" (SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   885
    DT ctxt "G" (WEAK_LAMBDA_RES_TAC ctxt),
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   886
    DT ctxt "H" (CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ})))
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   887
    ])
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   888
*}
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   889
fafcc54e531d some diagnostic code for r_mk_comb
Christian Urban <urbanc@in.tum.de>
parents: 391
diff changeset
   890
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   891
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   892
399
646bfe5905b3 tuned comments
Christian Urban <urbanc@in.tum.de>
parents: 398
diff changeset
   893
section {* Cleaning of the theorem *}
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   894
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   895
ML {*
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   896
fun applic_prs lthy absrep (rty, qty) =
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   897
  let
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   898
    fun mk_rep (T, T') tm = (Quotient_Def.get_fun repF lthy (T, T')) $ tm;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   899
    fun mk_abs (T, T') tm = (Quotient_Def.get_fun absF lthy (T, T')) $ tm;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   900
    val (raty, rgty) = Term.strip_type rty;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   901
    val (qaty, qgty) = Term.strip_type qty;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   902
    val vs = map (fn _ => "x") qaty;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   903
    val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   904
    val f = Free (fname, qaty ---> qgty);
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   905
    val args = map Free (vfs ~~ qaty);
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   906
    val rhs = list_comb(f, args);
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   907
    val largs = map2 mk_rep (raty ~~ qaty) args;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   908
    val lhs = mk_abs (rgty, qgty) (list_comb((mk_rep (raty ---> rgty, qaty ---> qgty) f), largs));
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   909
    val llhs = Syntax.check_term lthy lhs;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   910
    val eq = Logic.mk_equals (llhs, rhs);
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   911
    val ceq = cterm_of (ProofContext.theory_of lthy') eq;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   912
    val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps map_id id_apply});
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   913
    val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   914
    val t_id = MetaSimplifier.rewrite_rule @{thms eq_reflection[OF id_apply] id_def_sym} t;
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   915
  in
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   916
    singleton (ProofContext.export lthy' lthy) t_id
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   917
  end
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   918
*}
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   919
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   920
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   921
fun findaps_all rty tm =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   922
  case tm of
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   923
    Abs(_, T, b) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   924
      findaps_all rty (subst_bound ((Free ("x", T)), b))
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   925
  | (f $ a) => (findaps_all rty f @ findaps_all rty a)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   926
  | Free (_, (T as (Type ("fun", (_ :: _))))) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   927
      (if needs_lift rty T then [T] else [])
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   928
  | _ => [];
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   929
fun findaps rty tm = distinct (op =) (findaps_all rty tm)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   930
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   931
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   932
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   933
ML {*
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   934
fun find_aps_all rtm qtm =
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   935
  case (rtm, qtm) of
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   936
    (Abs(_, T1, s1), Abs(_, T2, s2)) =>
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   937
      find_aps_all (subst_bound ((Free ("x", T1)), s1)) (subst_bound ((Free ("x", T2)), s2))
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   938
  | (((f1 as (Free (_, T1))) $ a1), ((f2 as (Free (_, T2))) $ a2)) =>
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   939
      let
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   940
        val sub = (find_aps_all f1 f2) @ (find_aps_all a1 a2)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   941
      in
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   942
        if T1 = T2 then sub else (T1, T2) :: sub
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   943
      end
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   944
  | ((f1 $ a1), (f2 $ a2)) => (find_aps_all f1 f2) @ (find_aps_all a1 a2)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   945
  | _ => [];
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   946
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   947
fun find_aps rtm qtm = distinct (op =) (find_aps_all rtm qtm)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   948
*}
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   949
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
   950
ML {*
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   951
(* FIXME: allex_prs and lambda_prs can be one function *)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   952
fun allex_prs_tac lthy quot =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   953
  (EqSubst.eqsubst_tac lthy [0] @{thms FORALL_PRS[symmetric] EXISTS_PRS[symmetric]})
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   954
  THEN' (quotient_tac quot);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   955
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   956
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   957
ML {* 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   958
fun prep_trm thy (x, (T, t)) = 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   959
  (cterm_of thy (Var (x, T)), cterm_of thy t) 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   960
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   961
fun prep_ty thy (x, (S, ty)) = 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   962
  (ctyp_of thy (TVar (x, S)), ctyp_of thy ty) 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   963
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   964
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   965
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   966
fun matching_prs thy pat trm = 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   967
let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   968
  val univ = Unify.matchers thy [(pat, trm)] 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   969
  val SOME (env, _) = Seq.pull univ
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   970
  val tenv = Vartab.dest (Envir.term_env env)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   971
  val tyenv = Vartab.dest (Envir.type_env env)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   972
in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   973
  (map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   974
end 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   975
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   976
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   977
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   978
fun lambda_prs_conv1 ctxt quot ctrm =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   979
  case (term_of ctrm) of ((Const (@{const_name "fun_map"}, _) $ r1 $ a2) $ (Abs _)) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   980
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   981
    val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   982
    val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   983
    val thy = ProofContext.theory_of ctxt;
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   984
    val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d]
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   985
    val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d];
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   986
    val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   987
    val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS};
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   988
    val tac =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   989
      (compose_tac (false, lpi, 2)) THEN_ALL_NEW
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   990
      (quotient_tac quot);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   991
    val gc = Drule.strip_imp_concl (cprop_of lpi);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   992
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   993
    val te = @{thm eq_reflection} OF [t]
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   994
    val ts = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] te
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   995
    val tl = Thm.lhs_of ts
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   996
(*    val _ = tracing (Syntax.string_of_term @{context} (term_of ctrm));*)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   997
(*    val _ = tracing (Syntax.string_of_term @{context} (term_of tl));*)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   998
    val insts = matching_prs (ProofContext.theory_of ctxt) (term_of tl) (term_of ctrm);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
   999
    val ti = Drule.eta_contraction_rule (Drule.instantiate insts ts);
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1000
(*    val _ = tracing (Syntax.string_of_term @{context} (term_of (cprop_of ti)));*)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1001
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1002
    Conv.rewr_conv ti ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1003
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1004
(* TODO: We can add a proper error message... *)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1005
  handle Bind => Conv.all_conv ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1006
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1007
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1008
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1009
(* quot stands for the QUOTIENT theorems: *) 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1010
(* could be potentially all of them       *)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1011
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1012
fun lambda_prs_conv ctxt quot ctrm =
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1013
  case (term_of ctrm) of
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1014
    (Const (@{const_name "fun_map"}, _) $ _ $ _) $ (Abs _) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1015
      (Conv.arg_conv (Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1016
      then_conv (lambda_prs_conv1 ctxt quot)) ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1017
  | _ $ _ => Conv.comb_conv (lambda_prs_conv ctxt quot) ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1018
  | Abs _ => Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1019
  | _ => Conv.all_conv ctrm
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1020
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1021
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1022
ML {*
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1023
fun lambda_prs_tac ctxt quot = CSUBGOAL (fn (goal, i) =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1024
  CONVERSION
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1025
    (Conv.params_conv ~1 (fn ctxt =>
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1026
       (Conv.prems_conv ~1 (lambda_prs_conv ctxt quot) then_conv
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1027
          Conv.concl_conv ~1 (lambda_prs_conv ctxt quot))) ctxt) i)
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1028
*}
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1029
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1030
ML {*
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1031
fun clean_tac lthy quot defs reps_same absrep aps =
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1032
  let
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1033
    val lower = flat (map (add_lower_defs lthy) defs)
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1034
    val aps_thms = map (applic_prs lthy absrep) aps
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1035
  in
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1036
    EVERY' [TRY o REPEAT_ALL_NEW (allex_prs_tac lthy quot), 
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1037
            lambda_prs_tac lthy quot,
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1038
            TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] aps_thms),
387
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1039
            TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] lower),
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1040
            simp_tac (HOL_ss addsimps [reps_same])]
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1041
  end
f78aa16daae5 reordered the code
Christian Urban <urbanc@in.tum.de>
parents: 386
diff changeset
  1042
*}
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
  1043
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1044
section {* Genralisation of free variables in a goal *}
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1045
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1046
ML {*
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1047
fun inst_spec ctrm =
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1048
let
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1049
   val cty = ctyp_of_term ctrm
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1050
in
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1051
   Drule.instantiate' [SOME cty] [NONE, SOME ctrm] @{thm spec}
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1052
end
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1053
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1054
fun inst_spec_tac ctrms =
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1055
  EVERY' (map (dtac o inst_spec) ctrms)
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1056
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1057
fun abs_list (xs, t) = 
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1058
  fold (fn (x, T) => fn t' => HOLogic.all_const T $ (lambda (Free (x, T)) t')) xs t
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1059
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1060
fun gen_frees_tac ctxt =
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1061
 SUBGOAL (fn (concl, i) =>
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1062
  let
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1063
    val thy = ProofContext.theory_of ctxt
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1064
    val concl' = HOLogic.dest_Trueprop concl
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1065
    val vrs = Term.add_frees concl' []
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1066
    val cvrs = map (cterm_of thy o Free) vrs
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1067
    val concl'' = HOLogic.mk_Trueprop (abs_list (vrs, concl'))
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1068
    val goal = Logic.mk_implies (concl'', concl)
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1069
    val rule = Goal.prove ctxt [] [] goal 
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1070
      (K ((inst_spec_tac (rev cvrs) THEN' atac) 1))
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1071
  in
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1072
    rtac rule i
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1073
  end)  
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1074
*}
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1075
402
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
  1076
section {* General outline of the lifting procedure *}
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
  1077
dd64cca9265c recommited changes of comments
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
  1078
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1079
(* **************************************** *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1080
(*                                          *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1081
(* - A is the original raw theorem          *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1082
(* - B is the regularized theorem           *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1083
(* - C is the rep/abs injected version of B *) 
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1084
(* - D is the lifted theorem                *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1085
(*                                          *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1086
(* - b is the regularization step           *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1087
(* - c is the rep/abs injection step        *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1088
(* - d is the cleaning part                 *)
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1089
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1090
lemma procedure:
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1091
  assumes a: "A"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1092
  and     b: "A \<Longrightarrow> B"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1093
  and     c: "B = C"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1094
  and     d: "C = D"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1095
  shows   "D"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1096
  using a b c d
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1097
  by simp
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1098
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1099
ML {*
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1100
fun lift_error ctxt fun_str rtrm qtrm =
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1101
let
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1102
  val rtrm_str = Syntax.string_of_term ctxt rtrm
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1103
  val qtrm_str = Syntax.string_of_term ctxt qtrm
388
aa452130ae7f polishing
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
  1104
  val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str, 
aa452130ae7f polishing
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
  1105
             "and the lifted theorem\n", rtrm_str, "do not match"]
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1106
in
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1107
  error (space_implode " " msg)
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1108
end
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1109
*}
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1110
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1111
ML {* 
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1112
fun procedure_inst ctxt rtrm qtrm =
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1113
let
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1114
  val thy = ProofContext.theory_of ctxt
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1115
  val rtrm' = HOLogic.dest_Trueprop rtrm
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1116
  val qtrm' = HOLogic.dest_Trueprop qtrm
383
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1117
  val reg_goal = 
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1118
        Syntax.check_term ctxt (REGULARIZE_trm ctxt rtrm' qtrm')
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1119
        handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1120
  val inj_goal = 
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1121
        Syntax.check_term ctxt (inj_REPABS ctxt (reg_goal, qtrm'))
73a3670fb00e comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents: 382
diff changeset
  1122
        handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1123
in
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1124
  Drule.instantiate' []
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1125
    [SOME (cterm_of thy rtrm'),
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1126
     SOME (cterm_of thy reg_goal),
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1127
     SOME (cterm_of thy inj_goal)]
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1128
  @{thm procedure}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1129
end
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1130
*}
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1131
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1132
(* Left for debugging *)
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1133
ML {*
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1134
fun procedure_tac lthy rthm =
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1135
  ObjectLogic.full_atomize_tac
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1136
  THEN' gen_frees_tac lthy
374
980fdf92a834 fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents: 372
diff changeset
  1137
  THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1138
    let
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1139
      val rthm' = atomize_thm rthm
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1140
      val rule = procedure_inst context (prop_of rthm') (term_of concl)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1141
    in
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1142
      rtac rule THEN' rtac rthm'
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1143
    end 1) lthy
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1144
*}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1145
361
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1146
ML {*
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1147
fun lift_tac lthy rthm rel_eqv rel_refl rty quot trans2 rsp_thms reps_same absrep defs =
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1148
  ObjectLogic.full_atomize_tac
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1149
  THEN' gen_frees_tac lthy
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1150
  THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1151
    let
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1152
      val rthm' = atomize_thm rthm
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1153
      val rule = procedure_inst context (prop_of rthm') (term_of concl)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1154
      val aps = find_aps (prop_of rthm') (term_of concl)
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1155
    in
404
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1156
      rtac rule THEN' 
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1157
       RANGE [rtac rthm',
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1158
              regularize_tac lthy [rel_eqv] rel_refl,
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1159
              REPEAT_ALL_NEW (r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms),
d676974e3c89 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 403
diff changeset
  1160
              clean_tac lthy quot defs reps_same absrep aps]
389
d67240113f68 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 388
diff changeset
  1161
    end 1) lthy
361
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1162
*}
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1163
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1164
end
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1165
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1166