QuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Mon, 28 Sep 2009 19:10:27 +0200
changeset 44 f078dbf557b7
parent 43 e51af8bace65
parent 41 72d63aa8af68
child 45 d98224cafb86
permissions -rw-r--r--
Merged
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
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  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
    14
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    22
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  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
    26
  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
    27
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    32
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    33
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    34
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    36
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  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
    39
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    46
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    52
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    58
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    64
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    65
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    66
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    67
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
    68
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    69
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    79
lemma R_trans:
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
    80
  assumes ab: "R a b"
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
    81
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    82
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    83
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    84
  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
    85
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    86
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    87
  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
    88
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    89
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    90
lemma R_sym:
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
    91
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
    92
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    93
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    94
  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
    95
  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
    96
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
    97
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
    98
lemma R_trans2:
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
    99
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   100
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   101
  shows "R a b = R c d"
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   102
proof
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   103
  assume "R a b"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   104
  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
   105
  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
   106
  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
   107
  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
   108
next
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   109
  assume "R c d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   110
  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
   111
  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
   112
  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
   113
  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
   114
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   115
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   116
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   117
  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
   118
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   119
  have "R (REP a) (REP b) = (a = b)"
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
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   122
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   123
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   124
      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
   125
    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
   126
    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
   127
    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
   128
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   129
    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
   130
    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
   131
    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
   132
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   133
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   134
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   135
    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
   136
    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
   137
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   138
  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
   139
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   140
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
ML {*
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   146
(* constructs the term \<lambda>(c::ty \<Rightarrow> bool). \<exists>x. c = rel x *)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
fun typedef_term rel ty lthy =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   148
let
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   149
  val [x, c] = [("x", ty), ("c", ty --> @{typ bool})]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
               |> Variable.variant_frees lthy [rel]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
               |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
in
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   153
  lambda c
39
980d45c4a726 fixed a bug in my code: function typedef_term constructs now now the correct term when the relation is called x
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   154
    (HOLogic.exists_const ty $ 
980d45c4a726 fixed a bug in my code: function typedef_term constructs now now the correct term when the relation is called x
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   155
       lambda x (HOLogic.mk_eq (c, (rel $ x))))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   158
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   159
(* makes the new type definitions and proves non-emptyness*)
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   160
fun typedef_make (qty_name, rel, ty) lthy =
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   161
let  
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   162
  val typedef_tac =
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   163
     EVERY1 [rewrite_goal_tac @{thms mem_def},
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   164
             rtac @{thm exI}, 
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   165
             rtac @{thm exI}, 
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   166
             rtac @{thm refl}]
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   167
in
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   168
  LocalTheory.theory_result
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   169
    (Typedef.add_typedef false NONE
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   170
       (qty_name, map fst (Term.add_tfreesT ty []), NoSyn)
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   171
         (typedef_term rel ty lthy)
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   172
           NONE typedef_tac) lthy
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   173
end
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   175
40
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   176
(* tactic to prove the QUOT_TYPE theorem for the new type *)
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   177
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  val rep_thm = #Rep typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  val rep_inv = #Rep_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  val abs_inv = #Abs_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  val rep_inj = #Rep_inject typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  val ss = HOL_basic_ss addsimps @{thms mem_def}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  val rep_thm_simpd = Simplifier.asm_full_simplify ss rep_thm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  val abs_inv_simpd = Simplifier.asm_full_simplify ss abs_inv
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  EVERY1 [rtac @{thm QUOT_TYPE.intro},
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   189
          rtac equiv_thm,
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   190
          rtac rep_thm_simpd,
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   191
          rtac rep_inv,
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
          rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
          rtac rep_inj]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   196
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
             |> Syntax.check_term lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  Goal.prove lthy [] [] goal
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   204
    (K (typedef_quot_type_tac equiv_thm typedef_info))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   207
40
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   208
(* proves the quotient theorem *)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  val quotient_const = Const (@{const_name "QUOTIENT"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
             |> Syntax.check_term lthy
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   214
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   215
  val typedef_quotient_thm_tac =
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   216
    EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]),
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   217
            rtac @{thm QUOT_TYPE.QUOTIENT},
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   218
            rtac quot_type_thm]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
in
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   220
  Goal.prove lthy [] [] goal 
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   221
    (K typedef_quotient_thm_tac)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
text {* two wrappers for define and note *}
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   226
ML {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   227
fun make_def (name, mx, rhs) lthy =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   228
let
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   229
  val ((rhs, (_ , thm)), lthy') =
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   230
     LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, rhs)) lthy
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
in
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   232
  ((rhs, thm), lthy')
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
*}
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 {*
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   237
fun note_thm (name, thm) lthy =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
let
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   239
  val ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
in
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   241
  (thm', lthy')
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   245
ML {*
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   246
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
   247
  let
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   248
    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
   249
    val ((_, [th']), _) = Variable.import true [th] ctxt;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   250
  in th' end);
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   251
*}
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   252
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   253
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
fun typedef_main (qty_name, rel, ty, equiv_thm) lthy =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   255
let
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  (* generates typedef *)
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   257
  val ((_, typedef_info), lthy1) = typedef_make (qty_name, rel, ty) lthy
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
  (* abs and rep functions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
  val abs_ty = #abs_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
  val rep_ty = #rep_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  val abs_name = #Abs_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
  val rep_name = #Rep_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
  val abs = Const (abs_name, rep_ty --> abs_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
  val rep = Const (rep_name, abs_ty --> rep_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
  (* ABS and REP definitions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
  val ABS_const = Const (@{const_name "QUOT_TYPE.ABS"}, dummyT )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
  val REP_const = Const (@{const_name "QUOT_TYPE.REP"}, dummyT )
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   270
  val ABS_trm = Syntax.check_term lthy1 (ABS_const $ rel $ abs)
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   271
  val REP_trm = Syntax.check_term lthy1 (REP_const $ rep)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
  val ABS_name = Binding.prefix_name "ABS_" qty_name
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   273
  val REP_name = Binding.prefix_name "REP_" qty_name
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   274
  val (((ABS, ABS_def), (REP, REP_def)), lthy2) =
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   275
         lthy1 |> make_def (ABS_name, NoSyn, ABS_trm)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
               ||>> make_def (REP_name, NoSyn, REP_trm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  (* quot_type theorem *)
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   279
  val quot_thm = typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy2
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  val quot_thm_name = Binding.prefix_name "QUOT_TYPE_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  (* quotient theorem *)
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   283
  val quotient_thm = typedef_quotient_thm (rel, ABS, REP, ABS_def, REP_def, quot_thm) lthy2
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
  val quotient_thm_name = Binding.prefix_name "QUOTIENT_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   286
  (* interpretation *)
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   287
  val bindd = ((Binding.make ("", Position.none)), ([]: Attrib.src list))
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   288
  val ((_, [eqn1pre]), lthy3) = Variable.import true [ABS_def] lthy2;
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   289
  val eqn1i = Thm.prop_of (symmetric eqn1pre)
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   290
  val ((_, [eqn2pre]), lthy4) = Variable.import true [REP_def] lthy3;
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   291
  val eqn2i = Thm.prop_of (symmetric eqn2pre)
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   292
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   293
  val exp_morphism = ProofContext.export_morphism lthy4 (ProofContext.init (ProofContext.theory_of lthy4));
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   294
  val exp_term = Morphism.term exp_morphism;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   295
  val exp = Morphism.thm exp_morphism;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   296
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   297
  val mthd = Method.SIMPLE_METHOD ((rtac quot_thm 1) THEN
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   298
    ALLGOALS (simp_tac (HOL_basic_ss addsimps [(symmetric (exp ABS_def)), (symmetric (exp REP_def))])))
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   299
  val mthdt = Method.Basic (fn _ => mthd)
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   300
  val bymt = Proof.global_terminal_proof (mthdt, NONE)
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   301
  val exp_i = [(@{const_name QUOT_TYPE}, ((("QUOT_TYPE_I_" ^ (Binding.name_of qty_name)), true),
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   302
    Expression.Named [
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   303
     ("R", rel),
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   304
     ("Abs", abs),
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   305
     ("Rep", rep)
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   306
    ]))]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
in
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   308
  lthy4
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   309
  |> note_thm (quot_thm_name, quot_thm)
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   310
  ||>> note_thm (quotient_thm_name, quotient_thm)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   311
  ||> LocalTheory.theory (fn thy =>
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   312
      let
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   313
        val global_eqns = map exp_term [eqn2i, eqn1i];
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   314
        (* Not sure if the following context should not be used *)
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   315
        val (global_eqns2, lthy5) = Variable.import_terms true global_eqns lthy4;
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   316
        val global_eqns3 = map (fn t => (bindd, t)) global_eqns2;
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   317
      in ProofContext.theory_of (bymt (Expression.interpretation (exp_i, []) global_eqns3 thy)) end)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
section {* various tests for quotient types*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
datatype trm =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   323
  var  "nat"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
| app  "trm" "trm"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
| lam  "nat" "trm"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   326
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   327
axiomatization 
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   328
  RR :: "trm \<Rightarrow> trm \<Rightarrow> bool" 
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   329
where
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   330
  r_eq: "EQUIV RR"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
local_setup {*
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   333
  typedef_main (@{binding "qtrm"}, @{term "RR"}, @{typ trm}, @{thm r_eq}) #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
term Rep_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   337
term REP_qtrm
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
term Abs_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
term ABS_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
thm QUOT_TYPE_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
thm QUOTIENT_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   342
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   343
(* Test interpretation *)
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   344
thm QUOT_TYPE_I_qtrm.thm11
26
68d64432623e slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 24
diff changeset
   345
thm QUOT_TYPE.thm11
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   346
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   347
print_theorems
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   348
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
thm Rep_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
text {* another test *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
datatype 'a trm' =
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   353
  var'  "'a"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
| app'  "'a trm'" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
| lam'  "'a" "'a trm'"
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   356
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
consts R' :: "'a trm' \<Rightarrow> 'a trm' \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
axioms r_eq': "EQUIV R'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   360
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
local_setup {*
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   362
  typedef_main (@{binding "qtrm'"}, @{term "R'"}, @{typ "'a trm'"}, @{thm r_eq'}) #> snd
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   365
print_theorems
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   366
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
term ABS_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
term REP_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
thm QUOT_TYPE_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
thm QUOTIENT_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
thm Rep_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   373
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
text {* a test with lists of terms *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
datatype t =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
  vr "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
| ap "t list"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
| lm "string" "t"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
consts Rt :: "t \<Rightarrow> t \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
axioms t_eq: "EQUIV Rt"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
  typedef_main (@{binding "qt"}, @{term "Rt"}, @{typ "t"}, @{thm t_eq}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
section {* lifting of constants *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
text {* information about map-functions for type-constructor *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
type typ_info = {mapfun: string}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
local
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
  structure Data = GenericDataFun
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
  (type T = typ_info Symtab.table
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
   val empty = Symtab.empty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
   val extend = I
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
   fun merge _ = Symtab.merge (K true))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
 val lookup = Symtab.lookup o Data.get
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   401
 fun update k v = Data.map (Symtab.update (k, v))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
*}
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
(* mapfuns for some standard types *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
    Context.theory_map (update @{type_name "list"} {mapfun = @{const_name "map"}})
28
15d549bb986b some comments
Christian Urban <urbanc@in.tum.de>
parents: 27
diff changeset
   408
 #> Context.theory_map (update @{type_name "*"}    {mapfun = @{const_name "prod_fun"}})
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
 #> Context.theory_map (update @{type_name "fun"}  {mapfun = @{const_name "fun_map"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
ML {* lookup (Context.Proof @{context}) @{type_name list} *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
datatype abs_or_rep = abs | rep
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   417
fun get_fun abs_or_rep rty qty lthy ty =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
  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
   420
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
    val (fs, tys) = split_list fs_tys
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   424
    val (otys, ntys) = split_list tys
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
  in
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   429
   (case (lookup (Context.Proof lthy) s) of
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
      SOME info => (list_comb (Const (#mapfun info, ftys ---> oty --> nty), fs), (oty, nty))
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   431
    | NONE      => raise ERROR ("no map association for type " ^ s))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
  fun get_const abs = (Const ("QuotMain.ABS_" ^ qty_name, rty --> qty), (rty, qty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
    | get_const rep = (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
   436
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   437
  fun mk_identity ty = Abs ("x", ty, Bound 0)
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   438
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
  if ty = qty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
  then (get_const abs_or_rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
  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
   443
          TFree _ => (mk_identity ty, (ty, ty))
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   444
        | Type (_, []) => (mk_identity ty, (ty, ty))
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   445
        | Type (s, tys) => get_fun_aux s (map (get_fun abs_or_rep 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
   446
        | _ => raise ERROR ("no type variables")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   452
  get_fun rep @{typ t} @{typ qt} @{context} @{typ "t * nat"}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   453
  |> fst
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   454
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   455
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   456
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   457
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   458
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   459
text {* produces the definition for a lifted constant *}
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   460
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
  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
   465
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
  val fresh_args = arg_tys |> map (pair "x")
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   467
                           |> Variable.variant_frees lthy [nconst, oconst]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
                           |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
  val rep_fns = map (fst o get_fun rep rty qty lthy) arg_tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
  val abs_fn  = (fst o get_fun abs rty qty lthy) res_ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
  map (op $) (rep_fns ~~ fresh_args)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  |> curry list_comb oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
  |> curry (op $) abs_fn
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
  |> fold_rev lambda fresh_args
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
ML {*
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   482
fun exchange_ty rty qty ty =
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   483
  if ty = rty 
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   484
  then qty
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   485
  else
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
       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
   488
      | _ => ty
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   489
    )
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
ML {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   493
fun make_const_def nconst_bname oconst mx rty qty lthy =
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
  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
   497
  val nconst = Const (Binding.name_of nconst_bname, nconst_ty)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
in
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   500
  make_def (nconst_bname, mx, def_trm) lthy
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   501
end
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   504
local_setup {*
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   505
  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
   506
  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
   507
  make_const_def @{binding LM} @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   508
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   509
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   510
term vr
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   511
term ap
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   512
term lm
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   513
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
   514
term LM
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   515
term VR
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   516
term AP
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   517
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   518
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
text {* a test with functions *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
datatype 'a t' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
  vr' "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
| ap' "('a t') * ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
| lm' "'a" "string \<Rightarrow> ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
consts Rt' :: "('a t') \<Rightarrow> ('a t') \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
axioms t_eq': "EQUIV Rt'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   528
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  typedef_main (@{binding "qt'"}, @{term "Rt'"}, @{typ "'a t'"}, @{thm t_eq'}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   533
print_theorems
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   534
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
local_setup {*
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   536
  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
   537
  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
   538
  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
   539
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   541
term vr'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   542
term ap'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   543
term ap'
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   544
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
   545
term LM'
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
term VR'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
term AP'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   549
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
text {* finite set example *}
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   551
print_syntax
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   552
inductive
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   553
  list_eq (infix "\<approx>" 50)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
  "a#b#xs \<approx> b#a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
| "[] \<approx> []"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
| "a#a#xs \<approx> a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   562
lemma list_eq_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
  shows "xs \<approx> xs"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   564
  apply (induct xs)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   565
   apply (auto intro: list_eq.intros)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   566
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
lemma equiv_list_eq:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
  shows "EQUIV list_eq"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   570
  unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   571
  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
   572
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
  typedef_main (@{binding "fset"}, @{term "list_eq"}, @{typ "'a list"}, @{thm "equiv_list_eq"}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   578
print_theorems
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   579
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
typ "'a fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
thm "Rep_fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   584
  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
   585
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   587
term Nil
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
term EMPTY
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   589
thm EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   590
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   593
  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
   594
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   596
term Cons
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
term INSERT
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   598
thm INSERT_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   601
  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
   602
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   604
term append
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
term UNION
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   606
thm UNION_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   607
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   608
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
thm QUOTIENT_fset
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   611
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
   612
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   613
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   614
fun
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   615
  membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
  m1: "(x memb []) = False"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   620
lemma mem_respects:
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   621
  fixes z
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   622
  assumes a: "list_eq x y"
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   623
  shows "(z memb x) = (z memb y)"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   624
  using a by induct auto
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   625
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   626
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   627
fun
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   628
  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
   629
where
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   630
  card1_nil: "(card1 []) = 0"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   631
| 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
   632
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   633
local_setup {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   634
  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
   635
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   636
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   637
term card1
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   638
term card
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   639
thm card_def
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   640
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   641
(* text {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   642
 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
   643
 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
   644
 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
   645
*}*)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   646
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   647
lemma card1_rsp:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   648
  fixes a b :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   649
  assumes e: "a \<approx> b"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   650
  shows "card1 a = card1 b"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   651
  using e apply induct
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   652
  apply (simp_all add:mem_respects)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   653
  done
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   654
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   655
lemma card1_0:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   656
  fixes a :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   657
  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
   658
  apply (induct a)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   659
   apply (simp)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   660
  apply (simp_all)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   661
   apply meson
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   662
  apply (simp_all)
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   663
  done
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   664
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   665
lemma not_mem_card1:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   666
  fixes x :: "'a"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   667
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   668
  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
   669
  by simp
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   670
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   671
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   672
lemma mem_cons:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   673
  fixes x :: "'a"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   674
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   675
  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
   676
  shows "x # xs \<approx> xs"
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   677
  using a 
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   678
  apply (induct xs)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   679
  apply (auto intro: list_eq.intros)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   680
  done
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   681
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   682
lemma card1_suc:
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   683
  fixes xs :: "'a list"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   684
  fixes n :: "nat"
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   685
  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
   686
  shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   687
  using c 
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   688
apply(induct xs)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   689
apply (metis Suc_neq_Zero card1_0)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   690
apply (metis QUOT_TYPE_I_fset.R_trans QuotMain.card1_cons list_eq_sym mem_cons)
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   691
done
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   692
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   693
lemma cons_preserves:
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   694
  fixes z
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   695
  assumes a: "xs \<approx> ys"
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   696
  shows "(z # xs) \<approx> (z # ys)"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   697
  using a by (rule QuotMain.list_eq.intros(5))
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   698
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   699
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   700
text {*
40
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   701
  Unlam_def converts a definition given as 
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   702
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   703
    c \<equiv> %x. %y. f x y
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   704
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   705
  to a theorem of the form 
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   706
   
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   707
    c x y \<equiv> f x y 
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   708
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   709
  This function is needed to rewrite the right-hand
c8187c293587 slightly tuned the comment for unlam
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
   710
  side to the left-hand side.
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   711
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   712
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   713
ML {*
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   714
fun unlam_def_aux orig_ctxt ctxt t =
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   715
  let val rhs = Thm.rhs_of t in
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   716
  (case try (Thm.dest_abs NONE) rhs of
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   717
    SOME (v, vt) =>
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   718
      let
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   719
        val (vname, vt) = Term.dest_Free (Thm.term_of v)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   720
        val ([vnname], ctxt) = Variable.variant_fixes [vname] ctxt
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   721
        val nv = Free(vnname, vt)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   722
        val t2 = Drule.fun_cong_rule t (Thm.cterm_of (ProofContext.theory_of ctxt) nv)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   723
        val tnorm = equal_elim (Drule.beta_eta_conversion (Thm.cprop_of t2)) t2
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   724
      in unlam_def_aux orig_ctxt ctxt tnorm end
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   725
  | NONE => singleton (ProofContext.export ctxt orig_ctxt) t)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   726
  end;
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   727
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   728
fun unlam_def ctxt t = unlam_def_aux ctxt ctxt t
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   729
*}
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   730
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   731
local_setup {*
17
55b646c6c4cd More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 16
diff changeset
   732
  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
   733
*}
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   734
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
term membship
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
term IN
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   737
thm IN_def
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   738
ML {* unlam_def @{context} @{thm IN_def} *}
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   740
lemmas a = QUOT_TYPE.ABS_def[OF QUOT_TYPE_fset]
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   741
thm QUOT_TYPE.thm11[OF QUOT_TYPE_fset, THEN iffD1, simplified a]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   743
lemma yy:
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   744
  shows "(False = x memb []) = (False = IN (x::nat) EMPTY)"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   745
unfolding IN_def EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   746
apply(rule_tac f="(op =) False" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   747
apply(rule mem_respects)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   748
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   749
apply(rule list_eq.intros)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   751
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   752
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   753
  shows "IN (x::nat) EMPTY = False"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   754
using m1
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   755
apply -
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   756
apply(rule yy[THEN iffD1, symmetric])
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   757
apply(simp)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   760
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   761
  shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) =
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   762
         ((x=y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))"
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   763
unfolding IN_def INSERT_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   764
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   765
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   766
apply(rule mem_respects)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   767
apply(rule list_eq.intros(3))
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   768
apply(unfold REP_fset_def ABS_fset_def)
5
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 4
diff changeset
   769
apply(simp only: QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   770
apply(rule list_eq_refl)
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   771
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   772
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   773
lemma append_respects_fst:
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   774
  assumes a : "list_eq l1 l2"
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   775
  shows "list_eq (l1 @ s) (l2 @ s)"
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   776
  using a
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   777
  apply(induct)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   778
  apply(auto intro: list_eq.intros)
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   779
  apply(simp add: list_eq_refl)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   780
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   781
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   782
lemma yyy:
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   783
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   784
    (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   785
     (UNION EMPTY s = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   786
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   787
    ) = (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   788
     ((ABS_fset ([] @ REP_fset s)) = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   789
     ((ABS_fset ((e # (REP_fset s1)) @ REP_fset s2)) = ABS_fset (e # (REP_fset s1 @ REP_fset s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   790
    )"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   791
  unfolding UNION_def EMPTY_def INSERT_def
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   792
  apply(rule_tac f="(op &)" in arg_cong2)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   793
  apply(rule_tac f="(op =)" in arg_cong2)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   794
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   795
  apply(rule append_respects_fst)
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   796
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   797
  apply(rule list_eq_refl)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   798
  apply(simp)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   799
  apply(rule_tac f="(op =)" in arg_cong2)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   800
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   801
  apply(rule append_respects_fst)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   802
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   803
  apply(rule list_eq_refl)
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   804
  apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   805
  apply(rule list_eq.intros(5))
14
5f6ee943c697 Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 13
diff changeset
   806
  apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   807
  apply(rule list_eq_refl)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   808
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   809
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   810
lemma
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   811
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   812
     (UNION EMPTY s = s) &
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   813
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))"
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   814
  apply (simp add: yyy)
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
   815
  apply (simp add: QUOT_TYPE_I_fset.thm10)
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   816
  done
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   817
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   818
ML {*
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   819
  fun mk_rep_abs x = @{term REP_fset} $ (@{term ABS_fset} $ x)
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   820
  val consts = [@{const_name "Nil"}, @{const_name "append"}, 
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   821
                @{const_name "Cons"}, @{const_name "membship"}, 
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   822
                @{const_name "card1"}]
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   823
*}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   824
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   825
ML {*
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   826
fun build_goal ctxt thm constructors lifted_type mk_rep_abs =
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   827
  let
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   828
    fun is_constructor (Const (x, _)) = member (op =) constructors x
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   829
      | is_constructor _ = false;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   830
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   831
    fun maybe_mk_rep_abs t =
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   832
      let
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   833
        val _ = writeln ("Maybe: " ^ Syntax.string_of_term ctxt t)
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   834
      in
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   835
        if type_of t = lifted_type then mk_rep_abs t else t
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   836
      end;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   837
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   838
    fun build_aux ctxt1 tm =
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   839
      let
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   840
        val (head, args) = Term.strip_comb tm;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   841
        val args' = map (build_aux ctxt1) args;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   842
      in
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   843
        (case head of
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   844
          Abs (x, T, t) =>
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   845
            let
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   846
              val ([x'], ctxt2) = Variable.variant_fixes [x] ctxt1;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   847
              val v = Free (x', T);
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   848
              val t' = subst_bound (v, t);
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   849
              val rec_term = build_aux ctxt2 t';
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   850
            in Term.lambda_name (x, v) rec_term end
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   851
        | _ =>
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   852
            if is_constructor head then
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   853
              maybe_mk_rep_abs (list_comb (head, map maybe_mk_rep_abs args'))
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   854
            else list_comb (head, args'))
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   855
      end;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   856
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   857
    val concl2 = Thm.prop_of thm;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   858
  in
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   859
    Logic.mk_equals (build_aux ctxt concl2, concl2)
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   860
  end
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   861
*}
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   862
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   863
ML {*
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   864
fun build_goal' ctxt thm constructors lifted_type mk_rep_abs =
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   865
  let
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   866
    fun is_const (Const (x, t)) = member (op =) constructors x
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   867
      | is_const _ = false
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   868
  
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   869
    fun maybe_mk_rep_abs t =
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   870
      let
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   871
        val _ = writeln ("Maybe: " ^ Syntax.string_of_term ctxt t)
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   872
      in
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   873
        if type_of t = lifted_type then mk_rep_abs t else t
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   874
      end
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   875
(*      handle TYPE _ => t*)
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   876
    fun build_aux ctxt1 (Abs (x, T, t)) =
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   877
          let
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   878
            val ([x'], ctxt2) = Variable.variant_fixes [x] ctxt1;
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   879
            val v = Free (x', T);
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   880
            val t' = subst_bound (v, t);
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   881
            val rec_term = build_aux ctxt2 t';
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   882
          in Term.lambda_name (x, v) rec_term end
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   883
      | build_aux ctxt1 (f $ a) =
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   884
          let
16
06b158ee1545 Code cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 15
diff changeset
   885
            val (f, args) = strip_comb (f $ a)
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   886
            val _ = writeln (Syntax.string_of_term ctxt f)
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   887
           in
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   888
            if is_const f then
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   889
              maybe_mk_rep_abs
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   890
                (list_comb (f, map maybe_mk_rep_abs (map (build_aux ctxt1) args)))
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   891
            else list_comb (build_aux ctxt1 f, map (build_aux ctxt1) args)
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   892
          end
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   893
      | build_aux _ x =
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   894
          if is_const x then maybe_mk_rep_abs x else x
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
   895
    
31
322ae3432548 Proper code for getting the prop out of the theorem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 30
diff changeset
   896
    val concl2 = term_of (#prop (crep_thm thm))
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   897
  in
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   898
  Logic.mk_equals (build_aux ctxt concl2, concl2)
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   899
end *}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   900
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
   901
ML {* val fset_defs = @{thms EMPTY_def IN_def UNION_def card_def INSERT_def} *}
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
   902
ML {* val fset_defs_sym = map (fn t => symmetric (unlam_def @{context} t)) fset_defs *}
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   903
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   904
ML {*
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   905
  fun dest_cbinop t =
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   906
    let
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   907
      val (t2, rhs) = Thm.dest_comb t;
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   908
      val (bop, lhs) = Thm.dest_comb t2;
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   909
    in
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   910
      (bop, (lhs, rhs))
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   911
    end
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   912
*}
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   913
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   914
ML {*
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   915
  fun dest_ceq t =
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   916
    let
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   917
      val (bop, pair) = dest_cbinop t;
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   918
      val (bop_s, _) = Term.dest_Const (Thm.term_of bop);
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   919
    in
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   920
      if bop_s = "op =" then pair else (raise CTERM ("Not an equality", [t]))
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   921
    end
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   922
*}
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   923
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   924
ML Thm.instantiate
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   925
ML {*@{thm arg_cong2}*}
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   926
ML {*@{thm arg_cong2[of _ _ _ _ "op ="]} *}
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   927
ML {* val cT = @{cpat "op ="} |> Thm.ctyp_of_term |> Thm.dest_ctyp |> hd *}
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   928
ML {*
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   929
  Toplevel.program (fn () =>
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   930
    Drule.instantiate' [SOME cT,SOME cT,SOME @{ctyp bool}] [NONE,NONE,NONE,NONE,SOME (@{cpat "op ="})] @{thm arg_cong2}
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   931
  )
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   932
*}
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   933
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   934
ML {*
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   935
  fun split_binop_conv t =
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   936
    let
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   937
      val (lhs, rhs) = dest_ceq t;
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   938
      val (bop, _) = dest_cbinop lhs;
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   939
      val [clT, cr2] = bop |> Thm.ctyp_of_term |> Thm.dest_ctyp;
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   940
      val [cmT, crT] = Thm.dest_ctyp cr2;
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   941
    in
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
   942
      Drule.instantiate' [SOME clT, SOME cmT, SOME crT] [NONE, NONE, NONE, NONE, SOME bop] @{thm arg_cong2}
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   943
    end
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   944
*}
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   945
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   946
ML {*
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   947
  fun split_arg_conv t =
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   948
    let
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   949
      val (lhs, rhs) = dest_ceq t;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   950
      val (lop, larg) = Thm.dest_comb lhs;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   951
      val [caT, crT] = lop |> Thm.ctyp_of_term |> Thm.dest_ctyp;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   952
    in
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
   953
      Drule.instantiate' [SOME caT, SOME crT] [NONE, NONE, SOME lop] @{thm arg_cong}
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   954
    end
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   955
*}
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   956
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   957
ML {*
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   958
  fun split_binop_tac n thm =
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   959
    let
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   960
      val concl = Thm.cprem_of thm n;
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   961
      val (_, cconcl) = Thm.dest_comb concl;
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   962
      val rewr = split_binop_conv cconcl;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   963
    in
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   964
      rtac rewr n thm
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   965
    end
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   966
      handle CTERM _ => Seq.empty
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   967
*}
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   968
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   969
ML {*
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   970
  fun split_arg_tac n thm =
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   971
    let
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   972
      val concl = Thm.cprem_of thm n;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   973
      val (_, cconcl) = Thm.dest_comb concl;
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   974
      val rewr = split_arg_conv cconcl;
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   975
    in
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   976
      rtac rewr n thm
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   977
    end
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   978
      handle CTERM _ => Seq.empty
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
   979
*}
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   980
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
   981
(* Has all the theorems about fset plugged in. These should be parameters to the tactic *)
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
   982
32
999300935e9c Make the tactic use Trueprop_cong and atomize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 31
diff changeset
   983
lemma trueprop_cong:
999300935e9c Make the tactic use Trueprop_cong and atomize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 31
diff changeset
   984
  shows "(a \<equiv> b) \<Longrightarrow> (Trueprop a \<equiv> Trueprop b)"
999300935e9c Make the tactic use Trueprop_cong and atomize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 31
diff changeset
   985
  by auto
999300935e9c Make the tactic use Trueprop_cong and atomize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 31
diff changeset
   986
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   987
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   988
thm QUOT_TYPE_I_fset.R_trans2
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   989
ML {*
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   990
  fun foo_tac' ctxt =
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   991
    REPEAT_ALL_NEW (FIRST' [
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   992
(*      rtac @{thm trueprop_cong},*)
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
   993
      rtac @{thm list_eq_refl},
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   994
      rtac @{thm cons_preserves},
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
   995
      rtac @{thm mem_respects},
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
   996
      rtac @{thm card1_rsp},
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   997
      rtac @{thm QUOT_TYPE_I_fset.R_trans2},
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   998
      CHANGED o (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms QUOT_TYPE_I_fset.REP_ABS_rsp})),
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
   999
      DatatypeAux.cong_tac,
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
  1000
      rtac @{thm ext},
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1001
      rtac @{thm eq_reflection},
32
999300935e9c Make the tactic use Trueprop_cong and atomize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 31
diff changeset
  1002
      CHANGED o (ObjectLogic.full_atomize_tac)
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1003
    ])
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
  1004
*}
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
  1005
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1006
ML {*
44
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1007
<<<<<<< variant A
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1008
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1009
  val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
44
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1010
>>>>>>> variant B
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
  1011
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m1}))
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
  1012
  val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
44
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1013
####### Ancestor
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1014
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1015
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43 41
diff changeset
  1016
======= end
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1017
  val cgoal = cterm_of @{theory} goal
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1018
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1019
*}
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1020
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1021
(*notation ( output) "prop" ("#_" [1000] 1000) *)
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1022
notation ( output) "Trueprop" ("#_" [1000] 1000)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1023
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1024
lemma atomize_eqv [atomize]: "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1025
  (is "?rhs \<equiv> ?lhs")
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1026
proof
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1027
  assume "PROP ?lhs" then show "PROP ?rhs" by unfold
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1028
next
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1029
  assume *: "PROP ?rhs"
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1030
  have "A = B"
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1031
  proof (cases A)
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1032
    case True
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1033
    with * have B by unfold
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1034
    with `A` show ?thesis by simp
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1035
  next
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1036
    case False
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1037
    with * have "~ B" by auto
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1038
    with `~ A` show ?thesis by simp
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1039
  qed
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1040
  then show "PROP ?lhs" by (rule eq_reflection)
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1041
qed
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1042
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1043
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1044
prove {* (Thm.term_of cgoal2) *}
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1045
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1046
  apply (atomize (full))
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1047
  
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1048
  apply (rule trueprop_cong)
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1049
  apply (tactic {* foo_tac' @{context} 1 *})
43
e51af8bace65 Cleaning the code with Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 42
diff changeset
  1050
  thm eq_reflection
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1051
  done
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1052
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1053
thm length_append (* Not true but worth checking that the goal is correct *)
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1054
ML {*
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1055
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append}))
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1056
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1057
  val cgoal = cterm_of @{theory} goal
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1058
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1059
*}
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1060
prove {* Thm.term_of cgoal2 *}
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1061
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1062
  apply (tactic {* foo_tac' @{context} 1 *})
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1063
  sorry
19
55aefc2d524a The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 18
diff changeset
  1064
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1065
thm m2
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1066
ML {*
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1067
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1068
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1069
  val cgoal = cterm_of @{theory} goal
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1070
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
20
ccc220a23887 Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 19
diff changeset
  1071
*}
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1072
prove {* Thm.term_of cgoal2 *}
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1073
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1074
  apply (tactic {* foo_tac' @{context} 1 *})
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1075
  done
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1076
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1077
thm list_eq.intros(4)
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1078
ML {*
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1079
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)}))
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1080
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1081
  val cgoal = cterm_of @{theory} goal
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1082
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1083
  val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1084
*}
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1085
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1086
(* It is the same, but we need a name for it. *)
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1087
prove {* Thm.term_of cgoal3 *}
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1088
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1089
  apply (tactic {* foo_tac' @{context} 1 *})
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1090
  done
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1091
lemma zzz :
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1092
  "Trueprop (REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1093
    \<equiv> Trueprop (a # a # xs \<approx> a # xs)"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1094
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1095
  apply (tactic {* foo_tac' @{context} 1 *})
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1096
  done
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1097
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1098
lemma zzz' :
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1099
  "(REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1100
  using list_eq.intros(4) by (simp only: zzz)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1101
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
  1102
thm QUOT_TYPE_I_fset.REPS_same
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1103
ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *}
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1104
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1105
thm list_eq.intros(5)
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1106
ML {*
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1107
  val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)}))
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1108
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
  1109
*}
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
  1110
ML {*
36
395beba59d55 Minor cleaning: whitespace, commas etc.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35
diff changeset
  1111
  val cgoal =
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1112
    Toplevel.program (fn () =>
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1113
      cterm_of @{theory} goal
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1114
    )
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1115
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1116
ML {*
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
  1117
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1118
*}
30
e35198635d64 Using "atomize" the versions with arbitrary Trueprops can be proven.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 29
diff changeset
  1119
prove {* Thm.term_of cgoal2 *}
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1120
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
  1121
  apply (tactic {* foo_tac' @{context} 1 *})
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1122
  done
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1123
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1124
thm list.induct
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1125
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1126
ML {*
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
  1127
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm list.induct}))
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1128
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1129
ML {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1130
  val goal =
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1131
    Toplevel.program (fn () =>
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
  1132
      build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1133
    )
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1134
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1135
ML {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1136
  val cgoal = cterm_of @{theory} goal
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
  1137
*}
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
  1138
ML {*
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
  1139
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1140
*}
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
  1141
33
e8f1fa50329a Found the source for the exception and added a handle for it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 32
diff changeset
  1142
prove {* (Thm.term_of cgoal2) *}
e8f1fa50329a Found the source for the exception and added a handle for it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 32
diff changeset
  1143
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
  1144
  apply (tactic {* foo_tac' @{context} 1 *})
33
e8f1fa50329a Found the source for the exception and added a handle for it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 32
diff changeset
  1145
  sorry
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1146
37
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1147
ML {*
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1148
  fun lift_theorem_fset_aux thm lthy =
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1149
    let
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1150
      val ((_, [novars]), lthy2) = Variable.import true [thm] lthy;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1151
      val goal = build_goal novars consts @{typ "'a list"} mk_rep_abs;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1152
      val cgoal = cterm_of @{theory} goal;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1153
      val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal);
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1154
      val tac = (LocalDefs.unfold_tac @{context} fset_defs) THEN (foo_tac' @{context}) 1;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1155
      val cthm = Goal.prove_internal [] cgoal2 (fn _ => tac);
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1156
      val nthm = MetaSimplifier.rewrite_rule [symmetric cthm] (snd (no_vars (Context.Theory @{theory}, thm)))
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1157
      val nthm2 = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same QUOT_TYPE_I_fset.thm10} nthm;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1158
      val [nthm3] = ProofContext.export lthy2 lthy [nthm2]
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1159
    in
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1160
      nthm3
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1161
    end
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1162
*}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1163
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1164
ML {* lift_theorem_fset_aux @{thm m1} @{context} *}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1165
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1166
ML {*
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1167
  fun lift_theorem_fset name thm lthy =
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1168
    let
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1169
      val lifted_thm = lift_theorem_fset_aux thm lthy;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1170
      val (_, lthy2) = note_thm (name, lifted_thm) lthy;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1171
    in
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1172
      lthy2
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1173
    end;
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1174
*}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1175
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1176
local_setup {* lift_theorem_fset @{binding "m1_lift"} @{thm m1} *}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1177
local_setup {* lift_theorem_fset @{binding "leqi4_lift"} @{thm list_eq.intros(4)} *}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1178
local_setup {* lift_theorem_fset @{binding "leqi5_lift"} @{thm list_eq.intros(5)} *}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1179
local_setup {* lift_theorem_fset @{binding "m2_lift"} @{thm m2} *}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1180
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1181
thm m1_lift
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1182
thm leqi4_lift
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1183
thm leqi5_lift
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1184
thm m2_lift
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1185
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1186
ML Drule.instantiate'
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1187
text {*
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1188
  We lost the schematic variable again :(.
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1189
  Another variable export will still be necessary...
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1190
*}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1191
ML {*
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1192
  Toplevel.program (fn () =>
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1193
    MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.thm10} (
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1194
      Drule.instantiate' [] [NONE, NONE, SOME (@{cpat "REP_fset x"})] @{thm m2_lift}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1195
    )
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1196
  )
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1197
*}
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1198
42
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1199
thm leqi4_lift
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1200
ML {*
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1201
  val (nam, typ) = (hd (Term.add_vars (term_of (#prop (crep_thm @{thm leqi4_lift}))) []))
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1202
  val (_, l) = dest_Type typ
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1203
  val t = Type ("QuotMain.fset", l)
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1204
  val v = Var (nam, t)
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1205
  val cv = cterm_of @{theory} ((term_of @{cpat "REP_fset"}) $ v)
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1206
*}
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1207
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1208
ML {*
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1209
term_of (#prop (crep_thm @{thm sym}))
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1210
*}
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1211
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1212
ML {*
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1213
  Toplevel.program (fn () =>
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1214
    MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.thm10} (
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1215
      Drule.instantiate' [] [NONE, SOME (cv)] @{thm leqi4_lift}
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1216
    )
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1217
  )
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1218
*}
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1219
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1220
37
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1221
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1222
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1223
3767a6f3d9ee A version of the tactic that exports variables correctly.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36
diff changeset
  1224
ML {* MRS *}
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1225
thm card1_suc
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1226
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1227
ML {*
38
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
  1228
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm card1_suc}))
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1229
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1230
ML {*
41
72d63aa8af68 added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents: 40
diff changeset
  1231
  val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1232
*}
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1233
ML {*
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1234
  val cgoal = cterm_of @{theory} goal
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
  1235
  val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1236
*}
35
fdc5962936fa Correctly handling abstractions while building goals
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 34
diff changeset
  1237
ML {* @{term "\<exists>x. P x"} *}
42
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1238
ML {*  Thm.bicompose *}
33
e8f1fa50329a Found the source for the exception and added a handle for it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 32
diff changeset
  1239
prove {* (Thm.term_of cgoal2) *}
42
1d08221f48c4 Instnatiation with a schematic variable
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 37
diff changeset
  1240
  apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} ) 
34
33d23470cf8d Minor cleanup
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 33
diff changeset
  1241
  apply (tactic {* foo_tac' @{context} 1 *})
29
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1242
2b59bf690633 Proper definition of CARD and some properties of it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 28
diff changeset
  1243
18
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1244
(*
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1245
datatype obj1 =
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1246
  OVAR1 "string"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1247
| OBJ1 "(string * (string \<Rightarrow> obj1)) list"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1248
| INVOKE1 "obj1 \<Rightarrow> string"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1249
| UPDATE1 "obj1 \<Rightarrow> string \<Rightarrow> (string \<Rightarrow> obj1)"
ce522150c1f7 Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 17
diff changeset
  1250
*)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1251
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
  1252