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