QuotMain.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 24 Oct 2009 01:33:29 +0200
changeset 165 2c83d04262f9
parent 163 3da18bf6886c
child 168 c1e76f09db70
permissions -rw-r--r--
fixed problem with incorrect ABS/REP name
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
165
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     6
definition 
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     7
  EQ_TRUE 
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     8
where
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     9
  "EQ_TRUE X \<equiv> (X = True)"
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    10
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    11
lemma test: "EQ_TRUE ?X"
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    12
  unfolding EQ_TRUE_def
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    13
  by (rule refl)
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    14
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    15
thm test
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
    16
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  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
    26
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    34
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  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
    38
  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
    39
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    44
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    45
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    46
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    48
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  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
    51
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    58
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    64
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    70
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    76
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    77
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    78
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    79
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    80
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    81
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    91
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    92
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    93
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    94
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    95
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    96
  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
    97
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    98
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    99
  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
   100
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   101
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   102
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   103
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   104
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   105
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   106
  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
   107
  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
   108
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   109
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   110
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   111
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   112
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   113
  shows "R a b = R c d"
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   114
proof
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   115
  assume "R a b"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   116
  then have "R b a" using R_sym by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   117
  then have "R b c" using ac R_trans by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   118
  then have "R c b" using R_sym by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   119
  then show "R c d" using bd R_trans by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   120
next
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   121
  assume "R c d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   122
  then have "R a d" using ac R_trans by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   123
  then have "R d a" using R_sym by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   124
  then have "R b a" using bd R_trans by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   125
  then show "R a b" using R_sym by blast
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   126
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   127
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   128
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   129
  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
   130
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   131
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   132
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   133
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   134
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   135
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   136
      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
   137
    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
   138
    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
   139
    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
   140
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   141
    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
   142
    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
   143
    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
   144
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   145
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   146
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   147
    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
   148
    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
   149
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   150
  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
   151
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   152
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
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
   155
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents: 70
diff changeset
   158
use "quotient.ML"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   160
(* mapfuns for some standard types *)
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   161
165
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   162
ML {* quotdata_lookup @{theory} *}
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   163
setup {* quotdata_update_thy (@{typ nat}, @{typ bool}, @{term "True"})*}
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   164
ML {* quotdata_lookup @{theory} *}
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   165
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   166
ML {* print_quotdata @{context} *}
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   167
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   168
ML {* maps_lookup @{theory} @{type_name list} *}
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   169
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   170
ML {*
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   171
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
   172
  let
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   173
    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
   174
    val ((_, [th']), _) = Variable.import true [th] ctxt;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   175
  in th' end);
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   176
*}
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   177
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
section {* lifting of constants *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
ML {*
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   181
(* 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
   182
   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
   183
   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
   184
   change
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   185
*)
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   186
datatype flag = absF | repF
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
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
   188
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
   189
  | 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
   190
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   191
fun get_fun flag rty qty lthy ty =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  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
   194
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
    val (fs, tys) = split_list fs_tys
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   198
    val (otys, ntys) = split_list tys
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  in
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   203
   (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
   204
      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
   205
    | 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
   206
  end
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   207
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   208
  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
   209
  let
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   210
    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
   211
    val ([oty1, oty2], [nty1, nty2]) = split_list tys
128
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   212
    val oty = nty1 --> oty2
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   213
    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
   214
    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
   215
  in
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   216
    (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
   217
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
165
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   219
  val thy = ProofContext.theory_of lthy
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   220
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   221
  fun get_const absF = (Const (Sign.full_bname thy ("ABS_" ^ qty_name), rty --> qty), (rty, qty))
2c83d04262f9 fixed problem with incorrect ABS/REP name
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   222
    | 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
   223
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
   224
  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
   225
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  if ty = qty
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   228
  then (get_const flag)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  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
   230
          TFree _ => (mk_identity ty, (ty, ty))
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   231
        | 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
   232
        | Type ("fun" , [ty1, ty2]) => 
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   233
                 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
   234
        | 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
   235
        | _ => raise ERROR ("no type variables")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   240
text {* produces the definition for a lifted constant *}
86
133af7260a12 Regularizing HOL all.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 85
diff changeset
   241
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   242
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  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
   247
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
  val fresh_args = arg_tys |> map (pair "x")
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   249
                           |> Variable.variant_frees lthy [nconst, oconst]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
                           |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   252
  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
   253
  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
   254
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  map (op $) (rep_fns ~~ fresh_args)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  |> curry list_comb oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
  |> curry (op $) abs_fn
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
  |> fold_rev lambda fresh_args
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
ML {*
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   264
fun exchange_ty rty qty ty =
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   265
  if ty = rty
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   266
  then qty
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   267
  else
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
       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
   270
      | _ => ty
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   271
    )
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
ML {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   275
fun make_const_def nconst_bname oconst mx rty qty lthy =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  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
   279
  val nconst = Const (Binding.name_of nconst_bname, nconst_ty)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
in
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   282
  define (nconst_bname, mx, def_trm) lthy
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   283
end
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   286
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   287
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   288
text {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   289
  Unabs_def converts a definition given as
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   290
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   291
    c \<equiv> %x. %y. f x y
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
  to a theorem of the form
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   294
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   295
    c x y \<equiv> f x y
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   296
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   297
  This function is needed to rewrite the right-hand
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   298
  side to the left-hand side.
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
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   301
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   302
fun unabs_def ctxt def =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   303
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   304
  val (lhs, rhs) = Thm.dest_equals (cprop_of def)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   305
  val xs = strip_abs_vars (term_of rhs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   306
  val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   307
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   308
  val thy = ProofContext.theory_of ctxt'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   309
  val cxs = map (cterm_of thy o Free) xs
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   310
  val new_lhs = Drule.list_comb (lhs, cxs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   311
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   312
  fun get_conv [] = Conv.rewr_conv def
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   313
    | get_conv (x::xs) = Conv.fun_conv (get_conv xs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   314
in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   315
  get_conv xs new_lhs |>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   316
  singleton (ProofContext.export ctxt' ctxt)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   317
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   318
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   319
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   320
lemma atomize_eqv[atomize]: 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   321
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   322
proof
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   323
  assume "A \<equiv> B" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   324
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   325
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   326
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   327
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   328
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   329
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   330
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   331
    then show "A = B" using * by simp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   332
  next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   333
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   334
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   335
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   336
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   337
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   338
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   339
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   340
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   341
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   342
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   343
  val thm' = forall_intr_vars thm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   344
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   345
in
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   346
  Thm.freezeT (Simplifier.rewrite_rule [thm''] thm')
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   347
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   348
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   349
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   350
ML {* atomize_thm @{thm list.induct} *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   351
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   352
section {* REGULARIZE *}
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
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
   355
  type needs to respect. *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   356
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   357
fun tyRel ty rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   358
  if ty = rty 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   359
  then rel
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   360
  else (case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   361
          Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   362
            let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   363
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   364
              val ty_out = ty --> ty --> @{typ bool};
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   365
              val tys_out = tys_rel ---> ty_out;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   366
            in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   367
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   368
               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
   369
             | NONE  => HOLogic.eq_const ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   370
            )
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   371
            end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   372
        | _ => HOLogic.eq_const ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   373
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   374
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   375
definition
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   376
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   377
where
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   378
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   379
(* TODO: Consider defining it with an "if"; sth like:
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   380
   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
   381
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   382
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   383
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   384
fun needs_lift (rty as Type (rty_s, _)) ty =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   385
  case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   386
    Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   387
      (s = rty_s) orelse (exists (needs_lift rty) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   388
  | _ => false
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   389
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   390
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   391
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   392
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   393
(* trm \<Rightarrow> new_trm *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   394
fun regularise trm rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   395
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   396
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   397
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   398
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   399
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   400
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   401
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   402
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   403
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   404
        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
   405
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   406
        val ty = fastype_of trm;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   407
        val rabs = Const (@{const_name Babs}, (fastype_of res_term) --> ty --> ty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   408
        val rabs_term = (rabs $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   409
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   410
        rabs_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   411
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   412
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   413
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   414
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   415
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   416
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   417
        Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   418
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   419
  | ((Const (@{const_name "All"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   420
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   421
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   422
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   423
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   424
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   425
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   426
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   427
        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
   428
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   429
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   430
        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
   431
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   432
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   433
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   434
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   435
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   436
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   437
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   438
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   439
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   440
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   441
        Const(@{const_name "All"}, at) $ lam_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   442
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   443
  | ((Const (@{const_name "All"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   444
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   445
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   446
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   447
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   448
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   449
      in regularise ((Const (@{const_name "All"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   450
  | ((Const (@{const_name "Ex"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   451
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   452
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   453
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   454
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   455
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   456
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   457
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   458
        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
   459
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   460
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   461
        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
   462
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   463
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   464
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   465
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   466
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   467
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   468
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   469
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   470
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   471
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   472
        Const(@{const_name "Ex"}, at) $ lam_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   473
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   474
  | ((Const (@{const_name "Ex"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   475
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   476
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   477
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   478
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   479
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   480
      in regularise ((Const (@{const_name "Ex"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   481
  | a $ b => (regularise a rty rel lthy) $ (regularise b rty rel lthy)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   482
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   483
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   484
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   485
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   486
(* my version of regularise *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   487
(****************************)
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
(* some helper functions *)
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
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   492
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   493
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
   494
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   495
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   496
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
   497
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   498
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   499
(* 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
   500
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   501
fun apply_subt f trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   502
  case trm of
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   503
    Abs (x, T, t) => 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   504
       let 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   505
         val (x', t') = Term.dest_abs (x, T, t)
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   506
       in
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   507
         Term.absfree (x', T, f t') 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   508
       end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   509
  | _ => f trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   510
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   511
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   512
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   513
(* FIXME: assumes always the typ is qty! *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   514
(* 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
   515
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   516
fun my_reg rel trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   517
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   518
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   519
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   520
          val ty1 = fastype_of trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   521
       in
146
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
   522
         (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
   523
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   524
  | Const (@{const_name "All"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   525
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   526
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   527
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   528
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   529
         (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
   530
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   531
  | Const (@{const_name "Ex"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   532
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   533
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   534
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   535
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   536
         (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
   537
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   538
  | t1 $ t2 => (my_reg rel t1) $ (my_reg rel t2)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   539
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   540
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   541
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   542
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   543
(*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
   544
  trm == new_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
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   547
text {* Assumes that the given theorem is atomized *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   548
ML {*
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   549
  fun build_regularize_goal thm rty rel lthy =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   550
     Logic.mk_implies
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   551
       ((prop_of thm),
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   552
       (regularise (prop_of thm) rty rel lthy))
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   553
*}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   554
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   555
section {* RepAbs injection *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   556
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   557
(* 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
   558
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
   559
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
   560
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   561
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   562
fun build_repabs_term lthy thm constructors rty qty =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   563
  let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   564
    fun mk_rep tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   565
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   566
        val ty = exchange_ty rty qty (fastype_of tm)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   567
      in fst (get_fun repF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   568
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   569
    fun mk_abs tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   570
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   571
        val ty = exchange_ty rty qty (fastype_of tm) in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   572
      fst (get_fun absF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   573
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   574
    fun is_constructor (Const (x, _)) = member (op =) constructors x
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   575
      | is_constructor _ = false;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   576
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   577
    fun build_aux lthy tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   578
      case tm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   579
      Abs (a as (_, vty, _)) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   580
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   581
        val (vs, t) = Term.dest_abs a;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   582
        val v = Free(vs, vty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   583
        val t' = lambda v (build_aux lthy t)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   584
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   585
      if (not (needs_lift rty (fastype_of tm))) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   586
      else mk_rep (mk_abs (
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   587
        if not (needs_lift rty vty) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   588
        else
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   589
          let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   590
            val v' = mk_rep (mk_abs v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   591
            val t1 = Envir.beta_norm (t' $ v')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   592
          in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   593
            lambda v t1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   594
          end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   595
      ))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   596
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   597
    | x =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   598
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   599
        val (opp, tms0) = Term.strip_comb tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   600
        val tms = map (build_aux lthy) tms0
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   601
        val ty = fastype_of tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   602
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   603
        if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   604
          then (list_comb (opp, (hd tms0) :: (tl tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   605
      else if (is_constructor opp andalso needs_lift rty ty) then
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   606
          mk_rep (mk_abs (list_comb (opp,tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   607
        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
   608
          mk_rep(mk_abs(list_comb(opp,tms)))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   609
        else if tms = [] then opp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   610
        else list_comb(opp, tms)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   611
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   612
  in
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   613
    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
   614
      (build_aux lthy (Thm.prop_of thm))
139
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
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   618
text {* Assumes that it is given a regularized theorem *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   619
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   620
fun build_repabs_goal ctxt thm cons rty qty =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   621
  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
   622
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   623
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
   624
end