Quot/QuotMain.thy
author Christian Urban <urbanc@in.tum.de>
Mon, 07 Dec 2009 18:49:14 +0100
changeset 606 38aa6b67a80b
parent 605 120e479ed367
child 608 678315da994e
child 610 2bee5ca44ef5
permissions -rw-r--r--
clarified the function examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotMain
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
     2
imports QuotScript QuotProd Prove
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
uses ("quotient_info.ML")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
     ("quotient.ML")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
     ("quotient_def.ML")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
locale QUOT_TYPE =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  assumes equivp: "equivp R"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
begin
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
definition
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  ABS::"'a \<Rightarrow> 'b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
where
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  "ABS x \<equiv> Abs (R x)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
definition
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  REP::"'b \<Rightarrow> 'a"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
where
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  "REP a = Eps (Rep a)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
lemma lem9:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  shows "R (Eps (R x)) = R x"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
proof -
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  have a: "R x x" using equivp by (simp add: equivp_reflp_symp_transp reflp_def)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  then have "R x (Eps (R x))" by (rule someI)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  then show "R (Eps (R x)) = R x"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
    using equivp unfolding equivp_def by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
theorem thm10:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  shows "ABS (REP a) \<equiv> a"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  apply  (rule eq_reflection)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  unfolding ABS_def REP_def
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
proof -
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  from rep_prop
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  obtain x where eq: "Rep a = R x" by auto
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  also have "\<dots> = Abs (R x)" using lem9 by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  also have "\<dots> = Abs (Rep a)" using eq by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  also have "\<dots> = a" using rep_inverse by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  finally
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  show "Abs (R (Eps (Rep a))) = a" by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
lemma REP_refl:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  shows "R (REP a) (REP a)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
unfolding REP_def
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
by (simp add: equivp[simplified equivp_def])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
lemma lem7:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(rule iffI)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
apply(simp)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
apply(drule rep_inject[THEN iffD2])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
apply(simp add: abs_inverse)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
done
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
theorem thm11:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  shows "R r r' = (ABS r = ABS r')"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
unfolding ABS_def
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
by (simp only: equivp[simplified equivp_def] lem7)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
lemma REP_ABS_rsp:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  shows "R f (REP (ABS g)) = R f g"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  and   "R (REP (ABS g)) f = R g f"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
by (simp_all add: thm10 thm11)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
lemma Quotient:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  "Quotient R ABS REP"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(unfold Quotient_def)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(simp add: thm10)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
apply(simp add: REP_refl)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
apply(subst thm11[symmetric])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
apply(simp add: equivp[simplified equivp_def])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
done
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
lemma R_trans:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  assumes ab: "R a b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  and     bc: "R b c"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  shows "R a c"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
proof -
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  have tr: "transp R" using equivp equivp_reflp_symp_transp[of R] by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  moreover have ab: "R a b" by fact
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  moreover have bc: "R b c" by fact
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  ultimately show "R a c" unfolding transp_def by blast
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
lemma R_sym:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  assumes ab: "R a b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  shows "R b a"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
proof -
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  have re: "symp R" using equivp equivp_reflp_symp_transp[of R] by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  then show "R b a" using ab unfolding symp_def by blast
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
lemma R_trans2:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  assumes ac: "R a c"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  and     bd: "R b d"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  shows "R a b = R c d"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
using ac bd
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
by (blast intro: R_trans R_sym)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
lemma REPS_same:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  shows "R (REP a) (REP b) \<equiv> (a = b)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
proof -
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  have "R (REP a) (REP b) = (a = b)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  proof
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
    assume as: "R (REP a) (REP b)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    from rep_prop
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
    obtain x y
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
      where eqs: "Rep a = R x" "Rep b = R y" by blast
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
    from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
    then have "R x (Eps (R y))" using lem9 by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
    then have "R (Eps (R y)) x" using R_sym by blast
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
    then have "R y x" using lem9 by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
    then have "R x y" using R_sym by blast
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
    then have "ABS x = ABS y" using thm11 by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
    then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
    then show "a = b" using rep_inverse by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  next
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
    assume ab: "a = b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
    have "reflp R" using equivp equivp_reflp_symp_transp[of R] by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
    then show "R (REP a) (REP b)" unfolding reflp_def using ab by auto
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
section {* type definition for the quotient type *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
(* the auxiliary data for the quotient types *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
use "quotient_info.ML"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
declare [[map * = (prod_fun, prod_rel)]]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
declare [[map "fun" = (fun_map, fun_rel)]]
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   147
(* FIXME: This should throw an exception:
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   148
declare [[map "option" = (bla, blu)]]
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   149
*)
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
(* identity quotient is not here as it has to be applied first *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
lemmas [quotient_thm] =
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   153
  fun_quotient prod_quotient
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
lemmas [quotient_rsp] =
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   156
  quot_rel_rsp pair_rsp
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
(* fun_map is not here since equivp is not true *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
(* TODO: option, ... *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
lemmas [quotient_equiv] =
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   161
  identity_equivp prod_equivp
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
ML {* maps_lookup @{theory} "*" *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
ML {* maps_lookup @{theory} "fun" *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
(* definition of the quotient types *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
(* FIXME: should be called quotient_typ.ML *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
use "quotient.ML"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
(* lifting of constants *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
use "quotient_def.ML"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
section {* Simset setup *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
(* since HOL_basic_ss is too "big", we need to set up *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
(* our own minimal simpset                            *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
fun  mk_minimal_ss ctxt =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  Simplifier.context ctxt empty_ss
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
    setsubgoaler asm_simp_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
    setmksimps (mksimps [])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   186
ML {*
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   187
(* TODO/FIXME not needed anymore? *)
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   188
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   189
*}
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   190
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
section {* atomize *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
lemma atomize_eqv[atomize]:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
proof
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  assume "A \<equiv> B"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  then show "Trueprop A \<equiv> Trueprop B" by unfold
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
next
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  assume *: "Trueprop A \<equiv> Trueprop B"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  have "A = B"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
  proof (cases A)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
    case True
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
    have "A" by fact
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
    then show "A = B" using * by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  next
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
    case False
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
    have "\<not>A" by fact
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
    then show "A = B" using * by auto
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  then show "A \<equiv> B" by (rule eq_reflection)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
qed
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
fun atomize_thm thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  val thm' = Thm.freezeT (forall_intr_vars thm)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  val thm'' = ObjectLogic.atomize (cprop_of thm')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  @{thm equal_elim_rule1} OF [thm'', thm']
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
section {* infrastructure about id *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   225
(* TODO: think where should this be *)
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
lemma prod_fun_id: "prod_fun id id \<equiv> id"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  by (rule eq_reflection) (simp add: prod_fun_def)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   229
(* FIXME: make it a list and add map_id to it *)
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
lemmas id_simps =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  fun_map_id[THEN eq_reflection]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  id_apply[THEN eq_reflection]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
  id_def[THEN eq_reflection,symmetric]
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   234
  prod_fun_id
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
fun simp_ids thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  MetaSimplifier.rewrite_rule @{thms id_simps} thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
section {* Debugging infrastructure for testing tactics *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
fun my_print_tac ctxt s i thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  val prem_str = nth (prems_of thm) (i - 1)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
                 |> Syntax.string_of_term ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
                 handle Subscript => "no subgoal"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
  val _ = tracing (s ^ "\n" ^ prem_str)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
  Seq.single thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
end *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
fun DT ctxt s tac i thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  val before_goal = nth (prems_of thm) (i - 1)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
                    |> Syntax.string_of_term ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
  val before_msg = ["before: " ^ s, before_goal, "after: " ^ s]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
                   |> cat_lines
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
in 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  EVERY [tac i, my_print_tac ctxt before_msg i] thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
fun NDT ctxt s tac thm = tac thm  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
section {* Matching of terms and types *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
fun matches_typ (ty, ty') =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
  case (ty, ty') of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
    (_, TVar _) => true
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
  | (TFree x, TFree x') => x = x'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
  | (Type (s, tys), Type (s', tys')) => 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
       s = s' andalso 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
       if (length tys = length tys') 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
       then (List.all matches_typ (tys ~~ tys')) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
       else false
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  | _ => false
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
fun matches_term (trm, trm') = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
   case (trm, trm') of 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
     (_, Var _) => true
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
   | (Const (s, ty), Const (s', ty')) => s = s' andalso matches_typ (ty, ty')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
   | (Free (x, ty), Free (x', ty')) => x = x' andalso matches_typ (ty, ty')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
   | (Bound i, Bound j) => i = j
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
   | (Abs (_, T, t), Abs (_, T', t')) => matches_typ (T, T') andalso matches_term (t, t')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
   | (t $ s, t' $ s') => matches_term (t, t') andalso matches_term (s, s') 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
   | _ => false
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
section {* Infrastructure for collecting theorems for starting the lifting *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
fun lookup_quot_data lthy qty =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
    val qty_name = fst (dest_Type qty)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
    val SOME quotdata = quotdata_lookup lthy qty_name
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
    (* TODO: Should no longer be needed *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
    val rty = Logic.unvarifyT (#rtyp quotdata)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
    val rel = #rel quotdata
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
    val rel_eqv = #equiv_thm quotdata
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
    val rel_refl = @{thm equivp_reflp} OF [rel_eqv]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
    (rty, rel, rel_refl, rel_eqv)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
fun lookup_quot_thms lthy qty_name =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
    val thy = ProofContext.theory_of lthy;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
    val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
    val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
    val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
    val quot = PureThy.get_thm thy ("Quotient_" ^ qty_name)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
    (trans2, reps_same, absrep, quot)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
section {* Regularization *} 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
(*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
Regularizing an rtrm means:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
 - quantifiers over a type that needs lifting are replaced by
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
   bounded quantifiers, for example:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
      \<forall>x. P     \<Longrightarrow>     \<forall>x \<in> (Respects R). P  /  All (Respects R) P
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
   the relation R is given by the rty and qty;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
 - abstractions over a type that needs lifting are replaced
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
   by bounded abstractions:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
 - equalities over the type being lifted are replaced by
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
   corresponding relations:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
      A = B     \<Longrightarrow>     A \<approx> B
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
   example with more complicated types of A, B:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
*)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
(* builds the relation that is the argument of respects *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
fun mk_resp_arg lthy (rty, qty) =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  val thy = ProofContext.theory_of lthy
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
in  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
  if rty = qty
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
  then HOLogic.eq_const rty
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
  else
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
    case (rty, qty) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
      (Type (s, tys), Type (s', tys')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
       if s = s' 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
       then let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
              val SOME map_info = maps_lookup thy s
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
              val args = map (mk_resp_arg lthy) (tys ~~ tys')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
            in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
              list_comb (Const (#relfun map_info, dummyT), args) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
            end  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
       else let  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
              val SOME qinfo = quotdata_lookup_thy thy s'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
              (* FIXME: check in this case that the rty and qty *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
              (* FIXME: correspond to each other *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
              val (s, _) = dest_Const (#rel qinfo)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
              (* FIXME: the relation should only be the string        *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
              (* FIXME: and the type needs to be calculated as below; *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
              (* FIXME: maybe one should actually have a term         *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
              (* FIXME: and one needs to force it to have this type   *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
            in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
              Const (s, rty --> rty --> @{typ bool})
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
            end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
      | _ => HOLogic.eq_const dummyT 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
             (* FIXME: check that the types correspond to each other? *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
val mk_babs = Const (@{const_name Babs}, dummyT)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
val mk_ball = Const (@{const_name Ball}, dummyT)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
val mk_bex  = Const (@{const_name Bex}, dummyT)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
val mk_resp = Const (@{const_name Respects}, dummyT)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
(* - applies f to the subterm of an abstraction,   *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
(*   otherwise to the given term,                  *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
(* - used by regularize, therefore abstracted      *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
(*   variables do not have to be treated specially *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
fun apply_subt f trm1 trm2 =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
  case (trm1, trm2) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
    (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
  | _ => f trm1 trm2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
(* the major type of All and Ex quantifiers *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
fun qnt_typ ty = domain_type (domain_type ty)  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
(* produces a regularized version of rtm      *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
(* - the result is still not completely typed *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
(* - does not need any special treatment of   *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
(*   bound variables                          *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
fun regularize_trm lthy rtrm qtrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
  case (rtrm, qtrm) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
    (Abs (x, ty, t), Abs (x', ty', t')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
       let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
         val subtrm = Abs(x, ty, regularize_trm lthy t t')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
       in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
         if ty = ty'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
         then subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
         else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
       end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
       let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
         val subtrm = apply_subt (regularize_trm lthy) t t'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
       in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
         if ty = ty'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
         then Const (@{const_name "All"}, ty) $ subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
         else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
       end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
       let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
         val subtrm = apply_subt (regularize_trm lthy) t t'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
       in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
         if ty = ty'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
         then Const (@{const_name "Ex"}, ty) $ subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
         else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
       end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
  | (* equalities need to be replaced by appropriate equivalence relations *) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
    (Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
         if ty = ty'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
         then rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
         else mk_resp_arg lthy (domain_type ty, domain_type ty') 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
  | (* in this case we check whether the given equivalence relation is correct *) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
    (rel, Const (@{const_name "op ="}, ty')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
       let 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
         val exc = LIFT_MATCH "regularise (relation mismatch)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
         val rel_ty = (fastype_of rel) handle TERM _ => raise exc 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
         val rel' = mk_resp_arg lthy (domain_type rel_ty, domain_type ty') 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
       in 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
         if rel' = rel
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
         then rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
         else raise exc
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
       end  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
  | (_, Const (s, _)) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
       let 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
         fun same_name (Const (s, _)) (Const (s', _)) = (s = s')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
           | same_name _ _ = false
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
       in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
         if same_name rtrm qtrm 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
         then rtrm 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
         else 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
           let 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
             fun exc1 s = LIFT_MATCH ("regularize (constant " ^ s ^ " not found)")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
             val exc2   = LIFT_MATCH ("regularize (constant mismatch)")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
             val thy = ProofContext.theory_of lthy
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
             val rtrm' = (#rconst (qconsts_lookup thy s)) handle NotFound => raise (exc1 s) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
           in 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
             if matches_term (rtrm, rtrm')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
             then rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
             else raise exc2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
           end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
       end 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
  | (t1 $ t2, t1' $ t2') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
       (regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
  | (Free (x, ty), Free (x', ty')) => 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
       (* this case cannot arrise as we start with two fully atomized terms *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
       raise (LIFT_MATCH "regularize (frees)")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  | (Bound i, Bound i') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
       if i = i' 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
       then rtrm 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
       else raise (LIFT_MATCH "regularize (bounds mismatch)")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
  | (rt, qt) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
       raise (LIFT_MATCH "regularize (default)")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
fun equiv_tac ctxt =
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   494
  (K (print_tac "equiv tac")) THEN'
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   495
  REPEAT_ALL_NEW (resolve_tac (equiv_rules_get ctxt))
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
val equiv_solver = Simplifier.mk_solver' "Equivalence goal solver" equiv_solver_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
fun prep_trm thy (x, (T, t)) =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
  (cterm_of thy (Var (x, T)), cterm_of thy t)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
fun prep_ty thy (x, (S, ty)) =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
  (ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
fun matching_prs thy pat trm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
  val univ = Unify.matchers thy [(pat, trm)]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
  val SOME (env, _) = Seq.pull univ
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
  val tenv = Vartab.dest (Envir.term_env env)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
  val tyenv = Vartab.dest (Envir.type_env env)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  (map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
fun calculate_instance ctxt thm redex R1 R2 =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
  val thy = ProofContext.theory_of ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
  val goal = Const (@{const_name "equivp"}, dummyT) $ R2  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
             |> Syntax.check_term ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
             |> HOLogic.mk_Trueprop 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  val eqv_prem = Goal.prove ctxt [] [] goal (fn {context,...} => equiv_tac context 1)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
  val thm = (@{thm eq_reflection} OF [thm OF [eqv_prem]])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
  val R1c = cterm_of thy R1
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
  val thmi = Drule.instantiate' [] [SOME R1c] thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
  val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) redex
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
  val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
  SOME thm2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
handle _ => NONE
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
(* FIXME/TODO: what is the place where the exception can be raised: matching_prs? *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
fun ball_bex_range_simproc ss redex =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
  val ctxt = Simplifier.the_context ss
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
in 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
 case redex of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
    (Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $ 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
      (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
        calculate_instance ctxt @{thm ball_reg_eqv_range} redex R1 R2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
  | (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $ 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
      (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
        calculate_instance ctxt @{thm bex_reg_eqv_range} redex R1 R2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
  | _ => NONE
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
lemma eq_imp_rel: 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
  shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
by (simp add: equivp_reflp)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
(* FIXME/TODO: How does regularizing work? *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
(* FIXME/TODO: needs to be adapted
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
To prove that the raw theorem implies the regularised one, 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
we try in order:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
 - Reflexivity of the relation
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
 - Assumption
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
 - Elimnating quantifiers on both sides of toplevel implication
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
 - Simplifying implications on both sides of toplevel implication
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
 - Ball (Respects ?E) ?P = All ?P
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
*)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
fun regularize_tac ctxt =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
  val thy = ProofContext.theory_of ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
  val pat_ball = @{term "Ball (Respects (R1 ===> R2)) P"}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
  val pat_bex  = @{term "Bex (Respects (R1 ===> R2)) P"}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
  val simproc = Simplifier.simproc_i thy "" [pat_ball, pat_bex] (K (ball_bex_range_simproc))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
  val simpset = (mk_minimal_ss ctxt) 
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   585
                       addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv}
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
                       addsimprocs [simproc] addSolver equiv_solver
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
  (* TODO: Make sure that there are no list_rel, pair_rel etc involved *)
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   588
  (* can this cause loops in equiv_tac ? *)
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  val eq_eqvs = map (fn x => @{thm eq_imp_rel} OF [x]) (equiv_rules_get ctxt)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   590
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
  simp_tac simpset THEN'
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   592
  REPEAT_ALL_NEW (CHANGED o FIRST' [
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
    rtac @{thm ball_reg_right},
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
    rtac @{thm bex_reg_left},
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
    resolve_tac (Inductive.get_monos ctxt),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
    rtac @{thm ball_all_comm},
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
    rtac @{thm bex_ex_comm},
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   598
    resolve_tac eq_eqvs,  
606
38aa6b67a80b clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents: 605
diff changeset
   599
    (* should be equivalent to the above, but causes loops:   *) 
605
120e479ed367 first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents: 602
diff changeset
   600
    (* rtac @{thm eq_imp_rel} THEN' SOLVES' (equiv_tac ctxt), *)
606
38aa6b67a80b clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents: 605
diff changeset
   601
    (* the culprit is aslread rtac @{thm eq_imp_rel}          *)
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
    simp_tac simpset])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
section {* Injections of rep and abses *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
(*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
Injecting repabs means:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
  For abstractions:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
  * If the type of the abstraction doesn't need lifting we recurse.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
  * If it does we add RepAbs around the whole term and check if the
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
    variable needs lifting.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
    * If it doesn't then we recurse
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
    * If it does we recurse and put 'RepAbs' around all occurences
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
      of the variable in the obtained subterm. This in combination
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
      with the RepAbs above will let us change the type of the
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
      abstraction with rewriting.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
  For applications:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
  * If the term is 'Respects' applied to anything we leave it unchanged
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
  * If the term needs lifting and the head is a constant that we know
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
    how to lift, we put a RepAbs and recurse
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
  * If the term needs lifting and the head is a free applied to subterms
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
    (if it is not applied we treated it in Abs branch) then we
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
    put RepAbs and recurse
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
  * Otherwise just recurse.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
*)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
fun mk_repabs lthy (T, T') trm = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
  Quotient_Def.get_fun repF lthy (T, T') 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
    $ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
(* bound variables need to be treated properly,    *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
(* as the type of subterms need to be calculated   *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
(* in the abstraction case                         *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
fun inj_repabs_trm lthy (rtrm, qtrm) =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
 case (rtrm, qtrm) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
    (Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
       Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
  | (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
       Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
  | (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
       Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
  | (Abs (x, T, t), Abs (x', T', t')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
      let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
        val rty = fastype_of rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
        val qty = fastype_of qtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
        val (y, s) = Term.dest_abs (x, T, t)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
        val (_, s') = Term.dest_abs (x', T', t')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
        val yvar = Free (y, T)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
        val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
      in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
        if rty = qty 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
        then result
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
        else mk_repabs lthy (rty, qty) result
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
      end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
  | (t $ s, t' $ s') =>  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
       (inj_repabs_trm lthy (t, t')) $ (inj_repabs_trm lthy (s, s'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
  | (Free (_, T), Free (_, T')) => 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
        if T = T' 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
        then rtrm 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
        else mk_repabs lthy (T, T') rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  | (_, Const (@{const_name "op ="}, _)) => rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
    (* FIXME: check here that rtrm is the corresponding definition for the const *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
  | (_, Const (_, T')) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
      let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
        val rty = fastype_of rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
      in 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
        if rty = T'                    
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
        then rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
        else mk_repabs lthy (rty, T') rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
      end   
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   685
  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   686
  | _ => raise (LIFT_MATCH "injection")
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   688
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
section {* RepAbs Injection Tactic *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   690
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   691
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
fun quotient_tac ctxt =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
  REPEAT_ALL_NEW (FIRST'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
    [rtac @{thm identity_quotient},
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
     resolve_tac (quotient_rules_get ctxt)])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   696
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   697
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   698
(* solver for the simplifier *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   700
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   702
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   703
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
fun solve_quotient_assums ctxt thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
  let val gl = hd (Drule.strip_imp_prems (cprop_of thm)) in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
  thm OF [Goal.prove_internal [] gl (fn _ => quotient_tac ctxt 1)]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
  handle _ => error "solve_quotient_assums failed. Maybe a quotient_thm is missing"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
(* Not used *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
(* It proves the Quotient assumptions by calling quotient_tac *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
fun solve_quotient_assum i ctxt thm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
    val tac =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
      (compose_tac (false, thm, i)) THEN_ALL_NEW
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
      (quotient_tac ctxt);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
    val gc = Drule.strip_imp_concl (cprop_of thm);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
    Goal.prove_internal [] gc (fn _ => tac 1)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
  handle _ => error "solve_quotient_assum"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
definition
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
  "QUOT_TRUE x \<equiv> True"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   729
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   730
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
fun find_qt_asm asms =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
    fun find_fun trm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
      case trm of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
        (Const(@{const_name Trueprop}, _) $ (Const (@{const_name QUOT_TRUE}, _) $ _)) => true
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
      | _ => false
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
    case find_first find_fun asms of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
      SOME (_ $ (_ $ (f $ a))) => (f, a)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
    | SOME _ => error "find_qt_asm: no pair"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
    | NONE => error "find_qt_asm: no assumption"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
(*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
To prove that the regularised theorem implies the abs/rep injected, 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
we try:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
 1) theorems 'trans2' from the appropriate QUOT_TYPE
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
 2) remove lambdas from both sides: lambda_rsp_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   751
 3) remove Ball/Bex from the right hand side
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   752
 4) use user-supplied RSP theorems
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   753
 5) remove rep_abs from the right side
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
 6) reflexivity of equality
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
 7) split applications of lifted type (apply_rsp)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
 8) split applications of non-lifted type (cong_tac)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757
 9) apply extentionality
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
 A) reflexivity of the relation
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
 B) assumption
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   760
    (Lambdas under respects may have left us some assumptions)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   761
 C) proving obvious higher order equalities by simplifying fun_rel
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   762
    (not sure if it is still needed?)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   763
 D) unfolding lambda on one side
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   764
 E) simplifying (= ===> =) for simpler respectfulness
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   765
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   766
*)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   767
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   768
lemma quot_true_dests:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   769
  shows QT_all: "QUOT_TRUE (All P) \<Longrightarrow> QUOT_TRUE P"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   770
  and   QT_ex:  "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   771
  and   QT_lam: "QUOT_TRUE (\<lambda>x. P x) \<Longrightarrow> (\<And>x. QUOT_TRUE  (P x))"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   772
  and   QT_ext: "(\<And>x. QUOT_TRUE (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (QUOT_TRUE a \<Longrightarrow> f = g)"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   773
apply(simp_all add: QUOT_TRUE_def ext)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   774
done
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   775
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   776
lemma QUOT_TRUE_i: "(QUOT_TRUE (a :: bool) \<Longrightarrow> P) \<Longrightarrow> P"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   777
by (simp add: QUOT_TRUE_def)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   778
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   779
lemma QUOT_TRUE_imp: "QUOT_TRUE a \<equiv> QUOT_TRUE b"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   780
by (simp add: QUOT_TRUE_def)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   781
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   782
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   783
fun quot_true_conv1 ctxt fnctn ctrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   784
  case (term_of ctrm) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   785
    (Const (@{const_name QUOT_TRUE}, _) $ x) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   786
    let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   787
      val fx = fnctn x;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   788
      val thy = ProofContext.theory_of ctxt;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   789
      val cx = cterm_of thy x;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   790
      val cfx = cterm_of thy fx;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   791
      val cxt = ctyp_of thy (fastype_of x);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   792
      val cfxt = ctyp_of thy (fastype_of fx);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   793
      val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   794
    in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   795
      Conv.rewr_conv thm ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
    end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   799
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
fun quot_true_conv ctxt fnctn ctrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
  case (term_of ctrm) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
    (Const (@{const_name QUOT_TRUE}, _) $ _) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803
      quot_true_conv1 ctxt fnctn ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   804
  | _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   805
  | Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
  | _ => Conv.all_conv ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   807
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   809
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   810
fun quot_true_tac ctxt fnctn = CONVERSION
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   811
    ((Conv.params_conv ~1 (fn ctxt =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   812
       (Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   813
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
ML {* fun dest_comb (f $ a) = (f, a) *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   816
ML {* fun dest_bcomb ((_ $ l) $ r) = (l, r) *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   817
(* TODO: Can this be done easier? *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   818
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   819
fun unlam t =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
  case t of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   821
    (Abs a) => snd (Term.dest_abs a)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   822
  | _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0)))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   823
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   824
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   825
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   826
fun dest_fun_type (Type("fun", [T, S])) = (T, S)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   827
  | dest_fun_type _ = error "dest_fun_type"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   829
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   830
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   831
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   832
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   833
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   834
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
val apply_rsp_tac =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   836
  Subgoal.FOCUS (fn {concl, asms, context,...} =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   837
    case ((HOLogic.dest_Trueprop (term_of concl))) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   838
      ((R2 $ (f $ x) $ (g $ y))) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   839
        (let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   840
          val (asmf, asma) = find_qt_asm (map term_of asms);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   841
        in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   842
          if (fastype_of asmf) = (fastype_of f) then no_tac else let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   843
            val ty_a = fastype_of x;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   844
            val ty_b = fastype_of asma;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   845
            val ty_c = range_type (type_of f);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
            val thy = ProofContext.theory_of context;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   847
            val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c];
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
            val thm = Drule.instantiate' ty_inst [] @{thm apply_rsp}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
            val te = solve_quotient_assums context thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
            val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   851
            val thm = Drule.instantiate' [] t_inst te
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   852
          in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   853
            compose_tac (false, thm, 2) 1
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   854
          end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   855
        end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   856
        handle ERROR "find_qt_asm: no pair" => no_tac)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   857
    | _ => no_tac)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   858
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   859
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   860
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   861
fun rep_abs_rsp_tac ctxt =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   862
  SUBGOAL (fn (goal, i) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   863
    case (bare_concl goal) of 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   864
      (rel $ _ $ (rep $ (abs $ _))) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   865
        (let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   866
           val thy = ProofContext.theory_of ctxt;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   867
           val (ty_a, ty_b) = dest_fun_type (fastype_of abs);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   868
           val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   869
           val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep];
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   870
           val thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   871
           val te = solve_quotient_assums ctxt thm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   872
         in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   873
           rtac te i
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   874
         end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   875
         handle _ => no_tac)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   876
    | _ => no_tac)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   877
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   878
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   879
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   880
fun inj_repabs_tac_match ctxt trans2 = SUBGOAL (fn (goal, i) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   881
(case (bare_concl goal) of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   882
    (* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   883
  ((Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   884
      => rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   885
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   886
    (* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   887
| (Const (@{const_name "op ="},_) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   888
    (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   889
    (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   890
      => rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   891
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   892
    (* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   893
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   894
    (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   895
    (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   896
      => rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   897
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   898
    (* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   899
| Const (@{const_name "op ="},_) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   900
    (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   901
    (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   902
      => rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   903
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   904
    (* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   905
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   906
    (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   907
    (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   908
      => rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   909
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   910
| (_ $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   911
    (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   912
    (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   913
      => rtac @{thm babs_rsp} THEN' RANGE [quotient_tac ctxt]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   914
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   915
    (* reflexivity of operators arising from Cong_tac *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   916
| Const (@{const_name "op ="},_) $ _ $ _ 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   917
      => rtac @{thm refl} ORELSE'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   918
          (resolve_tac trans2 THEN' RANGE [
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   919
            quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   920
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   921
(* TODO: These patterns should should be somehow combined and generalized... *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   922
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   923
    (Const (@{const_name fun_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   924
    (Const (@{const_name fun_rel}, _) $ _ $ _)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   925
    => rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   926
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   927
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   928
    (Const (@{const_name prod_rel}, _) $ _ $ _) $
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   929
    (Const (@{const_name prod_rel}, _) $ _ $ _)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   930
    => rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   931
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   932
   (* respectfulness of constants; in particular of a simple relation *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   933
| _ $ (Const _) $ (Const _)  (* fun_rel, list_rel, etc but not equality *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   934
    => resolve_tac (rsp_rules_get ctxt) THEN_ALL_NEW quotient_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   935
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   936
    (* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   937
    (* observe ---> *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   938
| _ $ _ $ _ 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   939
    => rep_abs_rsp_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   940
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   941
| _ => error "inj_repabs_tac not a relation"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   942
) i)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   943
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   944
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   945
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   946
fun inj_repabs_tac ctxt rel_refl trans2 =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   947
  (FIRST' [
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   948
    inj_repabs_tac_match ctxt trans2,
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   949
    (* R (t $ \<dots>) (t' $ \<dots>) ----> apply_rsp   provided type of t needs lifting *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   950
    NDT ctxt "A" (apply_rsp_tac ctxt THEN'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   951
                (RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   952
    (* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong   provided type of t does not need lifting *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   953
    (* merge with previous tactic *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   954
    NDT ctxt "B" (Cong_Tac.cong_tac @{thm cong} THEN'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   955
                (RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   956
    (* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   957
    NDT ctxt "C" (rtac @{thm ext} THEN' quot_true_tac ctxt unlam),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   958
    (* resolving with R x y assumptions *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   959
    NDT ctxt "E" (atac),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   960
    (* reflexivity of the basic relations *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   961
    (* R \<dots> \<dots> *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   962
    NDT ctxt "D" (resolve_tac rel_refl)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   963
    ])
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   964
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   965
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   966
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   967
fun all_inj_repabs_tac ctxt rel_refl trans2 =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   968
  REPEAT_ALL_NEW (inj_repabs_tac ctxt rel_refl trans2)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   969
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   970
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   971
section {* Cleaning of the theorem *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   972
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   973
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   974
fun make_inst lhs t =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   975
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   976
    val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   977
    val _ $ (Abs (_, _, g)) = t;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   978
    fun mk_abs i t =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   979
      if incr_boundvars i u aconv t then Bound i
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   980
      else (case t of
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   981
        t1 $ t2 => mk_abs i t1 $ mk_abs i t2
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   982
      | Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   983
      | Bound j => if i = j then error "make_inst" else t
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   984
      | _ => t);
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   985
  in (f, Abs ("x", T, mk_abs 0 g)) end;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   986
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   987
602
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   988
(* Since the patterns for the lhs are different; there are 2 different make-insts *)
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   989
ML {*
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   990
fun make_inst2 lhs t =
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   991
  let
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   992
    val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs;
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   993
    val _ = tracing "a";
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   994
    val _ $ (Abs (_, _, (_ $ g))) = t;
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   995
    fun mk_abs i t =
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   996
      if incr_boundvars i u aconv t then Bound i
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   997
      else (case t of
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   998
        t1 $ t2 => mk_abs i t1 $ mk_abs i t2
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
   999
      | Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1000
      | Bound j => if i = j then error "make_inst" else t
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1001
      | _ => t);
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1002
  in (f, Abs ("x", T, mk_abs 0 g)) end;
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1003
*}
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1004
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1005
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1006
fun lambda_prs_simple_conv ctxt ctrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1007
  case (term_of ctrm) of
602
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1008
   ((Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _)) =>
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1009
     let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1010
       val thy = ProofContext.theory_of ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1011
       val (ty_b, ty_a) = dest_fun_type (fastype_of r1)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1012
       val (ty_c, ty_d) = dest_fun_type (fastype_of a2)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1013
       val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1014
       val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1015
       val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1016
       val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1017
       val _ = tracing ("te rule:\n" ^ (Syntax.string_of_term ctxt (prop_of te)));
602
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1018
       val ti =
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1019
         (let
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1020
           val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1021
           val (insp, inst) = make_inst (term_of (Thm.lhs_of ts)) (term_of ctrm)
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1022
         in
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1023
           Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1024
         end handle Bind =>
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1025
         let
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1026
           val (insp, inst) = make_inst2 (term_of (Thm.lhs_of te)) (term_of ctrm)
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1027
           val td = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) te
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1028
         in
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1029
           MetaSimplifier.rewrite_rule @{thms id_simps} td
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1030
         end);
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1031
       val _ = if not (Term.is_Const a2 andalso fst (dest_Const a2) = @{const_name "id"}) then
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1032
                  (tracing "lambda_prs";
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1033
                   tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm)));
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1034
                   tracing ("lpi rule:\n" ^ (Syntax.string_of_term ctxt (prop_of lpi)));
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1035
                   tracing ("te rule:\n" ^ (Syntax.string_of_term ctxt (prop_of te)));
602
e56eeb9fedb3 make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 600
diff changeset
  1036
                   tracing ("ti rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ti))))
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1037
               else ()
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1038
     in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1039
       Conv.rewr_conv ti ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1040
     end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1041
  | _ => Conv.all_conv ctrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1042
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1043
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1044
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1045
val lambda_prs_conv =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1046
  More_Conv.top_conv lambda_prs_simple_conv
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1047
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1048
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1049
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1050
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1051
(*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1052
 Cleaning the theorem consists of three rewriting steps.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1053
 The first two need to be done before fun_map is unfolded
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1054
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1055
 1) lambda_prs:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1056
     (Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x)))  ---->  f
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1057
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1058
    Implemented as conversion since it is not a pattern.
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1059
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1060
 2) all_prs (the same for exists):
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1061
     Ball (Respects R) ((abs ---> id) f)  ---->  All f
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1062
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1063
    Rewriting with definitions from the argument defs
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1064
     (rep ---> abs) oldConst ----> newconst
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1065
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1066
 3) Quotient_rel_rep:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1067
      Rel (Rep x) (Rep y)  ---->  x = y
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1068
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1069
    Quotient_abs_rep:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1070
      Abs (Rep x)  ---->  x
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1071
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1072
    id_simps; fun_map.simps
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1073
*)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1074
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1075
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1076
fun clean_tac lthy =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1077
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1078
    val thy = ProofContext.theory_of lthy;
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1079
    val defs = map (Thm.varifyT o symmetric o #def) (qconsts_dest thy)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1080
      (* FIXME: shouldn't the definitions already be varified? *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1081
    val thms1 = @{thms all_prs ex_prs} @ defs
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1082
    val thms2 = @{thms eq_reflection[OF fun_map.simps]} 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1083
                @ @{thms id_simps Quotient_abs_rep Quotient_rel_rep} 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1084
    fun simps thms = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1085
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1086
    EVERY' [lambda_prs_tac lthy,
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1087
            simp_tac (simps thms1),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1088
            simp_tac (simps thms2),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1089
            TRY o rtac refl]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1090
  end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1091
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1092
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1093
section {* Genralisation of free variables in a goal *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1094
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1095
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1096
fun inst_spec ctrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1097
   Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1098
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1099
fun inst_spec_tac ctrms =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1100
  EVERY' (map (dtac o inst_spec) ctrms)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1101
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1102
fun all_list xs trm = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1103
  fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1104
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1105
fun apply_under_Trueprop f = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1106
  HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1107
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1108
fun gen_frees_tac ctxt =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1109
 SUBGOAL (fn (concl, i) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1110
  let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1111
    val thy = ProofContext.theory_of ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1112
    val vrs = Term.add_frees concl []
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1113
    val cvrs = map (cterm_of thy o Free) vrs
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1114
    val concl' = apply_under_Trueprop (all_list vrs) concl
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1115
    val goal = Logic.mk_implies (concl', concl)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1116
    val rule = Goal.prove ctxt [] [] goal 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1117
      (K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1118
  in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1119
    rtac rule i
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1120
  end)  
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1121
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1122
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1123
section {* General outline of the lifting procedure *}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1124
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1125
(* - A is the original raw theorem          *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1126
(* - B is the regularized theorem           *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1127
(* - C is the rep/abs injected version of B *) 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1128
(* - D is the lifted theorem                *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1129
(*                                          *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1130
(* - b is the regularization step           *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1131
(* - c is the rep/abs injection step        *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1132
(* - d is the cleaning part                 *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1133
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1134
lemma lifting_procedure:
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1135
  assumes a: "A"
606
38aa6b67a80b clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents: 605
diff changeset
  1136
  and     b: "A \<longrightarrow> B"
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1137
  and     c: "B = C"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1138
  and     d: "C = D"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1139
  shows   "D"
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1140
  using a b c d
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1141
  by simp
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1142
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1143
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1144
fun lift_match_error ctxt fun_str rtrm qtrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1145
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1146
  val rtrm_str = Syntax.string_of_term ctxt rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1147
  val qtrm_str = Syntax.string_of_term ctxt qtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1148
  val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str, 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1149
             "and the lifted theorem\n", rtrm_str, "do not match"]
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1150
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1151
  error (space_implode " " msg)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1152
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1153
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1154
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1155
ML {* 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1156
fun procedure_inst ctxt rtrm qtrm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1157
let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1158
  val thy = ProofContext.theory_of ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1159
  val rtrm' = HOLogic.dest_Trueprop rtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1160
  val qtrm' = HOLogic.dest_Trueprop qtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1161
  val reg_goal = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1162
        Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm')
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1163
        handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1164
  val _ = warning "Regularization done."
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1165
  val inj_goal = 
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1166
        Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm'))
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1167
        handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1168
  val _ = warning "RepAbs Injection done."
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1169
in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1170
  Drule.instantiate' []
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1171
    [SOME (cterm_of thy rtrm'),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1172
     SOME (cterm_of thy reg_goal),
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1173
     SOME (cterm_of thy inj_goal)] @{thm lifting_procedure}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1174
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1175
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1176
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1177
(* Left for debugging *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1178
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1179
fun procedure_tac ctxt rthm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1180
  ObjectLogic.full_atomize_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1181
  THEN' gen_frees_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1182
  THEN' CSUBGOAL (fn (gl, i) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1183
    let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1184
      val rthm' = atomize_thm rthm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1185
      val rule = procedure_inst ctxt (prop_of rthm') (term_of gl)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1186
      val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb gl))] @{thm QUOT_TRUE_i}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1187
    in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1188
      (rtac rule THEN' RANGE [rtac rthm', (fn _ => all_tac), rtac thm]) i
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1189
    end)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1190
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1191
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1192
ML {*
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1193
(* FIXME/TODO should only get as arguments the rthm like procedure_tac *)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1194
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1195
fun lift_tac ctxt rthm =
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1196
  ObjectLogic.full_atomize_tac
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1197
  THEN' gen_frees_tac ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1198
  THEN' CSUBGOAL (fn (gl, i) =>
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1199
    let
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1200
      val rthm' = atomize_thm rthm
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1201
      val rule = procedure_inst ctxt (prop_of rthm') (term_of gl)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1202
      val rel_refl = map (fn x => @{thm equivp_reflp} OF [x]) (equiv_rules_get ctxt)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1203
      val quotients = quotient_rules_get ctxt
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1204
      val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quotients
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1205
      val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb gl))] @{thm QUOT_TRUE_i}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1206
    in
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1207
      (rtac rule THEN'
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1208
       RANGE [rtac rthm',
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1209
              regularize_tac ctxt,
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1210
              rtac thm THEN' all_inj_repabs_tac ctxt rel_refl trans2,
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1211
              clean_tac ctxt]) i
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1212
    end)
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1213
*}
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1214
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1215
end
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1216