QuotMain.thy
author cek@localhost.localdomain
Thu, 20 Aug 2009 14:44:29 +0200
changeset 3 672e14609e6e
parent 2 e0b4bca46c6a
child 4 0eb89a350f43
permissions -rw-r--r--
UNION - Append theorem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotMain
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports QuotScript QuotList
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
begin 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
lemma lem9: 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  then have "R x (Eps (R x))" by (rule someI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  then show "R (Eps (R x)) = R x" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
theorem thm10:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  shows "ABS (REP a) = a"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
unfolding ABS_def REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  from rep_prop 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
lemma REP_refl: 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
lemma lem7:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  "(R x = R y) = (Abs (R x) = Abs (R y))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    63
lemma REP_ABS_rsp:
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    64
  shows "R f g \<Longrightarrow> R f (REP (ABS g))"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    65
apply(subst thm11)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    66
apply(simp add: thm10 thm11)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    67
done
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    68
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    83
Variable.variant_frees
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    84
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    85
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    86
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    87
ML {*
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
    88
(* constructs the term \<lambda>(c::ty \<Rightarrow> bool). \<exists>x. c = rel x *)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
fun typedef_term rel ty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
let 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  val [x, c] = [("x", ty), ("c", ty --> @{typ bool})] 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
               |> Variable.variant_frees lthy [rel]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
               |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
in
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
    95
  lambda c 
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
    96
    (HOLogic.mk_exists 
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
    97
       ("x", ty, HOLogic.mk_eq (c, (rel $ x))))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   102
 typedef_term @{term R} @{typ "nat"} @{context} 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   103
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   104
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   105
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   106
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   107
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
val typedef_tac =  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  EVERY1 [rewrite_goal_tac @{thms mem_def},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
          rtac @{thm exI}, rtac @{thm exI}, rtac @{thm refl}]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
(* makes the new type definitions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
fun typedef_make (qty_name, rel, ty) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  LocalTheory.theory_result
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   117
  (Typedef.add_typedef false NONE 
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
     (qty_name, map fst (Term.add_tfreesT ty []), NoSyn)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
       (typedef_term rel ty lthy)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
         NONE typedef_tac) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   123
text {* proves the QUOT_TYPE theorem for the new type *}
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
ML {*
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   125
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = 
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  val rep_thm = #Rep typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  val rep_inv = #Rep_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  val abs_inv = #Abs_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  val rep_inj = #Rep_inject typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  val ss = HOL_basic_ss addsimps @{thms mem_def}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  val rep_thm_simpd = Simplifier.asm_full_simplify ss rep_thm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  val abs_inv_simpd = Simplifier.asm_full_simplify ss abs_inv
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  EVERY1 [rtac @{thm QUOT_TYPE.intro},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
          rtac equiv_thm, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
          rtac rep_thm_simpd, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
          rtac rep_inv, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
          rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
          rtac rep_inj]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   145
term QUOT_TYPE
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   146
ML {* HOLogic.mk_Trueprop *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   147
ML {* Goal.prove *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   148
ML {* Syntax.check_term *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   149
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
             |> Syntax.check_term lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  Goal.prove lthy [] [] goal
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
    (fn _ => typedef_quot_type_tac equiv_thm typedef_info)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
fun typedef_quotient_thm_tac defs quot_type_thm =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  EVERY1 [K (rewrite_goals_tac defs), 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
          rtac @{thm QUOT_TYPE.QUOTIENT}, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
          rtac quot_type_thm]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
  val quotient_const = Const (@{const_name "QUOTIENT"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
             |> Syntax.check_term lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  Goal.prove lthy [] [] goal
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
    (fn _ => typedef_quotient_thm_tac [abs_def, rep_def] quot_type_thm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
text {* two wrappers for define and note *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
fun make_def (name, mx, trm) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
let   
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  val ((trm, (_ , thm)), lthy') = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
     LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, trm)) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  ((trm, thm), lthy')
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
fun reg_thm (name, thm) lthy = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
  val ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  (thm',lthy')
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
fun typedef_main (qty_name, rel, ty, equiv_thm) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
let 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  (* generates typedef *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  val ((_,typedef_info), lthy') = typedef_make (qty_name, rel, ty) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  (* abs and rep functions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  val abs_ty = #abs_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  val rep_ty = #rep_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  val abs_name = #Abs_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  val rep_name = #Rep_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  val abs = Const (abs_name, rep_ty --> abs_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  val rep = Const (rep_name, abs_ty --> rep_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  (* ABS and REP definitions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  val ABS_const = Const (@{const_name "QUOT_TYPE.ABS"}, dummyT )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  val REP_const = Const (@{const_name "QUOT_TYPE.REP"}, dummyT )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  val ABS_trm = Syntax.check_term lthy' (ABS_const $ rel $ abs) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  val REP_trm = Syntax.check_term lthy' (REP_const $ rep) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  val ABS_name = Binding.prefix_name "ABS_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
  val REP_name = Binding.prefix_name "REP_" qty_name  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  val (((ABS, ABS_def), (REP, REP_def)), lthy'') = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
         lthy' |> make_def (ABS_name, NoSyn, ABS_trm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
               ||>> make_def (REP_name, NoSyn, REP_trm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  (* quot_type theorem *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  val quot_thm = typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy''
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  val quot_thm_name = Binding.prefix_name "QUOT_TYPE_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  (* quotient theorem *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  val quotient_thm = typedef_quotient_thm (rel, ABS, REP, ABS_def, REP_def, quot_thm) lthy''
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  val quotient_thm_name = Binding.prefix_name "QUOTIENT_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
  lthy'' 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  |> reg_thm (quot_thm_name, quot_thm)  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  ||>> reg_thm (quotient_thm_name, quotient_thm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
section {* various tests for quotient types*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
datatype trm =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  var  "nat" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
| app  "trm" "trm"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
| lam  "nat" "trm"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
consts R :: "trm \<Rightarrow> trm \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
axioms r_eq: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   250
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   251
  typedef_main 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   252
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   253
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  typedef_main (@{binding "qtrm"}, @{term "R"}, @{typ trm}, @{thm r_eq}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
term Rep_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   259
term REP_qtrm
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
term Abs_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
term ABS_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
thm QUOT_TYPE_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
thm QUOTIENT_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   264
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
thm Rep_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
text {* another test *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
datatype 'a my = foo
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
consts Rmy :: "'a my \<Rightarrow> 'a my \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
axioms rmy_eq: "EQUIV Rmy"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
term "\<lambda>(c::'a my\<Rightarrow>bool). \<exists>x. c = Rmy x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
datatype 'a trm' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
  var'  "'a" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
| app'  "'a trm'" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
| lam'  "'a" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
consts R' :: "'a trm' \<Rightarrow> 'a trm' \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
axioms r_eq': "EQUIV R'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
  typedef_main (@{binding "qtrm'"}, @{term "R'"}, @{typ "'a trm'"}, @{thm r_eq'}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
term ABS_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
term REP_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
thm QUOT_TYPE_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
thm QUOTIENT_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
thm Rep_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
text {* a test with lists of terms *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
datatype t =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
  vr "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
| ap "t list"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
| lm "string" "t"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
consts Rt :: "t \<Rightarrow> t \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
axioms t_eq: "EQUIV Rt"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
  typedef_main (@{binding "qt"}, @{term "Rt"}, @{typ "t"}, @{thm t_eq}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
section {* lifting of constants *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
text {* information about map-functions for type-constructor *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
type typ_info = {mapfun: string}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
local
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
  structure Data = GenericDataFun
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  (type T = typ_info Symtab.table
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
   val empty = Symtab.empty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
   val extend = I
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
   fun merge _ = Symtab.merge (K true))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
 val lookup = Symtab.lookup o Data.get
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
 fun update k v = Data.map (Symtab.update (k, v)) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
(* mapfuns for some standard types *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
    Context.theory_map (update @{type_name "list"} {mapfun = @{const_name "map"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
 #> Context.theory_map (update @{type_name "*"} {mapfun = @{const_name "prod_fun"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
 #> Context.theory_map (update @{type_name "fun"}  {mapfun = @{const_name "fun_map"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   330
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
ML {* lookup (Context.Proof @{context}) @{type_name list} *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
datatype abs_or_rep = abs | rep
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
fun get_fun abs_or_rep rty qty lthy ty = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  val qty_name = Long_Name.base_name (fst (dest_Type qty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
    val (fs, tys) = split_list fs_tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
    val (otys, ntys) = split_list tys 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
  in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
   (case (lookup (Context.Proof lthy) s) of 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
      SOME info => (list_comb (Const (#mapfun info, ftys ---> oty --> nty), fs), (oty, nty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
    | NONE => raise ERROR ("no map association for type " ^ s))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
  fun get_const abs = (Const ("QuotMain.ABS_" ^ qty_name, rty --> qty), (rty, qty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
    | get_const rep = (Const ("QuotMain.REP_" ^ qty_name, qty --> rty), (qty, rty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
  if ty = qty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
  then (get_const abs_or_rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
  else (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
          TFree _ => (Abs ("x", ty, Bound 0), (ty, ty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
        | Type (_, []) => (Abs ("x", ty, Bound 0), (ty, ty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
        | Type (s, tys) => get_fun_aux s (map (get_fun abs_or_rep rty qty lthy) tys)  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
        | _ => raise ERROR ("no variables")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   368
  get_fun rep @{typ t} @{typ qt} @{context} @{typ "t * nat"}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   369
  |> fst
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   370
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   371
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   372
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   373
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   374
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   375
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
  val (arg_tys, res_ty) = strip_type ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
  val fresh_args = arg_tys |> map (pair "x")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
                           |> Variable.variant_frees lthy [nconst, oconst] 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
                           |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
  val rep_fns = map (fst o get_fun rep rty qty lthy) arg_tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
  val abs_fn  = (fst o get_fun abs rty qty lthy) res_ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
  map (op $) (rep_fns ~~ fresh_args)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
  |> curry list_comb oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
  |> curry (op $) abs_fn
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
  |> fold_rev lambda fresh_args
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
fun exchange_ty rty qty ty = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
  if ty = rty then qty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
  else 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
       Type (s, tys) => Type (s, map (exchange_ty rty qty) tys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
      | _ => ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
fun make_const_def nconst_name oconst mx rty qty lthy = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
  val nconst_ty = exchange_ty rty qty oconst_ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
  val nconst = Const (nconst_name, nconst_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
  make_def (Binding.name nconst_name, mx, def_trm) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
end  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   417
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   418
  make_const_def "VR" @{term "vr"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   419
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   420
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   421
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   422
  make_const_def "AP" @{term "ap"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   423
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   424
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   425
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   426
  make_const_def "LM" @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   427
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   428
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   429
thm VR_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   430
thm AP_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   431
thm LM_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   432
term LM 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   433
term VR
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   434
term AP
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   435
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   436
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
text {* a test with functions *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
datatype 'a t' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
  vr' "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
| ap' "('a t') * ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
| lm' "'a" "string \<Rightarrow> ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
consts Rt' :: "('a t') \<Rightarrow> ('a t') \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
axioms t_eq': "EQUIV Rt'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  typedef_main (@{binding "qt'"}, @{term "Rt'"}, @{typ "'a t'"}, @{thm t_eq'}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   450
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
  make_const_def "VR'" @{term "vr'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
  make_const_def "AP'" @{term "ap'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
  make_const_def "LM'" @{term "lm'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
thm VR'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
thm AP'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
thm LM'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
term LM' 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
term VR'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
term AP'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
text {* finite set example *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
inductive 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
  list_eq ("_ \<approx> _")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  "a#b#xs \<approx> b#a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
| "[] \<approx> []"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
| "a#a#xs \<approx> a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
lemma list_eq_sym:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  shows "xs \<approx> xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
apply(induct xs)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
apply(auto intro: list_eq.intros)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
lemma equiv_list_eq:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
  shows "EQUIV list_eq"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
apply(auto intro: list_eq.intros list_eq_sym)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  typedef_main (@{binding "fset"}, @{term "list_eq"}, @{typ "'a list"}, @{thm "equiv_list_eq"}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
typ "'a fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
thm "Rep_fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
  make_const_def "EMPTY" @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
term Nil 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
term EMPTY
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   507
thm EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   508
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
  make_const_def "INSERT" @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
term Cons 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
term INSERT
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   516
thm INSERT_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  make_const_def "UNION" @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
term append 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
term UNION
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   524
thm UNION_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   525
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
thm QUOTIENT_fset
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
fun 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
  membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" ("_ memb _")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
  m1: "(x memb []) = False"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   534
lemma mem_respects:
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   535
  fixes z::"nat"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   536
  assumes a: "list_eq x y"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   537
  shows "z memb x = z memb y"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   538
using a
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   539
apply(induct)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   540
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   541
done
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   542
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
  make_const_def "IN" @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
term membship
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
term IN
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   550
thm IN_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   552
lemmas a = QUOT_TYPE.ABS_def[OF QUOT_TYPE_fset]
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   553
thm QUOT_TYPE.thm11[OF QUOT_TYPE_fset, THEN iffD1, simplified a]
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   555
lemma yy:
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   556
  shows "(False = x memb []) = (False = IN (x::nat) EMPTY)"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   557
unfolding IN_def EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   558
apply(rule_tac f="(op =) False" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   559
apply(rule mem_respects)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   560
apply(unfold REP_fset_def ABS_fset_def)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   561
apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   562
apply(rule list_eq.intros)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   565
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   566
  shows "IN (x::nat) EMPTY = False"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   567
using m1
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   568
apply -
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   569
apply(rule yy[THEN iffD1, symmetric])
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   570
apply(simp)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   573
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   574
  shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) =
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   575
         ((x = y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   576
unfolding IN_def INSERT_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   577
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   578
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   579
apply(rule mem_respects)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   580
apply(rule list_eq.intros(3))
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   581
apply(unfold REP_fset_def ABS_fset_def)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   582
apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   583
apply(rule list_eq_sym)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   584
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   586
lemma helper:
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   587
  assumes a : "list_eq l1 r1"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   588
  shows "list_eq (l1 @ l) (r1 @ l)"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   589
  using a
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   590
  apply(induct)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   591
  apply(simp add:list_eq.intros)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   592
  apply(simp add:list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   593
  apply(simp add:list_eq.intros(3))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   594
  apply(simp add:list_eq.intros(4))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   595
  apply(simp add:list_eq.intros(5))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   596
  apply(rule_tac list_eq.intros(6))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   597
  apply(assumption)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   598
  apply(assumption)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   599
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   600
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   601
lemma yyy :
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   602
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   603
    (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   604
     (UNION EMPTY s = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   605
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   606
    ) = (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   607
     ((ABS_fset ([] @ REP_fset s)) = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   608
     ((ABS_fset ((e # (REP_fset s1)) @ REP_fset s2)) = ABS_fset (e # (REP_fset s1 @ REP_fset s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   609
    )"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   610
  unfolding UNION_def EMPTY_def INSERT_def
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   611
  apply(rule_tac f="(op &)" in arg_cong2)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   612
  apply(rule_tac f="(op =)" in arg_cong2)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   613
  apply (unfold REP_fset_def ABS_fset_def)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   614
  apply(simp only: QUOT_TYPE.thm11[OF QUOT_TYPE_fset,symmetric])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   615
  apply(rule helper)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   616
  apply(rule list_eq.intros(3))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   617
  apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   618
  apply(rule list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   619
  apply(simp)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   620
  apply(rule_tac f="(op =)" in arg_cong2)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   621
  apply(simp only: QUOT_TYPE.thm11[OF QUOT_TYPE_fset,symmetric])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   622
  apply(rule helper)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   623
  apply(rule list_eq.intros(3))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   624
  apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   625
  apply(rule list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   626
  apply(simp only: QUOT_TYPE.thm11[OF QUOT_TYPE_fset,symmetric])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   627
  apply(fold REP_fset_def ABS_fset_def)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   628
  apply(rule list_eq.intros(5))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   629
  apply(rule list_eq.intros(3))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   630
  apply (unfold REP_fset_def ABS_fset_def)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   631
  apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   632
  apply(rule list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   633
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   634
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   635
lemma
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   636
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   637
    (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   638
     (UNION EMPTY s = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   639
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   640
    )"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   641
  apply(simp add:yyy)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   642
  apply (unfold REP_fset_def ABS_fset_def)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   643
  apply (rule QUOT_TYPE.thm10[OF QUOT_TYPE_fset])
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   644
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   645