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