QuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 10 Nov 2009 09:32:16 +0100
changeset 303 991b0e53f9dc
parent 302 a840c232e04e
child 307 9aa3aba71ecc
permissions -rw-r--r--
More code cleaning and commenting
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
297
28b264299590 updated to new Isabelle version and added a new example file
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
     8
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  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
    18
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    21
  ABS::"'a \<Rightarrow> 'b"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    22
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    26
  REP::"'b \<Rightarrow> 'a"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    27
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    30
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  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
    34
  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
    35
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    40
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    41
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    42
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    44
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  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
    47
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    54
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    60
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    66
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    72
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    73
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    74
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    75
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    76
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    77
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    87
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    88
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    89
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    90
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    91
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    92
  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
    93
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    94
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    95
  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
    96
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    97
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    98
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    99
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   100
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   101
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   102
  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
   103
  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
   104
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   105
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   106
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   107
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   108
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   109
  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
   110
using ac bd
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   111
by (blast intro: R_trans R_sym)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   112
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   113
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   114
  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
   115
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   116
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   117
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   118
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   119
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   120
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   121
      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
   122
    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
   123
    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
   124
    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
   125
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   126
    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
   127
    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
   128
    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
   129
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   130
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   131
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   132
    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
   133
    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
   134
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   135
  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
   136
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   137
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
127
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 126
diff changeset
   140
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
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
(* 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
   144
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
   145
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   146
declare [[map list = (map, LIST_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   147
declare [[map * = (prod_fun, prod_rel)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   148
declare [[map "fun" = (fun_map, FUN_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   149
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   150
ML {* maps_lookup @{theory} "List.list" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   151
ML {* maps_lookup @{theory} "*" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   152
ML {* maps_lookup @{theory} "fun" *}
174
09048a951dca moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   153
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
   154
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
(* 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
   156
(* 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
   157
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
   158
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
   159
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   160
(* lifting of constants *)
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   161
use "quotient_def.ML"
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   162
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   163
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   164
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   165
lemma atomize_eqv[atomize]: 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   166
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   167
proof
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   168
  assume "A \<equiv> B" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   169
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   170
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   171
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   172
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   173
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   174
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   175
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   176
    then show "A = B" using * by simp
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
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   179
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   180
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   181
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   182
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   183
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   184
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   185
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   186
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   187
let
221
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 219
diff changeset
   188
  val thm' = Thm.freezeT (forall_intr_vars thm)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   189
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   190
in
221
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 219
diff changeset
   191
  @{thm Pure.equal_elim_rule1} OF [thm'', thm']
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   192
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   193
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   194
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   195
ML {* atomize_thm @{thm list.induct} *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   196
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   197
section {* REGULARIZE *}
282
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   198
(*
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   199
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   200
Regularizing a theorem means:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   201
 - Quantifiers over a type that needs lifting are replaced by
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   202
   bounded quantifiers, for example:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   203
      \<forall>x. P     \<Longrightarrow>     \<forall>x\<in>(Respects R). P
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   204
 - Abstractions over a type that needs lifting are replaced
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   205
   by bounded abstractions:
282
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   206
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   207
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   208
 - Equalities over the type being lifted are replaced by
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   209
   appropriate relations:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   210
      A = B     \<Longrightarrow>     A \<approx> B
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   211
   Example with more complicated types of A, B:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   212
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   213
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   214
Regularizing is done in 3 phases:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   215
 - First a regularized term is created
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   216
 - Next we prove that the original theorem implies the new one
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   217
 - Finally using MP we get the new theorem.
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   218
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   219
To prove that the old theorem implies the new one, we first
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   220
atomize it and then try:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   221
 - Reflexivity of the relation
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   222
 - Assumption
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   223
 - Elimnating quantifiers on both sides of toplevel implication
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   224
 - Simplifying implications on both sides of toplevel implication
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   225
 - Ball (Respects ?E) ?P = All ?P
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   226
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   227
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   228
*)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   229
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   230
text {* tyRel takes a type and builds a relation that a quantifier over this
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   231
  type needs to respect. *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   232
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   233
fun tyRel ty rty rel lthy =
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   234
  if Sign.typ_instance (ProofContext.theory_of lthy) (ty, rty)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   235
  then rel
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   236
  else (case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   237
          Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   238
            let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   239
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   240
              val ty_out = ty --> ty --> @{typ bool};
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   241
              val tys_out = tys_rel ---> ty_out;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   242
            in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   243
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   244
               SOME (info) => list_comb (Const (#relfun info, tys_out),
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   245
                              map (fn ty => tyRel ty rty rel lthy) tys)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   246
             | NONE  => HOLogic.eq_const ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   247
            )
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   248
            end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   249
        | _ => HOLogic.eq_const ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   250
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   251
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   252
(* ML {* cterm_of @{theory} (tyRel @{typ "'a \<Rightarrow> 'a list \<Rightarrow> 't \<Rightarrow> 't"} (Logic.varifyT @{typ "'a list"}) @{term "f::('a list \<Rightarrow> 'a list \<Rightarrow> bool)"} @{context}) *} *)
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   253
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   254
definition
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   255
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   256
where
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   257
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   258
(* TODO: Consider defining it with an "if"; sth like:
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   259
   Babs p m = \<lambda>x. if x \<in> p then m x else undefined
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   260
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   261
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   262
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   263
fun needs_lift (rty as Type (rty_s, _)) ty =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   264
  case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   265
    Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   266
      (s = rty_s) orelse (exists (needs_lift rty) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   267
  | _ => false
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   268
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   269
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   270
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   271
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   272
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   273
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   274
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   275
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   276
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   277
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   278
(* applies f to the subterm of an abstractions, otherwise to the given term *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   279
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   280
fun apply_subt f trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   281
  case trm of
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   282
    Abs (x, T, t) => 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   283
       let 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   284
         val (x', t') = Term.dest_abs (x, T, t)
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   285
       in
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   286
         Term.absfree (x', T, f t') 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   287
       end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   288
  | _ => f trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   289
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   290
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   291
(* FIXME: if there are more than one quotient, then you have to look up the relation *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   292
ML {*
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   293
fun my_reg lthy rel rty trm =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   294
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   295
    Abs (x, T, t) =>
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   296
       if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   297
         let
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   298
            val rrel = tyRel T rty rel lthy
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   299
         in
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   300
           (mk_babs (fastype_of trm) T) $ (mk_resp T $ rrel) $ (apply_subt (my_reg lthy rel rty) trm)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   301
         end
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   302
       else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   303
         Abs(x, T, (apply_subt (my_reg lthy rel rty) t))
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   304
  | Const (@{const_name "All"}, ty) $ (t as Abs (x, T, _)) =>
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   305
       let
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   306
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   307
          val ty2 = domain_type ty1
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   308
          val rrel = tyRel T rty rel lthy
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   309
       in
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   310
         if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   311
           (mk_ball ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   312
         else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   313
           Const (@{const_name "All"}, ty) $ apply_subt (my_reg lthy rel rty) t
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   314
       end
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   315
  | Const (@{const_name "Ex"}, ty) $ (t as Abs (x, T, _)) =>
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   316
       let
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   317
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   318
          val ty2 = domain_type ty1
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   319
          val rrel = tyRel T rty rel lthy
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   320
       in
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   321
         if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   322
           (mk_bex ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   323
         else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   324
           Const (@{const_name "Ex"}, ty) $ apply_subt (my_reg lthy rel rty) t
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   325
       end
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   326
  | Const (@{const_name "op ="}, ty) $ t =>
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   327
      if needs_lift rty (fastype_of t) then
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   328
        (tyRel (fastype_of t) rty rel lthy) $ t
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   329
      else Const (@{const_name "op ="}, ty) $ (my_reg lthy rel rty t)
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   330
  | t1 $ t2 => (my_reg lthy rel rty t1) $ (my_reg lthy rel rty t2)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   331
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   332
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   333
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   334
(* For polymorphic types we need to find the type of the Relation term. *)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   335
(* TODO: we assume that the relation is a Constant. Is this always true? *)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   336
ML {*
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   337
fun my_reg_inst lthy rel rty trm =
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   338
  case rel of
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   339
    Const (n, _) => Syntax.check_term lthy
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   340
      (my_reg lthy (Const (n, dummyT)) (Logic.varifyT rty) trm)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   341
*}
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   342
288
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   343
(*
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   344
ML {*
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   345
  val r = Free ("R", dummyT);
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   346
  val t = (my_reg_inst @{context} r @{typ "'a list"} @{term "\<forall>(x::'b list). P x"});
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   347
  val t2 = Syntax.check_term @{context} t;
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   348
  cterm_of @{theory} t2
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   349
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   350
*)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   351
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   352
text {* Assumes that the given theorem is atomized *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   353
ML {*
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   354
  fun build_regularize_goal thm rty rel lthy =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   355
     Logic.mk_implies
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   356
       ((prop_of thm),
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   357
       (my_reg_inst lthy rel rty (prop_of thm)))
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   358
*}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   359
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   360
lemma universal_twice:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   361
  assumes *: "\<And>x. (P x \<longrightarrow> Q x)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   362
  shows "(\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   363
using * by auto
252
e30997c88050 Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 251
diff changeset
   364
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   365
lemma implication_twice:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   366
  assumes a: "c \<longrightarrow> a"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   367
  assumes b: "a \<Longrightarrow> b \<longrightarrow> d"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   368
  shows "(a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   369
using a b by auto
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   370
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   371
ML {*
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   372
fun regularize thm rty rel rel_eqv rel_refl lthy =
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   373
  let
288
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   374
    val goal = build_regularize_goal thm rty rel lthy;
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   375
    fun tac ctxt =
252
e30997c88050 Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 251
diff changeset
   376
      (ObjectLogic.full_atomize_tac) THEN'
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   377
      REPEAT_ALL_NEW (FIRST' [
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   378
        rtac rel_refl,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   379
        atac,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   380
        rtac @{thm universal_twice},
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   381
        (rtac @{thm impI} THEN' atac),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   382
        rtac @{thm implication_twice},
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   383
        EqSubst.eqsubst_tac ctxt [0]
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   384
          [(@{thm equiv_res_forall} OF [rel_eqv]),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   385
           (@{thm equiv_res_exists} OF [rel_eqv])],
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   386
        (* For a = b \<longrightarrow> a \<approx> b *)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   387
        (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   388
        (rtac @{thm RIGHT_RES_FORALL_REGULAR})
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   389
      ]);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   390
    val cthm = Goal.prove lthy [] [] goal
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   391
      (fn {context, ...} => tac context 1);
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   392
  in
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   393
    cthm OF [thm]
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   394
  end
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   395
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   396
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   397
section {* RepAbs injection *}
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   398
(*
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   399
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   400
RepAbs injection is done in the following phases:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   401
 1) build_repabs_term inserts rep-abs pairs in the term
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   402
 2) we prove the equality between the original theorem and this one
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   403
 3) we use Pure.equal_elim_rule1 to get the new theorem.
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   404
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   405
build_repabs_term does:
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   406
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   407
  For abstractions:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   408
  * If the type of the abstraction doesn't need lifting we recurse.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   409
  * If it does we add RepAbs around the whole term and check if the
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   410
    variable needs lifting.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   411
    * If it doesn't then we recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   412
    * If it does we recurse and put 'RepAbs' around all occurences
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   413
      of the variable in the obtained subterm. This in combination
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   414
      with the RepAbs above will let us change the type of the
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   415
      abstraction with rewriting.
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   416
  For applications:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   417
  * If the term is 'Respects' applied to anything we leave it unchanged
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   418
  * If the term needs lifting and the head is a constant that we know
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   419
    how to lift, we put a RepAbs and recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   420
  * If the term needs lifting and the head is a free applied to subterms
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   421
    (if it is not applied we treated it in Abs branch) then we
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   422
    put RepAbs and recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   423
  * Otherwise just recurse.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   424
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   425
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   426
To prove that the old theorem implies the new one, we first
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   427
atomize it and then try:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   428
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   429
 1) theorems 'trans2' from the appropriate QUOT_TYPE
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   430
 2) remove lambdas from both sides (LAMBDA_RES_TAC)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   431
 3) remove Ball/Bex from the right hand side
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   432
 4) use user-supplied RSP theorems
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   433
 5) remove rep_abs from the right side
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   434
 6) reflexivity of equality
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   435
 7) split applications of lifted type (apply_rsp)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   436
 8) split applications of non-lifted type (cong_tac)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   437
 9) apply extentionality
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   438
10) reflexivity of the relation
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   439
11) assumption
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   440
    (Lambdas under respects may have left us some assumptions)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   441
12) proving obvious higher order equalities by simplifying fun_rel
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   442
    (not sure if it is still needed?)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   443
13) unfolding lambda on one side
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   444
14) simplifying (= ===> =) for simpler respectfullness
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   445
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   446
*)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   447
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   448
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   449
(* changes (?'a ?'b raw) (?'a ?'b quo) (int 'b raw \<Rightarrow> bool) to (int 'b quo \<Rightarrow> bool) *)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   450
ML {*
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   451
fun exchange_ty lthy rty qty ty =
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   452
  let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   453
    val thy = ProofContext.theory_of lthy
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   454
  in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   455
    if Sign.typ_instance thy (ty, rty) then
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   456
      let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   457
        val inst = Sign.typ_match thy (rty, ty) Vartab.empty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   458
      in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   459
        Envir.subst_type inst qty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   460
      end
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   461
    else
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   462
      let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   463
        val (s, tys) = dest_Type ty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   464
      in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   465
        Type (s, map (exchange_ty lthy rty qty) tys)
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   466
      end
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   467
  end
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   468
  handle TYPE _ => ty (* for dest_Type *)
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   469
*}
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   470
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   471
(*consts Rl :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   472
axioms Rl_eq: "EQUIV Rl"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   473
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   474
quotient ql = "'a list" / "Rl"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   475
  by (rule Rl_eq)
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   476
ML {*
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   477
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "'a list"}) (Logic.varifyT @{typ "'a ql"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"});
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   478
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "nat \<times> nat"}) (Logic.varifyT @{typ "int"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"})
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   479
*}
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   480
*)
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   481
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   482
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   483
ML {*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   484
fun negF absF = repF
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   485
  | negF repF = absF
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   486
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   487
fun get_fun_noexchange flag (rty, qty) lthy ty =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   488
let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   489
  fun get_fun_aux s fs_tys =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   490
  let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   491
    val (fs, tys) = split_list fs_tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   492
    val (otys, ntys) = split_list tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   493
    val oty = Type (s, otys)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   494
    val nty = Type (s, ntys)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   495
    val ftys = map (op -->) tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   496
  in
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   497
   (case (maps_lookup (ProofContext.theory_of lthy) s) of
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   498
      SOME info => (list_comb (Const (#mapfun info, ftys ---> (oty --> nty)), fs), (oty, nty))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   499
    | NONE      => error ("no map association for type " ^ s))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   500
  end
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   501
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   502
  fun get_fun_fun fs_tys =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   503
  let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   504
    val (fs, tys) = split_list fs_tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   505
    val ([oty1, oty2], [nty1, nty2]) = split_list tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   506
    val oty = nty1 --> oty2
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   507
    val nty = oty1 --> nty2
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   508
    val ftys = map (op -->) tys
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   509
  in
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   510
    (list_comb (Const (@{const_name "fun_map"}, ftys ---> oty --> nty), fs), (oty, nty))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   511
  end
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   512
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   513
  val thy = ProofContext.theory_of lthy
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   514
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   515
  fun get_const flag (rty, qty) =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   516
  let 
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   517
    val qty_name = Long_Name.base_name (fst (dest_Type qty))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   518
  in
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   519
    case flag of
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   520
      absF => (Const (Sign.full_bname thy ("ABS_" ^ qty_name), rty --> qty), (rty, qty))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   521
    | repF => (Const (Sign.full_bname thy ("REP_" ^ qty_name), qty --> rty), (qty, rty))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   522
  end
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   523
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   524
  fun mk_identity ty = Abs ("", ty, Bound 0)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   525
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   526
in
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   527
  if (Sign.typ_instance thy (ty, rty))
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   528
  then (get_const flag (ty, (exchange_ty lthy rty qty ty)))
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   529
  else (case ty of
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   530
          TFree _ => (mk_identity ty, (ty, ty))
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   531
        | Type (_, []) => (mk_identity ty, (ty, ty))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   532
        | Type ("fun" , [ty1, ty2]) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   533
                 get_fun_fun [get_fun_noexchange (negF flag) (rty, qty) lthy ty1,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   534
                 get_fun_noexchange flag (rty, qty) lthy ty2]
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   535
        | Type (s, tys) => get_fun_aux s (map (get_fun_noexchange flag (rty, qty) lthy) tys)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   536
        | _ => raise ERROR ("no type variables"))
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   537
end
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   538
fun get_fun_noex flag (rty, qty) lthy ty =
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   539
  fst (get_fun_noexchange flag (rty, qty) lthy ty)
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   540
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   541
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   542
ML {*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   543
fun find_matching_types rty ty =
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   544
  if Type.raw_instance (Logic.varifyT ty, rty)
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   545
  then [ty]
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   546
  else
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   547
    let val (s, tys) = dest_Type ty in
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   548
    flat (map (find_matching_types rty) tys)
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   549
    end
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   550
    handle TYPE _ => []
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   551
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   552
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   553
ML {*
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   554
fun get_fun_new flag (rty, qty) lthy ty =
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   555
  let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   556
    val tys = find_matching_types rty ty;
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   557
    val qenv = map (fn t => (exchange_ty lthy rty qty t, t)) tys;
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   558
    val xchg_ty = exchange_ty lthy rty qty ty
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   559
  in
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   560
    get_fun flag qenv lthy xchg_ty
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   561
  end
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   562
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   563
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   564
(*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   565
consts Rl :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   566
axioms Rl_eq: "EQUIV Rl"
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   567
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   568
quotient ql = "'a list" / "Rl"
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   569
  by (rule Rl_eq)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   570
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   571
ML {* val al = snd (dest_Free (term_of @{cpat "f :: ?'a list"})) *}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   572
ML {* val aq = snd (dest_Free (term_of @{cpat "f :: ?'a ql"})) *}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   573
ML {* val ttt = term_of @{cterm "f :: bool list \<Rightarrow> nat list"} *}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   574
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   575
ML {*
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   576
  get_fun_noexchange absF (al, aq) @{context} (fastype_of ttt)
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   577
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   578
ML {*
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   579
  get_fun_new absF al aq @{context} (fastype_of ttt)
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   580
*}
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   581
ML {*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   582
  fun mk_abs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   583
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   584
      val ty = fastype_of tm
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   585
    in (get_fun_noexchange absF (al, aq) @{context} ty) $ tm end
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   586
  fun mk_repabs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   587
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   588
      val ty = fastype_of tm
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   589
    in (get_fun_noexchange repF (al, aq) @{context} ty) $ (mk_abs tm) end
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   590
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   591
ML {*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   592
  cterm_of @{theory} (mk_repabs ttt)
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   593
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   594
*)
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   595
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   596
text {* Does the same as 'subst' in a given prop or theorem *}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   597
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   598
fun eqsubst_prop ctxt thms t =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   599
  let
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   600
    val goalstate = Goal.init (cterm_of (ProofContext.theory_of ctxt) t)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   601
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   602
      NONE => error "eqsubst_prop"
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   603
    | SOME th => cprem_of th 1
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   604
  in term_of a' end
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   605
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   606
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   607
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   608
  fun repeat_eqsubst_prop ctxt thms t =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   609
    repeat_eqsubst_prop ctxt thms (eqsubst_prop ctxt thms t)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   610
    handle _ => t
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   611
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   612
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   613
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   614
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   615
fun eqsubst_thm ctxt thms thm =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   616
  let
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   617
    val goalstate = Goal.init (Thm.cprop_of thm)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   618
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   619
      NONE => error "eqsubst_thm"
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   620
    | SOME th => cprem_of th 1
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   621
    val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   622
    val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a');
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   623
    val cgoal = cterm_of (ProofContext.theory_of ctxt) goal
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   624
    val rt = Goal.prove_internal [] cgoal (fn _ => tac);
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   625
  in
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   626
    @{thm Pure.equal_elim_rule1} OF [rt, thm]
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   627
  end
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   628
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   629
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   630
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   631
  fun repeat_eqsubst_thm ctxt thms thm =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   632
    repeat_eqsubst_thm ctxt thms (eqsubst_thm ctxt thms thm)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   633
    handle _ => thm
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   634
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   635
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   636
(* Needed to have a meta-equality *)
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   637
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id"
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   638
by (simp add: id_def)
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   639
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   640
(* TODO: can be also obtained with: *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   641
ML {* symmetric (eq_reflection OF @{thms id_def}) *}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   642
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   643
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   644
fun build_repabs_term lthy thm consts rty qty =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   645
  let
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   646
    (* TODO: The rty and qty stored in the quotient_info should
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   647
       be varified, so this will soon not be needed *)
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   648
    val rty = Logic.varifyT rty;
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   649
    val qty = Logic.varifyT qty;
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   650
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   651
  fun mk_abs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   652
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   653
      val ty = fastype_of tm
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   654
    in Syntax.check_term lthy ((get_fun_new absF (rty, qty) lthy ty) $ tm) end
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   655
  fun mk_repabs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   656
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   657
      val ty = fastype_of tm
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   658
    in Syntax.check_term lthy ((get_fun_new repF (rty, qty) lthy ty) $ (mk_abs tm)) end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   659
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   660
    fun is_lifted_const (Const (x, _)) = member (op =) consts x
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   661
      | is_lifted_const _ = false;
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   662
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   663
    fun build_aux lthy tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   664
      case tm of
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   665
        Abs (a as (_, vty, _)) =>
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   666
          let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   667
            val (vs, t) = Term.dest_abs a;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   668
            val v = Free(vs, vty);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   669
            val t' = lambda v (build_aux lthy t)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   670
          in
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   671
            if (not (needs_lift rty (fastype_of tm))) then t'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   672
            else mk_repabs (
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   673
              if not (needs_lift rty vty) then t'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   674
              else
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   675
                let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   676
                  val v' = mk_repabs v;
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   677
                  (* TODO: I believe 'beta' is not needed any more *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   678
                  val t1 = (* Envir.beta_norm *) (t' $ v')
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   679
                in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   680
                  lambda v t1
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   681
                end)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   682
          end
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   683
      | x =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   684
        case Term.strip_comb tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   685
          (Const(@{const_name Respects}, _), _) => tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   686
        | (opp, tms0) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   687
          let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   688
            val tms = map (build_aux lthy) tms0
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   689
            val ty = fastype_of tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   690
          in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   691
            if (is_lifted_const opp andalso needs_lift rty ty) then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   692
            mk_repabs (list_comb (opp, tms))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   693
            else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   694
              mk_repabs (list_comb (opp, tms))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   695
            else if tms = [] then opp
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   696
            else list_comb(opp, tms)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   697
          end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   698
  in
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   699
    repeat_eqsubst_prop lthy @{thms id_def_sym}
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   700
      (build_aux lthy (Thm.prop_of thm))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   701
  end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   702
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   703
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   704
text {* Builds provable goals for regularized theorems *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   705
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   706
fun build_repabs_goal ctxt thm cons rty qty =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   707
  Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   708
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   709
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   710
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   711
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   712
  let
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   713
    val pat = Drule.strip_imp_concl (cprop_of thm)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   714
    val insts = Thm.match (pat, concl)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   715
  in
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   716
    rtac (Drule.instantiate insts thm) 1
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   717
  end
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   718
  handle _ => no_tac)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   719
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   720
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   721
ML {*
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   722
fun CHANGED' tac = (fn i => CHANGED (tac i))
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   723
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   724
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   725
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   726
fun quotient_tac quot_thm =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   727
  REPEAT_ALL_NEW (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   728
    rtac @{thm FUN_QUOTIENT},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   729
    rtac quot_thm,
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   730
    rtac @{thm IDENTITY_QUOTIENT},
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   731
    (* For functional identity quotients, (op = ---> op =) *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   732
    CHANGED' (
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   733
      (simp_tac (HOL_ss addsimps @{thms FUN_MAP_I})) THEN'
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   734
      rtac @{thm IDENTITY_QUOTIENT}
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   735
    )
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   736
  ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   737
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   738
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   739
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   740
fun LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   741
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   742
    (_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   743
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   744
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   745
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   746
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   747
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   748
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   749
fun WEAK_LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   750
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   751
    (_ $ (_ $ _ $ (Abs(_, _, _)))) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   752
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   753
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   754
  | (_ $ (_ $ (Abs(_, _, _)) $ _)) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   755
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   756
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   757
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   758
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   759
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   760
ML {*
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   761
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} =>
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   762
  let
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   763
    val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl;
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   764
    val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP});
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   765
    val insts = Thm.match (pat, concl)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   766
  in
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   767
    if needs_lift rty (type_of f) then
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   768
      rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   769
    else no_tac
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   770
  end
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   771
  handle _ => no_tac)
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   772
*}
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   773
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   774
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   775
val ball_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   776
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   777
    val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   778
                 (Const (@{const_name Ball}, _) $ _)) = term_of concl
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   779
  in
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   780
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   781
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   782
    THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   783
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   784
  end
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   785
  handle _ => no_tac)
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   786
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   787
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   788
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   789
val bex_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   790
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   791
    val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   792
                 (Const (@{const_name Bex}, _) $ _)) = term_of concl
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   793
  in
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   794
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   795
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   796
    THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN'
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   797
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   798
  end
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   799
  handle _ => no_tac)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   800
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   801
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   802
ML {*
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   803
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   804
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   805
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   806
ML {*
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   807
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   808
  (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   809
    rtac trans_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   810
    LAMBDA_RES_TAC ctxt,
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   811
    ball_rsp_tac ctxt,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   812
    bex_rsp_tac ctxt,
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   813
    FIRST' (map rtac rsp_thms),
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   814
    (instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])),
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   815
    rtac refl,
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   816
    (APPLY_RSP_TAC rty ctxt THEN' (RANGE [quotient_tac quot_thm, quotient_tac quot_thm])),
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   817
    Cong_Tac.cong_tac @{thm cong},
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   818
    rtac @{thm ext},
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   819
    rtac reflex_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   820
    atac,
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   821
    SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   822
    WEAK_LAMBDA_RES_TAC ctxt,
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   823
    CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   824
    ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   825
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   826
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   827
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   828
fun repabs lthy thm consts rty qty quot_thm reflex_thm trans_thm rsp_thms =
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   829
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   830
    val rt = build_repabs_term lthy thm consts rty qty;
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   831
    val rg = Logic.mk_equals ((Thm.prop_of thm), rt);
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   832
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   833
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms));
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   834
    val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1);
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   835
  in
210
f88ea69331bf Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 209
diff changeset
   836
    @{thm Pure.equal_elim_rule1} OF [cthm, thm]
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   837
  end
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   838
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   839
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   840
section {* Cleaning the goal *}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   841
236
23f9fead8bd6 Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 235
diff changeset
   842
lemma prod_fun_id: "prod_fun id id = id"
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   843
by (simp add: prod_fun_def)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   844
236
23f9fead8bd6 Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 235
diff changeset
   845
lemma map_id: "map id x = x"
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   846
by (induct x) (simp_all)
236
23f9fead8bd6 Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 235
diff changeset
   847
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   848
ML {*
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   849
fun simp_ids lthy thm =
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   850
  thm
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   851
  |> MetaSimplifier.rewrite_rule @{thms id_def_sym}
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   852
  |> repeat_eqsubst_thm lthy @{thms FUN_MAP_I id_apply prod_fun_id map_id}
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   853
*}
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   854
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   855
text {* expects atomized definition *}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   856
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   857
fun add_lower_defs_aux lthy thm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   858
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   859
    val e1 = @{thm fun_cong} OF [thm];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   860
    val f = eqsubst_thm lthy @{thms fun_map.simps} e1;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   861
    val g = simp_ids lthy f
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   862
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   863
    (simp_ids lthy thm) :: (add_lower_defs_aux lthy g)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   864
  end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   865
  handle _ => [simp_ids lthy thm]
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   866
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   867
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   868
ML {*
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   869
fun add_lower_defs lthy def =
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   870
  let
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   871
    val def_pre_sym = symmetric def
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   872
    val def_atom = atomize_thm def_pre_sym
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   873
    val defs_all = add_lower_defs_aux lthy def_atom
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   874
  in
214
a66f81c264aa Proof of append_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 213
diff changeset
   875
    map Thm.varifyT defs_all
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   876
  end
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   877
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   878
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   879
(* TODO: Check if it behaves properly with varifyed rty *)
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   880
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   881
fun findabs_all rty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   882
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   883
    Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   884
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   885
        val b' = subst_bound ((Free ("x", T)), b);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   886
        val tys = findabs_all rty b'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   887
        val ty = fastype_of tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   888
      in if needs_lift rty ty then (ty :: tys) else tys
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   889
      end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   890
  | f $ a => (findabs_all rty f) @ (findabs_all rty a)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   891
  | _ => [];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   892
fun findabs rty tm = distinct (op =) (findabs_all rty tm)
241
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   893
*}
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   894
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   895
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   896
fun findaps_all rty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   897
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   898
    Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   899
      findaps_all rty (subst_bound ((Free ("x", T)), b))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   900
  | (f $ a) => (findaps_all rty f @ findaps_all rty a)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   901
  | Free (_, (T as (Type ("fun", (_ :: _))))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   902
      (if needs_lift rty T then [T] else [])
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   903
  | _ => [];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   904
fun findaps rty tm = distinct (op =) (findaps_all rty tm)
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   905
*}
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   906
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   907
(* Currently useful only for LAMBDA_PRS *)
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   908
ML {*
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   909
fun make_simp_prs_thm lthy quot_thm thm typ =
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   910
  let
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   911
    val (_, [lty, rty]) = dest_Type typ;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   912
    val thy = ProofContext.theory_of lthy;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   913
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   914
    val inst = [SOME lcty, NONE, SOME rcty];
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   915
    val lpi = Drule.instantiate' inst [] thm;
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   916
    val tac =
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   917
      (compose_tac (false, lpi, 2)) THEN_ALL_NEW
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   918
      (quotient_tac quot_thm);
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
   919
    val gc = Drule.strip_imp_concl (cprop_of lpi);
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
   920
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   921
  in
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   922
    MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   923
  end
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   924
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   925
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   926
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   927
fun findallex_all rty qty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   928
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   929
    Const (@{const_name All}, T) $ (s as (Abs(_, _, b))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   930
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   931
        val (tya, tye) = findallex_all rty qty s
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   932
      in if needs_lift rty T then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   933
        ((T :: tya), tye)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   934
      else (tya, tye) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   935
  | Const (@{const_name Ex}, T) $ (s as (Abs(_, _, b))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   936
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   937
        val (tya, tye) = findallex_all rty qty s
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   938
      in if needs_lift rty T then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   939
        (tya, (T :: tye))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   940
      else (tya, tye) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   941
  | Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   942
      findallex_all rty qty (subst_bound ((Free ("x", T)), b))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   943
  | f $ a =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   944
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   945
        val (a1, e1) = findallex_all rty qty f;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   946
        val (a2, e2) = findallex_all rty qty a;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   947
      in (a1 @ a2, e1 @ e2) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   948
  | _ => ([], []);
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   949
*}
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   950
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   951
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   952
fun findallex lthy rty qty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   953
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   954
    val (a, e) = findallex_all rty qty tm;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   955
    val (ad, ed) = (map domain_type a, map domain_type e);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   956
    val (au, eu) = (distinct (op =) ad, distinct (op =) ed);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   957
    val (rty, qty) = (Logic.varifyT rty, Logic.varifyT qty)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   958
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   959
    (map (exchange_ty lthy rty qty) au, map (exchange_ty lthy rty qty) eu)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   960
  end
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   961
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   962
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   963
ML {*
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   964
fun make_allex_prs_thm lthy quot_thm thm typ =
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   965
  let
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   966
    val (_, [lty, rty]) = dest_Type typ;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   967
    val thy = ProofContext.theory_of lthy;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   968
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   969
    val inst = [NONE, SOME lcty];
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   970
    val lpi = Drule.instantiate' inst [] thm;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   971
    val tac =
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   972
      (compose_tac (false, lpi, 1)) THEN_ALL_NEW
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   973
      (quotient_tac quot_thm);
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   974
    val gc = Drule.strip_imp_concl (cprop_of lpi);
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   975
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   976
    val t_noid = MetaSimplifier.rewrite_rule
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   977
      [@{thm eq_reflection} OF @{thms id_apply}] t;
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   978
    val t_sym = @{thm "HOL.sym"} OF [t_noid];
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   979
    val t_eq = @{thm "eq_reflection"} OF [t_sym]
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   980
  in
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   981
    t_eq
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   982
  end
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   983
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   984
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
   985
ML {*
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
   986
fun applic_prs lthy rty qty absrep ty =
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   987
  let
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   988
    val rty = Logic.varifyT rty;
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   989
    val qty = Logic.varifyT qty;
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   990
    fun absty ty =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   991
      exchange_ty lthy rty qty ty
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   992
    fun mk_rep tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   993
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   994
        val ty = exchange_ty lthy qty rty (fastype_of tm)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   995
      in Syntax.check_term lthy ((get_fun_new repF (rty, qty) lthy ty) $ tm) end;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   996
    fun mk_abs tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   997
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   998
        val ty = fastype_of tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   999
      in Syntax.check_term lthy ((get_fun_new absF (rty, qty) lthy ty) $ tm) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1000
    val (l, ltl) = Term.strip_type ty;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1001
    val nl = map absty l;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1002
    val vs = map (fn _ => "x") l;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1003
    val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1004
    val args = map Free (vfs ~~ nl);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1005
    val lhs = list_comb((Free (fname, nl ---> ltl)), args);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1006
    val rargs = map mk_rep args;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1007
    val f = Free (fname, nl ---> ltl);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1008
    val rhs = mk_abs (list_comb((mk_rep f), rargs));
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1009
    val eq = Logic.mk_equals (rhs, lhs);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1010
    val ceq = cterm_of (ProofContext.theory_of lthy') eq;
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
  1011
    val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps});
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1012
    val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1013
    val t_id = MetaSimplifier.rewrite_rule @{thms id_def_sym} t;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1014
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1015
    singleton (ProofContext.export lthy' lthy) t_id
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1016
  end
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1017
*}
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1018
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1019
ML {*
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1020
fun lookup_quot_data lthy qty =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1021
  let
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
  1022
    fun matches (ty1, ty2) =
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
  1023
      Type.raw_instance (ty1, Logic.varifyT ty2);
257
68bd5c2a1b96 Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 255
diff changeset
  1024
    val SOME quotdata = find_first (fn x => matches ((#qtyp x), qty)) (quotdata_lookup lthy)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
  1025
    (* TODO: Should no longer be needed *)
257
68bd5c2a1b96 Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 255
diff changeset
  1026
    val rty = Logic.unvarifyT (#rtyp quotdata)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1027
    val rel = #rel quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1028
    val rel_eqv = #equiv_thm quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1029
    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
  1030
    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
  1031
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1032
    (rty, rel, rel_refl, rel_eqv)
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1033
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1034
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1035
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1036
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1037
fun lookup_quot_thms lthy qty_name =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1038
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1039
    val thy = ProofContext.theory_of lthy;
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1040
    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
  1041
    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
  1042
    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
  1043
    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
  1044
  in
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1045
    (trans2, reps_same, absrep, quot)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1046
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1047
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1048
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1049
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1050
fun lookup_quot_consts defs =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1051
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1052
    fun dest_term (a $ b) = (a, b);
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1053
    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
  1054
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1055
    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
  1056
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1057
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1058
275
34ad627ac5d5 fixed definition of PLUS
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
  1059
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1060
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1061
fun lift_thm lthy qty qty_name rsp_thms defs t = let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1062
  val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty;
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1063
  val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name;
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1064
  val consts = lookup_quot_consts defs;
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1065
  val t_a = atomize_thm t;
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
  1066
  val t_r = regularize t_a rty rel rel_eqv rel_refl lthy;
210
f88ea69331bf Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 209
diff changeset
  1067
  val t_t = repabs lthy t_r consts rty qty quot rel_refl trans2 rsp_thms;
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1068
  val (alls, exs) = findallex lthy rty qty (prop_of t_a);
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1069
  val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1070
  val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1071
  val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1072
  val abs = findabs rty (prop_of t_a);
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
  1073
  val aps = findaps rty (prop_of t_a);
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1074
  val app_prs_thms = map (applic_prs lthy rty qty absrep) aps;
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
  1075
  val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs;
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1076
  val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a;
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1077
  val defs_sym = flat (map (add_lower_defs lthy) defs);
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1078
  val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym;
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1079
  val t_id = simp_ids lthy t_l;
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1080
  val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_id;
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1081
  val t_d = repeat_eqsubst_thm lthy defs_sym t_d0;
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1082
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1083
  val t_rv = ObjectLogic.rulify t_r
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1084
in
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1085
  Thm.varifyT t_rv
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
  1086
end
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1087
*}
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1088
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1089
273
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1090
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1091
fun lift_thm_note qty qty_name rsp_thms defs thm name lthy =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1092
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1093
    val lifted_thm = lift_thm lthy qty qty_name rsp_thms defs thm;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1094
    val (_, lthy2) = note (name, lifted_thm) lthy;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1095
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1096
    lthy2
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1097
  end
273
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1098
*}
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1099
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1100
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1101
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1102
end
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1103