QuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 24 Nov 2009 18:13:18 +0100
changeset 370 09e28d4c19aa
parent 369 577539640a47
child 371 321d6c561575
permissions -rw-r--r--
Lambda & SOLVED' for new quotient_tac
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
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
     3
uses ("quotient_info.ML") 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
     4
     ("quotient.ML")
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
     5
     ("quotient_def.ML")
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
297
28b264299590 updated to new Isabelle version and added a new example file
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
     8
369
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
     9
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    10
let
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    11
   val parser = Args.context -- Scan.lift Args.name_source
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    12
   fun term_pat (ctxt, str) =
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    13
      str |> ProofContext.read_term_pattern ctxt
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    14
          |> ML_Syntax.print_term
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    15
          |> ML_Syntax.atomic
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    16
in
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    17
   ML_Antiquote.inline "term_pat" (parser >> term_pat)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    18
end
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    19
*}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    20
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    21
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    22
fun pretty_helper aux env =
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    23
  env |> Vartab.dest
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    24
      |> map ((fn (s1, s2) => s1 ^ " := " ^ s2) o aux)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    25
      |> commas
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    26
      |> enclose "[" "]"
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    27
      |> tracing
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    28
*}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    29
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    30
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    31
fun pretty_env ctxt env =
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    32
let
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    33
   fun get_trms (v, (T, t)) = (Var (v, T), t)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    34
   val print = pairself (Syntax.string_of_term ctxt)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    35
in
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    36
   pretty_helper (print o get_trms) env
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    37
end
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    38
*}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    39
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    40
ML {* val pat = @{term_pat "\<lambda>(x::'a list \<Rightarrow> bool). 
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    41
         (?f)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    42
         ((g::('a list \<Rightarrow> bool)\<Rightarrow>'a list \<Rightarrow> bool) x)"} *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    43
ML {* val trm = @{term_pat "\<lambda>(x::'a list \<Rightarrow> bool). 
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    44
          (f::('a List.list \<Rightarrow> bool) \<Rightarrow> ('a List.list \<Rightarrow> bool) \<Rightarrow> 'b)
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    45
          ((g::('a list \<Rightarrow> bool)\<Rightarrow>'a list \<Rightarrow> bool) x) ((g::('a list \<Rightarrow> bool)\<Rightarrow>'a list \<Rightarrow> bool) x)"} *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    46
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    47
ML {* val univ = let
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    48
  val init = Envir.empty 0
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    49
in
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    50
  Unify.unifiers (@{theory}, init, [(pat, trm)])
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    51
end
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    52
*}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    53
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    54
ML {* val SOME ((u1, _), next) = Seq.pull univ *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    55
ML {* val NEXT = Seq.pull next *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    56
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    57
ML {* show_types := true *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    58
ML {* pretty_env @{context} (Envir.term_env u1); *}
Christian Urban <urbanc@in.tum.de>
parents: 366
diff changeset
    59
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  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
    69
begin
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    72
  ABS::"'a \<Rightarrow> 'b"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    73
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
definition
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    77
  REP::"'b \<Rightarrow> 'a"
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
    78
where
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    81
lemma lem9:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  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
    85
  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
    86
  then show "R (Eps (R x)) = R x"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
theorem thm10:
24
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    91
  shows "ABS (REP a) \<equiv> a"
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    92
  apply  (rule eq_reflection)
6885fa184e89 Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 23
diff changeset
    93
  unfolding ABS_def REP_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
proof -
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
    95
  from rep_prop
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  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
    98
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   105
lemma REP_refl:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
lemma lem7:
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   111
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
done
15
f46eddb570a3 Cleaning the code
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 14
diff changeset
   117
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   123
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   124
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   125
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   126
  and   "R (REP (ABS g)) f = R g f"
23
f6c6cf8c3b98 some more beautification
Ning@localhost
parents: 22
diff changeset
   127
by (simp_all add: thm10 thm11)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   128
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   138
lemma R_trans:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   139
  assumes ab: "R a b"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   140
  and     bc: "R b c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   141
  shows "R a c"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   142
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   143
  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
   144
  moreover have ab: "R a b" by fact
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   145
  moreover have bc: "R b c" by fact
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   146
  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
   147
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   148
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   149
lemma R_sym:
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   150
  assumes ab: "R a b"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   151
  shows "R b a"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   152
proof -
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   153
  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
   154
  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
   155
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   156
49
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   157
lemma R_trans2:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 47
diff changeset
   158
  assumes ac: "R a c"
22
5023bf36d81a beautification of some proofs
Ning@localhost
parents: 21
diff changeset
   159
  and     bd: "R b d"
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   160
  shows "R a b = R c d"
200
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   161
using ac bd
d6a24dad5882 made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents: 198
diff changeset
   162
by (blast intro: R_trans R_sym)
21
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   163
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   164
lemma REPS_same:
25
9020ee23a020 The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 24
diff changeset
   165
  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
   166
proof -
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   167
  have "R (REP a) (REP b) = (a = b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   168
  proof
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   169
    assume as: "R (REP a) (REP b)"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   170
    from rep_prop
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   171
    obtain x y
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   172
      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
   173
    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
   174
    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
   175
    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
   176
    then have "R y x" using lem9 by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   177
    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
   178
    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
   179
    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
   180
    then show "a = b" using rep_inverse by simp
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   181
  next
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   182
    assume ab: "a = b"
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   183
    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
   184
    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
   185
  qed
cac00e8b972b tuned slightly one proof
Christian Urban <urbanc@in.tum.de>
parents: 37
diff changeset
   186
  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
   187
qed
d15121412caa Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 20
diff changeset
   188
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   193
(* the auxiliary data for the quotient types *)
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
   194
use "quotient_info.ML"
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   195
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   196
declare [[map list = (map, LIST_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   197
declare [[map * = (prod_fun, prod_rel)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   198
declare [[map "fun" = (fun_map, FUN_REL)]]
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   199
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   200
ML {* maps_lookup @{theory} "List.list" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   201
ML {* maps_lookup @{theory} "*" *}
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   202
ML {* maps_lookup @{theory} "fun" *}
174
09048a951dca moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   203
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   204
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   205
(* definition of the quotient types *)
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   206
(* FIXME: should be called quotient_typ.ML *)
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   207
use "quotient.ML"
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   208
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   209
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   210
(* lifting of constants *)
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   211
use "quotient_def.ML"
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   212
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   213
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   214
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   215
section {* ATOMIZE *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   216
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   217
lemma atomize_eqv[atomize]: 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   218
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   219
proof
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   220
  assume "A \<equiv> B" 
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   221
  then show "Trueprop A \<equiv> Trueprop B" by unfold
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   222
next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   223
  assume *: "Trueprop A \<equiv> Trueprop B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   224
  have "A = B"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   225
  proof (cases A)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   226
    case True
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   227
    have "A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   228
    then show "A = B" using * by simp
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   229
  next
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   230
    case False
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   231
    have "\<not>A" by fact
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   232
    then show "A = B" using * by auto
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   233
  qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   234
  then show "A \<equiv> B" by (rule eq_reflection)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   235
qed
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   236
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   237
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   238
fun atomize_thm thm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   239
let
221
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 219
diff changeset
   240
  val thm' = Thm.freezeT (forall_intr_vars thm)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   241
  val thm'' = ObjectLogic.atomize (cprop_of thm')
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   242
in
221
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 219
diff changeset
   243
  @{thm Pure.equal_elim_rule1} OF [thm'', thm']
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   244
end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   245
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   246
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   247
ML {* atomize_thm @{thm list.induct} *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   248
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   249
section {* REGULARIZE *}
282
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   250
(*
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   251
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   252
Regularizing a theorem means:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   253
 - Quantifiers over a type that needs lifting are replaced by
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   254
   bounded quantifiers, for example:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   255
      \<forall>x. P     \<Longrightarrow>     \<forall>x\<in>(Respects R). P
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   256
 - Abstractions over a type that needs lifting are replaced
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   257
   by bounded abstractions:
282
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   258
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   259
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   260
 - Equalities over the type being lifted are replaced by
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   261
   appropriate relations:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   262
      A = B     \<Longrightarrow>     A \<approx> B
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   263
   Example with more complicated types of A, B:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   264
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   265
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   266
Regularizing is done in 3 phases:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   267
 - First a regularized term is created
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   268
 - Next we prove that the original theorem implies the new one
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   269
 - Finally using MP we get the new theorem.
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   270
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   271
To prove that the old theorem implies the new one, we first
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   272
atomize it and then try:
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   273
 - Reflexivity of the relation
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   274
 - Assumption
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   275
 - Elimnating quantifiers on both sides of toplevel implication
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   276
 - Simplifying implications on both sides of toplevel implication
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   277
 - Ball (Respects ?E) ?P = All ?P
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   278
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   279
e9212a4a44be Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 277
diff changeset
   280
*)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   281
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   282
text {* tyRel takes a type and builds a relation that a quantifier over this
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   283
  type needs to respect. *}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   284
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   285
fun tyRel ty rty rel lthy =
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   286
  if Sign.typ_instance (ProofContext.theory_of lthy) (ty, rty)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   287
  then rel
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   288
  else (case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   289
          Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   290
            let
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   291
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   292
              val ty_out = ty --> ty --> @{typ bool};
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   293
              val tys_out = tys_rel ---> ty_out;
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   294
            in
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   295
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   296
               SOME (info) => list_comb (Const (#relfun info, tys_out),
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   297
                              map (fn ty => tyRel ty rty rel lthy) tys)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   298
             | NONE  => HOLogic.eq_const ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   299
            )
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   300
            end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   301
        | _ => HOLogic.eq_const ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   302
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   303
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   304
(* 
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   305
ML {* cterm_of @{theory} 
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   306
  (tyRel @{typ "'a \<Rightarrow> 'a list \<Rightarrow> 't \<Rightarrow> 't"} (Logic.varifyT @{typ "'a list"}) 
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   307
         @{term "f::('a list \<Rightarrow> 'a list \<Rightarrow> bool)"} @{context}) 
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   308
*} 
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   309
*)
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   310
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   311
definition
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   312
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   313
where
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   314
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   315
(* TODO: Consider defining it with an "if"; sth like:
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   316
   Babs p m = \<lambda>x. if x \<in> p then m x else undefined
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   317
*)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   318
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   319
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   320
fun needs_lift (rty as Type (rty_s, _)) ty =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   321
  case ty of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   322
    Type (s, tys) =>
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   323
      (s = rty_s) orelse (exists (needs_lift rty) tys)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   324
  | _ => false
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   325
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   326
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   327
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   328
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   329
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   330
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   331
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   332
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool})
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   333
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   334
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   335
(* applies f to the subterm of an abstractions, otherwise to the given term *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   336
ML {*
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   337
fun apply_subt f trm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   338
  case trm of
145
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   339
    Abs (x, T, t) => 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   340
       let 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   341
         val (x', t') = Term.dest_abs (x, T, t)
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   342
       in
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   343
         Term.absfree (x', T, f t') 
881600d5ff1e fixed my_reg
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   344
       end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   345
  | _ => f trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   346
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   347
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   348
(* FIXME: if there are more than one quotient, then you have to look up the relation *)
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   349
ML {*
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   350
fun my_reg lthy rel rty trm =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   351
  case trm of
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   352
    Abs (x, T, t) =>
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   353
       if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   354
         let
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   355
            val rrel = tyRel T rty rel lthy
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   356
         in
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   357
           (mk_babs (fastype_of trm) T) $ (mk_resp T $ rrel) $ (apply_subt (my_reg lthy rel rty) trm)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   358
         end
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   359
       else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   360
         Abs(x, T, (apply_subt (my_reg lthy rel rty) t))
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   361
  | Const (@{const_name "All"}, ty) $ (t as Abs (x, T, _)) =>
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   362
       let
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   363
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   364
          val ty2 = domain_type ty1
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   365
          val rrel = tyRel T rty rel lthy
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   366
       in
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   367
         if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   368
           (mk_ball ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   369
         else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   370
           Const (@{const_name "All"}, ty) $ apply_subt (my_reg lthy rel rty) t
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   371
       end
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   372
  | Const (@{const_name "Ex"}, ty) $ (t as Abs (x, T, _)) =>
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   373
       let
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   374
          val ty1 = domain_type ty
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   375
          val ty2 = domain_type ty1
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   376
          val rrel = tyRel T rty rel lthy
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   377
       in
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   378
         if (needs_lift rty T) then
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   379
           (mk_bex ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   380
         else
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   381
           Const (@{const_name "Ex"}, ty) $ apply_subt (my_reg lthy rel rty) t
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   382
       end
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   383
  | Const (@{const_name "op ="}, ty) $ t =>
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   384
      if needs_lift rty (fastype_of t) then
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
   385
        (tyRel (fastype_of t) rty rel lthy) $ t   (* FIXME: t should be regularised too *)
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   386
      else Const (@{const_name "op ="}, ty) $ (my_reg lthy rel rty t)
248
6ed87b3d358c Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 241
diff changeset
   387
  | t1 $ t2 => (my_reg lthy rel rty t1) $ (my_reg lthy rel rty t2)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   388
  | _ => trm
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   389
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   390
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   391
(* For polymorphic types we need to find the type of the Relation term. *)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   392
(* TODO: we assume that the relation is a Constant. Is this always true? *)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   393
ML {*
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   394
fun my_reg_inst lthy rel rty trm =
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   395
  case rel of
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   396
    Const (n, _) => Syntax.check_term lthy
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   397
      (my_reg lthy (Const (n, dummyT)) (Logic.varifyT rty) trm)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   398
*}
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   399
288
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   400
(*
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   401
ML {*
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   402
  val r = Free ("R", dummyT);
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   403
  val t = (my_reg_inst @{context} r @{typ "'a list"} @{term "\<forall>(x::'b list). P x"});
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   404
  val t2 = Syntax.check_term @{context} t;
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   405
  cterm_of @{theory} t2
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   406
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   407
*)
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   408
141
0ffc37761e53 Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 140
diff changeset
   409
text {* Assumes that the given theorem is atomized *}
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   410
ML {*
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   411
  fun build_regularize_goal thm rty rel lthy =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   412
     Logic.mk_implies
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   413
       ((prop_of thm),
283
5470176d6730 Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 282
diff changeset
   414
       (my_reg_inst lthy rel rty (prop_of thm)))
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   415
*}
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   416
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   417
lemma universal_twice:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   418
  assumes *: "\<And>x. (P x \<longrightarrow> Q x)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   419
  shows "(\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   420
using * by auto
252
e30997c88050 Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 251
diff changeset
   421
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   422
lemma implication_twice:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   423
  assumes a: "c \<longrightarrow> a"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   424
  assumes b: "a \<Longrightarrow> b \<longrightarrow> d"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   425
  shows "(a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)"
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   426
using a b by auto
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   427
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   428
ML {*
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
   429
fun regularize thm rty rel rel_eqv rel_refl lthy =
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   430
  let
288
f1a840dd0743 removed Simplifier.context
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   431
    val goal = build_regularize_goal thm rty rel lthy;
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   432
    fun tac ctxt =
252
e30997c88050 Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 251
diff changeset
   433
      (ObjectLogic.full_atomize_tac) THEN'
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   434
      REPEAT_ALL_NEW (FIRST' [
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   435
        rtac rel_refl,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   436
        atac,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   437
        rtac @{thm universal_twice},
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   438
        (rtac @{thm impI} THEN' atac),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   439
        rtac @{thm implication_twice},
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   440
        EqSubst.eqsubst_tac ctxt [0]
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   441
          [(@{thm equiv_res_forall} OF [rel_eqv]),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   442
           (@{thm equiv_res_exists} OF [rel_eqv])],
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   443
        (* For a = b \<longrightarrow> a \<approx> b *)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   444
        (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   445
        (rtac @{thm RIGHT_RES_FORALL_REGULAR})
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   446
      ]);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   447
    val cthm = Goal.prove lthy [] [] goal
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   448
      (fn {context, ...} => tac context 1);
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   449
  in
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   450
    cthm OF [thm]
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   451
  end
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   452
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   453
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   454
section {* RepAbs injection *}
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   455
(*
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   456
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   457
RepAbs injection is done in the following phases:
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   458
 1) build_repabs_term inserts rep-abs pairs in the term
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   459
 2) we prove the equality between the original theorem and this one
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   460
 3) we use Pure.equal_elim_rule1 to get the new theorem.
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   461
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   462
build_repabs_term does:
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   463
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   464
  For abstractions:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   465
  * If the type of the abstraction doesn't need lifting we recurse.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   466
  * If it does we add RepAbs around the whole term and check if the
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   467
    variable needs lifting.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   468
    * If it doesn't then we recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   469
    * If it does we recurse and put 'RepAbs' around all occurences
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   470
      of the variable in the obtained subterm. This in combination
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   471
      with the RepAbs above will let us change the type of the
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   472
      abstraction with rewriting.
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   473
  For applications:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   474
  * If the term is 'Respects' applied to anything we leave it unchanged
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   475
  * If the term needs lifting and the head is a constant that we know
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   476
    how to lift, we put a RepAbs and recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   477
  * If the term needs lifting and the head is a free applied to subterms
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   478
    (if it is not applied we treated it in Abs branch) then we
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   479
    put RepAbs and recurse
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   480
  * Otherwise just recurse.
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   481
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   482
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   483
To prove that the old theorem implies the new one, we first
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   484
atomize it and then try:
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   485
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   486
 1) theorems 'trans2' from the appropriate QUOT_TYPE
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   487
 2) remove lambdas from both sides (LAMBDA_RES_TAC)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   488
 3) remove Ball/Bex from the right hand side
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   489
 4) use user-supplied RSP theorems
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   490
 5) remove rep_abs from the right side
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   491
 6) reflexivity of equality
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   492
 7) split applications of lifted type (apply_rsp)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   493
 8) split applications of non-lifted type (cong_tac)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   494
 9) apply extentionality
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   495
10) reflexivity of the relation
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   496
11) assumption
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   497
    (Lambdas under respects may have left us some assumptions)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   498
12) proving obvious higher order equalities by simplifying fun_rel
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   499
    (not sure if it is still needed?)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   500
13) unfolding lambda on one side
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   501
14) simplifying (= ===> =) for simpler respectfullness
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   502
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   503
*)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   504
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   505
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   506
(* changes (?'a ?'b raw) (?'a ?'b quo) (int 'b raw \<Rightarrow> bool) to (int 'b quo \<Rightarrow> bool) *)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   507
ML {*
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   508
fun exchange_ty lthy rty qty ty =
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   509
  let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   510
    val thy = ProofContext.theory_of lthy
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   511
  in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   512
    if Sign.typ_instance thy (ty, rty) then
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   513
      let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   514
        val inst = Sign.typ_match thy (rty, ty) Vartab.empty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   515
      in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   516
        Envir.subst_type inst qty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   517
      end
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   518
    else
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   519
      let
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   520
        val (s, tys) = dest_Type ty
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   521
      in
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   522
        Type (s, map (exchange_ty lthy rty qty) tys)
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   523
      end
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   524
  end
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   525
  handle TYPE _ => ty (* for dest_Type *)
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   526
*}
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   527
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   528
(*consts Rl :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   529
axioms Rl_eq: "EQUIV Rl"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   530
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   531
quotient ql = "'a list" / "Rl"
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   532
  by (rule Rl_eq)
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   533
ML {*
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   534
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "'a list"}) (Logic.varifyT @{typ "'a ql"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"});
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   535
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "nat \<times> nat"}) (Logic.varifyT @{typ "int"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"})
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   536
*}
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   537
*)
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   538
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   539
ML {*
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   540
fun find_matching_types rty ty =
300
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   541
  if Type.raw_instance (Logic.varifyT ty, rty)
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   542
  then [ty]
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   543
  else
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   544
    let val (s, tys) = dest_Type ty in
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   545
    flat (map (find_matching_types rty) tys)
c6a9b4e4d548 Fixes for the other get_fun implementation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 297
diff changeset
   546
    end
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   547
    handle TYPE _ => []
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   548
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   549
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   550
ML {*
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   551
fun negF absF = repF
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   552
  | negF repF = absF
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   553
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   554
fun get_fun flag qenv lthy ty =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   555
let
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   556
  
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   557
  fun get_fun_aux s fs =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   558
   (case (maps_lookup (ProofContext.theory_of lthy) s) of
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   559
      SOME info => list_comb (Const (#mapfun info, dummyT), fs)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   560
    | NONE      => error ("no map association for type " ^ s))
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   561
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   562
  fun get_const flag qty =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   563
  let 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   564
    val thy = ProofContext.theory_of lthy
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   565
    val qty_name = Long_Name.base_name (fst (dest_Type qty))
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   566
  in
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   567
    case flag of
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   568
      absF => Const (Sign.full_bname thy ("ABS_" ^ qty_name), dummyT)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   569
    | repF => Const (Sign.full_bname thy ("REP_" ^ qty_name), dummyT)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   570
  end
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   571
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   572
  fun mk_identity ty = Abs ("", ty, Bound 0)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   573
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   574
in
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   575
  if (AList.defined (op=) qenv ty)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   576
  then (get_const flag ty)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   577
  else (case ty of
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   578
          TFree _ => mk_identity ty
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   579
        | Type (_, []) => mk_identity ty 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   580
        | Type ("fun" , [ty1, ty2]) => 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   581
            let
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   582
              val fs_ty1 = get_fun (negF flag) qenv lthy ty1
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   583
              val fs_ty2 = get_fun flag qenv lthy ty2
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   584
            in  
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   585
              get_fun_aux "fun" [fs_ty1, fs_ty2]
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   586
            end 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   587
        | Type (s, tys) => get_fun_aux s (map (get_fun flag qenv lthy) tys)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   588
        | _ => error ("no type variables allowed"))
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   589
end
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   590
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   591
(* returns all subterms where two types differ *)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   592
fun diff (T, S) Ds =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   593
  case (T, S) of
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   594
    (TVar v, TVar u) => if v = u then Ds else (T, S)::Ds 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   595
  | (TFree x, TFree y) => if x = y then Ds else (T, S)::Ds
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   596
  | (Type (a, Ts), Type (b, Us)) => 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   597
      if a = b then diffs (Ts, Us) Ds else (T, S)::Ds
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   598
  | _ => (T, S)::Ds
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   599
and diffs (T::Ts, U::Us) Ds = diffs (Ts, Us) (diff (T, U) Ds)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   600
  | diffs ([], []) Ds = Ds
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   601
  | diffs _ _ = error "Unequal length of type arguments"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   602
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   603
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   604
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   605
ML {*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   606
fun get_fun_OLD flag (rty, qty) lthy ty =
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   607
  let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   608
    val tys = find_matching_types rty ty;
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   609
    val qenv = map (fn t => (exchange_ty lthy rty qty t, t)) tys;
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
   610
    val xchg_ty = exchange_ty lthy rty qty ty
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   611
  in
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   612
    get_fun flag qenv lthy xchg_ty
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   613
  end
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   614
*}
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   615
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   616
text {* Does the same as 'subst' in a given prop or theorem *}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   617
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   618
fun eqsubst_prop ctxt thms t =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   619
  let
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   620
    val goalstate = Goal.init (cterm_of (ProofContext.theory_of ctxt) t)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   621
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   622
      NONE => error "eqsubst_prop"
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   623
    | SOME th => cprem_of th 1
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   624
  in term_of a' end
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   625
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   626
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   627
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   628
  fun repeat_eqsubst_prop ctxt thms t =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   629
    repeat_eqsubst_prop ctxt thms (eqsubst_prop ctxt thms t)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   630
    handle _ => t
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   631
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   632
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   633
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   634
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   635
fun eqsubst_thm ctxt thms thm =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   636
  let
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   637
    val goalstate = Goal.init (Thm.cprop_of thm)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   638
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   639
      NONE => error "eqsubst_thm"
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   640
    | SOME th => cprem_of th 1
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   641
    val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   642
    val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a');
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   643
    val cgoal = cterm_of (ProofContext.theory_of ctxt) goal
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   644
    val rt = Goal.prove_internal [] cgoal (fn _ => tac);
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   645
  in
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   646
    @{thm Pure.equal_elim_rule1} OF [rt, thm]
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   647
  end
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   648
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   649
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   650
ML {*
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   651
  fun repeat_eqsubst_thm ctxt thms thm =
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   652
    repeat_eqsubst_thm ctxt thms (eqsubst_thm ctxt thms thm)
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   653
    handle _ => thm
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   654
*}
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   655
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   656
(* Needed to have a meta-equality *)
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   657
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id"
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   658
by (simp add: id_def)
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   659
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   660
(* TODO: can be also obtained with: *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   661
ML {* symmetric (eq_reflection OF @{thms id_def}) *}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   662
218
df05cd030d2f added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents: 214
diff changeset
   663
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   664
fun build_repabs_term lthy thm consts rty qty =
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   665
  let
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   666
    (* TODO: The rty and qty stored in the quotient_info should
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   667
       be varified, so this will soon not be needed *)
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   668
    val rty = Logic.varifyT rty;
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   669
    val qty = Logic.varifyT qty;
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   670
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   671
  fun mk_abs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   672
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   673
      val ty = fastype_of tm
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   674
    in Syntax.check_term lthy ((get_fun_OLD absF (rty, qty) lthy ty) $ tm) end
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   675
  fun mk_repabs tm =
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   676
    let
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
   677
      val ty = fastype_of tm
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
   678
    in Syntax.check_term lthy ((get_fun_OLD repF (rty, qty) lthy ty) $ (mk_abs tm)) end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   679
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   680
    fun is_lifted_const (Const (x, _)) = member (op =) consts x
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   681
      | is_lifted_const _ = false;
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   682
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   683
    fun build_aux lthy tm =
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   684
      case tm of
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   685
        Abs (a as (_, vty, _)) =>
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   686
          let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   687
            val (vs, t) = Term.dest_abs a;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   688
            val v = Free(vs, vty);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   689
            val t' = lambda v (build_aux lthy t)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   690
          in
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   691
            if (not (needs_lift rty (fastype_of tm))) then t'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   692
            else mk_repabs (
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   693
              if not (needs_lift rty vty) then t'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   694
              else
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   695
                let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   696
                  val v' = mk_repabs v;
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   697
                  (* TODO: I believe 'beta' is not needed any more *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   698
                  val t1 = (* Envir.beta_norm *) (t' $ v')
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   699
                in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   700
                  lambda v t1
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   701
                end)
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   702
          end
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   703
      | x =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   704
        case Term.strip_comb tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   705
          (Const(@{const_name Respects}, _), _) => tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   706
        | (opp, tms0) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   707
          let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   708
            val tms = map (build_aux lthy) tms0
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   709
            val ty = fastype_of tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   710
          in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   711
            if (is_lifted_const opp andalso needs_lift rty ty) then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   712
            mk_repabs (list_comb (opp, tms))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   713
            else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   714
              mk_repabs (list_comb (opp, tms))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   715
            else if tms = [] then opp
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   716
            else list_comb(opp, tms)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   717
          end
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   718
  in
235
7affee8f90f5 Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 223
diff changeset
   719
    repeat_eqsubst_prop lthy @{thms id_def_sym}
161
2ee03759a22f Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 160
diff changeset
   720
      (build_aux lthy (Thm.prop_of thm))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   721
  end
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   722
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   723
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   724
text {* Builds provable goals for regularized theorems *}
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   725
ML {*
140
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   726
fun build_repabs_goal ctxt thm cons rty qty =
00d141f2daa7 Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 139
diff changeset
   727
  Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty))
139
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   728
*}
4cc5db28b1c3 Reordering
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 138
diff changeset
   729
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   730
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   731
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   732
  let
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   733
    val pat = Drule.strip_imp_concl (cprop_of thm)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   734
    val insts = Thm.match (pat, concl)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   735
  in
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   736
    rtac (Drule.instantiate insts thm) 1
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   737
  end
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   738
  handle _ => no_tac)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   739
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   740
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   741
ML {*
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   742
fun CHANGED' tac = (fn i => CHANGED (tac i))
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   743
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   744
359
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   745
lemma prod_fun_id: "prod_fun id id \<equiv> id"
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   746
by (rule eq_reflection) (simp add: prod_fun_def)
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   747
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   748
lemma map_id: "map id \<equiv> id"
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   749
apply (rule eq_reflection)
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   750
apply (rule ext)
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   751
apply (rule_tac list="x" in list.induct)
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   752
apply (simp_all)
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   753
done
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   754
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   755
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   756
fun quotient_tac quot_thm =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   757
  REPEAT_ALL_NEW (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   758
    rtac @{thm FUN_QUOTIENT},
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   759
    rtac quot_thm,
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   760
    rtac @{thm IDENTITY_QUOTIENT},
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   761
    (* For functional identity quotients, (op = ---> op =) *)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   762
    CHANGED' (
359
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   763
      (simp_tac (HOL_ss addsimps @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id}
64c3c83e0ed4 New cleaning tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 357
diff changeset
   764
      )))
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   765
  ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   766
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   767
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   768
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   769
fun LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   770
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   771
    (_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   772
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   773
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   774
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   775
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   776
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   777
ML {*
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   778
fun WEAK_LAMBDA_RES_TAC ctxt i st =
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   779
  (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   780
    (_ $ (_ $ _ $ (Abs(_, _, _)))) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   781
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   782
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   783
  | (_ $ (_ $ (Abs(_, _, _)) $ _)) =>
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   784
      (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   785
      (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   786
  | _ => fn _ => no_tac) i st
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   787
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   788
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   789
ML {*
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   790
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} =>
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   791
  let
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   792
    val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl;
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   793
    val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP});
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   794
    val insts = Thm.match (pat, concl)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   795
  in
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   796
    if needs_lift rty (type_of f) then
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   797
      rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   798
    else no_tac
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   799
  end
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   800
  handle _ => no_tac)
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   801
*}
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   802
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   803
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   804
val ball_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   805
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   806
    val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   807
                 (Const (@{const_name Ball}, _) $ _)) = term_of concl
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   808
  in
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   809
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   810
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   811
    THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   812
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   813
  end
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   814
  handle _ => no_tac)
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   815
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   816
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   817
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   818
val bex_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   819
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   820
    val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   821
                 (Const (@{const_name Bex}, _) $ _)) = term_of concl
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   822
  in
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   823
    ((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   824
    THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   825
    THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN'
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
   826
    (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   827
  end
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   828
  handle _ => no_tac)
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   829
*}
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   830
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   831
ML {*
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   832
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   833
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   834
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   835
ML {*
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   836
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   837
  (FIRST' [
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   838
    rtac trans_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   839
    LAMBDA_RES_TAC ctxt,
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   840
    ball_rsp_tac ctxt,
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   841
    bex_rsp_tac ctxt,
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   842
    FIRST' (map rtac rsp_thms),
364
4c455d58ac99 Fixes to the tactic after quotient_tac changed.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 363
diff changeset
   843
    rtac refl,
370
09e28d4c19aa Lambda & SOLVED' for new quotient_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 369
diff changeset
   844
    (instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [SOLVES' (quotient_tac quot_thm)])),
09e28d4c19aa Lambda & SOLVED' for new quotient_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 369
diff changeset
   845
    (APPLY_RSP_TAC rty ctxt THEN' (RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)])),
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   846
    Cong_Tac.cong_tac @{thm cong},
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   847
    rtac @{thm ext},
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   848
    rtac reflex_thm,
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   849
    atac,
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   850
    SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   851
    WEAK_LAMBDA_RES_TAC ctxt,
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   852
    CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   853
    ])
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   854
*}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   855
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   856
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   857
fun repabs lthy thm consts rty qty quot_thm reflex_thm trans_thm rsp_thms =
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   858
  let
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   859
    val rt = build_repabs_term lthy thm consts rty qty;
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   860
    val rg = Logic.mk_equals ((Thm.prop_of thm), rt);
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   861
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
206
1e227c9ee915 Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 200
diff changeset
   862
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms));
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   863
    val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1);
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   864
  in
210
f88ea69331bf Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 209
diff changeset
   865
    @{thm Pure.equal_elim_rule1} OF [cthm, thm]
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   866
  end
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   867
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   868
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   869
section {* Cleaning the goal *}
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
   870
236
23f9fead8bd6 Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 235
diff changeset
   871
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   872
ML {*
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   873
fun simp_ids lthy thm =
307
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   874
  MetaSimplifier.rewrite_rule @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id} thm
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   875
*}
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   876
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   877
ML {*
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   878
fun simp_ids_trm trm =
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   879
  trm |>
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   880
  MetaSimplifier.rewrite false @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id}
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   881
  |> cprop_of |> Thm.dest_equals |> snd
9aa3aba71ecc Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 303
diff changeset
   882
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   883
*}
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   884
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   885
text {* expects atomized definition *}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   886
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   887
fun add_lower_defs_aux lthy thm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   888
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   889
    val e1 = @{thm fun_cong} OF [thm];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   890
    val f = eqsubst_thm lthy @{thms fun_map.simps} e1;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   891
    val g = simp_ids lthy f
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   892
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   893
    (simp_ids lthy thm) :: (add_lower_defs_aux lthy g)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   894
  end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   895
  handle _ => [simp_ids lthy thm]
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   896
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   897
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   898
ML {*
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   899
fun add_lower_defs lthy def =
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   900
  let
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   901
    val def_pre_sym = symmetric def
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   902
    val def_atom = atomize_thm def_pre_sym
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
   903
    val defs_all = add_lower_defs_aux lthy def_atom
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   904
  in
214
a66f81c264aa Proof of append_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 213
diff changeset
   905
    map Thm.varifyT defs_all
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   906
  end
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   907
*}
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   908
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   909
(* TODO: Check if it behaves properly with varifyed rty *)
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   910
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   911
fun findabs_all rty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   912
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   913
    Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   914
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   915
        val b' = subst_bound ((Free ("x", T)), b);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   916
        val tys = findabs_all rty b'
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   917
        val ty = fastype_of tm
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   918
      in if needs_lift rty ty then (ty :: tys) else tys
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   919
      end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   920
  | f $ a => (findabs_all rty f) @ (findabs_all rty a)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   921
  | _ => [];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   922
fun findabs rty tm = distinct (op =) (findabs_all rty tm)
241
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   923
*}
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   924
60acf3d3a4a0 Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 239
diff changeset
   925
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   926
fun findaps_all rty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   927
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   928
    Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   929
      findaps_all rty (subst_bound ((Free ("x", T)), b))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   930
  | (f $ a) => (findaps_all rty f @ findaps_all rty a)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   931
  | Free (_, (T as (Type ("fun", (_ :: _))))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   932
      (if needs_lift rty T then [T] else [])
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   933
  | _ => [];
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   934
fun findaps rty tm = distinct (op =) (findaps_all rty tm)
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 190
diff changeset
   935
*}
190
ca1a24aa822e Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 187
diff changeset
   936
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   937
(* Currently useful only for LAMBDA_PRS *)
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   938
ML {*
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   939
fun make_simp_prs_thm lthy quot_thm thm typ =
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   940
  let
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   941
    val (_, [lty, rty]) = dest_Type typ;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   942
    val thy = ProofContext.theory_of lthy;
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   943
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   944
    val inst = [SOME lcty, NONE, SOME rcty];
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   945
    val lpi = Drule.instantiate' inst [] thm;
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   946
    val tac =
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   947
      (compose_tac (false, lpi, 2)) THEN_ALL_NEW
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   948
      (quotient_tac quot_thm);
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
   949
    val gc = Drule.strip_imp_concl (cprop_of lpi);
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
   950
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   951
  in
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
   952
    MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   953
  end
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   954
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   955
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   956
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   957
fun findallex_all rty qty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   958
  case tm of
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   959
    Const (@{const_name All}, T) $ (s as (Abs(_, _, b))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   960
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   961
        val (tya, tye) = findallex_all rty qty s
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   962
      in if needs_lift rty T then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   963
        ((T :: tya), tye)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   964
      else (tya, tye) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   965
  | Const (@{const_name Ex}, T) $ (s as (Abs(_, _, b))) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   966
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   967
        val (tya, tye) = findallex_all rty qty s
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   968
      in if needs_lift rty T then
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   969
        (tya, (T :: tye))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   970
      else (tya, tye) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   971
  | Abs(_, T, b) =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   972
      findallex_all rty qty (subst_bound ((Free ("x", T)), b))
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   973
  | f $ a =>
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   974
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   975
        val (a1, e1) = findallex_all rty qty f;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   976
        val (a2, e2) = findallex_all rty qty a;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   977
      in (a1 @ a2, e1 @ e2) end
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   978
  | _ => ([], []);
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   979
*}
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
   980
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   981
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   982
fun findallex lthy rty qty tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   983
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   984
    val (a, e) = findallex_all rty qty tm;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   985
    val (ad, ed) = (map domain_type a, map domain_type e);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   986
    val (au, eu) = (distinct (op =) ad, distinct (op =) ed);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   987
    val (rty, qty) = (Logic.varifyT rty, Logic.varifyT qty)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   988
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   989
    (map (exchange_ty lthy rty qty) au, map (exchange_ty lthy rty qty) eu)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
   990
  end
197
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   991
*}
c0f2db9a243b Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 193
diff changeset
   992
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
   993
ML {*
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   994
fun make_allex_prs_thm lthy quot_thm thm typ =
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   995
  let
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   996
    val (_, [lty, rty]) = dest_Type typ;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   997
    val thy = ProofContext.theory_of lthy;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   998
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
   999
    val inst = [NONE, SOME lcty];
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1000
    val lpi = Drule.instantiate' inst [] thm;
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1001
    val tac =
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1002
      (compose_tac (false, lpi, 1)) THEN_ALL_NEW
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1003
      (quotient_tac quot_thm);
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1004
    val gc = Drule.strip_imp_concl (cprop_of lpi);
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1005
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1006
    val t_noid = MetaSimplifier.rewrite_rule
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1007
      [@{thm eq_reflection} OF @{thms id_apply}] t;
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1008
    val t_sym = @{thm "HOL.sym"} OF [t_noid];
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1009
    val t_eq = @{thm "eq_reflection"} OF [t_sym]
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1010
  in
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1011
    t_eq
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1012
  end
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1013
*}
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1014
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1015
ML {*
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1016
fun applic_prs lthy rty qty absrep ty =
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1017
  let
285
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
  1018
    val rty = Logic.varifyT rty;
8ebdef196fd5 Infrastructure for polymorphic types
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 283
diff changeset
  1019
    val qty = Logic.varifyT qty;
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1020
    fun absty ty =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1021
      exchange_ty lthy rty qty ty
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1022
    fun mk_rep tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1023
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1024
        val ty = exchange_ty lthy qty rty (fastype_of tm)
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1025
      in Syntax.check_term lthy ((get_fun_OLD repF (rty, qty) lthy ty) $ tm) end;
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1026
    fun mk_abs tm =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1027
      let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1028
        val ty = fastype_of tm
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1029
      in Syntax.check_term lthy ((get_fun_OLD absF (rty, qty) lthy ty) $ tm) end
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1030
    val (l, ltl) = Term.strip_type ty;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1031
    val nl = map absty l;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1032
    val vs = map (fn _ => "x") l;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1033
    val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1034
    val args = map Free (vfs ~~ nl);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1035
    val lhs = list_comb((Free (fname, nl ---> ltl)), args);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1036
    val rargs = map mk_rep args;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1037
    val f = Free (fname, nl ---> ltl);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1038
    val rhs = mk_abs (list_comb((mk_rep f), rargs));
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1039
    val eq = Logic.mk_equals (rhs, lhs);
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1040
    val ceq = cterm_of (ProofContext.theory_of lthy') eq;
302
a840c232e04e Minor cleaning and removing of some 'handle _'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 301
diff changeset
  1041
    val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps});
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1042
    val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1043
    val t_id = MetaSimplifier.rewrite_rule @{thms id_def_sym} t;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1044
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1045
    singleton (ProofContext.export lthy' lthy) t_id
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1046
  end
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1047
*}
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1048
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1049
ML {*
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1050
fun lookup_quot_data lthy qty =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1051
  let
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
  1052
    val qty_name = fst (dest_Type qty)
314
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 311
diff changeset
  1053
    val SOME quotdata = quotdata_lookup lthy qty_name
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
  1054
                  (* cu: Changed the lookup\<dots>not sure whether this works *)
303
991b0e53f9dc More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 302
diff changeset
  1055
    (* TODO: Should no longer be needed *)
257
68bd5c2a1b96 Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 255
diff changeset
  1056
    val rty = Logic.unvarifyT (#rtyp quotdata)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1057
    val rel = #rel quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1058
    val rel_eqv = #equiv_thm quotdata
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1059
    val rel_refl_pre = @{thm EQUIV_REFL} OF [rel_eqv]
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1060
    val rel_refl = @{thm spec} OF [MetaSimplifier.rewrite_rule [@{thm REFL_def}] rel_refl_pre]
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1061
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1062
    (rty, rel, rel_refl, rel_eqv)
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1063
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1064
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1065
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1066
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1067
fun lookup_quot_thms lthy qty_name =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1068
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1069
    val thy = ProofContext.theory_of lthy;
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1070
    val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1071
    val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1072
    val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1073
    val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name)
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1074
  in
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1075
    (trans2, reps_same, absrep, quot)
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1076
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1077
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1078
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1079
ML {*
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1080
fun lookup_quot_consts defs =
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1081
  let
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1082
    fun dest_term (a $ b) = (a, b);
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1083
    val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1084
  in
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1085
    map (fst o dest_Const o snd o dest_term) def_terms
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1086
  end
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1087
*}
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1088
275
34ad627ac5d5 fixed definition of PLUS
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
  1089
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1090
ML {*
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1091
fun lift_thm lthy qty qty_name rsp_thms defs rthm = 
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1092
let
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1093
  val _ = tracing ("raw theorem:\n" ^ Syntax.string_of_term lthy (prop_of rthm))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1094
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1095
  val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty;
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1096
  val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name;
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1097
  val consts = lookup_quot_consts defs;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1098
  val t_a = atomize_thm rthm;
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1099
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1100
  val _ = tracing ("raw atomized theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_a))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1101
251
c770f36f9459 Regularization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 248
diff changeset
  1102
  val t_r = regularize t_a rty rel rel_eqv rel_refl lthy;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1103
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1104
  val _ = tracing ("regularised theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_r))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1105
210
f88ea69331bf Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 209
diff changeset
  1106
  val t_t = repabs lthy t_r consts rty qty quot rel_refl trans2 rsp_thms;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1107
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1108
  val _ = tracing ("rep/abs injected theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_t))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1109
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1110
  val (alls, exs) = findallex lthy rty qty (prop_of t_a);
267
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1111
  val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1112
  val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs
3764566c1151 Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 264
diff changeset
  1113
  val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1114
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1115
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_a))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1116
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1117
  val abs = findabs rty (prop_of t_a);
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
  1118
  val aps = findaps rty (prop_of t_a);
269
fe6eb116b341 applic_prs
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 267
diff changeset
  1119
  val app_prs_thms = map (applic_prs lthy rty qty absrep) aps;
253
e169a99c6ada Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 252
diff changeset
  1120
  val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs;
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1121
  val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1122
  
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1123
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_l))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1124
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1125
  val defs_sym = flat (map (add_lower_defs lthy) defs);
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1126
  val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym;
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1127
  val t_id = simp_ids lthy t_l;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1128
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1129
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_id))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1130
292
bd76f0398aa9 More functionality for lifting list.cases and list.recs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 289
diff changeset
  1131
  val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_id;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1132
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1133
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_d0))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1134
259
22c199522bef Optimization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 257
diff changeset
  1135
  val t_d = repeat_eqsubst_thm lthy defs_sym t_d0;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1136
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1137
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_d))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1138
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1139
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1140
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1141
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_r))
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1142
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1143
  val t_rv = ObjectLogic.rulify t_r
316
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1144
13ea9a34c269 added some tracing information to all phases of lifting to the function lift_thm
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
  1145
  val _ = tracing ("lifted theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_rv))
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1146
in
289
7e8617f20b59 Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 288
diff changeset
  1147
  Thm.varifyT t_rv
187
f8fc085db38f Cleaning and fixing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 185
diff changeset
  1148
end
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1149
*}
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1150
273
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1151
ML {*
301
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1152
fun lift_thm_note qty qty_name rsp_thms defs thm name lthy =
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1153
  let
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1154
    val lifted_thm = lift_thm lthy qty qty_name rsp_thms defs thm;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1155
    val (_, lthy2) = note (name, lifted_thm) lthy;
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1156
  in
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1157
    lthy2
40bb0c4718a6 Cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 300
diff changeset
  1158
  end
273
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1159
*}
b82e765ca464 Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 270
diff changeset
  1160
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1161
(******************************************)
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1162
(******************************************)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1163
(* version with explicit qtrm             *)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1164
(******************************************)
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1165
(******************************************)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1166
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1167
ML {*
338
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1168
fun atomize_goal thy gl =
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1169
  let
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1170
    val vars = map Free (Term.add_frees gl []);
348
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1171
    val all = if fastype_of gl = @{typ bool} then HOLogic.all_const else Term.all;
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1172
    fun lambda_all (var as Free(_, T)) trm = (all T) $ lambda var trm;
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1173
    val glv = fold lambda_all vars gl
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1174
    val gla = (term_of o snd o Thm.dest_equals o cprop_of) (ObjectLogic.atomize (cterm_of thy glv))
338
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1175
    val glf = Type.legacy_freeze gla
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1176
  in
348
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1177
    if fastype_of gl = @{typ bool} then @{term Trueprop} $ glf else glf
338
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1178
  end
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1179
*}
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1180
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1181
348
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1182
ML {* atomize_goal @{theory} @{term "x memb [] = False"} *}
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1183
ML {* atomize_goal @{theory} @{term "x = xa \<Longrightarrow> a # x = a # xa"} *}
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1184
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1185
338
62b188959c8a Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 336
diff changeset
  1186
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1187
(* builds the relation for respects *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1188
 
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1189
fun mk_resp_arg lthy (rty, qty) =
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1190
let
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1191
  val thy = ProofContext.theory_of lthy
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1192
in  
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1193
  if rty = qty
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1194
  then HOLogic.eq_const rty
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1195
  else
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1196
    case (rty, qty) of
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1197
      (Type (s, tys), Type (s', tys')) =>
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1198
       if s = s' 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1199
       then let
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1200
              val SOME map_info = maps_lookup thy s
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1201
              val args = map (mk_resp_arg lthy) (tys ~~ tys')
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1202
            in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1203
              list_comb (Const (#relfun map_info, dummyT), args) 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1204
            end  
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1205
       else let  
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1206
              val SOME qinfo = quotdata_lookup_thy thy s'
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1207
              (* FIXME: check in this case that the rty and qty *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1208
              (* FIXME: correspond to each other *)
353
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
  1209
              val (s, _) = dest_Const (#rel qinfo)
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
  1210
              (* FIXME: the relation should only be the string       *)
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
  1211
              (* FIXME: and the type needs to be calculated as below *) 
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1212
            in
353
9a0e8ab42ee8 fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
  1213
              Const (s, rty --> rty --> @{typ bool})
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1214
            end
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1215
      | _ => HOLogic.eq_const dummyT 
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
  1216
             (* FIXME: check that the types correspond to each other? *)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1217
end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1218
*}
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1219
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1220
ML {*
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1221
val mk_babs = Const (@{const_name "Babs"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1222
val mk_ball = Const (@{const_name "Ball"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1223
val mk_bex  = Const (@{const_name "Bex"}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1224
val mk_resp = Const (@{const_name Respects}, dummyT)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1225
*}
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1226
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1227
ML {*
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1228
fun trm_lift_error lthy rtrm qtrm =
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1229
let
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1230
  val rtrm_str = quote (Syntax.string_of_term lthy rtrm) 
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1231
  val qtrm_str = quote (Syntax.string_of_term lthy qtrm)
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1232
  val msg = ["The quotient theorem", qtrm_str, "and lifted theorem", rtrm_str, "do not match."]
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1233
in
365
ba057402ea53 use error instead of raising our own exception
Christian Urban <urbanc@in.tum.de>
parents: 363
diff changeset
  1234
  raise error (space_implode " " msg)
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1235
end 
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1236
*}
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1237
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1238
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1239
(* - applies f to the subterm of an abstraction,   *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1240
(*   otherwise to the given term,                  *)
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
  1241
(* - used by REGULARIZE, therefore abstracted      *)
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1242
(*   variables do not have to be treated specially *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1243
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1244
fun apply_subt f trm1 trm2 =
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1245
  case (trm1, trm2) of
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1246
    (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1247
  | _ => f trm1 trm2
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1248
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1249
(* the major type of All and Ex quantifiers *)
334
5a7024be9083 code review with Cezary
Christian Urban <urbanc@in.tum.de>
parents: 330
diff changeset
  1250
fun qnt_typ ty = domain_type (domain_type ty)  
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1251
*}
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1252
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1253
(*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1254
Regularizing an rtrm means:
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1255
 - quantifiers over a type that needs lifting are replaced by
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1256
   bounded quantifiers, for example:
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1257
      \<forall>x. P     \<Longrightarrow>     \<forall>x \<in> (Respects R). P  /  All (Respects R) P
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1258
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1259
   the relation R is given by the rty and qty;
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1260
 
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1261
 - abstractions over a type that needs lifting are replaced
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1262
   by bounded abstractions:
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1263
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1264
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1265
 - equalities over the type being lifted are replaced by
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1266
   corresponding relations:
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1267
      A = B     \<Longrightarrow>     A \<approx> B
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1268
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1269
   example with more complicated types of A, B:
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1270
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1271
*)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1272
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1273
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1274
(* produces a regularized version of rtm      *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1275
(* - the result is still not completely typed *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1276
(* - does not need any special treatment of   *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1277
(*   bound variables                          *)
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1278
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1279
fun REGULARIZE_trm lthy rtrm qtrm =
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1280
  case (rtrm, qtrm) of
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1281
    (Abs (x, ty, t), Abs (x', ty', t')) =>
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1282
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1283
         val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1284
       in     
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1285
         if ty = ty'
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1286
         then Abs (x, ty, subtrm)
326
e755a5da14c8 my first version of repabs injection
Christian Urban <urbanc@in.tum.de>
parents: 325
diff changeset
  1287
         else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1288
       end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1289
  | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1290
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1291
         val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1292
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1293
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1294
         then Const (@{const_name "All"}, ty) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1295
         else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1296
       end
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1297
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1298
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1299
         val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1300
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1301
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1302
         then Const (@{const_name "Ex"}, ty) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1303
         else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1304
       end
351
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
  1305
    (* FIXME: Should = only be replaced, when fully applied? *) 
3aba0cf85f97 tuned some comments
Christian Urban <urbanc@in.tum.de>
parents: 349
diff changeset
  1306
    (* Then there must be a 2nd argument                     *)
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1307
  | (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1308
       let
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1309
         val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1310
       in
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1311
         if ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1312
         then Const (@{const_name "op ="}, ty) $ subtrm
349
f507f088de73 domain_type in regularizing equality
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 348
diff changeset
  1313
         else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1314
       end 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1315
  | (t1 $ t2, t1' $ t2') =>
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1316
       (REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2')
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1317
  | (Free (x, ty), Free (x', ty')) =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1318
       if x = x' 
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1319
       then rtrm     (* FIXME: check whether types corresponds *)
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1320
       else trm_lift_error lthy rtrm qtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1321
  | (Bound i, Bound i') =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1322
       if i = i' 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1323
       then rtrm 
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1324
       else trm_lift_error lthy rtrm qtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1325
  | (Const (s, ty), Const (s', ty')) =>
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1326
       if s = s' andalso ty = ty'
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1327
       then rtrm
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1328
       else rtrm (* FIXME: check correspondence according to definitions *) 
323
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
  1329
  | _ => trm_lift_error lthy rtrm qtrm
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1330
*}
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1331
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
  1332
ML {*
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1333
fun mk_REGULARIZE_goal lthy rtrm qtrm =
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1334
  Logic.mk_implies (rtrm, Syntax.check_term lthy (REGULARIZE_trm lthy rtrm qtrm))
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
  1335
*}
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1336
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1337
(*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1338
To prove that the old theorem implies the new one, we first
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1339
atomize it and then try:
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1340
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1341
 - Reflexivity of the relation
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1342
 - Assumption
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1343
 - Elimnating quantifiers on both sides of toplevel implication
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1344
 - Simplifying implications on both sides of toplevel implication
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1345
 - Ball (Respects ?E) ?P = All ?P
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1346
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1347
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1348
*)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1349
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1350
lemma my_equiv_res_forall2:
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1351
  fixes P::"'a \<Rightarrow> bool"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1352
  fixes Q::"'b \<Rightarrow> bool"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1353
  assumes a: "(All Q) \<longrightarrow> (All P)"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1354
  shows "(All Q) \<longrightarrow> Ball (Respects E) P"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1355
using a by auto
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1356
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1357
lemma my_equiv_res_exists:
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1358
  fixes P::"'a \<Rightarrow> bool"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1359
  fixes Q::"'b \<Rightarrow> bool"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1360
  assumes a: "EQUIV E"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1361
  and     b: "(Ex Q) \<longrightarrow> (Ex P)"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1362
  shows "(Ex Q) \<longrightarrow> Bex (Respects E) P"
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1363
apply(subst equiv_res_exists)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1364
apply(rule a)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1365
apply(rule b)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1366
done
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1367
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1368
ML {*
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1369
(* FIXME: get_rid of rel_refl rel_eqv *)
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1370
fun REGULARIZE_tac lthy rel_refl rel_eqv =
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1371
   (REPEAT1 o FIRST1) 
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1372
     [rtac rel_refl,
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1373
      atac,
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1374
      rtac @{thm universal_twice},
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1375
      rtac @{thm impI} THEN' atac,
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1376
      rtac @{thm implication_twice},
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1377
      rtac @{thm my_equiv_res_forall2},
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1378
      rtac (rel_eqv RS @{thm my_equiv_res_exists}),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1379
      (* For a = b \<longrightarrow> a \<approx> b *)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1380
      rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl,
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1381
      rtac @{thm RIGHT_RES_FORALL_REGULAR}]
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1382
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1383
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1384
(* version of REGULARIZE_tac including debugging information *)
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1385
ML {*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1386
fun my_print_tac ctxt s thm =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1387
let
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1388
  val prems_str = prems_of thm
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1389
                  |> map (Syntax.string_of_term ctxt)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1390
                  |> cat_lines
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1391
  val _ = tracing (s ^ "\n" ^ prems_str)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1392
in
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1393
  Seq.single thm
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1394
end
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1395
 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1396
fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))]
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1397
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1398
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1399
ML {*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1400
fun REGULARIZE_tac' lthy rel_refl rel_eqv =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1401
   (REPEAT1 o FIRST1) 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1402
     [(K (print_tac "start")) THEN' (K no_tac), 
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1403
      DT lthy "1" (rtac rel_refl),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1404
      DT lthy "2" atac,
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1405
      DT lthy "3" (rtac @{thm universal_twice}),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1406
      DT lthy "4" (rtac @{thm impI} THEN' atac),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1407
      DT lthy "5" (rtac @{thm implication_twice}),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1408
      DT lthy "6" (rtac @{thm my_equiv_res_forall2}),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1409
      DT lthy "7" (rtac (rel_eqv RS @{thm my_equiv_res_exists})),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1410
      (* For a = b \<longrightarrow> a \<approx> b *)
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1411
      DT lthy "8" (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1412
      DT lthy "9" (rtac @{thm RIGHT_RES_FORALL_REGULAR})]
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1413
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1414
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1415
ML {*
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1416
fun REGULARIZE_prove rtrm qtrm rel_eqv rel_refl lthy =
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1417
  let
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1418
    val goal = mk_REGULARIZE_goal lthy rtrm qtrm
330
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1419
  in
1a0f0b758071 a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
  1420
    Goal.prove lthy [] [] goal 
325
Christian Urban <urbanc@in.tum.de>
parents: 323
diff changeset
  1421
      (fn {context, ...} => REGULARIZE_tac' context rel_refl rel_eqv)
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1422
  end
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1423
*}
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1424
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1425
(* rep-abs injection *)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1426
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1427
ML {*
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1428
fun mk_repabs lthy (T, T') trm = 
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1429
  Quotient_Def.get_fun repF lthy (T, T') 
354
2eb6d527dfe4 addded a tactic, which sets up the three goals of the `algorithm'
Christian Urban <urbanc@in.tum.de>
parents: 353
diff changeset
  1430
    $ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1431
*}
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1432
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1433
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1434
ML {*
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1435
(* bound variables need to be treated properly,  *)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1436
(* as the type of subterms need to be calculated *)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1437
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1438
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1439
fun inj_REPABS lthy (rtrm, qtrm) =
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1440
let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1441
  val rty = fastype_of rtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1442
  val qty = fastype_of qtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1443
in
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1444
  case (rtrm, qtrm) of
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1445
    (Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1446
       Const (@{const_name "Ball"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1447
  | (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1448
       Const (@{const_name "Bex"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1449
  | (Const (@{const_name "Babs"}, T) $ r $ t, t') =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1450
       Const (@{const_name "Babs"}, T) $ r $ (inj_REPABS lthy (t, t'))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1451
  | (Abs (x, T, t), Abs (x', T', t')) =>
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1452
      let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1453
        val (y, s) = Term.dest_abs (x, T, t)
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1454
        val (_, s') = Term.dest_abs (x', T', t')
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1455
        val yvar = Free (y, T)
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1456
        val result = lambda yvar (inj_REPABS lthy (s, s'))
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1457
      in
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1458
        if rty = qty 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1459
        then result
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1460
        else mk_repabs lthy (rty, qty) result
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1461
      end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1462
  | _ =>
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1463
      (* FIXME / TODO: this is a case that needs to be looked at          *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1464
      (* - variables get a rep-abs insde and outside an application       *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1465
      (* - constants only get a rep-abs on the outside of the application *)
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1466
      (* - applications get a rep-abs insde and outside an application    *)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1467
      let
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1468
        val (rhead, rargs) = strip_comb rtrm
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1469
        val (qhead, qargs) = strip_comb qtrm
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1470
        val rargs' = map (inj_REPABS lthy) (rargs ~~ qargs)
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1471
      in
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1472
        if rty = qty
355
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1473
        then
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1474
          case (rhead, qhead) of
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1475
            (Free (_, T), Free (_, T')) =>
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1476
              if T = T' then list_comb (rhead, rargs')
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1477
              else list_comb (mk_repabs lthy (T, T') rhead, rargs')
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1478
          | _ => list_comb (rhead, rargs')
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1479
        else
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1480
          case (rhead, qhead, length rargs') of
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1481
            (Const _, Const _, 0) => mk_repabs lthy (rty, qty) rhead
355
abc6bfd0576e More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 354
diff changeset
  1482
          | (Free (_, T), Free (_, T'), 0) => mk_repabs lthy (T, T') rhead
345
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1483
          | (Const _, Const _, _) =>  mk_repabs lthy (rty, qty) (list_comb (rhead, rargs')) 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1484
          | (Free (x, T), Free (x', T'), _) => 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1485
               mk_repabs lthy (rty, qty) (list_comb (mk_repabs lthy (T, T') rhead, rargs'))
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1486
          | (Abs _, Abs _, _ ) =>
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1487
               mk_repabs lthy (rty, qty) (list_comb (inj_REPABS lthy (rhead, qhead), rargs')) 
573e2b625e8e a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents: 341
diff changeset
  1488
          | _ => trm_lift_error lthy rtrm qtrm
336
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1489
      end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1490
end
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1491
*}
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1492
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1493
ML {*
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1494
fun mk_inj_REPABS_goal lthy (rtrm, qtrm) =
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1495
  Logic.mk_equals (rtrm, Syntax.check_term lthy (inj_REPABS lthy (rtrm, qtrm)))
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1496
*}
e6b6e5ba0cc5 Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 334
diff changeset
  1497
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1498
(* Final wrappers *)
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1499
357
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1500
ML {*
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1501
fun regularize_tac ctxt rel_eqv rel_refl =
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1502
  (ObjectLogic.full_atomize_tac) THEN'
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1503
  REPEAT_ALL_NEW (FIRST' [
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1504
    rtac rel_refl,
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1505
    atac,
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1506
    rtac @{thm universal_twice},
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1507
    (rtac @{thm impI} THEN' atac),
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1508
    rtac @{thm implication_twice},
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1509
    EqSubst.eqsubst_tac ctxt [0]
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1510
      [(@{thm equiv_res_forall} OF [rel_eqv]),
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1511
       (@{thm equiv_res_exists} OF [rel_eqv])],
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1512
    (* For a = b \<longrightarrow> a \<approx> b *)
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1513
    (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1514
    (rtac @{thm RIGHT_RES_FORALL_REGULAR})
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1515
  ]);
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1516
*}
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1517
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1518
ML {*
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1519
fun regularize_goal lthy thm rel_eqv rel_refl qtrm =
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1520
  let
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1521
    val reg_trm = mk_REGULARIZE_goal lthy (prop_of thm) qtrm;
357
ea27275eba9a Separate regularize_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 355
diff changeset
  1522
    fun tac lthy = regularize_tac lthy rel_eqv rel_refl;
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1523
    val cthm = Goal.prove lthy [] [] reg_trm
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1524
      (fn {context, ...} => tac context 1);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1525
  in
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1526
    cthm OF [thm]
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1527
  end
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1528
*}
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1529
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1530
ML {*
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1531
fun repabs_goal lthy thm rty quot_thm reflex_thm trans_thm rsp_thms qtrm =
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1532
  let
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1533
    val rg = Syntax.check_term lthy (mk_inj_REPABS_goal lthy ((prop_of thm), qtrm));
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1534
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1535
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms));
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1536
    val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1537
  in
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1538
    @{thm Pure.equal_elim_rule1} OF [cthm, thm]
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1539
  end
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1540
*}
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1541
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1542
ML {*
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1543
fun lift_thm_goal lthy qty qty_name rsp_thms defs rthm goal =
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1544
let
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1545
  val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1546
  val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1547
  val t_a = atomize_thm rthm;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1548
  val goal_a = atomize_goal (ProofContext.theory_of lthy) goal;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1549
  val t_r = regularize_goal lthy t_a rel_eqv rel_refl goal_a;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1550
  val t_t = repabs_goal lthy t_r rty quot rel_refl trans2 rsp_thms goal_a;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1551
  val (alls, exs) = findallex lthy rty qty (prop_of t_a);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1552
  val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1553
  val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1554
  val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1555
  val abs = findabs rty (prop_of t_a);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1556
  val aps = findaps rty (prop_of t_a);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1557
  val app_prs_thms = map (applic_prs lthy rty qty absrep) aps;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1558
  val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1559
  val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1560
  val defs_sym = flat (map (add_lower_defs lthy) defs);
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1561
  val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1562
  val t_id = simp_ids lthy t_l;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1563
  val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_id;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1564
  val t_d = repeat_eqsubst_thm lthy defs_sym t_d0;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1565
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1566
  val t_rv = ObjectLogic.rulify t_r
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1567
in
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1568
  Thm.varifyT t_rv
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1569
end
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1570
*}
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1571
348
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1572
ML {*
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1573
fun lift_thm_goal_note lthy qty qty_name rsp_thms defs thm name goal =
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1574
  let
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1575
    val lifted_thm = lift_thm_goal lthy qty qty_name rsp_thms defs thm goal;
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1576
    val (_, lthy2) = note (name, lifted_thm) lthy;
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1577
  in
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1578
    lthy2
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1579
  end
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1580
*}
b1f83c7a8674 More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 347
diff changeset
  1581
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1582
ML {*
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1583
fun spec_frees_tac [] = []
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1584
  | spec_frees_tac (x::xs) = 
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1585
       let
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1586
         val spec' =  Drule.instantiate' [SOME (ctyp_of_term x)] [NONE, SOME x] @{thm spec} 
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1587
       in
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1588
         (rtac spec')::(spec_frees_tac xs)
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1589
       end
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1590
*}  
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1591
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1592
ML {*
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1593
val prepare_tac = CSUBGOAL (fn (concl, i) =>
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1594
    let
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1595
      val vrs = Thm.add_cterm_frees concl []
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1596
    in
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1597
      EVERY' (ObjectLogic.full_atomize_tac::spec_frees_tac vrs) i
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1598
    end)
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1599
*}
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1600
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1601
lemma procedure:
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1602
  assumes a: "A"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1603
  and     b: "A \<Longrightarrow> B"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1604
  and     c: "B = C"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1605
  and     d: "C = D"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1606
  shows   "D"
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1607
  using a b c d
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1608
  by simp
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1609
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1610
ML {* 
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1611
fun procedure_inst ctxt rtrm qtrm =
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1612
let
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1613
  val thy = ProofContext.theory_of ctxt
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1614
  val rtrm' = HOLogic.dest_Trueprop rtrm
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1615
  val qtrm' = HOLogic.dest_Trueprop qtrm
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1616
  val reg_goal = Syntax.check_term ctxt (REGULARIZE_trm ctxt rtrm' qtrm')
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1617
  val inj_goal = Syntax.check_term ctxt (inj_REPABS ctxt (reg_goal, qtrm'))
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1618
in
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1619
  Drule.instantiate' []
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1620
    [SOME (cterm_of thy rtrm'),
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1621
     SOME (cterm_of thy reg_goal),
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1622
     SOME (cterm_of thy inj_goal)]
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1623
  @{thm procedure}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1624
end
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1625
*}
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1626
  
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1627
ML {*
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1628
fun procedure_tac rthm ctxt =
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1629
  prepare_tac THEN'
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1630
  Subgoal.FOCUS (fn {context, concl, ...} =>
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1631
    let
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1632
      val rthm' = atomize_thm rthm
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1633
      val rule = procedure_inst context (prop_of rthm') (term_of concl)
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1634
    in
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1635
      EVERY1 [rtac rule, rtac rthm']
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1636
    end) ctxt
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1637
*}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1638
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1639
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1640
ML {*
362
7a3d86050e72 added a prepare_tac
Christian Urban <urbanc@in.tum.de>
parents: 360
diff changeset
  1641
(* FIXME: allex_prs and lambda_prs can be one function *)
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1642
fun allex_prs_tac lthy quot =
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1643
  (EqSubst.eqsubst_tac lthy [0] @{thms FORALL_PRS[symmetric] EXISTS_PRS[symmetric]})
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1644
  THEN' (quotient_tac quot);
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1645
*}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1646
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1647
ML {*
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1648
fun lambda_prs_tac lthy quot =
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1649
  (EqSubst.eqsubst_tac lthy [0] @{thms LAMBDA_PRS}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1650
  THEN' (RANGE [quotient_tac quot, quotient_tac quot]));
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1651
*}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1652
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1653
ML {*
361
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1654
  fun TRY' tac = fn i => TRY (tac i)
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1655
*}
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1656
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1657
ML {*
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1658
fun clean_tac lthy quot defs reps_same =
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1659
  let
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1660
    val lower = flat (map (add_lower_defs lthy) defs)
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1661
  in
361
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1662
    TRY' (REPEAT_ALL_NEW (allex_prs_tac lthy quot)) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1663
    TRY' (REPEAT_ALL_NEW (lambda_prs_tac lthy quot)) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1664
    TRY' (REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] lower)) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1665
    simp_tac (HOL_ss addsimps [reps_same])
360
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1666
  end
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1667
*}
07fb696efa3d Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 359
diff changeset
  1668
361
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1669
ML {*
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1670
fun lift_tac lthy thm rel_eqv rel_refl rty quot trans2 rsp_thms reps_same defs =
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1671
  (procedure_tac thm lthy) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1672
  (regularize_tac lthy rel_eqv rel_refl) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1673
  (REPEAT_ALL_NEW (r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms)) THEN'
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1674
  (clean_tac lthy quot defs reps_same)
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1675
*}
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1676
e9bcbdeb3a1e TRY' for clean_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 360
diff changeset
  1677
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 320
diff changeset
  1678
198
ff4425e000db Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 197
diff changeset
  1679
end
239
02b14a21761a Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 236
diff changeset
  1680
347
7e82493c6253 Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 346
diff changeset
  1681