QuotMainNew.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 29 Nov 2009 19:48:55 +0100
changeset 454 cc0b9cb367cd
child 455 9cb45d022524
permissions -rw-r--r--
added a new version of QuotMain to experiment with qids
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
454
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotMain
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports QuotScript QuotList Prove
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
uses ("quotient_info.ML") 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
     ("quotient.ML")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
     ("quotient_def.ML")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
locale QUOT_TYPE =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  assumes equiv: "EQUIV R"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
begin
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
definition
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  ABS::"'a \<Rightarrow> 'b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
where
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  "ABS x \<equiv> Abs (R x)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
definition
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  REP::"'b \<Rightarrow> 'a"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
where
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  "REP a = Eps (Rep a)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
lemma lem9:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  shows "R (Eps (R x)) = R x"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
proof -
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  then have "R x (Eps (R x))" by (rule someI)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  then show "R (Eps (R x)) = R x"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
    using equiv unfolding EQUIV_def by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
theorem thm10:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  shows "ABS (REP a) \<equiv> a"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  apply  (rule eq_reflection)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  unfolding ABS_def REP_def
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
proof -
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  from rep_prop
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  obtain x where eq: "Rep a = R x" by auto
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  also have "\<dots> = Abs (R x)" using lem9 by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  also have "\<dots> = Abs (Rep a)" using eq by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  also have "\<dots> = a" using rep_inverse by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  finally
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  show "Abs (R (Eps (Rep a))) = a" by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
lemma REP_refl:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  shows "R (REP a) (REP a)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
unfolding REP_def
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
by (simp add: equiv[simplified EQUIV_def])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
lemma lem7:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  shows "(R x = R y) = (Abs (R x) = Abs (R y))"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(rule iffI)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(simp)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
apply(drule rep_inject[THEN iffD2])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
apply(simp add: abs_inverse)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
done
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
theorem thm11:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  shows "R r r' = (ABS r = ABS r')"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
unfolding ABS_def
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
by (simp only: equiv[simplified EQUIV_def] lem7)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
lemma REP_ABS_rsp:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  shows "R f (REP (ABS g)) = R f g"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  and   "R (REP (ABS g)) f = R g f"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
by (simp_all add: thm10 thm11)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
lemma QUOTIENT:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  "QUOTIENT R ABS REP"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
apply(unfold QUOTIENT_def)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
apply(simp add: thm10)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(simp add: REP_refl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
apply(subst thm11[symmetric])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
apply(simp add: equiv[simplified EQUIV_def])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
done
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
lemma R_trans:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  assumes ab: "R a b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  and     bc: "R b c"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  shows "R a c"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
proof -
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  moreover have ab: "R a b" by fact
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  moreover have bc: "R b c" by fact
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  ultimately show "R a c" unfolding TRANS_def by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
lemma R_sym:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  assumes ab: "R a b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  shows "R b a"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
proof -
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  then show "R b a" using ab unfolding SYM_def by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
lemma R_trans2:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  assumes ac: "R a c"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  and     bd: "R b d"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  shows "R a b = R c d"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
using ac bd
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
by (blast intro: R_trans R_sym)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
lemma REPS_same:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  shows "R (REP a) (REP b) \<equiv> (a = b)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
proof -
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  have "R (REP a) (REP b) = (a = b)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  proof
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
    assume as: "R (REP a) (REP b)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
    from rep_prop
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    obtain x y
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
      where eqs: "Rep a = R x" "Rep b = R y" by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
    then have "R x (Eps (R y))" using lem9 by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
    then have "R (Eps (R y)) x" using R_sym by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
    then have "R y x" using lem9 by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
    then have "R x y" using R_sym by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
    then have "ABS x = ABS y" using thm11 by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
    then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
    then show "a = b" using rep_inverse by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  next
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
    assume ab: "a = b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
    have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
    then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
lemma equiv_trans2:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  assumes e: "EQUIV R"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  and     ac: "R a c"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  and     bd: "R b d"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  shows "R a b = R c d"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
using ac bd e
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
unfolding EQUIV_REFL_SYM_TRANS TRANS_def SYM_def
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
by (blast)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
section {* type definition for the quotient type *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
(* the auxiliary data for the quotient types *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
use "quotient_info.ML"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
declare [[map list = (map, LIST_REL)]]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
declare [[map * = (prod_fun, prod_rel)]]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
declare [[map "fun" = (fun_map, FUN_REL)]]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
ML {* maps_lookup @{theory} "List.list" *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
ML {* maps_lookup @{theory} "*" *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
ML {* maps_lookup @{theory} "fun" *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
(* definition of the quotient types *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
(* FIXME: should be called quotient_typ.ML *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
use "quotient.ML"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
(* lifting of constants *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
use "quotient_def.ML"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
(* TODO: Consider defining it with an "if"; sth like:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
   Babs p m = \<lambda>x. if x \<in> p then m x else undefined
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
definition
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
where
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
section {* ATOMIZE *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
lemma atomize_eqv[atomize]:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
proof
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
  assume "A \<equiv> B"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  then show "Trueprop A \<equiv> Trueprop B" by unfold
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
next
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  assume *: "Trueprop A \<equiv> Trueprop B"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  have "A = B"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  proof (cases A)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
    case True
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
    have "A" by fact
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
    then show "A = B" using * by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  next
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
    case False
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
    have "\<not>A" by fact
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
    then show "A = B" using * by auto
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  then show "A \<equiv> B" by (rule eq_reflection)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
qed
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
fun atomize_thm thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  val thm' = Thm.freezeT (forall_intr_vars thm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  val thm'' = ObjectLogic.atomize (cprop_of thm')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  @{thm equal_elim_rule1} OF [thm'', thm']
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
section {* infrastructure about id *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
lemma prod_fun_id: "prod_fun id id \<equiv> id"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  by (rule eq_reflection) (simp add: prod_fun_def)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
lemma map_id: "map id \<equiv> id"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  apply (rule eq_reflection)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  apply (rule ext)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  apply (rule_tac list="x" in list.induct)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  apply (simp_all)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  done
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
lemmas id_simps =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  FUN_MAP_I[THEN eq_reflection]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  id_apply[THEN eq_reflection]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
  id_def[THEN eq_reflection,symmetric]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  prod_fun_id map_id
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
fun simp_ids thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  MetaSimplifier.rewrite_rule @{thms id_simps} thm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
section {* Debugging infrastructure for testing tactics *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
fun my_print_tac ctxt s i thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  val prem_str = nth (prems_of thm) (i - 1)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
                 |> Syntax.string_of_term ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
                 handle Subscript => "no subgoal"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  val _ = tracing (s ^ "\n" ^ prem_str)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  Seq.single thm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
end *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
fun DT ctxt s tac i thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
  val before_goal = nth (prems_of thm) (i - 1)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
                    |> Syntax.string_of_term ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
  val before_msg = ["before: " ^ s, before_goal, "after: " ^ s]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
                   |> cat_lines
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
in 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  EVERY [tac i, my_print_tac ctxt before_msg i] thm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
fun NDT ctxt s tac thm = tac thm  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
section {*  Infrastructure about definitions *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
(* Does the same as 'subst' in a given theorem *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
fun eqsubst_thm ctxt thms thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
    val goalstate = Goal.init (Thm.cprop_of thm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
      NONE => error "eqsubst_thm"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
    | SOME th => cprem_of th 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
    val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
    val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a');
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
    val cgoal = cterm_of (ProofContext.theory_of ctxt) goal
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
    val rt = Goal.prove_internal [] cgoal (fn _ => tac);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
    @{thm equal_elim_rule1} OF [rt, thm]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
(* expects atomized definitions *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
fun add_lower_defs_aux lthy thm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
    val e1 = @{thm fun_cong} OF [thm];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
    val f = eqsubst_thm lthy @{thms fun_map.simps} e1;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
    val g = simp_ids f
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
    (simp_ids thm) :: (add_lower_defs_aux lthy g)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
  handle _ => [simp_ids thm]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
fun add_lower_defs lthy def =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
    val def_pre_sym = symmetric def
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
    val def_atom = atomize_thm def_pre_sym
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
    val defs_all = add_lower_defs_aux lthy def_atom
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
    map Thm.varifyT defs_all
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
section {* Infrastructure for collecting theorems for starting the lifting *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
fun lookup_quot_data lthy qty =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
    val qty_name = fst (dest_Type qty)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
    val SOME quotdata = quotdata_lookup lthy qty_name
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
                  (* cu: Changed the lookup\<dots>not sure whether this works *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
    (* TODO: Should no longer be needed *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
    val rty = Logic.unvarifyT (#rtyp quotdata)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
    val rel = #rel quotdata
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
    val rel_eqv = #equiv_thm quotdata
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
    val rel_refl = @{thm EQUIV_REFL} OF [rel_eqv]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
    (rty, rel, rel_refl, rel_eqv)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
fun lookup_quot_thms lthy qty_name =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
    val thy = ProofContext.theory_of lthy;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
    val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
    val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
    val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
    val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
    (trans2, reps_same, absrep, quot)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
fun lookup_quot_consts defs =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
    fun dest_term (a $ b) = (a, b);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
    val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
    map (fst o dest_Const o snd o dest_term) def_terms
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
section {* Infrastructure for special quotient identity *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
definition
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
  "qid TYPE('a) TYPE('b) x \<equiv> x"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
fun get_typ_aux (Type ("itself", [T])) = T 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
fun get_typ (Const ("TYPE", T)) = get_typ_aux T
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
fun get_tys (Const (@{const_name "qid"},_) $ ty1 $ ty2) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
  (get_typ ty1, get_typ ty2)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
fun is_qid (Const (@{const_name "qid"},_) $ _ $ _) = true
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
  | is_qid _ = false
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
fun mk_itself ty = Type ("itself", [ty])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
fun mk_TYPE ty = Const ("TYPE", mk_itself ty)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
fun mk_qid (rty, qty, trm) = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
  Const (@{const_name "qid"}, [mk_itself rty, mk_itself qty, dummyT] ---> dummyT) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
    $ mk_TYPE rty $ mk_TYPE qty $ trm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
fun insertion_aux rtrm qtrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
  case (rtrm, qtrm) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
    (Abs (x, ty, t), Abs (x', ty', t')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
       let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
         val (y, s) = Term.dest_abs (x, ty, t)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
         val (_, s') = Term.dest_abs (x', ty', t')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
         val yvar = Free (y, ty)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
         val result = Term.lambda_name (y, yvar) (insertion_aux s s')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
       in     
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
         if ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
         then result
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
         else mk_qid (ty, ty', result)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
       end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
  | (t1 $ t2, t1' $ t2') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
       let 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
         val rty = fastype_of rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
         val qty = fastype_of qtrm 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
         val subtrm1 = insertion_aux t1 t1' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
         val subtrm2 = insertion_aux t2 t2'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
       in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
         if rty = qty
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
         then subtrm1 $ subtrm2
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
         else mk_qid (rty, qty, subtrm1 $ subtrm2)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
       end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  | (Free (_, ty), Free (_, ty')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
       if ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
       then rtrm 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
       else mk_qid (ty, ty', rtrm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
  | (Const (s, ty), Const (s', ty')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
       if s = s' andalso ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
       then rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
       else mk_qid (ty, ty', rtrm) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
  | (_, _) => raise (LIFT_MATCH "insertion")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
section {* Regularization *} 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
(*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
Regularizing an rtrm means:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
 - quantifiers over a type that needs lifting are replaced by
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
   bounded quantifiers, for example:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
      \<forall>x. P     \<Longrightarrow>     \<forall>x \<in> (Respects R). P  /  All (Respects R) P
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
   the relation R is given by the rty and qty;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
 - abstractions over a type that needs lifting are replaced
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
   by bounded abstractions:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
      \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
 - equalities over the type being lifted are replaced by
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
   corresponding relations:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
      A = B     \<Longrightarrow>     A \<approx> B
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
   example with more complicated types of A, B:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
      A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
(* builds the relation that is the argument of respects *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
fun mk_resp_arg lthy (rty, qty) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
  val thy = ProofContext.theory_of lthy
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
in  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
  if rty = qty
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
  then HOLogic.eq_const rty
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
  else
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
    case (rty, qty) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
      (Type (s, tys), Type (s', tys')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
       if s = s' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
       then let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
              val SOME map_info = maps_lookup thy s
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
              val args = map (mk_resp_arg lthy) (tys ~~ tys')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
            in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
              list_comb (Const (#relfun map_info, dummyT), args) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
            end  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
       else let  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
              val SOME qinfo = quotdata_lookup_thy thy s'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
              (* FIXME: check in this case that the rty and qty *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
              (* FIXME: correspond to each other *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
              val (s, _) = dest_Const (#rel qinfo)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
              (* FIXME: the relation should only be the string        *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
              (* FIXME: and the type needs to be calculated as below; *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
              (* FIXME: maybe one should actually have a term         *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
              (* FIXME: and one needs to force it to have this type   *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
            in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
              Const (s, rty --> rty --> @{typ bool})
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
            end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
      | _ => HOLogic.eq_const dummyT 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
             (* FIXME: check that the types correspond to each other? *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
val mk_babs = Const (@{const_name "Babs"}, dummyT)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
val mk_ball = Const (@{const_name "Ball"}, dummyT)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
val mk_bex  = Const (@{const_name "Bex"}, dummyT)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
val mk_resp = Const (@{const_name Respects}, dummyT)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
(* - applies f to the subterm of an abstraction,   *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
(*   otherwise to the given term,                  *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
(* - used by regularize, therefore abstracted      *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
(*   variables do not have to be treated specially *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
fun apply_subt f trm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  case trm of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
    (Abs (x, T, t)) => Abs (x, T, f t)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
  | _ => f trm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
(* the major type of All and Ex quantifiers *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
fun qnt_typ ty = domain_type (domain_type ty)  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
(* produces a regularized version of trm      *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
(* - the result is still not completely typed *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
(* - does not need any special treatment of   *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
(*   bound variables                          *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
fun regularize_trm lthy trm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
  case trm of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
    (Const (@{const_name "qid"},_) $ rty' $ qty' $ Abs (x, ty, t)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
       let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
         val rty = get_typ rty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
         val qty = get_typ qty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
         val subtrm = regularize_trm lthy t
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
       in     
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
         mk_qid (rty, qty, mk_babs $ (mk_resp $ mk_resp_arg lthy (rty, qty)) $ subtrm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
       end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
  | (Const (@{const_name "qid"},_) $ rty' $ qty' $ (Const (@{const_name "All"}, ty) $ t)) => 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
       let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
         val subtrm = apply_subt (regularize_trm lthy) t
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
       in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
         if ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
         then Const (@{const_name "All"}, ty) $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
         else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
       end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
       let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
         val subtrm = apply_subt (regularize_trm lthy) t t'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
       in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
         if ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
         then Const (@{const_name "Ex"}, ty) $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
         else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
       end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
    (* FIXME: Should = only be replaced, when fully applied? *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
    (* Then there must be a 2nd argument                     *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
  | (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
       let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
         val subtrm = regularize_trm lthy t t'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
       in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
         if ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
         then Const (@{const_name "op ="}, ty) $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
         else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
       end 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
  | (t1 $ t2, t1' $ t2') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
       (regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
  | (Free (x, ty), Free (x', ty')) => 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
       (* this case cannot arrise as we start with two fully atomized terms *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
       raise (LIFT_MATCH "regularize (frees)")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  | (Bound i, Bound i') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
       if i = i' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
       then rtrm 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
       else raise (LIFT_MATCH "regularize (bounds)")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
  | (Const (s, ty), Const (s', ty')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
       if s = s' andalso ty = ty'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
       then rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
       else rtrm (* FIXME: check correspondence according to definitions *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
  | (rt, qt) => 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
       raise (LIFT_MATCH "regularize (default)")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
(*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
FIXME / TODO: needs to be adapted
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
To prove that the raw theorem implies the regularised one, 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
we try in order:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
 - Reflexivity of the relation
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
 - Assumption
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
 - Elimnating quantifiers on both sides of toplevel implication
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
 - Simplifying implications on both sides of toplevel implication
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
 - Ball (Respects ?E) ?P = All ?P
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
 - (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
(* FIXME: they should be in in the new Isabelle *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
lemma [mono]: 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
  "(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (Ex P) \<longrightarrow> (Ex Q)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
by blast
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
by auto
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
(* FIXME: OPTION_EQUIV, PAIR_EQUIV, ... *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
fun equiv_tac rel_eqvs =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
  REPEAT_ALL_NEW (FIRST' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
    [resolve_tac rel_eqvs,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
     rtac @{thm IDENTITY_EQUIV},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
     rtac @{thm LIST_EQUIV}])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
fun ball_reg_eqv_simproc rel_eqvs ss redex =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
    val ctxt = Simplifier.the_context ss
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
  case redex of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
      (ogl as ((Const (@{const_name "Ball"}, _)) $
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
        ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
      (let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
        val gl = Const (@{const_name "EQUIV"}, dummyT) $ R;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
        val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
        val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
        val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv} OF [eqv]]);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
(*        val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   590
        SOME thm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
      handle _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
      )
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
  | _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
fun bex_reg_eqv_simproc rel_eqvs ss redex =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
    val ctxt = Simplifier.the_context ss
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
  case redex of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
      (ogl as ((Const (@{const_name "Bex"}, _)) $
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
        ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
      (let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
        val gl = Const (@{const_name "EQUIV"}, dummyT) $ R;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
        val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
        val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
        val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv} OF [eqv]]);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
(*        val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
        SOME thm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
      handle _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
      )
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
  | _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
fun prep_trm thy (x, (T, t)) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
  (cterm_of thy (Var (x, T)), cterm_of thy t)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
fun prep_ty thy (x, (S, ty)) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
  (ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
fun matching_prs thy pat trm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
  val univ = Unify.matchers thy [(pat, trm)]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  val SOME (env, _) = Seq.pull univ
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
  val tenv = Vartab.dest (Envir.term_env env)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
  val tyenv = Vartab.dest (Envir.type_env env)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  (map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
fun ball_reg_eqv_range_simproc rel_eqvs ss redex =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
    val ctxt = Simplifier.the_context ss
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
  case redex of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
      (ogl as ((Const (@{const_name "Ball"}, _)) $
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
        ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
      (let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
        val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
        val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
        val _ = tracing (Syntax.string_of_term ctxt glc);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
        val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
        val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv_range} OF [eqv]]);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
        val R1c = cterm_of thy R1;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
        val thmi = Drule.instantiate' [] [SOME R1c] thm;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
(*        val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi)); *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
        val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
        val _ = tracing "AAA";
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
        val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
        val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2));
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
        SOME thm2
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
      handle _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
      )
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
  | _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
fun bex_reg_eqv_range_simproc rel_eqvs ss redex =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
    val ctxt = Simplifier.the_context ss
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
  case redex of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
      (ogl as ((Const (@{const_name "Bex"}, _)) $
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
        ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
      (let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
        val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   685
        val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   686
        val _ = tracing (Syntax.string_of_term ctxt glc);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
        val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   688
        val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv_range} OF [eqv]]);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
        val R1c = cterm_of thy R1;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   690
        val thmi = Drule.instantiate' [] [SOME R1c] thm;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   691
(*        val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi)); *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
        val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
        val _ = tracing "AAA";
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
        val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
        val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2));
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   696
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   697
        SOME thm2
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   698
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
      handle _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   700
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
      )
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   702
  | _ => NONE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   703
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
lemma eq_imp_rel: "EQUIV R \<Longrightarrow> a = b \<longrightarrow> R a b"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
by (simp add: EQUIV_REFL)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
fun regularize_tac ctxt rel_eqvs =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
    val pat1 = [@{term "Ball (Respects R) P"}];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
    val pat2 = [@{term "Bex (Respects R) P"}];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
    val pat3 = [@{term "Ball (Respects (R1 ===> R2)) P"}];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
    val pat4 = [@{term "Bex (Respects (R1 ===> R2)) P"}];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
    val simproc1 = Simplifier.simproc_i thy "" pat1 (K (ball_reg_eqv_simproc rel_eqvs))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
    val simproc2 = Simplifier.simproc_i thy "" pat2 (K (bex_reg_eqv_simproc rel_eqvs))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
    val simproc3 = Simplifier.simproc_i thy "" pat3 (K (ball_reg_eqv_range_simproc rel_eqvs))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
    val simproc4 = Simplifier.simproc_i thy "" pat4 (K (bex_reg_eqv_range_simproc rel_eqvs))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
    val simp_ctxt = (Simplifier.context ctxt empty_ss) addsimprocs [simproc1, simproc2, simproc3, simproc4]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
    (* TODO: Make sure that there are no LIST_REL, PAIR_REL etc involved *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
    val eq_eqvs = map (fn x => @{thm eq_imp_rel} OF [x]) rel_eqvs
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
  ObjectLogic.full_atomize_tac THEN'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
  simp_tac simp_ctxt THEN'
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
  REPEAT_ALL_NEW (FIRST' [
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
    rtac @{thm ball_reg_right},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   729
    rtac @{thm bex_reg_left},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   730
    resolve_tac (Inductive.get_monos ctxt),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
    rtac @{thm ball_all_comm},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
    rtac @{thm bex_ex_comm},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
    resolve_tac eq_eqvs,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
    simp_tac simp_ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
  ])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
section {* Injections of REP and ABSes *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
(*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
Injecting REPABS means:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
  For abstractions:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
  * If the type of the abstraction doesn't need lifting we recurse.
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
  * If it does we add RepAbs around the whole term and check if the
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
    variable needs lifting.
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
    * If it doesn't then we recurse
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
    * If it does we recurse and put 'RepAbs' around all occurences
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
      of the variable in the obtained subterm. This in combination
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   751
      with the RepAbs above will let us change the type of the
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   752
      abstraction with rewriting.
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   753
  For applications:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
  * If the term is 'Respects' applied to anything we leave it unchanged
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
  * If the term needs lifting and the head is a constant that we know
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
    how to lift, we put a RepAbs and recurse
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757
  * If the term needs lifting and the head is a free applied to subterms
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
    (if it is not applied we treated it in Abs branch) then we
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
    put RepAbs and recurse
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   760
  * Otherwise just recurse.
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   761
*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   762
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   763
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   764
fun mk_repabs lthy (T, T') trm = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   765
  Quotient_Def.get_fun repF lthy (T, T') 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   766
    $ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   767
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   768
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   769
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   770
(* bound variables need to be treated properly,  *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   771
(* as the type of subterms need to be calculated *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   772
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   773
fun inj_repabs_trm lthy (rtrm, qtrm) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   774
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   775
  val rty = fastype_of rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   776
  val qty = fastype_of qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   777
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   778
  case (rtrm, qtrm) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   779
    (Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   780
       Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   781
  | (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   782
       Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   783
  | (Const (@{const_name "Babs"}, T) $ r $ t, t') =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   784
       Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   785
  | (Abs (x, T, t), Abs (x', T', t')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   786
      let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   787
        val (y, s) = Term.dest_abs (x, T, t)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   788
        val (_, s') = Term.dest_abs (x', T', t')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   789
        val yvar = Free (y, T)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   790
        val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   791
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   792
        if rty = qty 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   793
        then result
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   794
        else mk_repabs lthy (rty, qty) result
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   795
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
  | _ =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
      (* FIXME / TODO: this is a case that needs to be looked at          *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
      (* - variables get a rep-abs insde and outside an application       *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   799
      (* - constants only get a rep-abs on the outside of the application *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
      (* - applications get a rep-abs insde and outside an application    *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
      let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
        val (rhead, rargs) = strip_comb rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803
        val (qhead, qargs) = strip_comb qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   804
        val rargs' = map (inj_repabs_trm lthy) (rargs ~~ qargs)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   805
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
        if rty = qty
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   807
        then
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
          case (rhead, qhead) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   809
            (Free (_, T), Free (_, T')) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   810
              if T = T' then list_comb (rhead, rargs')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   811
              else list_comb (mk_repabs lthy (T, T') rhead, rargs')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   812
          | _ => list_comb (rhead, rargs')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   813
        else
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
          case (rhead, qhead, length rargs') of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
            (Const _, Const _, 0) => mk_repabs lthy (rty, qty) rhead
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   816
          | (Free (_, T), Free (_, T'), 0) => mk_repabs lthy (T, T') rhead
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   817
          | (Const _, Const _, _) =>  mk_repabs lthy (rty, qty) (list_comb (rhead, rargs')) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   818
          | (Free (x, T), Free (x', T'), _) => 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   819
               mk_repabs lthy (rty, qty) (list_comb (mk_repabs lthy (T, T') rhead, rargs'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
          | (Abs _, Abs _, _ ) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   821
               mk_repabs lthy (rty, qty) (list_comb (inj_repabs_trm lthy (rhead, qhead), rargs')) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   822
          | _ => raise (LIFT_MATCH "injection")
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   823
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   824
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   825
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   826
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   827
section {* RepAbs Injection Tactic *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   829
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   830
fun stripped_term_of ct =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   831
  ct |> term_of |> HOLogic.dest_Trueprop
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   832
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   833
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   834
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
fun instantiate_tac thm = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   836
  Subgoal.FOCUS (fn {concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   837
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   838
    val pat = Drule.strip_imp_concl (cprop_of thm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   839
    val insts = Thm.match (pat, concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   840
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   841
    rtac (Drule.instantiate insts thm) 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   842
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   843
  handle _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   844
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   845
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   847
fun quotient_tac quot_thms =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
  REPEAT_ALL_NEW (FIRST' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
    [rtac @{thm FUN_QUOTIENT},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
     resolve_tac quot_thms,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   851
     rtac @{thm IDENTITY_QUOTIENT},
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   852
     (* For functional identity quotients, (op = ---> op =) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   853
     (* TODO: think about the other way around, if we need to shorten the relation *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   854
     CHANGED o (simp_tac (HOL_ss addsimps @{thms id_simps}))])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   855
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   856
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   857
lemma FUN_REL_I:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   858
  assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   859
  shows "(R1 ===> R2) f g"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   860
using a by (simp add: FUN_REL.simps)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   861
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   862
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   863
val lambda_res_tac =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   864
  Subgoal.FOCUS (fn {concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   865
    case (stripped_term_of concl) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   866
       (_ $ (Abs _) $ (Abs _)) => rtac @{thm FUN_REL_I} 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   867
     | _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   868
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   869
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   870
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   871
val weak_lambda_res_tac =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   872
  Subgoal.FOCUS (fn {concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   873
    case (stripped_term_of concl) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   874
       (_ $ _ $ (Abs _)) => rtac @{thm FUN_REL_I} 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   875
     | (_ $ (Abs _) $ _) => rtac @{thm FUN_REL_I} 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   876
     | _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   877
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   878
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   879
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   880
val ball_rsp_tac = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   881
  Subgoal.FOCUS (fn {concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   882
     case (stripped_term_of concl) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   883
        (_ $ (Const (@{const_name Ball}, _) $ _) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   884
           $ (Const (@{const_name Ball}, _) $ _)) => rtac @{thm FUN_REL_I} 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   885
      |_ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   886
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   887
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   888
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   889
val bex_rsp_tac = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   890
  Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   891
     case (stripped_term_of concl) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   892
        (_ $ (Const (@{const_name Bex}, _) $ _) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   893
           $ (Const (@{const_name Bex}, _) $ _)) => rtac @{thm FUN_REL_I} 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   894
      | _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   895
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   896
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   897
ML {* (* Legacy *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   898
fun needs_lift (rty as Type (rty_s, _)) ty =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   899
  case ty of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   900
    Type (s, tys) => (s = rty_s) orelse (exists (needs_lift rty) tys)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   901
  | _ => false
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   902
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   903
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   904
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   905
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   906
fun APPLY_RSP_TAC rty = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   907
  Subgoal.FOCUS (fn {concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   908
    case (stripped_term_of concl) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   909
       (_ $ (f $ _) $ (_ $ _)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   910
          let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   911
            val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP});
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   912
            val insts = Thm.match (pat, concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   913
          in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   914
            if needs_lift rty (fastype_of f) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   915
            then rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   916
            else no_tac
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   917
          end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   918
     | _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   919
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   920
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   921
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   922
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   923
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   924
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   925
(*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   926
To prove that the regularised theorem implies the abs/rep injected, 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   927
we try:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   928
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   929
 1) theorems 'trans2' from the appropriate QUOT_TYPE
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   930
 2) remove lambdas from both sides: lambda_res_tac
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   931
 3) remove Ball/Bex from the right hand side
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   932
 4) use user-supplied RSP theorems
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   933
 5) remove rep_abs from the right side
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   934
 6) reflexivity of equality
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   935
 7) split applications of lifted type (apply_rsp)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   936
 8) split applications of non-lifted type (cong_tac)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   937
 9) apply extentionality
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   938
 A) reflexivity of the relation
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   939
 B) assumption
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   940
    (Lambdas under respects may have left us some assumptions)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   941
 C) proving obvious higher order equalities by simplifying fun_rel
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   942
    (not sure if it is still needed?)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   943
 D) unfolding lambda on one side
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   944
 E) simplifying (= ===> =) for simpler respectfulness
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   945
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   946
*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   947
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   948
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   949
fun inj_repabs_tac ctxt rty quot_thms rel_refl trans2 =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   950
  (FIRST' [
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   951
    (* "cong" rule of the of the relation / transitivity*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   952
    (* (op =) (R a b) (R c d) ----> \<lbrakk>R a c; R b d\<rbrakk> *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   953
    NDT ctxt "1" (resolve_tac trans2),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   954
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   955
    (* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   956
    NDT ctxt "2" (lambda_res_tac ctxt),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   957
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   958
    (* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   959
    NDT ctxt "3" (rtac @{thm RES_FORALL_RSP}),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   960
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   961
    (* (R1 ===> R2) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (Ball\<dots>x) (Ball\<dots>y) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   962
    NDT ctxt "4" (ball_rsp_tac ctxt),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   963
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   964
    (* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   965
    NDT ctxt "5" (rtac @{thm RES_EXISTS_RSP}),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   966
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   967
    (* (R1 ===> R2) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (Bex\<dots>x) (Bex\<dots>y) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   968
    NDT ctxt "6" (bex_rsp_tac ctxt),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   969
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   970
    (* respectfulness of constants *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   971
    NDT ctxt "7" (resolve_tac (rsp_rules_get ctxt)),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   972
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   973
    (* reflexivity of operators arising from Cong_tac *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   974
    NDT ctxt "8" (rtac @{thm refl}),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   975
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   976
    (* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   977
    (* observe ---> *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   978
    NDT ctxt "9" ((instantiate_tac @{thm REP_ABS_RSP(1)} ctxt 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   979
                  THEN' (RANGE [SOLVES' (quotient_tac quot_thms)]))),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   980
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   981
    (* R (t $ \<dots>) (t' $ \<dots>) ----> APPLY_RSP   provided type of t needs lifting *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   982
    NDT ctxt "A" ((APPLY_RSP_TAC rty ctxt THEN' 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   983
                (RANGE [SOLVES' (quotient_tac quot_thms), SOLVES' (quotient_tac quot_thms)]))),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   984
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   985
    (* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong   provided type of t does not need lifting *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   986
    (* merge with previous tactic *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   987
    NDT ctxt "B" (Cong_Tac.cong_tac @{thm cong}),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   988
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   989
    (* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   990
    NDT ctxt "C" (rtac @{thm ext}),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   991
    
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   992
    (* reflexivity of the basic relations *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   993
    (* R \<dots> \<dots> *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   994
    NDT ctxt "D" (resolve_tac rel_refl),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   995
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   996
    (* resolving with R x y assumptions *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   997
    NDT ctxt "E" (atac),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   998
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   999
    (* seems not necessay:: NDT ctxt "F" (SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))),*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1000
    
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1001
    (* (R1 ===> R2) (\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1002
    (* (R1 ===> R2) (\<lambda>x\<dots>) (\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1003
    (*NDT ctxt "G" (weak_lambda_res_tac ctxt),*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1004
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1005
    (* (op =) ===> (op =)  \<Longrightarrow> (op =), needed in order to apply respectfulness theorems *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1006
    (* global simplification *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1007
    NDT ctxt "H" (CHANGED o (asm_full_simp_tac ((Simplifier.context ctxt empty_ss) addsimps @{thms eq_reflection[OF FUN_REL_EQ]})))])
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1008
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1009
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1010
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1011
fun all_inj_repabs_tac ctxt rty quot_thms rel_refl trans2 =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1012
  REPEAT_ALL_NEW (inj_repabs_tac ctxt rty quot_thms rel_refl trans2)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1013
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1014
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1015
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1016
section {* Cleaning of the theorem *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1017
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1018
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1019
fun applic_prs lthy absrep (rty, qty) =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1020
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1021
    fun mk_rep (T, T') tm = (Quotient_Def.get_fun repF lthy (T, T')) $ tm;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1022
    fun mk_abs (T, T') tm = (Quotient_Def.get_fun absF lthy (T, T')) $ tm;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1023
    val (raty, rgty) = Term.strip_type rty;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1024
    val (qaty, qgty) = Term.strip_type qty;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1025
    val vs = map (fn _ => "x") qaty;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1026
    val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1027
    val f = Free (fname, qaty ---> qgty);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1028
    val args = map Free (vfs ~~ qaty);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1029
    val rhs = list_comb(f, args);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1030
    val largs = map2 mk_rep (raty ~~ qaty) args;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1031
    val lhs = mk_abs (rgty, qgty) (list_comb((mk_rep (raty ---> rgty, qaty ---> qgty) f), largs));
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1032
    val llhs = Syntax.check_term lthy lhs;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1033
    val eq = Logic.mk_equals (llhs, rhs);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1034
    val ceq = cterm_of (ProofContext.theory_of lthy') eq;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1035
    val sctxt = HOL_ss addsimps (@{thms fun_map.simps id_simps} @ absrep);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1036
    val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1037
    val t_id = MetaSimplifier.rewrite_rule @{thms id_simps} t;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1038
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1039
    singleton (ProofContext.export lthy' lthy) t_id
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1040
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1041
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1042
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1043
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1044
fun find_aps_all rtm qtm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1045
  case (rtm, qtm) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1046
    (Abs(_, T1, s1), Abs(_, T2, s2)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1047
      find_aps_all (subst_bound ((Free ("x", T1)), s1)) (subst_bound ((Free ("x", T2)), s2))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1048
  | (((f1 as (Free (_, T1))) $ a1), ((f2 as (Free (_, T2))) $ a2)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1049
      let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1050
        val sub = (find_aps_all f1 f2) @ (find_aps_all a1 a2)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1051
      in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1052
        if T1 = T2 then sub else (T1, T2) :: sub
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1053
      end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1054
  | ((f1 $ a1), (f2 $ a2)) => (find_aps_all f1 f2) @ (find_aps_all a1 a2)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1055
  | _ => [];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1056
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1057
fun find_aps rtm qtm = distinct (op =) (find_aps_all rtm qtm)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1058
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1059
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1060
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1061
fun allex_prs_tac lthy quot =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1062
  (EqSubst.eqsubst_tac lthy [0] @{thms FORALL_PRS[symmetric] EXISTS_PRS[symmetric]})
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1063
  THEN' (quotient_tac quot)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1064
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1065
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1066
(* Rewrites the term with LAMBDA_PRS thm.
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1067
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1068
Replaces: (Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x)))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1069
    with: f
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1070
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1071
It proves the QUOTIENT assumptions by calling quotient_tac
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1072
 *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1073
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1074
fun make_inst lhs t =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1075
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1076
    val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1077
    val _ $ (Abs (_, _, g)) = t;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1078
    fun mk_abs i t =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1079
      if incr_boundvars i u aconv t then Bound i
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1080
      else (case t of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1081
        t1 $ t2 => mk_abs i t1 $ mk_abs i t2
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1082
      | Abs (s, T, t') => Abs (s, T, mk_abs (i+1) t')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1083
      | Bound j => if i = j then error "make_inst" else t
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1084
      | _ => t);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1085
  in (f, Abs ("x", T, mk_abs 0 g)) end;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1086
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1087
fun lambda_prs_conv1 ctxt quot_thms ctrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1088
  case (term_of ctrm) of ((Const (@{const_name "fun_map"}, _) $ r1 $ a2) $ (Abs _)) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1089
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1090
    val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1091
    val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1092
    val thy = ProofContext.theory_of ctxt;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1093
    val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1094
    val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d];
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1095
    val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1096
    val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS};
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1097
    val tac =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1098
      (compose_tac (false, lpi, 2)) THEN_ALL_NEW
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1099
      (quotient_tac quot_thms);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1100
    val gc = Drule.strip_imp_concl (cprop_of lpi);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1101
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1102
    val te = @{thm eq_reflection} OF [t]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1103
    val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1104
    val tl = Thm.lhs_of ts;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1105
    val (insp, inst) = make_inst (term_of tl) (term_of ctrm);
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1106
    val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts;
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1107
(*    val _ = writeln (Syntax.string_of_term @{context} (term_of (cprop_of ti)));*)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1108
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1109
    Conv.rewr_conv ti ctrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1110
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1111
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1112
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1113
(* quot stands for the QUOTIENT theorems: *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1114
(* could be potentially all of them       *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1115
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1116
fun lambda_prs_conv ctxt quot ctrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1117
  case (term_of ctrm) of
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1118
    (Const (@{const_name "fun_map"}, _) $ _ $ _) $ (Abs _) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1119
      (Conv.arg_conv (Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1120
      then_conv (lambda_prs_conv1 ctxt quot)) ctrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1121
  | _ $ _ => Conv.comb_conv (lambda_prs_conv ctxt quot) ctrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1122
  | Abs _ => Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt ctrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1123
  | _ => Conv.all_conv ctrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1124
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1125
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1126
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1127
fun lambda_prs_tac ctxt quot = CSUBGOAL (fn (goal, i) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1128
  CONVERSION
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1129
    (Conv.params_conv ~1 (fn ctxt =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1130
       (Conv.prems_conv ~1 (lambda_prs_conv ctxt quot) then_conv
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1131
          Conv.concl_conv ~1 (lambda_prs_conv ctxt quot))) ctxt) i)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1132
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1133
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1134
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1135
fun clean_tac lthy quot defs aps =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1136
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1137
    val lower = flat (map (add_lower_defs lthy) defs)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1138
    val meta_lower = map (fn x => @{thm eq_reflection} OF [x]) lower
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1139
    val absrep = map (fn x => @{thm QUOTIENT_ABS_REP} OF [x]) quot
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1140
    val reps_same = map (fn x => @{thm QUOTIENT_REL_REP} OF [x]) quot
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1141
    val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1142
    val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps (meta_reps_same @ meta_lower)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1143
    val aps_thms = map (applic_prs lthy absrep) aps
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1144
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1145
    EVERY' [lambda_prs_tac lthy quot,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1146
            TRY o simp_tac simp_ctxt,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1147
            TRY o REPEAT_ALL_NEW (allex_prs_tac lthy quot),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1148
            TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] aps_thms),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1149
            TRY o rtac refl]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1150
  end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1151
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1152
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1153
section {* Genralisation of free variables in a goal *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1154
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1155
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1156
fun inst_spec ctrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1157
   Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1158
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1159
fun inst_spec_tac ctrms =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1160
  EVERY' (map (dtac o inst_spec) ctrms)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1161
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1162
fun all_list xs trm = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1163
  fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1164
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1165
fun apply_under_Trueprop f = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1166
  HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1167
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1168
fun gen_frees_tac ctxt =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1169
 SUBGOAL (fn (concl, i) =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1170
  let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1171
    val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1172
    val vrs = Term.add_frees concl []
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1173
    val cvrs = map (cterm_of thy o Free) vrs
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1174
    val concl' = apply_under_Trueprop (all_list vrs) concl
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1175
    val goal = Logic.mk_implies (concl', concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1176
    val rule = Goal.prove ctxt [] [] goal 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1177
      (K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1178
  in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1179
    rtac rule i
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1180
  end)  
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1181
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1182
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1183
section {* General outline of the lifting procedure *}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1184
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1185
(* - A is the original raw theorem          *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1186
(* - B is the regularized theorem           *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1187
(* - C is the rep/abs injected version of B *) 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1188
(* - D is the lifted theorem                *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1189
(*                                          *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1190
(* - b is the regularization step           *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1191
(* - c is the rep/abs injection step        *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1192
(* - d is the cleaning part                 *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1193
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1194
lemma lifting_procedure:
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1195
  assumes a: "A"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1196
  and     b: "A \<Longrightarrow> B"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1197
  and     c: "B = C"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1198
  and     d: "C = D"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1199
  shows   "D"
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1200
  using a b c d
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1201
  by simp
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1202
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1203
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1204
fun lift_match_error ctxt fun_str rtrm qtrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1205
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1206
  val rtrm_str = Syntax.string_of_term ctxt rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1207
  val qtrm_str = Syntax.string_of_term ctxt qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1208
  val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str, 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1209
             "and the lifted theorem\n", rtrm_str, "do not match"]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1210
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1211
  error (space_implode " " msg)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1212
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1213
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1214
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1215
ML {* 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1216
fun procedure_inst ctxt rtrm qtrm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1217
let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1218
  val thy = ProofContext.theory_of ctxt
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1219
  val rtrm' = HOLogic.dest_Trueprop rtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1220
  val qtrm' = HOLogic.dest_Trueprop qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1221
  val reg_goal = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1222
        Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm')
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1223
        handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1224
  val inj_goal = 
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1225
        Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm'))
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1226
        handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1227
in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1228
  Drule.instantiate' []
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1229
    [SOME (cterm_of thy rtrm'),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1230
     SOME (cterm_of thy reg_goal),
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1231
     SOME (cterm_of thy inj_goal)] @{thm lifting_procedure}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1232
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1233
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1234
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1235
(* Left for debugging *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1236
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1237
fun procedure_tac lthy rthm =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1238
  ObjectLogic.full_atomize_tac
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1239
  THEN' gen_frees_tac lthy
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1240
  THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1241
    let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1242
      val rthm' = atomize_thm rthm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1243
      val rule = procedure_inst context (prop_of rthm') (term_of concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1244
    in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1245
      EVERY1 [rtac rule, rtac rthm']
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1246
    end) lthy
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1247
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1248
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1249
ML {*
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1250
(* FIXME/TODO should only get as arguments the rthm like procedure_tac *)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1251
fun lift_tac lthy rthm rel_eqv rty quot defs =
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1252
  ObjectLogic.full_atomize_tac
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1253
  THEN' gen_frees_tac lthy
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1254
  THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1255
    let
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1256
      val rthm' = atomize_thm rthm
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1257
      val rule = procedure_inst context (prop_of rthm') (term_of concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1258
      val aps = find_aps (prop_of rthm') (term_of concl)
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1259
      val rel_refl = map (fn x => @{thm EQUIV_REFL} OF [x]) rel_eqv
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1260
      val trans2 = map (fn x => @{thm equiv_trans2} OF [x]) rel_eqv
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1261
    in
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1262
      EVERY1
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1263
       [rtac rule,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1264
        RANGE [rtac rthm',
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1265
               regularize_tac lthy rel_eqv,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1266
               all_inj_repabs_tac lthy rty quot rel_refl trans2,
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1267
               clean_tac lthy quot defs aps]]
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1268
    end) lthy
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1269
*}
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1270
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1271
end
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1272
cc0b9cb367cd added a new version of QuotMain to experiment with qids
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1273