QuotMain.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 27 Oct 2009 11:27:53 +0100
changeset 200 d6a24dad5882
parent 198 ff4425e000db
child 203 7384115df9fd
child 206 1e227c9ee915
permissions -rw-r--r--
made quotients compatiple with Nominal; updated keyword file
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
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents: 70
diff changeset
     3
uses ("quotient.ML")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  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
    15
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    18
  ABS::"'a \<Rightarrow> 'b"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    19
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    23
  REP::"'b \<Rightarrow> 'a"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    24
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    27
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  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
    31
  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
    32
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    37
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    38
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    39
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    41
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  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
    44
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    51
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    57
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    63
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    69
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    70
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    71
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    72
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    73
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    74
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    84
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    85
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    86
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    87
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    88
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    89
  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
    90
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    91
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    92
  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
    93
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    94
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    95
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    96
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    97
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    98
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    99
  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
   100
  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
   101
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   102
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   103
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   104
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   105
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   106
  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
   107
using ac bd
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   108
by (blast intro: R_trans R_sym)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   109
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   110
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   111
  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
   112
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   113
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   114
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   115
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   116
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   117
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   118
      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
   119
    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
   120
    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
   121
    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
   122
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   123
    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
   124
    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
   125
    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
   126
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   127
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   128
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   129
    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
   130
    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
   131
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   132
  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
   133
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   134
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
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
   137
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents: 70
diff changeset
   140
use "quotient.ML"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   142
declare [[map list = (map, LIST_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   143
declare [[map * = (prod_fun, prod_rel)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   144
declare [[map "fun" = (fun_map, FUN_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   145
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   146
ML {* maps_lookup @{theory} "List.list" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   147
ML {* maps_lookup @{theory} "*" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   148
ML {* maps_lookup @{theory} "fun" *}
174
09048a951dca moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   149
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   150
ML {*
193
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   151
val quot_def_parser = 
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   152
  (OuterParse.$$$ "(" |-- OuterParse.$$$ "with" |-- 
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   153
    ((OuterParse.list1 OuterParse.binding) --| OuterParse.$$$ ")")) --
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   154
      (OuterParse.binding -- 
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   155
        Scan.option (OuterParse.$$$ "::" |-- OuterParse.typ) -- 
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   156
         OuterParse.mixfix --| OuterParse.where_ -- SpecParse.spec)
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   157
*}
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   158
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   159
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   160
fun test (qrtys, (((bind, typstr), mx), (attr, prop))) lthy = lthy
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   161
*}
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   162
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   163
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   164
val _ = OuterSyntax.local_theory "quotient_def" "lifted definition"
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   165
  OuterKeyword.thy_decl (quot_def_parser >> test)
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   166
*}
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   167
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   168
(* FIXME: auxiliary function *)
Christian Urban <urbanc@in.tum.de>
parents: 191
diff changeset
   169
ML {*
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   170
val no_vars = Thm.rule_attribute (fn context => fn th =>
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   171
  let
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   172
    val ctxt = Variable.set_body false (Context.proof_of context);
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   173
    val ((_, [th']), _) = Variable.import true [th] ctxt;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   174
  in th' end);
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   175
*}
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   176
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
section {* lifting of constants *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ML {*
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   180
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   181
*}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   182
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   183
ML {*
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   184
(* calculates the aggregate abs and rep functions for a given type; 
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   185
   repF is for constants' arguments; absF is for constants;
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   186
   function types need to be treated specially, since repF and absF
163
3da18bf6886c Split Finite Set example into separate file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 162
diff changeset
   187
   change
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   188
*)
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   189
datatype flag = absF | repF
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
109
386671ef36bd fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents: 108
diff changeset
   191
fun negF absF = repF
386671ef36bd fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents: 108
diff changeset
   192
  | negF repF = absF
386671ef36bd fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents: 108
diff changeset
   193
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   194
fun get_fun flag rty qty lthy ty =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  val qty_name = Long_Name.base_name (fst (dest_Type qty))
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   197
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
    val (fs, tys) = split_list fs_tys
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   201
    val (otys, ntys) = split_list tys
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  in
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   206
   (case (maps_lookup (ProofContext.theory_of lthy) s) of
110
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   207
      SOME info => (list_comb (Const (#mapfun info, ftys ---> (oty --> nty)), fs), (oty, nty))
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   208
    | NONE      => raise ERROR ("no map association for type " ^ s))
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   209
  end
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   210
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   211
  fun get_fun_fun fs_tys =
110
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   212
  let
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   213
    val (fs, tys) = split_list fs_tys
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   214
    val ([oty1, oty2], [nty1, nty2]) = split_list tys
128
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   215
    val oty = nty1 --> oty2
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   216
    val nty = oty1 --> nty2
110
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   217
    val ftys = map (op -->) tys
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   218
  in
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   219
    (list_comb (Const (@{const_name "fun_map"}, ftys ---> oty --> nty), fs), (oty, nty))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
170
22cd68da9ae4 Undid wrong merge
cek@localhost.localdomain
parents: 168
diff changeset
   222
  val thy = ProofContext.theory_of lthy
22cd68da9ae4 Undid wrong merge
cek@localhost.localdomain
parents: 168
diff changeset
   223
22cd68da9ae4 Undid wrong merge
cek@localhost.localdomain
parents: 168
diff changeset
   224
  fun get_const absF = (Const (Sign.full_bname thy ("ABS_" ^ qty_name), rty --> qty), (rty, qty))
22cd68da9ae4 Undid wrong merge
cek@localhost.localdomain
parents: 168
diff changeset
   225
    | get_const repF = (Const (Sign.full_bname thy ("REP_" ^ qty_name), qty --> rty), (qty, rty))
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   226
70
f3cbda066c3a consistent usage of rty (for the raw, unquotient type); tuned a bit the Isar
Christian Urban <urbanc@in.tum.de>
parents: 69
diff changeset
   227
  fun mk_identity ty = Abs ("", ty, Bound 0)
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   228
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  if ty = qty
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   231
  then (get_const flag)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  else (case ty of
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   233
          TFree _ => (mk_identity ty, (ty, ty))
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   234
        | Type (_, []) => (mk_identity ty, (ty, ty)) 
109
386671ef36bd fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents: 108
diff changeset
   235
        | Type ("fun" , [ty1, ty2]) => 
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   236
                 get_fun_fun [get_fun (negF flag) rty qty lthy ty1, get_fun flag rty qty lthy ty2]
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   237
        | Type (s, tys) => get_fun_aux s (map (get_fun flag rty qty lthy) tys)
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   238
        | _ => raise ERROR ("no type variables")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
180
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   243
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   244
text {* produces the definition for a lifted constant *}
86
133af7260a12 Regularizing HOL all.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 85
diff changeset
   245
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   246
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
  val (arg_tys, res_ty) = strip_type ty
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   251
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
  val fresh_args = arg_tys |> map (pair "x")
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   253
                           |> Variable.variant_frees lthy [nconst, oconst]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
                           |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   256
  val rep_fns = map (fst o get_fun repF rty qty lthy) arg_tys
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   257
  val abs_fn  = (fst o get_fun absF rty qty lthy) res_ty
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
180
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   259
  fun mk_fun_map (t1,t2) = Const (@{const_name "fun_map"}, dummyT) $ t1 $ t2
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   260
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   261
  val fns = Library.foldr (mk_fun_map) (rep_fns, abs_fn)
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   262
            |> Syntax.check_term lthy
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
in
180
fcacca9588b4 changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents: 174
diff changeset
   264
  fns $ oconst
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
ML {*
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   269
fun exchange_ty rty qty ty =
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   270
  if ty = rty
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   271
  then qty
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   272
  else
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
       Type (s, tys) => Type (s, map (exchange_ty rty qty) tys)
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   275
      | _ => ty
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   276
    )
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
ML {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   280
fun make_const_def nconst_bname oconst mx rty qty lthy =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
  val nconst_ty = exchange_ty rty qty oconst_ty
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   284
  val nconst = Const (Binding.name_of nconst_bname, nconst_ty)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
in
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   287
  define (nconst_bname, mx, def_trm) lthy
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   288
end
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   291
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   292
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   293
text {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   294
  Unabs_def converts a definition given as
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   295
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   296
    c \<equiv> %x. %y. f x y
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   297
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   298
  to a theorem of the form
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   299
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   300
    c x y \<equiv> f x y
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   301
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   302
  This function is needed to rewrite the right-hand
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   303
  side to the left-hand side.
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   304
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   305
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   306
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   307
fun unabs_def ctxt def =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   308
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   309
  val (lhs, rhs) = Thm.dest_equals (cprop_of def)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   310
  val xs = strip_abs_vars (term_of rhs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   311
  val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   312
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   313
  val thy = ProofContext.theory_of ctxt'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   314
  val cxs = map (cterm_of thy o Free) xs
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   315
  val new_lhs = Drule.list_comb (lhs, cxs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   316
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   317
  fun get_conv [] = Conv.rewr_conv def
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   318
    | get_conv (x::xs) = Conv.fun_conv (get_conv xs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   319
in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   320
  get_conv xs new_lhs |>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   321
  singleton (ProofContext.export ctxt' ctxt)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   322
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   323
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   324
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   325
lemma atomize_eqv[atomize]: 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   326
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   327
proof
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   328
  assume "A \<equiv> B" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   329
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   330
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   331
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   332
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   333
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   334
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   335
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   336
    then show "A = B" using * by simp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   337
  next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   338
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   339
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   340
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   341
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   342
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   343
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   344
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   345
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   346
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   347
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   348
  val thm' = forall_intr_vars thm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   349
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   350
in
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   351
  Thm.freezeT (Simplifier.rewrite_rule [thm''] thm')
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   352
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   353
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   354
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   355
ML {* atomize_thm @{thm list.induct} *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   356
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   357
section {* REGULARIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   358
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   359
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
   360
  type needs to respect. *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   361
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   362
fun tyRel ty rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   363
  if ty = rty 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   364
  then rel
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   365
  else (case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   366
          Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   367
            let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   368
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   369
              val ty_out = ty --> ty --> @{typ bool};
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   370
              val tys_out = tys_rel ---> ty_out;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   371
            in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   372
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   373
               SOME (info) => list_comb (Const (#relfun info, tys_out), map (fn ty => tyRel ty rty rel lthy) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   374
             | NONE  => HOLogic.eq_const ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   375
            )
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   376
            end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   377
        | _ => HOLogic.eq_const ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   378
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   379
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   380
definition
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   381
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   382
where
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   383
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   384
(* TODO: Consider defining it with an "if"; sth like:
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   385
   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
   386
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   387
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   388
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   389
fun needs_lift (rty as Type (rty_s, _)) ty =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   390
  case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   391
    Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   392
      (s = rty_s) orelse (exists (needs_lift rty) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   393
  | _ => false
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   394
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   395
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   396
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   397
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   398
(* trm \<Rightarrow> new_trm *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   399
fun regularise trm rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   400
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   401
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   402
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   403
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   404
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   405
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   406
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   407
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   408
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   409
        val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   410
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   411
        val ty = fastype_of trm;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   412
        val rabs = Const (@{const_name Babs}, (fastype_of res_term) --> ty --> ty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   413
        val rabs_term = (rabs $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   414
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   415
        rabs_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   416
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   417
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   418
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   419
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   420
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   421
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   422
        Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   423
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   424
  | ((Const (@{const_name "All"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   425
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   426
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   427
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   428
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   429
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   430
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   431
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   432
        val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   433
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   434
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   435
        val rall = Const (@{const_name Ball}, (fastype_of res_term) --> ty --> @{typ bool});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   436
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   437
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   438
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   439
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   440
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   441
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   442
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   443
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   444
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   445
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   446
        Const(@{const_name "All"}, at) $ lam_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   447
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   448
  | ((Const (@{const_name "All"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   449
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   450
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   451
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   452
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   453
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   454
      in regularise ((Const (@{const_name "All"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   455
  | ((Const (@{const_name "Ex"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   456
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   457
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   458
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   459
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   460
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   461
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   462
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   463
        val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   464
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   465
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   466
        val rall = Const (@{const_name Bex}, (fastype_of res_term) --> ty --> @{typ bool});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   467
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   468
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   469
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   470
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   471
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   472
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   473
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   474
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   475
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   476
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   477
        Const(@{const_name "Ex"}, at) $ lam_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   478
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   479
  | ((Const (@{const_name "Ex"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   480
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   481
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   482
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   483
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   484
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   485
      in regularise ((Const (@{const_name "Ex"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   486
  | a $ b => (regularise a rty rel lthy) $ (regularise b rty rel lthy)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   487
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   488
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   489
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   490
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   491
(* my version of regularise *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   492
(****************************)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   493
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   494
(* some helper functions *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   495
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   496
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   497
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   498
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
   499
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   500
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   501
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
   502
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   503
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   504
(* 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
   505
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   506
fun apply_subt f trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   507
  case trm of
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   508
    Abs (x, T, t) => 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   509
       let 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   510
         val (x', t') = Term.dest_abs (x, T, t)
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   511
       in
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   512
         Term.absfree (x', T, f t') 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   513
       end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   514
  | _ => f trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   515
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   516
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   517
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   518
(* FIXME: assumes always the typ is qty! *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   519
(* 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
   520
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   521
fun my_reg rel trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   522
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   523
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   524
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   525
          val ty1 = fastype_of trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   526
       in
146
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
   527
         (mk_babs ty1 T) $ (mk_resp T $ rel) $ (apply_subt (my_reg rel) trm)    
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   528
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   529
  | Const (@{const_name "All"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   530
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   531
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   532
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   533
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   534
         (mk_ball ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t)      
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   535
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   536
  | Const (@{const_name "Ex"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   537
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   538
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   539
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   540
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   541
         (mk_bex ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t)    
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   542
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   543
  | t1 $ t2 => (my_reg rel t1) $ (my_reg rel t2)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   544
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   545
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   546
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   547
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   548
(*fun prove_reg trm \<Rightarrow> thm (we might need some facts to do this)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   549
  trm == new_trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   550
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   551
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   552
text {* Assumes that the given theorem is atomized *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   553
ML {*
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   554
  fun build_regularize_goal thm rty rel lthy =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   555
     Logic.mk_implies
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   556
       ((prop_of thm),
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   557
       (regularise (prop_of thm) rty rel lthy))
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   558
*}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   559
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   560
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   561
fun regularize thm rty rel rel_eqv lthy =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   562
  let
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   563
    val g = build_regularize_goal thm rty rel lthy;
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   564
    fun tac ctxt =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   565
       (asm_full_simp_tac ((Simplifier.context ctxt HOL_ss) addsimps
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   566
        [(@{thm equiv_res_forall} OF [rel_eqv]),
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   567
         (@{thm equiv_res_exists} OF [rel_eqv])])) THEN_ALL_NEW
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   568
         (((rtac @{thm RIGHT_RES_FORALL_REGULAR}) THEN' (RANGE [fn _ => all_tac, atac]) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   569
         (MetisTools.metis_tac ctxt [])) ORELSE' (MetisTools.metis_tac ctxt []));
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   570
    val cthm = Goal.prove lthy [] [] g (fn x => tac (#context x) 1);
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   571
  in
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   572
    cthm OF [thm]
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   573
  end
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   574
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   575
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   576
section {* RepAbs injection *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   577
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   578
(* Needed to have a meta-equality *)
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   579
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id"
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   580
by (simp add: id_def)
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   581
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   582
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   583
fun build_repabs_term lthy thm constructors rty qty =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   584
  let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   585
    fun mk_rep tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   586
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   587
        val ty = exchange_ty rty qty (fastype_of tm)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   588
      in fst (get_fun repF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   589
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   590
    fun mk_abs tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   591
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   592
        val ty = exchange_ty rty qty (fastype_of tm) in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   593
      fst (get_fun absF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   594
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   595
    fun is_constructor (Const (x, _)) = member (op =) constructors x
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   596
      | is_constructor _ = false;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   597
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   598
    fun build_aux lthy tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   599
      case tm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   600
      Abs (a as (_, vty, _)) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   601
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   602
        val (vs, t) = Term.dest_abs a;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   603
        val v = Free(vs, vty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   604
        val t' = lambda v (build_aux lthy t)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   605
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   606
      if (not (needs_lift rty (fastype_of tm))) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   607
      else mk_rep (mk_abs (
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   608
        if not (needs_lift rty vty) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   609
        else
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   610
          let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   611
            val v' = mk_rep (mk_abs v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   612
            val t1 = Envir.beta_norm (t' $ v')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   613
          in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   614
            lambda v t1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   615
          end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   616
      ))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   617
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   618
    | x =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   619
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   620
        val (opp, tms0) = Term.strip_comb tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   621
        val tms = map (build_aux lthy) tms0
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   622
        val ty = fastype_of tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   623
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   624
        if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   625
          then (list_comb (opp, (hd tms0) :: (tl tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   626
      else if (is_constructor opp andalso needs_lift rty ty) then
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   627
          mk_rep (mk_abs (list_comb (opp,tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   628
        else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then
149
7cf1d7adfc5f Removed some debugging messages
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 148
diff changeset
   629
          mk_rep(mk_abs(list_comb(opp,tms)))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   630
        else if tms = [] then opp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   631
        else list_comb(opp, tms)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   632
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   633
  in
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   634
    MetaSimplifier.rewrite_term @{theory} @{thms id_def_sym} []
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   635
      (build_aux lthy (Thm.prop_of thm))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   636
  end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   637
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   638
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   639
text {* Assumes that it is given a regularized theorem *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   640
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   641
fun build_repabs_goal ctxt thm cons rty qty =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   642
  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
   643
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   644
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   645
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   646
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   647
let
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   648
  val pat = Drule.strip_imp_concl (cprop_of thm)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   649
  val insts = Thm.match (pat, concl)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   650
in
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   651
  rtac (Drule.instantiate insts thm) 1
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
   652
end
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   653
handle _ => no_tac
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   654
)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   655
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   656
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   657
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   658
fun res_forall_rsp_tac ctxt =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   659
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   660
  THEN' 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
   661
  THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   662
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   663
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   664
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   665
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   666
fun res_exists_rsp_tac ctxt =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   667
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   668
  THEN' 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
   669
  THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   670
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   671
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   672
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   673
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   674
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   675
fun quotient_tac quot_thm =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   676
  REPEAT_ALL_NEW (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   677
    rtac @{thm FUN_QUOTIENT},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   678
    rtac quot_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   679
    rtac @{thm IDENTITY_QUOTIENT}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   680
  ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   681
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   682
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   683
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   684
fun LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   685
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   686
    (_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) =>
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   687
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   688
      (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
   689
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   690
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   691
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   692
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   693
fun WEAK_LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   694
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   695
    (_ $ (_ $ _$(Abs(_,_,_)))) =>
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   696
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   697
      (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
   698
  | (_ $ (_ $ (Abs(_,_,_))$_)) =>
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   699
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   700
      (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
   701
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   702
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   703
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   704
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   705
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   706
fun r_mk_comb_tac ctxt quot_thm reflex_thm trans_thm rsp_thms =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   707
  (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   708
    rtac @{thm FUN_QUOTIENT},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   709
    rtac quot_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   710
    rtac @{thm IDENTITY_QUOTIENT},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   711
    rtac @{thm ext},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   712
    rtac trans_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   713
    LAMBDA_RES_TAC ctxt,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   714
    res_forall_rsp_tac ctxt,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   715
    res_exists_rsp_tac ctxt,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   716
    (
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   717
     (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps rsp_thms))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   718
     THEN_ALL_NEW (fn _ => no_tac)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   719
    ),
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   720
    (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
   721
    rtac refl,
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   722
    rtac @{thm arg_cong2[of _ _ _ _ "op ="]},
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   723
    (instantiate_tac @{thm APPLY_RSP} ctxt THEN' (RANGE [quotient_tac quot_thm, quotient_tac quot_thm])),
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   724
    rtac reflex_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   725
    atac,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   726
    (
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   727
     (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   728
     THEN_ALL_NEW (fn _ => no_tac)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   729
    ),
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   730
    WEAK_LAMBDA_RES_TAC ctxt
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   731
    ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   732
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   733
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
   734
ML {*
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   735
fun repabs_eq lthy thm constructors rty qty quot_thm reflex_thm trans_thm rsp_thms =
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   736
  let
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   737
    val rt = build_repabs_term lthy thm constructors rty qty;
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   738
    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
   739
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   740
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt quot_thm reflex_thm trans_thm rsp_thms));
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   741
    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
   742
  in
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   743
    (rt, cthm, thm)
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   744
  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
   745
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   746
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   747
ML {*
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   748
fun repabs_eq2 lthy (rt, thm, othm) =
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   749
  let
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   750
    fun tac2 ctxt =
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   751
     (simp_tac ((Simplifier.context ctxt empty_ss) addsimps [symmetric thm]))
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   752
     THEN' (rtac othm);
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   753
    val cthm = Goal.prove lthy [] [] rt (fn x => tac2 (#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
   754
  in
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   755
    cthm
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   756
  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
   757
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   758
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   759
section {* Cleaning the goal *}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   760
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   761
text {* Does the same as 'subst' in a given theorem *}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   762
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   763
fun eqsubst_thm ctxt thms thm =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   764
  let
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   765
    val goalstate = Goal.init (Thm.cprop_of thm)
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   766
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   767
      NONE => error "eqsubst_thm"
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   768
    | SOME th => cprem_of th 1
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   769
    val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   770
    val cgoal = cterm_of (ProofContext.theory_of ctxt) (Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a'))
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   771
    val rt = Toplevel.program (fn () => Goal.prove_internal [] cgoal (fn _ => tac));
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   772
  in
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   773
    Simplifier.rewrite_rule [rt] thm
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   774
  end
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   775
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   776
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
   777
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
   778
ML {*
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   779
  fun add_lower_defs_aux ctxt thm =
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   780
    let
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   781
      val e1 = @{thm fun_cong} OF [thm]
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   782
      val f = eqsubst_thm ctxt @{thms fun_map.simps} e1
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   783
    in
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   784
      thm :: (add_lower_defs_aux ctxt f)
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   785
    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
   786
    handle _ => [thm]
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   787
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   788
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   789
ML {*
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   790
fun add_lower_defs ctxt defs =
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   791
  let
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   792
    val defs_pre_sym = map symmetric defs
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   793
    val defs_atom = map atomize_thm defs_pre_sym
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   794
    val defs_all = flat (map (add_lower_defs_aux ctxt) defs_atom)
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   795
    val defs_sym = map (fn t => eq_reflection OF [t]) defs_all
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   796
  in
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   797
    map Thm.varifyT defs_sym
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   798
  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
   799
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   800
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   801
text {* the proper way to do it *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   802
ML {*
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   803
  fun findabs rty tm =
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   804
    case tm of
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   805
      Abs(_, T, b) =>
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   806
        let
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   807
          val b' = subst_bound ((Free ("x", T)), b);
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   808
          val tys = findabs rty b'
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   809
          val ty = fastype_of tm
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   810
        in if needs_lift rty ty then (ty :: tys) else tys
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   811
        end
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   812
    | f $ a => (findabs rty f) @ (findabs rty a)
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   813
    | _ => []
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   814
*}
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
   815
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   816
ML {*
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   817
fun make_simp_lam_prs_thm lthy quot_thm typ =
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   818
  let
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   819
    val (_, [lty, rty]) = dest_Type typ;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   820
    val thy = ProofContext.theory_of lthy;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   821
    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
   822
    val inst = [SOME lcty, NONE, SOME rcty];
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   823
    val lpi = Drule.instantiate' inst [] @{thm LAMBDA_PRS};
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   824
    val tac =
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   825
      (compose_tac (false, @{thm LAMBDA_PRS}, 2)) THEN_ALL_NEW
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   826
      (quotient_tac quot_thm);
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   827
    val t = Goal.prove lthy [] [] (concl_of lpi) (fn _ => tac 1);
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   828
    val ts = @{thm HOL.sym} OF [t]
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   829
  in
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   830
    MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] ts
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   831
  end
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   832
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   833
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   834
ML {*
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   835
  fun simp_allex_prs lthy quot thm =
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   836
    let
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   837
      val rwf = @{thm FORALL_PRS} OF [quot];
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   838
      val rwfs = @{thm "HOL.sym"} OF [rwf];
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   839
      val rwe = @{thm EXISTS_PRS} OF [quot];
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   840
      val rwes = @{thm "HOL.sym"} OF [rwe]
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   841
    in
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   842
      (simp_allex_prs lthy quot (eqsubst_thm lthy [rwfs, rwes] thm))
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   843
    end
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   844
    handle _ => thm
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   845
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   846
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   847
ML {*
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   848
fun lift_thm lthy consts rty qty rel rel_eqv rel_refl quot rsp_thms trans2 reps_same t_defs t = let
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   849
  val t_a = atomize_thm t;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   850
  val t_r = regularize t_a rty rel rel_eqv lthy;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   851
  val t_t1 = repabs_eq lthy t_r consts rty qty quot rel_refl trans2 rsp_thms;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   852
  val t_t2 = repabs_eq2 lthy t_t1;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   853
  val abs = findabs rty (prop_of t_a);
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   854
  val simp_lam_prs_thms = map (make_simp_lam_prs_thm lthy quot) abs;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   855
  fun simp_lam_prs lthy thm =
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   856
    simp_lam_prs lthy (eqsubst_thm lthy simp_lam_prs_thms thm)
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   857
    handle _ => thm
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   858
  val t_l = simp_lam_prs lthy t_t2;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   859
  val t_a = simp_allex_prs lthy quot t_l;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   860
  val t_defs_sym = add_lower_defs lthy t_defs;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   861
  val t_d = MetaSimplifier.rewrite_rule t_defs_sym t_a;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   862
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   863
in
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   864
  ObjectLogic.rulify t_r
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   865
end
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   866
*}
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   867
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   868
end