QuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 23 Oct 2009 09:21:45 +0200
changeset 160 6b475324cef7
parent 159 7cefc03224df
child 161 2ee03759a22f
permissions -rw-r--r--
Using RANGE tactical allows getting rid of the quotients immediately.
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
148
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
     6
ML {* Pretty.writeln *}
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
     7
ML {*  LocalTheory.theory_result *}
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
     8
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    18
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    26
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  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
    30
  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
    31
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    36
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    37
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    38
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    40
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  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
    43
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    50
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    56
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    62
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    68
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    69
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    70
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    71
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    72
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    73
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    83
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    84
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    85
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    86
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    87
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    88
  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
    89
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    90
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    91
  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
    92
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    93
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    94
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
    95
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    96
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    97
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    98
  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
    99
  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
   100
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   101
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   102
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   103
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   104
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   105
  shows "R a b = R c d"
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   106
proof
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   107
  assume "R a b"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   108
  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
   109
  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
   110
  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
   111
  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
   112
next
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   113
  assume "R c d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   114
  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
   115
  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
   116
  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
   117
  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
   118
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   119
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   120
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   121
  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
   122
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   123
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   124
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   125
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   126
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   127
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   128
      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
   129
    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
   130
    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
   131
    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
   132
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   133
    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
   134
    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
   135
    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
   136
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   137
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   138
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   139
    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
   140
    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
   141
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   142
  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
   143
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   144
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
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
   147
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents: 70
diff changeset
   150
use "quotient.ML"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   152
(* 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
   153
setup {*
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   154
  maps_update @{type_name "list"} {mapfun = @{const_name "map"},      relfun = @{const_name "LIST_REL"}} #>
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   155
  maps_update @{type_name "*"}    {mapfun = @{const_name "prod_fun"}, relfun = @{const_name "prod_rel"}} #>
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   156
  maps_update @{type_name "fun"}  {mapfun = @{const_name "fun_map"},  relfun = @{const_name "FUN_REL"}}
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   157
*}
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   158
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   159
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   160
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
   161
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   162
ML {*
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   163
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
   164
  let
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   165
    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
   166
    val ((_, [th']), _) = Variable.import true [th] ctxt;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   167
  in th' end);
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   168
*}
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   169
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
section {* various tests for quotient types*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
datatype trm =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   172
  var  "nat"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
| app  "trm" "trm"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
| lam  "nat" "trm"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   175
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   176
axiomatization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   177
  RR :: "trm \<Rightarrow> trm \<Rightarrow> bool"
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   178
where
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   179
  r_eq: "EQUIV RR"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
148
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   181
ML {* print_quotdata @{context} *}
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   182
81
c8d58e2cda58 slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
   183
quotient qtrm = trm / "RR"
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   184
  apply(rule r_eq)
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   185
  done
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   186
148
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   187
ML {* print_quotdata @{context} *}
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   188
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   189
typ qtrm
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
term Rep_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   191
term REP_qtrm
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
term Abs_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
term ABS_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
thm QUOT_TYPE_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
thm QUOTIENT_qtrm
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   196
thm REP_qtrm_def
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   197
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   198
(* Test interpretation *)
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   199
thm QUOT_TYPE_I_qtrm.thm11
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   200
thm QUOT_TYPE.thm11
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   201
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   202
print_theorems
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   203
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
thm Rep_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
text {* another test *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
datatype 'a trm' =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   208
  var'  "'a"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
| app'  "'a trm'" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
| lam'  "'a" "'a trm'"
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   211
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
consts R' :: "'a trm' \<Rightarrow> 'a trm' \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
axioms r_eq': "EQUIV R'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
81
c8d58e2cda58 slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
   215
quotient qtrm' = "'a trm'" / "R'"
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   216
  apply(rule r_eq')
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   217
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   219
print_theorems
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   220
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
term ABS_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
term REP_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
thm QUOT_TYPE_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
thm QUOTIENT_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
thm Rep_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   227
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
text {* a test with lists of terms *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
datatype t =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  vr "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
| ap "t list"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
| lm "string" "t"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
consts Rt :: "t \<Rightarrow> t \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
axioms t_eq: "EQUIV Rt"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
81
c8d58e2cda58 slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
   237
quotient qt = "t" / "Rt"
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   238
  by (rule t_eq)
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
section {* lifting of constants *}
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
ML {*
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   243
(* 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
   244
   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
   245
   function types need to be treated specially, since repF and absF
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   246
   change   
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   247
*)
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   248
datatype flag = absF | repF
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
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
   250
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
   251
  | 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
   252
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   253
fun get_fun flag rty qty lthy ty =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  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
   256
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
    val (fs, tys) = split_list fs_tys
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   260
    val (otys, ntys) = split_list tys
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
  in
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   265
   (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
   266
      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
   267
    | 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
   268
  end
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   269
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   270
  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
   271
  let
f5f641c05794 A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 109
diff changeset
   272
    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
   273
    val ([oty1, oty2], [nty1, nty2]) = split_list tys
128
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   274
    val oty = nty1 --> oty2
6ddb2f99be1d slight fix and tuning
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   275
    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
   276
    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
   277
  in
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   278
    (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
   279
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   281
  fun get_const absF = (Const ("QuotMain.ABS_" ^ qty_name, rty --> qty), (rty, qty))
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   282
    | get_const repF = (Const ("QuotMain.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
   283
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
   284
  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
   285
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
  if ty = qty
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   288
  then (get_const flag)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
  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
   290
          TFree _ => (mk_identity ty, (ty, ty))
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   291
        | 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
   292
        | Type ("fun" , [ty1, ty2]) => 
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   293
                 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
   294
        | 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
   295
        | _ => raise ERROR ("no type variables")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
ML {*
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   301
  get_fun repF @{typ t} @{typ qt} @{context} @{typ "((((qt \<Rightarrow> qt) \<Rightarrow> qt) \<Rightarrow> qt) list) * nat"}
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   302
  |> fst
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   303
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   304
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   305
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   306
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   307
ML {*
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
   308
  get_fun absF @{typ t} @{typ qt} @{context} @{typ "qt * nat"}
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   309
  |> fst
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   310
  |> Syntax.string_of_term @{context}
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   311
  |> writeln
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
   312
*}
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
   313
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
   314
ML {*
118
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   315
  get_fun absF @{typ t} @{typ qt} @{context} @{typ "(qt \<Rightarrow> qt) \<Rightarrow> qt"}
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   316
  |> fst
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   317
  |> Syntax.pretty_term @{context}
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   318
  |> Pretty.string_of
1c30d48bfc15 slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents: 117
diff changeset
   319
  |> writeln
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
   320
*}
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
   321
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   322
text {* produces the definition for a lifted constant *}
86
133af7260a12 Regularizing HOL all.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 85
diff changeset
   323
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   324
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
  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
   329
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
  val fresh_args = arg_tys |> map (pair "x")
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   331
                           |> Variable.variant_frees lthy [nconst, oconst]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
                           |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
46
e801b929216b some tuning of my code
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
   334
  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
   335
  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
   336
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  map (op $) (rep_fns ~~ fresh_args)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  |> curry list_comb oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
  |> curry (op $) abs_fn
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  |> fold_rev lambda fresh_args
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
ML {*
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   346
fun exchange_ty rty qty ty =
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   347
  if ty = rty
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   348
  then qty
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   349
  else
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
       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
   352
      | _ => ty
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   353
    )
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
ML {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   357
fun make_const_def nconst_bname oconst mx rty qty lthy =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
  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
   361
  val nconst = Const (Binding.name_of nconst_bname, nconst_ty)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
in
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   364
  define (nconst_bname, mx, def_trm) lthy
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   365
end
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
111
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   368
(* A test whether get_fun works properly
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   369
consts bla :: "(t \<Rightarrow> t) \<Rightarrow> t"
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   370
local_setup {*
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   371
  fn lthy => (Toplevel.program (fn () =>
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   372
    make_const_def @{binding bla'} @{term "bla"} NoSyn @{typ "t"} @{typ "qt"} lthy
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   373
  )) |> snd
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   374
*}
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   375
*)
4683292581bc Finally fix get_fun.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 110
diff changeset
   376
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   377
local_setup {*
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   378
  make_const_def @{binding VR} @{term "vr"} NoSyn @{typ "t"} @{typ "qt"} #> snd #>
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   379
  make_const_def @{binding AP} @{term "ap"} NoSyn @{typ "t"} @{typ "qt"} #> snd #>
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   380
  make_const_def @{binding LM} @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   381
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   382
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   383
term vr
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   384
term ap
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   385
term lm
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   386
thm VR_def AP_def LM_def
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   387
term LM
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   388
term VR
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   389
term AP
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   390
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
text {* a test with functions *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
datatype 'a t' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  vr' "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
| ap' "('a t') * ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
| lm' "'a" "string \<Rightarrow> ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
consts Rt' :: "('a t') \<Rightarrow> ('a t') \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
axioms t_eq': "EQUIV Rt'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
81
c8d58e2cda58 slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
   400
quotient qt' = "'a t'" / "Rt'"
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   401
  apply(rule t_eq')
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   402
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   404
print_theorems
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   405
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
local_setup {*
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   407
  make_const_def @{binding VR'} @{term "vr'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd #>
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   408
  make_const_def @{binding AP'} @{term "ap'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd #>
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   409
  make_const_def @{binding LM'} @{term "lm'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   412
term vr'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   413
term ap'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   414
term ap'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   415
thm VR'_def AP'_def LM'_def
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   416
term LM'
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
term VR'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
term AP'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   420
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   421
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   422
text {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   423
  Unabs_def converts a definition given as
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   424
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   425
    c \<equiv> %x. %y. f x y
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   426
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   427
  to a theorem of the form
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   428
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   429
    c x y \<equiv> f x y
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   430
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   431
  This function is needed to rewrite the right-hand
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   432
  side to the left-hand side.
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   433
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   434
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   435
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   436
fun unabs_def ctxt def =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   437
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   438
  val (lhs, rhs) = Thm.dest_equals (cprop_of def)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   439
  val xs = strip_abs_vars (term_of rhs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   440
  val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   441
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   442
  val thy = ProofContext.theory_of ctxt'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   443
  val cxs = map (cterm_of thy o Free) xs
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   444
  val new_lhs = Drule.list_comb (lhs, cxs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   445
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   446
  fun get_conv [] = Conv.rewr_conv def
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   447
    | get_conv (x::xs) = Conv.fun_conv (get_conv xs)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   448
in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   449
  get_conv xs new_lhs |>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   450
  singleton (ProofContext.export ctxt' ctxt)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   451
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   452
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   453
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   454
lemma atomize_eqv[atomize]: 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   455
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   456
proof
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   457
  assume "A \<equiv> B" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   458
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   459
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   460
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   461
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   462
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   463
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   464
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   465
    then show "A = B" using * by simp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   466
  next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   467
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   468
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   469
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   470
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   471
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   472
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   473
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   474
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   475
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   476
let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   477
  val thm' = forall_intr_vars thm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   478
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   479
in
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   480
  Thm.freezeT (Simplifier.rewrite_rule [thm''] thm')
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   481
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   482
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   483
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   484
ML {* atomize_thm @{thm list.induct} *}
139
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
section {* REGULARIZE *}
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
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
   489
  type needs to respect. *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   490
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   491
fun tyRel ty rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   492
  if ty = rty 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   493
  then rel
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   494
  else (case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   495
          Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   496
            let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   497
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   498
              val ty_out = ty --> ty --> @{typ bool};
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   499
              val tys_out = tys_rel ---> ty_out;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   500
            in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   501
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   502
               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
   503
             | NONE  => HOLogic.eq_const ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   504
            )
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   505
            end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   506
        | _ => HOLogic.eq_const ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   507
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   508
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   509
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   510
  cterm_of @{theory} (tyRel @{typ "trm \<Rightarrow> bool"} @{typ "trm"} @{term "RR"} @{context})
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
definition
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   514
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   515
where
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   516
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   517
(* TODO: Consider defining it with an "if"; sth like:
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   518
   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
   519
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   520
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   521
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   522
fun needs_lift (rty as Type (rty_s, _)) ty =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   523
  case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   524
    Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   525
      (s = rty_s) orelse (exists (needs_lift rty) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   526
  | _ => false
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   527
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   528
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   529
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   530
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   531
(* trm \<Rightarrow> new_trm *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   532
fun regularise trm rty rel lthy =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   533
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   534
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   535
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   536
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   537
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   538
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   539
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   540
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   541
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   542
        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
   543
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   544
        val ty = fastype_of trm;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   545
        val rabs = Const (@{const_name Babs}, (fastype_of res_term) --> ty --> ty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   546
        val rabs_term = (rabs $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   547
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   548
        rabs_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   549
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   550
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   551
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   552
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   553
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   554
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   555
        Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   556
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   557
  | ((Const (@{const_name "All"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   558
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   559
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   560
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   561
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   562
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   563
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   564
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   565
        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
   566
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   567
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   568
        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
   569
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   570
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   571
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   572
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   573
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   574
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   575
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   576
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   577
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   578
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   579
        Const(@{const_name "All"}, at) $ lam_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   580
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   581
  | ((Const (@{const_name "All"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   582
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   583
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   584
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   585
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   586
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   587
      in regularise ((Const (@{const_name "All"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   588
  | ((Const (@{const_name "Ex"}, at)) $ (Abs (x, T, t))) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   589
      if (needs_lift rty T) then let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   590
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   591
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   592
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   593
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   594
        val lam_term = Term.lambda_name (x, v) rec_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   595
        val sub_res_term = tyRel T rty rel lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   596
        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
   597
        val res_term = respects $ sub_res_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   598
        val ty = fastype_of lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   599
        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
   600
        val rall_term = (rall $ res_term) $ lam_term;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   601
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   602
        rall_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   603
      end else let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   604
        val ([x'], lthy2) = Variable.variant_fixes [x] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   605
        val v = Free (x', T);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   606
        val t' = subst_bound (v, t);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   607
        val rec_term = regularise t' rty rel lthy2;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   608
        val lam_term = Term.lambda_name (x, v) rec_term
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   609
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   610
        Const(@{const_name "Ex"}, at) $ lam_term
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
  | ((Const (@{const_name "Ex"}, at)) $ P) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   613
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   614
        val (_, [al, _]) = dest_Type (fastype_of P);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   615
        val ([x], lthy2) = Variable.variant_fixes [""] lthy;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   616
        val v = (Free (x, al));
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   617
        val abs = Term.lambda_name (x, v) (P $ v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   618
      in regularise ((Const (@{const_name "Ex"}, at)) $ abs) rty rel lthy2 end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   619
  | a $ b => (regularise a rty rel lthy) $ (regularise b rty rel lthy)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   620
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   621
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
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   624
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   625
  cterm_of @{theory} (regularise @{term "\<lambda>x :: int. x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   626
  cterm_of @{theory} (regularise @{term "\<lambda>x :: trm. x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   627
  cterm_of @{theory} (regularise @{term "\<forall>x :: trm. P x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   628
  cterm_of @{theory} (regularise @{term "\<exists>x :: trm. P x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   629
  cterm_of @{theory} (regularise @{term "All (P :: trm \<Rightarrow> bool)"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   630
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   631
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   632
(* my version of regularise *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   633
(****************************)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   634
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   635
(* some helper functions *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   636
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
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   639
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
   640
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   641
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   642
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
   643
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   644
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   645
(* 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
   646
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   647
fun apply_subt f trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   648
  case trm of
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   649
    Abs (x, T, t) => 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   650
       let 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   651
         val (x', t') = Term.dest_abs (x, T, t)
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   652
       in
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   653
         Term.absfree (x', T, f t') 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   654
       end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   655
  | _ => f trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   656
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   657
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   658
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   659
(* FIXME: assumes always the typ is qty! *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   660
(* 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
   661
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   662
fun my_reg rel trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   663
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   664
    Abs (x, T, t) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   665
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   666
          val ty1 = fastype_of trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   667
       in
146
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
   668
         (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
   669
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   670
  | Const (@{const_name "All"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   671
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   672
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   673
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   674
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   675
         (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
   676
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   677
  | Const (@{const_name "Ex"}, ty) $ t =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   678
       let 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   679
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   680
          val ty2 = domain_type ty1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   681
       in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   682
         (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
   683
       end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   684
  | t1 $ t2 => (my_reg rel t1) $ (my_reg rel t2)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   685
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   686
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   687
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   688
ML {*  
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   689
  cterm_of @{theory} (regularise @{term "\<exists>(y::trm). P (\<lambda>(x::trm). y)"} @{typ "trm"} 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   690
     @{term "RR"} @{context});
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   691
  cterm_of @{theory} (my_reg @{term "RR"} @{term "\<exists>(y::trm). P (\<lambda>(x::trm). y)"})
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   692
*}
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   693
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   694
ML {*  
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   695
  cterm_of @{theory} (regularise @{term "\<lambda>x::trm. x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   696
  cterm_of @{theory} (my_reg @{term "RR"} @{term "\<lambda>x::trm. x"})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   697
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   698
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   699
ML {*  
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   700
  cterm_of @{theory} (regularise @{term "\<forall>(x::trm) (y::trm). P x y"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   701
  cterm_of @{theory} (my_reg @{term "RR"} @{term "\<forall>(x::trm) (y::trm). P x y"})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   702
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   703
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   704
ML {*  
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   705
  cterm_of @{theory} (regularise @{term "\<forall>x::trm. P x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   706
  cterm_of @{theory} (my_reg @{term "RR"} @{term "\<forall>x::trm. P x"})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   707
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   708
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   709
ML {*  
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   710
  cterm_of @{theory} (regularise @{term "\<exists>x::trm. P x"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   711
  cterm_of @{theory} (my_reg @{term "RR"} @{term "\<exists>x::trm. P x"})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   712
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   713
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   714
(* my version is not eta-expanded, but that should be OK *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   715
ML {*  
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   716
  cterm_of @{theory} (regularise @{term "All (P::trm \<Rightarrow> bool)"} @{typ "trm"} @{term "RR"} @{context});
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   717
  cterm_of @{theory} (my_reg @{term "RR"} @{term "All (P::trm \<Rightarrow> bool)"})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   718
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   719
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   720
(*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
   721
  trm == new_trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   722
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   723
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   724
text {* Assumes that the given theorem is atomized *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   725
ML {*
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   726
  fun build_regularize_goal thm rty rel lthy =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   727
     Logic.mk_implies
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   728
       ((prop_of thm),
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   729
       (regularise (prop_of thm) rty rel lthy))
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   730
*}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   731
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   732
section {* RepAbs injection *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   733
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   734
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   735
fun build_repabs_term lthy thm constructors rty qty =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   736
  let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   737
    fun mk_rep tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   738
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   739
        val ty = exchange_ty rty qty (fastype_of tm)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   740
      in fst (get_fun repF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   741
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   742
    fun mk_abs tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   743
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   744
        val ty = exchange_ty rty qty (fastype_of tm) in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   745
      fst (get_fun absF rty qty lthy ty) $ tm end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   746
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   747
    fun is_constructor (Const (x, _)) = member (op =) constructors x
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   748
      | is_constructor _ = false;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   749
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   750
    fun build_aux lthy tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   751
      case tm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   752
      Abs (a as (_, vty, _)) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   753
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   754
        val (vs, t) = Term.dest_abs a;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   755
        val v = Free(vs, vty);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   756
        val t' = lambda v (build_aux lthy t)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   757
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   758
      if (not (needs_lift rty (fastype_of tm))) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   759
      else mk_rep (mk_abs (
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   760
        if not (needs_lift rty vty) then t'
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   761
        else
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   762
          let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   763
            val v' = mk_rep (mk_abs v);
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   764
            val t1 = Envir.beta_norm (t' $ v')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   765
          in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   766
            lambda v t1
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   767
          end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   768
      ))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   769
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   770
    | x =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   771
      let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   772
        val (opp, tms0) = Term.strip_comb tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   773
        val tms = map (build_aux lthy) tms0
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   774
        val ty = fastype_of tm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   775
      in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   776
        if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   777
          then (list_comb (opp, (hd tms0) :: (tl tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   778
      else if (is_constructor opp andalso needs_lift rty ty) then
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   779
          mk_rep (mk_abs (list_comb (opp,tms)))
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   780
        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
   781
          mk_rep(mk_abs(list_comb(opp,tms)))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   782
        else if tms = [] then opp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   783
        else list_comb(opp, tms)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   784
      end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   785
  in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   786
    build_aux lthy (Thm.prop_of thm)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   787
  end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   788
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   789
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   790
text {* Assumes that it is given a regularized theorem *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   791
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   792
fun build_repabs_goal ctxt thm cons rty qty =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   793
  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
   794
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   795
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   796
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   797
section {* finite set example *}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   798
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   799
inductive
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   800
  list_eq (infix "\<approx>" 50)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
  "a#b#xs \<approx> b#a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803
| "[] \<approx> []"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   804
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   805
| "a#a#xs \<approx> a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   807
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
47
6a51704204e5 consistent state
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
   809
lemma list_eq_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   810
  shows "xs \<approx> xs"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   811
  apply (induct xs)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   812
   apply (auto intro: list_eq.intros)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   813
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
lemma equiv_list_eq:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   816
  shows "EQUIV list_eq"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   817
  unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
47
6a51704204e5 consistent state
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
   818
  apply(auto intro: list_eq.intros list_eq_refl)
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   819
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
81
c8d58e2cda58 slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
   821
quotient fset = "'a list" / "list_eq"
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   822
  apply(rule equiv_list_eq)
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 77
diff changeset
   823
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   824
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   825
print_theorems
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   826
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   827
typ "'a fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
thm "Rep_fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   829
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   830
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   831
  make_const_def @{binding EMPTY} @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   832
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   833
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   834
term Nil
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
term EMPTY
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   836
thm EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   837
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   838
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   839
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   840
  make_const_def @{binding INSERT} @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   841
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   842
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   843
term Cons
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   844
term INSERT
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   845
thm INSERT_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   847
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   848
  make_const_def @{binding UNION} @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   851
term append
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   852
term UNION
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   853
thm UNION_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   854
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   855
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   856
thm QUOTIENT_fset
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   857
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   858
thm QUOT_TYPE_I_fset.thm11
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   859
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   860
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   861
fun
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   862
  membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   863
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   864
  m1: "(x memb []) = False"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   865
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   866
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   867
fun
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   868
  card1 :: "'a list \<Rightarrow> nat"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   869
where
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   870
  card1_nil: "(card1 []) = 0"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   871
| card1_cons: "(card1 (x # xs)) = (if (x memb xs) then (card1 xs) else (Suc (card1 xs)))"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   872
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   873
local_setup {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   874
  make_const_def @{binding card} @{term "card1"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   875
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   876
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   877
term card1
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   878
term card
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   879
thm card_def
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   880
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   881
(* text {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   882
 Maybe make_const_def should require a theorem that says that the particular lifted function
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   883
 respects the relation. With it such a definition would be impossible:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   884
 make_const_def @{binding CARD} @{term "length"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   885
*}*)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   886
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   887
lemma card1_0:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   888
  fixes a :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   889
  shows "(card1 a = 0) = (a = [])"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   890
  apply (induct a)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   891
   apply (simp)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   892
  apply (simp_all)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   893
   apply meson
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   894
  apply (simp_all)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   895
  done
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   896
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   897
lemma not_mem_card1:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   898
  fixes x :: "'a"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   899
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   900
  shows "~(x memb xs) \<Longrightarrow> card1 (x # xs) = Suc (card1 xs)"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   901
  by simp
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   902
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   903
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   904
lemma mem_cons:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   905
  fixes x :: "'a"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   906
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   907
  assumes a : "x memb xs"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   908
  shows "x # xs \<approx> xs"
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   909
  using a
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   910
  apply (induct xs)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   911
  apply (auto intro: list_eq.intros)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   912
  done
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   913
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   914
lemma card1_suc:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   915
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   916
  fixes n :: "nat"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   917
  assumes c: "card1 xs = Suc n"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   918
  shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   919
  using c
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   920
apply(induct xs)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   921
apply (metis Suc_neq_Zero card1_0)
47
6a51704204e5 consistent state
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
   922
apply (metis QUOT_TYPE_I_fset.R_trans QuotMain.card1_cons list_eq_refl mem_cons)
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   923
done
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   924
97
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   925
primrec
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   926
  fold1
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   927
where
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   928
  "fold1 f (g :: 'a \<Rightarrow> 'b) (z :: 'b) [] = z"
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   929
| "fold1 f g z (a # A) =
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   930
     (if ((!u v. (f u v = f v u))
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   931
      \<and> (!u v w. ((f u (f v w) = f (f u v) w))))
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   932
     then (
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   933
       if (a memb A) then (fold1 f g z A) else (f (g a) (fold1 f g z A))
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   934
     ) else z)"
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   935
100
09f4d69f7b66 Reordering the code, part 2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 99
diff changeset
   936
(* fold1_def is not usable, but: *)
97
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   937
thm fold1.simps
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
   938
60
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   939
lemma fs1_strong_cases:
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   940
  fixes X :: "'a list"
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   941
  shows "(X = []) \<or> (\<exists>a. \<exists> Y. (~(a memb Y) \<and> (X \<approx> a # Y)))"
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   942
  apply (induct X)
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   943
  apply (simp)
72
4efc9e6661a4 Testing if I can prove the regularized version of induction manually
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 71
diff changeset
   944
  apply (metis QUOT_TYPE_I_fset.thm11 list_eq_refl mem_cons QuotMain.m1)
60
4826ad24f772 First theorem with quantifiers. Learned how to use sledgehammer.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 58
diff changeset
   945
  done
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   946
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   947
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   948
  make_const_def @{binding IN} @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   949
*}
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   950
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   951
term membship
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   952
term IN
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   953
thm IN_def
66
564bf4343f63 another improvement to unlam_def
Christian Urban <urbanc@in.tum.de>
parents: 65
diff changeset
   954
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   955
ML {*
107
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
   956
  val consts = [@{const_name "Nil"}, @{const_name "Cons"},
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
   957
                @{const_name "membship"}, @{const_name "card1"},
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
   958
                @{const_name "append"}, @{const_name "fold1"}];
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   959
*}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   960
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   961
ML {* val fset_defs = @{thms EMPTY_def IN_def UNION_def card_def INSERT_def} *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   962
ML {* val fset_defs_sym = map (fn t => symmetric (unabs_def @{context} t)) fset_defs *}
107
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
   963
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   964
text {* Respectfullness *}
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   965
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   966
lemma mem_respects:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   967
  fixes z
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   968
  assumes a: "list_eq x y"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   969
  shows "(z memb x) = (z memb y)"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   970
  using a by induct auto
103
4aef3882b436 Cleaning the code, part 4
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 101
diff changeset
   971
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   972
lemma card1_rsp:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   973
  fixes a b :: "'a list"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   974
  assumes e: "a \<approx> b"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   975
  shows "card1 a = card1 b"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   976
  using e apply induct
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   977
  apply (simp_all add:mem_respects)
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
   978
  done
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   979
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   980
lemma cons_preserves:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   981
  fixes z
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   982
  assumes a: "xs \<approx> ys"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   983
  shows "(z # xs) \<approx> (z # ys)"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   984
  using a by (rule QuotMain.list_eq.intros(5))
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   985
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   986
lemma append_respects_fst:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   987
  assumes a : "list_eq l1 l2"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   988
  shows "list_eq (l1 @ s) (l2 @ s)"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   989
  using a
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   990
  apply(induct)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   991
  apply(auto intro: list_eq.intros)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   992
  apply(simp add: list_eq_refl)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
   993
done
99
19e5aceb8c2d Reordering the code, part 1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 98
diff changeset
   994
19e5aceb8c2d Reordering the code, part 1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 98
diff changeset
   995
thm list.induct
114
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
   996
lemma list_induct_hol4:
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
   997
  fixes P :: "'a list \<Rightarrow> bool"
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
   998
  assumes "((P []) \<and> (\<forall>t. (P t) \<longrightarrow> (\<forall>h. (P (h # t)))))"
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
   999
  shows "(\<forall>l. (P l))"
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1000
  sorry
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1001
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1002
ML {* atomize_thm @{thm list_induct_hol4} *}
99
19e5aceb8c2d Reordering the code, part 1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 98
diff changeset
  1003
107
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
  1004
prove list_induct_r: {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
  1005
   build_regularize_goal (atomize_thm @{thm list_induct_hol4}) @{typ "'a List.list"} @{term "op \<approx>"} @{context} *}
93
ec29be471518 Manually regularized list_induct2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 92
diff changeset
  1006
  apply (simp only: equiv_res_forall[OF equiv_list_eq])
94
ecfc2e1fd15e Forgot to save, second part of the commit
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 93
diff changeset
  1007
  thm RIGHT_RES_FORALL_REGULAR
ecfc2e1fd15e Forgot to save, second part of the commit
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 93
diff changeset
  1008
  apply (rule RIGHT_RES_FORALL_REGULAR)
93
ec29be471518 Manually regularized list_induct2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 92
diff changeset
  1009
  prefer 2
ec29be471518 Manually regularized list_induct2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 92
diff changeset
  1010
  apply (assumption)
104
41a2ab50dd89 Cleaning the proofs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 103
diff changeset
  1011
  apply (metis)
94
ecfc2e1fd15e Forgot to save, second part of the commit
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 93
diff changeset
  1012
  done
87
9220c51e5155 atomize_thm and meta_quantify.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 86
diff changeset
  1013
143
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1014
ML {*
147
Christian Urban <urbanc@in.tum.de>
parents: 146
diff changeset
  1015
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
143
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1016
let
146
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
  1017
  val pat = Drule.strip_imp_concl (cprop_of thm)
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
  1018
  val insts = Thm.match (pat, concl)
143
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1019
in
146
6e9e3cba4be9 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
  1020
  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
  1021
end
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1022
handle _ => no_tac
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1023
)
143
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1024
*}
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1025
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1026
ML {*
158
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1027
fun res_forall_rsp_tac ctxt =
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1028
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1029
  THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1030
  THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1031
  (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1032
*}
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1033
159
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1034
ML {* 
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1035
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1036
((simp_tac ((Simplifier.context @{context}  HOL_ss) addsimps @{thms FUN_REL.simps})) THEN' (fn _ => no_tac))
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1037
*}
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1038
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1039
ML {* ((simp_tac ((Simplifier.context @{context} HOL_ss) addsimps @{thms FUN_REL.simps}))  THEN_ALL_NEW (fn _ => no_tac)) *}
160
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1040
ML {* RANGE *}
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1041
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1042
ML {*
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1043
fun quotient_tac quot_thm =
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1044
  REPEAT_ALL_NEW (FIRST' [
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1045
    rtac @{thm FUN_QUOTIENT},
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1046
    rtac quot_thm,
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1047
    rtac @{thm IDENTITY_QUOTIENT}
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1048
  ])
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1049
*}
158
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1050
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1051
ML {*
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1052
fun r_mk_comb_tac ctxt quot_thm reflex_thm trans_thm =
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1053
  (FIRST' [
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1054
    rtac @{thm FUN_QUOTIENT},
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1055
    rtac quot_thm,
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1056
    rtac @{thm IDENTITY_QUOTIENT},
157
ca0b28863ca9 Working on the proof and the tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 156
diff changeset
  1057
    rtac @{thm ext},
ca0b28863ca9 Working on the proof and the tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 156
diff changeset
  1058
    rtac trans_thm,
158
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1059
    res_forall_rsp_tac ctxt,
160
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1060
    (instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])),
6b475324cef7 Using RANGE tactical allows getting rid of the quotients immediately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 159
diff changeset
  1061
    (instantiate_tac @{thm APPLY_RSP} ctxt THEN' (RANGE [quotient_tac quot_thm, quotient_tac quot_thm])),
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1062
      rtac reflex_thm,
159
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1063
      atac,
7cefc03224df Further developing the tactic and simplifying the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 158
diff changeset
  1064
      ((simp_tac ((Simplifier.context @{context} HOL_ss) addsimps @{thms FUN_REL.simps}))  THEN_ALL_NEW (fn _ => no_tac))
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1065
    ])
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1066
*}
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1067
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1068
ML {*
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1069
fun r_mk_comb_tac_fset ctxt =
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1070
  r_mk_comb_tac ctxt @{thm QUOTIENT_fset} @{thm list_eq_refl} @{thm QUOT_TYPE_I_fset.R_trans2}
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1071
*}
143
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1072
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1073
1d0692e7ddd4 Simplified proof more
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 142
diff changeset
  1074
ML {* val thm = @{thm list_induct_r} OF [atomize_thm @{thm list_induct_hol4}] *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
  1075
ML {* val trm_r = build_repabs_goal @{context} thm consts @{typ "'a list"} @{typ "'a fset"} *}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
  1076
ML {* val trm = build_repabs_term @{context} thm consts @{typ "'a list"} @{typ "'a fset"} *}
129
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1077
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1078
prove list_induct_tr: trm_r
112
0d6d37d0589d Progressing with the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 111
diff changeset
  1079
apply (atomize(full))
113
e3a963e6418b Symmetric version of REP_ABS_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 112
diff changeset
  1080
apply (simp only: id_def[symmetric])
114
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1081
(* APPLY_RSP_TAC *)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1082
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1083
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
158
c0d13b337c66 res_forall_rsp_tac further simplifies the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 157
diff changeset
  1084
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
114
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1085
(* LAMBDA_RES_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1086
apply (simp only: FUN_REL.simps)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1087
apply (rule allI)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1088
apply (rule allI)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1089
apply (rule impI)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1090
(* MK_COMB_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1091
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1092
(* MK_COMB_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1093
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1094
(* REFL_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1095
apply (simp)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1096
(* MK_COMB_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1097
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1098
(* MK_COMB_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1099
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1100
(* REFL_TAC *)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1101
apply (simp)
3cdb743b7605 Fighting with the instantiation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 113
diff changeset
  1102
(* APPLY_RSP_TAC *)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1103
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1104
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1105
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1106
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
124
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1107
apply (simp only: FUN_REL.simps)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1108
apply (rule allI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1109
apply (rule allI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1110
apply (rule impI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1111
(* MK_COMB_TAC *)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1112
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1113
(* MK_COMB_TAC *)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1114
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1115
(* REFL_TAC *)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1116
apply (simp)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1117
(* APPLY_RSP *)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1118
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1119
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1120
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
124
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1121
(* MK_COMB_TAC *)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1122
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1123
(* REFL_TAC *)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1124
apply (simp)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1125
(* W(C (curry op THEN) (G... *)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1126
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1127
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1128
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1129
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1130
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1131
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
126
9cb8f9a59402 Partial simplification of the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 125
diff changeset
  1132
(* CONS respects *)
9cb8f9a59402 Partial simplification of the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 125
diff changeset
  1133
apply (simp add: FUN_REL.simps)
9cb8f9a59402 Partial simplification of the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 125
diff changeset
  1134
apply (rule allI)
124
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1135
apply (rule allI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1136
apply (rule allI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1137
apply (rule impI)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1138
apply (rule cons_preserves)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1139
apply (assumption)
de944fcd6a05 Only QUOTIENSs are left to fnish proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 123
diff changeset
  1140
apply (simp)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1141
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1142
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1143
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1144
apply (tactic {* r_mk_comb_tac_fset @{context} 1 *})
151
b4bef5ed8153 More proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 150
diff changeset
  1145
apply (simp only: FUN_REL.simps)
b4bef5ed8153 More proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 150
diff changeset
  1146
apply (rule allI)
b4bef5ed8153 More proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 150
diff changeset
  1147
apply (rule allI)
b4bef5ed8153 More proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 150
diff changeset
  1148
apply (rule impI)
152
53277fbb2dba Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 151
diff changeset
  1149
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
154
1610de61c44b The proof now including manually unfolded higher-order RES_FORALL_RSP.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 153
diff changeset
  1150
done
107
ab53ddefc542 A proper build_goal_term function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 106
diff changeset
  1151
129
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1152
prove list_induct_t: trm
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1153
apply (simp only: list_induct_tr[symmetric])
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1154
apply (tactic {* rtac thm 1 *})
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1155
done
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1156
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1157
ML {* val nthm = MetaSimplifier.rewrite_rule fset_defs_sym (snd (no_vars (Context.Theory @{theory}, @{thm list_induct_t}))) *}
89283c1dbba7 Test if we can already do sth with the transformed theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 128
diff changeset
  1158
112
0d6d37d0589d Progressing with the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 111
diff changeset
  1159
thm list.recs(2)
0d6d37d0589d Progressing with the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 111
diff changeset
  1160
0d6d37d0589d Progressing with the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 111
diff changeset
  1161
106
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1162
ML {* val card1_suc_f = Thm.freezeT (atomize_thm @{thm card1_suc}) *}
96
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1163
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1164
prove card1_suc_r: {*
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1165
 Logic.mk_implies
106
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1166
   ((prop_of card1_suc_f),
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1167
   (regularise (prop_of card1_suc_f) @{typ "'a List.list"} @{term "op \<approx>"} @{context})) *}
104
41a2ab50dd89 Cleaning the proofs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 103
diff changeset
  1168
  apply (simp add: equiv_res_forall[OF equiv_list_eq] equiv_res_exists[OF equiv_list_eq])
96
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1169
  done
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1170
106
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1171
ML {* @{thm card1_suc_r} OF [card1_suc_f] *}
96
4da714704611 A number of lemmas for REGULARIZE_TAC and regularizing card1.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 95
diff changeset
  1172
97
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1173
ML {* val li = Thm.freezeT (atomize_thm @{thm fold1.simps(2)}) *}
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1174
prove fold1_def_2_r: {*
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1175
 Logic.mk_implies
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1176
   ((prop_of li),
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1177
   (regularise (prop_of li) @{typ "'a List.list"} @{term "op \<approx>"} @{context})) *}
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1178
  apply (simp add: equiv_res_forall[OF equiv_list_eq])
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1179
  done
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1180
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1181
ML {* @{thm fold1_def_2_r} OF [li] *}
0d34f2e60d5d The definition of Fold1
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 96
diff changeset
  1182
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1183
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1184
lemma yy:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1185
  shows "(False = x memb []) = (False = IN (x::nat) EMPTY)"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1186
unfolding IN_def EMPTY_def
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1187
apply(rule_tac f="(op =) False" in arg_cong)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1188
apply(rule mem_respects)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1189
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1190
apply(rule list_eq.intros)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1191
done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1192
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1193
lemma
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1194
  shows "IN (x::nat) EMPTY = False"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1195
using m1
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1196
apply -
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1197
apply(rule yy[THEN iffD1, symmetric])
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1198
apply(simp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1199
done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1200
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1201
lemma
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1202
  shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) =
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1203
         ((x=y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1204
unfolding IN_def INSERT_def
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1205
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1206
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1207
apply(rule mem_respects)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1208
apply(rule list_eq.intros(3))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1209
apply(unfold REP_fset_def ABS_fset_def)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1210
apply(simp only: QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1211
apply(rule list_eq_refl)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1212
done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1213
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1214
lemma yyy:
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1215
  shows "
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1216
    (
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1217
     (UNION EMPTY s = s) &
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1218
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1219
    ) = (
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1220
     ((ABS_fset ([] @ REP_fset s)) = s) &
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1221
     ((ABS_fset ((e # (REP_fset s1)) @ REP_fset s2)) = ABS_fset (e # (REP_fset s1 @ REP_fset s2)))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1222
    )"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1223
  unfolding UNION_def EMPTY_def INSERT_def
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1224
  apply(rule_tac f="(op &)" in arg_cong2)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1225
  apply(rule_tac f="(op =)" in arg_cong2)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1226
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1227
  apply(rule append_respects_fst)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1228
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1229
  apply(rule list_eq_refl)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1230
  apply(simp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1231
  apply(rule_tac f="(op =)" in arg_cong2)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1232
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1233
  apply(rule append_respects_fst)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1234
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1235
  apply(rule list_eq_refl)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1236
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1237
  apply(rule list_eq.intros(5))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1238
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1239
  apply(rule list_eq_refl)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1240
done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1241
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1242
lemma
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1243
  shows "
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1244
     (UNION EMPTY s = s) &
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1245
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1246
  apply (simp add: yyy)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1247
  apply (simp add: QUOT_TYPE_I_fset.thm10)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1248
  done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1249
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1250
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1251
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1252
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1253
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1254
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1255
cterm_of @{theory} (prop_of m1_novars);
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1256
cterm_of @{theory} (build_repabs_term @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"});
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1257
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1258
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1259
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1260
(* Has all the theorems about fset plugged in. These should be parameters to the tactic *)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1261
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1262
  fun transconv_fset_tac' ctxt =
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1263
    (LocalDefs.unfold_tac @{context} fset_defs) THEN
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1264
    ObjectLogic.full_atomize_tac 1 THEN
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1265
    REPEAT_ALL_NEW (FIRST' [
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1266
      rtac @{thm list_eq_refl},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1267
      rtac @{thm cons_preserves},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1268
      rtac @{thm mem_respects},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1269
      rtac @{thm card1_rsp},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1270
      rtac @{thm QUOT_TYPE_I_fset.R_trans2},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1271
      CHANGED o (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms QUOT_TYPE_I_fset.REP_ABS_rsp})),
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1272
      Cong_Tac.cong_tac @{thm cong},
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1273
      rtac @{thm ext}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1274
    ]) 1
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1275
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1276
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1277
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1278
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1279
  val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1280
  val cgoal = cterm_of @{theory} goal
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1281
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1282
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1283
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1284
(*notation ( output) "prop" ("#_" [1000] 1000) *)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1285
notation ( output) "Trueprop" ("#_" [1000] 1000)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1286
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1287
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1288
prove {* (Thm.term_of cgoal2) *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1289
  apply (tactic {* transconv_fset_tac' @{context} *})
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1290
  done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1291
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1292
thm length_append (* Not true but worth checking that the goal is correct *)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1293
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1294
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1295
  val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1296
  val cgoal = cterm_of @{theory} goal
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1297
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1298
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1299
prove {* Thm.term_of cgoal2 *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1300
  apply (tactic {* transconv_fset_tac' @{context} *})
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1301
  sorry
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1302
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1303
thm m2
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1304
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1305
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1306
  val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1307
  val cgoal = cterm_of @{theory} goal
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1308
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1309
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1310
prove {* Thm.term_of cgoal2 *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1311
  apply (tactic {* transconv_fset_tac' @{context} *})
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1312
  done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1313
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1314
thm list_eq.intros(4)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1315
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1316
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1317
  val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1318
  val cgoal = cterm_of @{theory} goal
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1319
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1320
  val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1321
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1322
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1323
(* It is the same, but we need a name for it. *)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1324
prove zzz : {* Thm.term_of cgoal3 *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1325
  apply (tactic {* transconv_fset_tac' @{context} *})
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1326
  done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1327
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1328
(*lemma zzz' :
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1329
  "(REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))"
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1330
  using list_eq.intros(4) by (simp only: zzz)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1331
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1332
thm QUOT_TYPE_I_fset.REPS_same
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1333
ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1334
*)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1335
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1336
thm list_eq.intros(5)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1337
(* prove {* build_repabs_goal @{context} (atomize_thm @{thm list_eq.intros(5)}) consts @{typ "'a list"} @{typ "'a fset"} *} *)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1338
ML {*
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1339
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)}))
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1340
  val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1341
  val cgoal = cterm_of @{theory} goal
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1342
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1343
*}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1344
prove {* Thm.term_of cgoal2 *}
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1345
  apply (tactic {* transconv_fset_tac' @{context} *})
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1346
  done
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1347
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1348
ML {*
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1349
  fun lift_theorem_fset_aux thm lthy =
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1350
    let
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1351
      val ((_, [novars]), lthy2) = Variable.import true [thm] lthy;
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
  1352
      val goal = build_repabs_goal @{context} novars consts @{typ "'a list"} @{typ "'a fset"};
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1353
      val cgoal = cterm_of @{theory} goal;
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1354
      val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal);
106
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1355
      val tac = transconv_fset_tac' @{context};
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1356
      val cthm = Goal.prove_internal [] cgoal2 (fn _ => tac);
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1357
      val nthm = MetaSimplifier.rewrite_rule [symmetric cthm] (snd (no_vars (Context.Theory @{theory}, thm)))
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1358
      val nthm2 = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same QUOT_TYPE_I_fset.thm10} nthm;
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1359
      val [nthm3] = ProofContext.export lthy2 lthy [nthm2]
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1360
    in
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1361
      nthm3
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1362
    end
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1363
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1364
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1365
ML {* lift_theorem_fset_aux @{thm m1} @{context} *}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1366
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1367
ML {*
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1368
  fun lift_theorem_fset name thm lthy =
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1369
    let
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1370
      val lifted_thm = lift_theorem_fset_aux thm lthy;
88
19d3856abb81 slight simplification of atomize_thm
Christian Urban <urbanc@in.tum.de>
parents: 87
diff changeset
  1371
      val (_, lthy2) = note (name, lifted_thm) lthy;
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1372
    in
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1373
      lthy2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1374
    end;
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1375
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1376
144
d5098c950d27 Reorganization of the construction part
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 143
diff changeset
  1377
(* These do not work without proper definitions to rewrite back *)
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1378
local_setup {* lift_theorem_fset @{binding "m1_lift"} @{thm m1} *}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1379
local_setup {* lift_theorem_fset @{binding "leqi4_lift"} @{thm list_eq.intros(4)} *}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1380
local_setup {* lift_theorem_fset @{binding "leqi5_lift"} @{thm list_eq.intros(5)} *}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1381
local_setup {* lift_theorem_fset @{binding "m2_lift"} @{thm m2} *}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1382
thm m1_lift
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1383
thm leqi4_lift
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1384
thm leqi5_lift
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1385
thm m2_lift
106
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1386
ML {* @{thm card1_suc_r} OF [card1_suc_f] *}
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1387
(*ML {* Toplevel.program (fn () => lift_theorem_fset @{binding "card_suc"}
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1388
     (@{thm card1_suc_r} OF [card1_suc_f]) @{context}) *}*)
a250b56e7f2a Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 105
diff changeset
  1389
(*local_setup {* lift_theorem_fset @{binding "card_suc"} @{thm card1_suc} *}*)
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1390
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1391
thm leqi4_lift
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1392
ML {*
62
58384c90a5e5 used prop_of to get the term of a theorem (replaces crep_thm)
Christian Urban <urbanc@in.tum.de>
parents: 61
diff changeset
  1393
  val (nam, typ) = hd (Term.add_vars (prop_of @{thm leqi4_lift}) [])
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1394
  val (_, l) = dest_Type typ
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1395
  val t = Type ("QuotMain.fset", l)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1396
  val v = Var (nam, t)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1397
  val cv = cterm_of @{theory} ((term_of @{cpat "REP_fset"}) $ v)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1398
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1399
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1400
ML {*
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1401
  Toplevel.program (fn () =>
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1402
    MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.thm10} (
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1403
      Drule.instantiate' [] [NONE, SOME (cv)] @{thm leqi4_lift}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1404
    )
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1405
  )
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1406
*}
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
  1407
73
fdaf1466daf0 Further experiments with proving induction manually
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 72
diff changeset
  1408
72
4efc9e6661a4 Testing if I can prove the regularized version of induction manually
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 71
diff changeset
  1409
4efc9e6661a4 Testing if I can prove the regularized version of induction manually
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 71
diff changeset
  1410
(*prove aaa: {* (Thm.term_of cgoal2) *}
45
d98224cafb86 Cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 44
diff changeset
  1411
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
58
f2565006dc5a Just one atomize is enough for the currently lifted theorems. Properly lift 'all' and 'Ex'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 57
diff changeset
  1412
  apply (atomize(full))
101
4f93c5a026d2 Reordering the code, part 3
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 100
diff changeset
  1413
  apply (tactic {* transconv_fset_tac' @{context} 1 *})
72
4efc9e6661a4 Testing if I can prove the regularized version of induction manually
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 71
diff changeset
  1414
  done*)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1415
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1416
(*
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1417
datatype obj1 =
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1418
  OVAR1 "string"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1419
| OBJ1 "(string * (string \<Rightarrow> obj1)) list"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1420
| INVOKE1 "obj1 \<Rightarrow> string"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1421
| UPDATE1 "obj1 \<Rightarrow> string \<Rightarrow> (string \<Rightarrow> obj1)"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1422
*)
53
a036f6fb1516 Test line
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 52
diff changeset
  1423
148
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
  1424
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
  1425
8e24e65f1e9b tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
  1426
57
13be92f5b638 used new cong_tac
Christian Urban <urbanc@in.tum.de>
parents: 56
diff changeset
  1427
end
112
0d6d37d0589d Progressing with the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 111
diff changeset
  1428