QuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 28 Aug 2009 17:12:19 +0200
changeset 13 c13bb9e02eb7
parent 12 13b527da2157
child 14 5f6ee943c697
permissions -rw-r--r--
Fixes after suggestions from Makarius: - indentation - lowercase/uppercase - axioms -> axiomatization - proper operator priorities - proper exception handling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotMain
6
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     2
imports QuotScript QuotList Prove
0
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
6
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     5
(*
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     6
prove {* @{prop "True"} *}
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     7
apply(rule TrueI)
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     8
done
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     9
*)
6a1b4c22a386 added the prove command
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
    10
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
locale QUOT_TYPE =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  assumes equiv: "EQUIV R"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
begin 
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
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  "ABS x \<equiv> Abs (R x)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
definition
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  "REP a = Eps (Rep a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
lemma lem9: 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  shows "R (Eps (R x)) = R x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  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
    32
  then have "R x (Eps (R x))" by (rule someI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  then show "R (Eps (R x)) = R x" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
    using equiv unfolding EQUIV_def by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
theorem thm10:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  shows "ABS (REP a) = a"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
unfolding ABS_def REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
proof -
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  from rep_prop 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  obtain x where eq: "Rep a = R x" by auto
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  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
    44
  also have "\<dots> = Abs (R x)" using lem9 by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  also have "\<dots> = Abs (Rep a)" using eq by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  also have "\<dots> = a" using rep_inverse by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  finally
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  show "Abs (R (Eps (Rep a))) = a" by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
qed
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
lemma REP_refl: 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  shows "R (REP a) (REP a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
unfolding REP_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
by (simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
lemma lem7:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  "(R x = R y) = (Abs (R x) = Abs (R y))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
apply(rule iffI)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
apply(simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(drule rep_inject[THEN iffD2])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(simp add: abs_inverse)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
theorem thm11:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  shows "R r r' = (ABS r = ABS r')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
unfolding ABS_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
by (simp only: equiv[simplified EQUIV_def] lem7)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    69
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    70
lemma REP_ABS_rsp:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    71
  shows "R f (REP (ABS g)) = R f g"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    72
  and   "R (REP (ABS g)) f = R g f"
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    73
apply(subst thm11)
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    74
apply(simp add: thm10 thm11)
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    75
apply(subst thm11)
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    76
apply(simp add: thm10 thm11)
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    77
done
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
    78
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
lemma QUOTIENT:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  "QUOTIENT R ABS REP"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
apply(unfold QUOTIENT_def)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
apply(simp add: thm10)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
apply(simp add: REP_refl)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
apply(subst thm11[symmetric])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
apply(simp add: equiv[simplified EQUIV_def])
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
section {* type definition for the quotient type *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    93
Variable.variant_frees
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    94
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    95
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    96
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
    97
ML {*
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
    98
(* 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
    99
fun typedef_term rel ty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
let 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  val [x, c] = [("x", ty), ("c", ty --> @{typ bool})] 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
               |> Variable.variant_frees lthy [rel]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
               |> map Free
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
in
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   105
  lambda c 
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   106
    (HOLogic.mk_exists 
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   107
       ("x", ty, HOLogic.mk_eq (c, (rel $ x))))
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   112
 typedef_term @{term R} @{typ "nat"} @{context} 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   113
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   114
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   115
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   116
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   117
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
val typedef_tac =  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  EVERY1 [rewrite_goal_tac @{thms mem_def},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
          rtac @{thm exI}, rtac @{thm exI}, rtac @{thm refl}]
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
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
(* makes the new type definitions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
fun typedef_make (qty_name, rel, ty) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  LocalTheory.theory_result
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   127
  (Typedef.add_typedef false NONE 
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
     (qty_name, map fst (Term.add_tfreesT ty []), NoSyn)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
       (typedef_term rel ty lthy)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
         NONE typedef_tac) lthy
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
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   133
text {* proves the QUOT_TYPE theorem for the new type *}
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
ML {*
1
8d0fad689dce updated slightly
Christian Urban <urbanc@in.tum.de>
parents: 0
diff changeset
   135
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = 
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  val rep_thm = #Rep typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  val rep_inv = #Rep_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  val abs_inv = #Abs_inverse typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  val rep_inj = #Rep_inject typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  val ss = HOL_basic_ss addsimps @{thms mem_def}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  val rep_thm_simpd = Simplifier.asm_full_simplify ss rep_thm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  val abs_inv_simpd = Simplifier.asm_full_simplify ss abs_inv
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  EVERY1 [rtac @{thm QUOT_TYPE.intro},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
          rtac equiv_thm, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
          rtac rep_thm_simpd, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
          rtac rep_inv, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
          rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl},
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
          rtac rep_inj]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   155
term QUOT_TYPE
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   156
ML {* HOLogic.mk_Trueprop *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   157
ML {* Goal.prove *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   158
ML {* Syntax.check_term *}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   159
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
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
   162
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
             |> Syntax.check_term lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  Goal.prove lthy [] [] goal
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
    (fn _ => typedef_quot_type_tac equiv_thm typedef_info)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
fun typedef_quotient_thm_tac defs quot_type_thm =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  EVERY1 [K (rewrite_goals_tac defs), 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
          rtac @{thm QUOT_TYPE.QUOTIENT}, 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
          rtac quot_type_thm]
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
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
   181
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  val quotient_const = Const (@{const_name "QUOTIENT"}, dummyT)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
  val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
             |> Syntax.check_term lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  Goal.prove lthy [] [] goal
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
    (fn _ => typedef_quotient_thm_tac [abs_def, rep_def] quot_type_thm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
text {* two wrappers for define and note *}
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 make_def (name, mx, trm) 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 ((trm, (_ , thm)), lthy') = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
     LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, trm)) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  ((trm, thm), lthy')
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
end
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
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
fun reg_thm (name, thm) lthy = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  val ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  (thm',lthy')
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
ML {* 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
fun typedef_main (qty_name, rel, ty, equiv_thm) lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
let 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  (* generates typedef *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  val ((_,typedef_info), lthy') = typedef_make (qty_name, rel, ty) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  (* abs and rep functions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  val abs_ty = #abs_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  val rep_ty = #rep_type typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  val abs_name = #Abs_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
  val rep_name = #Rep_name typedef_info
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  val abs = Const (abs_name, rep_ty --> abs_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  val rep = Const (rep_name, abs_ty --> rep_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
  (* ABS and REP definitions *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  val ABS_const = Const (@{const_name "QUOT_TYPE.ABS"}, dummyT )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  val REP_const = Const (@{const_name "QUOT_TYPE.REP"}, dummyT )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  val ABS_trm = Syntax.check_term lthy' (ABS_const $ rel $ abs) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  val REP_trm = Syntax.check_term lthy' (REP_const $ rep) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  val ABS_name = Binding.prefix_name "ABS_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  val REP_name = Binding.prefix_name "REP_" qty_name  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  val (((ABS, ABS_def), (REP, REP_def)), lthy'') = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
         lthy' |> make_def (ABS_name, NoSyn, ABS_trm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
               ||>> make_def (REP_name, NoSyn, REP_trm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  (* quot_type theorem *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  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
   238
  val quot_thm_name = Binding.prefix_name "QUOT_TYPE_" qty_name
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
  (* quotient theorem *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  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
   242
  val quotient_thm_name = Binding.prefix_name "QUOTIENT_" qty_name
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
  lthy'' 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  |> reg_thm (quot_thm_name, quot_thm)  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
  ||>> reg_thm (quotient_thm_name, quotient_thm)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
section {* various tests for quotient types*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
datatype trm =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  var  "nat" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
| app  "trm" "trm"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
| lam  "nat" "trm"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   256
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   257
axiomatization R :: "trm \<Rightarrow> trm \<Rightarrow> bool" where
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   258
  r_eq: "EQUIV R"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   260
ML {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   261
  typedef_main 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   262
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   263
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
  typedef_main (@{binding "qtrm"}, @{term "R"}, @{typ trm}, @{thm r_eq}) #> snd
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
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
term Rep_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   269
term REP_qtrm
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
term Abs_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
term ABS_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
thm QUOT_TYPE_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
thm QUOTIENT_qtrm
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   274
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
thm Rep_qtrm
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
text {* another test *}
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   278
datatype 'a my = Foo
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
consts Rmy :: "'a my \<Rightarrow> 'a my \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
axioms rmy_eq: "EQUIV Rmy"
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
term "\<lambda>(c::'a my\<Rightarrow>bool). \<exists>x. c = Rmy x"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
datatype 'a trm' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
  var'  "'a" 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
| app'  "'a trm'" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
| lam'  "'a" "'a trm'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
consts R' :: "'a trm' \<Rightarrow> 'a trm' \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
axioms r_eq': "EQUIV R'"
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
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
  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
   294
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
term ABS_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
term REP_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
thm QUOT_TYPE_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
thm QUOTIENT_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
thm Rep_qtrm'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
text {* a test with lists of terms *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
datatype t =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
  vr "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
| ap "t list"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
| lm "string" "t"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
consts Rt :: "t \<Rightarrow> t \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
axioms t_eq: "EQUIV Rt"
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_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
  typedef_main (@{binding "qt"}, @{term "Rt"}, @{typ "t"}, @{thm t_eq}) #> snd
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
section {* lifting of constants *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
text {* information about map-functions for type-constructor *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
type typ_info = {mapfun: string}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
local
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  structure Data = GenericDataFun
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  (type T = typ_info Symtab.table
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
   val empty = Symtab.empty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
   val extend = I
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
   fun merge _ = Symtab.merge (K true))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
 val lookup = Symtab.lookup o Data.get
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
 fun update k v = Data.map (Symtab.update (k, v)) 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
*}
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
(* mapfuns for some standard types *)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
    Context.theory_map (update @{type_name "list"} {mapfun = @{const_name "map"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
 #> Context.theory_map (update @{type_name "*"} {mapfun = @{const_name "prod_fun"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
 #> Context.theory_map (update @{type_name "fun"}  {mapfun = @{const_name "fun_map"}})
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   340
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
ML {* lookup (Context.Proof @{context}) @{type_name list} *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
datatype abs_or_rep = abs | rep
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
fun get_fun abs_or_rep rty qty lthy ty = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
  val qty_name = Long_Name.base_name (fst (dest_Type qty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
  fun get_fun_aux s fs_tys =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
    val (fs, tys) = split_list fs_tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
    val (otys, ntys) = split_list tys 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
    val oty = Type (s, otys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
    val nty = Type (s, ntys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
    val ftys = map (op -->) tys
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
  in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
   (case (lookup (Context.Proof lthy) s) of 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
      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
   360
    | NONE => raise ERROR ("no map association for type " ^ s))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
  end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
  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
   364
    | get_const rep = (Const ("QuotMain.REP_" ^ qty_name, qty --> rty), (qty, rty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
  if ty = qty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
  then (get_const abs_or_rep)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
  else (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
          TFree _ => (Abs ("x", ty, Bound 0), (ty, ty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
        | Type (_, []) => (Abs ("x", ty, Bound 0), (ty, ty))
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
        | 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
   372
        | _ => raise ERROR ("no variables")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
       )
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
end
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
ML {*
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   378
  get_fun rep @{typ t} @{typ qt} @{context} @{typ "t * nat"}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   379
  |> fst
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   380
  |> Syntax.string_of_term @{context}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   381
  |> writeln
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   382
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   383
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   384
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   385
ML {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
fun get_const_def nconst oconst rty qty lthy =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
  val ty = fastype_of nconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
  val (arg_tys, res_ty) = strip_type ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
  val fresh_args = arg_tys |> map (pair "x")
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
                           |> Variable.variant_frees lthy [nconst, oconst] 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
                           |> map Free
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
  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
   396
  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
   397
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
  map (op $) (rep_fns ~~ fresh_args)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
  |> curry list_comb oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
  |> curry (op $) abs_fn
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
  |> fold_rev lambda fresh_args
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
end
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
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
fun exchange_ty rty qty ty = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
  if ty = rty then qty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
  else 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
    (case ty of
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
       Type (s, tys) => Type (s, map (exchange_ty rty qty) tys)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
      | _ => ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
ML {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
fun make_const_def nconst_name oconst mx rty qty lthy = 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
let
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
  val oconst_ty = fastype_of oconst
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
  val nconst_ty = exchange_ty rty qty oconst_ty
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
  val nconst = Const (nconst_name, nconst_ty)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  val def_trm = get_const_def nconst oconst rty qty lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
in
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
  make_def (Binding.name nconst_name, mx, def_trm) lthy
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
end  
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   427
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   428
  make_const_def "VR" @{term "vr"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   429
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   430
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   431
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   432
  make_const_def "AP" @{term "ap"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   433
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   434
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   435
local_setup {*
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   436
  make_const_def "LM" @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   437
*}
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   438
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   439
thm VR_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   440
thm AP_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   441
thm LM_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   442
term LM 
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   443
term VR
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   444
term AP
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   445
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   446
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
text {* a test with functions *}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
datatype 'a t' =
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
  vr' "string"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
| ap' "('a t') * ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
| lm' "'a" "string \<Rightarrow> ('a t')"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
consts Rt' :: "('a t') \<Rightarrow> ('a t') \<Rightarrow> bool"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
axioms t_eq': "EQUIV Rt'"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
  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
   458
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   460
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
  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
   463
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
  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
   467
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
  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
   471
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
thm VR'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
thm AP'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
thm LM'_def
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
term LM' 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
term VR'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
term AP'
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
text {* finite set example *}
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   481
print_syntax
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
inductive 
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   483
  list_eq (infix "\<approx>" 50)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
  "a#b#xs \<approx> b#a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
| "[] \<approx> []"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
| "a#a#xs \<approx> a#xs"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
lemma list_eq_sym:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
  shows "xs \<approx> xs"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   494
  apply (induct xs)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   495
   apply (auto intro: list_eq.intros)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   496
  done
0
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
lemma equiv_list_eq:
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
  shows "EQUIV list_eq"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   500
  unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   501
  apply(auto intro: list_eq.intros list_eq_sym)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   502
  done
0
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
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
  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
   506
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
typ "'a fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
thm "Rep_fset"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
  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
   513
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
term Nil 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
term EMPTY
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   517
thm EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   518
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
  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
   522
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
term Cons 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
term INSERT
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   526
thm INSERT_def
0
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
local_setup {*
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
  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
   530
*}
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
term append 
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
term UNION
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   534
thm UNION_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   535
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   536
local_setup {*
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   537
  make_const_def "CARD" @{term "length"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   538
*}
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   539
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   540
term length
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   541
term CARD
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   542
thm CARD_def
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   543
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
thm QUOTIENT_fset
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   546
(* This code builds the interpretation from ML level, currently only
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   547
   for fset *) 
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   548
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   549
ML {* val mthd = Method.SIMPLE_METHOD (rtac @{thm QUOT_TYPE_fset} 1 THEN
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   550
  simp_tac (HOL_basic_ss addsimps @{thms REP_fset_def [symmetric]}) 1 THEN
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   551
  simp_tac (HOL_basic_ss addsimps @{thms ABS_fset_def [symmetric]}) 1) *}
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   552
ML {* val mthdt = Method.Basic (fn _ => mthd) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   553
ML {* val bymt = Proof.global_terminal_proof (mthdt, NONE) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   554
ML {* val exp_i = [((Locale.intern @{theory} "QUOT_TYPE"),(("QUOT_TYPE_fset_i", true),
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   555
  Expression.Named [
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   556
   ("R",@{term list_eq}),
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   557
   ("Abs",@{term Abs_fset}),
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   558
   ("Rep",@{term Rep_fset})
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   559
  ]))] *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   560
ML {* val bindd = ((Binding.make ("",Position.none)),([]:Attrib.src list)) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   561
ML {* val eqn1i = (bindd, @{prop "QUOT_TYPE.ABS list_eq Abs_fset = ABS_fset"}) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   562
ML {* val eqn2i = (bindd, @{prop "QUOT_TYPE.REP Rep_fset = REP_fset"}) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   563
setup {* fn thy => ProofContext.theory_of
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   564
  (bymt (Expression.interpretation (exp_i, []) [eqn2i,eqn1i] thy)) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   565
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   566
(* It is eqivalent to the below:
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   567
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   568
interpretation QUOT_TYPE_fset_i: QUOT_TYPE list_eq Abs_fset Rep_fset
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   569
  where "QUOT_TYPE.ABS list_eq Abs_fset = ABS_fset"
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   570
    and "QUOT_TYPE.REP Rep_fset = REP_fset"
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   571
  unfolding ABS_fset_def REP_fset_def
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   572
  apply (rule QUOT_TYPE_fset)
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   573
  apply (simp only: ABS_fset_def[symmetric])
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   574
  apply (simp only: REP_fset_def[symmetric])
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   575
  done
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   576
*)
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   577
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   578
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   579
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   580
fun
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   581
  membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
  m1: "(x memb []) = False"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   586
lemma mem_respects:
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   587
  fixes z
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   588
  assumes a: "list_eq x y"
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   589
  shows "(z memb x) = (z memb y)"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   590
  using a by induct auto
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   591
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   592
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   593
lemma cons_preserves:
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   594
  fixes z
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   595
  assumes a: "xs \<approx> ys"
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   596
  shows "(z # xs) \<approx> (z # ys)"
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   597
  using a by (rule QuotMain.list_eq.intros(5))
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   598
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   599
ML {*
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   600
fun unlam_def orig_ctxt ctxt t =
13
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   601
  let val rhs = Thm.rhs_of t in
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   602
  (case try (Thm.dest_abs NONE) rhs of
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   603
    SOME (v, vt) =>
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   604
      let
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   605
        val (vname, vt) = Term.dest_Free (Thm.term_of v)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   606
        val ([vnname], ctxt) = Variable.variant_fixes [vname] ctxt
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   607
        val nv = Free(vnname, vt)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   608
        val t2 = Drule.fun_cong_rule t (Thm.cterm_of (ProofContext.theory_of ctxt) nv)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   609
        val tnorm = equal_elim (Drule.beta_eta_conversion (Thm.cprop_of t2)) t2
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   610
      in unlam_def orig_ctxt ctxt tnorm end
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   611
  | NONE => singleton (ProofContext.export ctxt orig_ctxt) t)
c13bb9e02eb7 Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 12
diff changeset
   612
  end
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   613
*}
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   614
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   615
local_setup {*
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
  make_const_def "IN" @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   617
*}
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   618
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
term membship
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
term IN
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   621
thm IN_def
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   623
lemmas a = QUOT_TYPE.ABS_def[OF QUOT_TYPE_fset]
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   624
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
   625
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   626
lemma yy:
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   627
  shows "(False = x memb []) = (False = IN (x::nat) EMPTY)"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   628
unfolding IN_def EMPTY_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   629
apply(rule_tac f="(op =) False" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   630
apply(rule mem_respects)
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   631
apply(simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   632
apply(rule list_eq.intros)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   635
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   636
  shows "IN (x::nat) EMPTY = False"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   637
using m1
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   638
apply -
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   639
apply(rule yy[THEN iffD1, symmetric])
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   640
apply(simp)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
done
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   643
lemma
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   644
  shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) =
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   645
         ((x = y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))"
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   646
unfolding IN_def INSERT_def
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   647
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   648
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   649
apply(rule mem_respects)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   650
apply(rule list_eq.intros(3))
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   651
apply(unfold REP_fset_def ABS_fset_def)
5
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 4
diff changeset
   652
apply(simp only: QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
2
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   653
apply(rule list_eq_sym)
Christian Urban <urbanc@in.tum.de>
parents: 1
diff changeset
   654
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   656
lemma append_respects_fst:
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   657
  assumes a : "list_eq l1 l2"  
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   658
  shows "list_eq (l1 @ s) (l2 @ s)"
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   659
  using a
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   660
  apply(induct)
4
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   661
  apply(auto intro: list_eq.intros)
Christian Urban <urbanc@in.tum.de>
parents: 3
diff changeset
   662
  apply(simp add: list_eq_sym)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   663
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   664
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   665
lemma yyy :
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   666
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   667
    (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   668
     (UNION EMPTY s = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   669
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   670
    ) = (
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   671
     ((ABS_fset ([] @ REP_fset s)) = s) &
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   672
     ((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
   673
    )"
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   674
  unfolding UNION_def EMPTY_def INSERT_def
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   675
  apply(rule_tac f="(op &)" in arg_cong2)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   676
  apply(rule_tac f="(op =)" in arg_cong2)
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   677
  apply(simp only: QUOT_TYPE_fset_i.thm11[symmetric])
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   678
  apply(rule append_respects_fst)
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   679
  apply(simp only:QUOT_TYPE_fset_i.REP_ABS_rsp)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   680
  apply(rule list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   681
  apply(simp)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   682
  apply(rule_tac f="(op =)" in arg_cong2)
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   683
  apply(simp only: QUOT_TYPE_fset_i.thm11[symmetric])
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   684
  apply(rule append_respects_fst)
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   685
  apply(simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   686
  apply(rule list_eq_sym)
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   687
  apply(simp only: QUOT_TYPE_fset_i.thm11[symmetric])
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   688
  apply(rule list_eq.intros(5))
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   689
  apply(simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   690
  apply(rule list_eq_sym)
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   691
done
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   692
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   693
lemma
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   694
  shows "
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   695
     (UNION EMPTY s = s) &
7
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   696
     ((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))"
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   697
  apply (simp add: yyy)
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   698
  apply (rule QUOT_TYPE_fset_i.thm10)
3e77ad0abc6a - Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 6
diff changeset
   699
  done
3
672e14609e6e UNION - Append theorem
cek@localhost.localdomain
parents: 2
diff changeset
   700
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   701
ML {*
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   702
  fun mk_rep_abs x = @{term REP_fset} $ (@{term ABS_fset} $ x)
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   703
  val consts = [@{const_name "Nil"}, @{const_name "append"}, @{const_name "Cons"}, @{const_name "membship"}]
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   704
*}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   705
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   706
ML {*
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   707
fun build_goal thm constructors lifted_type mk_rep_abs =
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   708
  let
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   709
    fun is_const (Const (x, t)) = x mem constructors
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   710
      | is_const _ = false
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   711
    fun maybe_mk_rep_abs t =
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   712
      let
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   713
        val _ = writeln ("Maybe: " ^ Syntax.string_of_term @{context} t)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   714
      in
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   715
        if type_of t = lifted_type then mk_rep_abs t else t
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   716
      end
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   717
    fun build_aux (Abs (s, t, tr)) = (Abs (s, t, build_aux tr))
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   718
      | build_aux (f $ a) =
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   719
          let
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   720
            val (f,args) = strip_comb (f $ a)
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   721
            val _ = writeln (Syntax.string_of_term @{context} f)
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   722
           in
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   723
            (if is_const f then maybe_mk_rep_abs (list_comb (f, (map maybe_mk_rep_abs (map build_aux args))))
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   724
            else list_comb ((build_aux f), (map build_aux args)))
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   725
          end
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   726
      | build_aux x =
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   727
          if is_const x then maybe_mk_rep_abs x else x
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   728
    val concl = HOLogic.dest_Trueprop (Thm.concl_of thm)
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   729
  in
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   730
  HOLogic.mk_eq ((build_aux concl), concl)
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   731
end *}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   732
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   733
ML {*
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   734
val no_vars = Thm.rule_attribute (fn context => fn th =>
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   735
  let
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   736
    val ctxt = Variable.set_body false (Context.proof_of context);
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   737
    val ((_, [th']), _) = Variable.import true [th] ctxt;
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   738
  in th' end);
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   739
*}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   740
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   741
ML {*
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   742
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m1}))
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   743
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
8
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   744
  val cgoal = cterm_of @{theory} goal
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   745
*}
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   746
54afbcf2a758 Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 7
diff changeset
   747
ML {* val emptyt = symmetric @{thm EMPTY_def} *}
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   748
ML {* val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false [emptyt] cgoal) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   749
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   750
ML {* val in_t = (symmetric (unlam_def @{context} @{context} @{thm IN_def})) *}
9
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   751
ML {* val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite false [in_t] (cgoal2)) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   752
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   753
(*theorem "(IN x EMPTY = False) = (x memb [] = False)"*)
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   754
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   755
prove {* HOLogic.mk_Trueprop (Thm.term_of cgoal3) *}
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   756
apply(rule_tac f="(op =)" in arg_cong2)
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   757
unfolding IN_def EMPTY_def
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   758
apply (rule_tac mem_respects)
eac147a5eb33 Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 8
diff changeset
   759
apply (simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
10
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   760
apply (simp_all)
b11b405b8271 Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 9
diff changeset
   761
apply (rule list_eq_sym)
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   762
done
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   763
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   764
thm length_append (* Not true but worth checking that the goal is correct *)
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   765
ML {*
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   766
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm length_append}))
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   767
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   768
  val cgoal = cterm_of @{theory} goal
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   769
*}
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   770
ML {* val uniont = symmetric (unlam_def @{context} @{context} @{thm UNION_def}) *}
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   771
ML {* val cardt =  symmetric (unlam_def @{context} @{context} @{thm CARD_def}) *}
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   772
ML {* val insertt =  symmetric (unlam_def @{context} @{context} @{thm INSERT_def}) *}
11
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   773
ML {* val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true [cardt] cgoal) *}
0bc0db2e83f2 Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 10
diff changeset
   774
ML {* val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true [uniont] cgoal2) *}
12
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   775
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   776
thm m2
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   777
ML {*
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   778
  val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m2}))
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   779
  val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   780
  val cgoal = cterm_of @{theory} goal
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   781
*}
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   782
ML {* val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true [in_t] cgoal) *}
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   783
ML {* val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true [insertt] cgoal2) *}
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   784
prove {* HOLogic.mk_Trueprop (Thm.term_of cgoal3) *}
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   785
apply(rule_tac f="(op =)" in arg_cong2)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   786
unfolding IN_def
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   787
apply (rule_tac mem_respects)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   788
unfolding INSERT_def
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   789
apply (simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   790
apply (rule cons_preserves)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   791
apply (simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   792
apply (rule list_eq_sym)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   793
apply(rule_tac f="(op \<or>)" in arg_cong2)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   794
apply (simp)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   795
apply (rule_tac mem_respects)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   796
apply (simp only: QUOT_TYPE_fset_i.REP_ABS_rsp)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   797
apply (rule list_eq_sym)
13b527da2157 More examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 11
diff changeset
   798
done