IntEx.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Mon, 26 Oct 2009 14:16:32 +0100
changeset 192 a296bf1a3b09
parent 191 b97f3f5fbc18
child 193 b888119a18ff
child 194 03c03e88efa9
permissions -rw-r--r--
Simplifying code in int
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
181
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory IntEx
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports QuotMain
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
fun
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" 
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  "intrel (x, y) (u, v) = (x + v = u + y)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
quotient my_int = "nat \<times> nat" / intrel
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  apply(unfold EQUIV_def)
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  apply(auto simp add: mem_def expand_fun_eq)
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  done
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
184
f3c192574d2a added "print_quotients" command to th ekeyword file
Christian Urban <urbanc@in.tum.de>
parents: 181
diff changeset
    15
print_quotients
f3c192574d2a added "print_quotients" command to th ekeyword file
Christian Urban <urbanc@in.tum.de>
parents: 181
diff changeset
    16
181
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
typ my_int
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  make_const_def @{binding "ZERO"} @{term "(0::nat, 0::nat)"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
term ZERO
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
thm ZERO_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  make_const_def @{binding ONE} @{term "(1::nat, 0::nat)"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
term ONE
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
thm ONE_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
fun
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  my_plus :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  "my_plus (x, y) (u, v) = (x + u, y + v)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  make_const_def @{binding PLUS} @{term "my_plus"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
term PLUS
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
thm PLUS_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fun
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  my_neg :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  "my_neg (x, y) = (y, x)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  make_const_def @{binding NEG} @{term "my_neg"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
term NEG
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
thm NEG_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
definition
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  MINUS :: "my_int \<Rightarrow> my_int \<Rightarrow> my_int"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  "MINUS z w = PLUS z (NEG w)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fun
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  my_mult :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  "my_mult (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  make_const_def @{binding MULT} @{term "my_mult"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
term MULT
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
thm MULT_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
(* NOT SURE WETHER THIS DEFINITION IS CORRECT *)
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
fun
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  my_le :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  "my_le (x, y) (u, v) = (x+v \<le> u+y)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
local_setup {*
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  make_const_def @{binding LE} @{term "my_le"} NoSyn @{typ "nat \<times> nat"} @{typ "my_int"} #> snd
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
*}
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
term LE
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
thm LE_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
definition
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  LESS :: "my_int \<Rightarrow> my_int \<Rightarrow> bool"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  "LESS z w = (LE z w \<and> z \<noteq> w)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
term LESS
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
thm LESS_def
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
definition
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  ABS :: "my_int \<Rightarrow> my_int"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  "ABS i = (if (LESS i ZERO) then (NEG i) else i)"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
definition
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  SIGN :: "my_int \<Rightarrow> my_int"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
where
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
 "SIGN i = (if i = ZERO then ZERO else if (LESS ZERO i) then ONE else (NEG ONE))"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   106
lemma plus_sym_pre:
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   107
  shows "intrel (my_plus a b) (my_plus b a)"
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   108
  sorry
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   109
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   110
lemma equiv_intrel: "EQUIV intrel"
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   111
  sorry
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   112
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   113
lemma intrel_refl: "intrel a a"
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   114
  sorry
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   115
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   116
lemma ho_plus_rsp : "IntEx.intrel ===> IntEx.intrel ===> IntEx.intrel my_plus my_plus"
192
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   117
  by (simp)
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   118
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   119
ML {* val consts = [@{const_name "my_plus"}] *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   120
ML {* val rty = @{typ "nat \<times> nat"} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   121
ML {* val qty = @{typ "my_int"} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   122
ML {* val rel = @{term "intrel"} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   123
ML {* val rel_eqv = @{thm equiv_intrel} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   124
ML {* val rel_refl = @{thm intrel_refl} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   125
ML {* val quot = @{thm QUOTIENT_my_int} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   126
ML {* val rsp_thms = @{thms ho_plus_rsp} @ @{thms ho_all_prs ho_ex_prs} *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   127
ML {* val trans2 = @{thm QUOT_TYPE_I_my_int.R_trans2} *}
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   128
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   129
ML {* val t_a = atomize_thm @{thm plus_sym_pre} *}
192
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   130
ML {* val t_r = regularize t_a rty rel rel_eqv @{context} *}
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   131
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   132
ML {* val (g, thm, othm) =
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   133
  Toplevel.program (fn () =>
192
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   134
  repabs_eq @{context} t_r consts rty qty
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   135
   quot rel_refl trans2
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   136
   rsp_thms
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   137
  )
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   138
*}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   139
ML {*
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   140
  val t_t2 =
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   141
  Toplevel.program (fn () =>
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   142
    repabs_eq2 @{context} (g, thm, othm)
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   143
  )
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   144
*}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   145
ML {*
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   146
 val lpi = Drule.instantiate'
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   147
   [SOME @{ctyp "nat \<times> nat"}, NONE, SOME @{ctyp "bool"}, NONE] [] @{thm LAMBDA_PRS};
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   148
*}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   149
prove lambda_prs_mn_b : {* concl_of lpi *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   150
apply (tactic {* compose_tac (false, @{thm LAMBDA_PRS}, 2) 1 *})
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   151
apply (tactic {* quotient_tac @{thm QUOTIENT_my_int} 1 *})
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   152
apply (tactic {* quotient_tac @{thm QUOTIENT_my_int} 1 *})
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   153
done
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   154
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   155
ML {*
192
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   156
fun make_simp_lam_prs_thm lthy quot_thm typ =
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   157
  let
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   158
    val (_, [lty, rty]) = dest_Type typ;
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   159
    val thy = ProofContext.theory_of lthy;
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   160
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   161
    val inst = [SOME lcty, NONE, SOME rcty];
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   162
    val lpi = Drule.instantiate' inst [] @{thm LAMBDA_PRS};
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   163
    val tac =
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   164
      (compose_tac (false, @{thm LAMBDA_PRS}, 2)) THEN_ALL_NEW
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   165
      (quotient_tac quot_thm);
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   166
    val t = Goal.prove lthy [] [] (concl_of lpi) (fn _ => tac 1);
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   167
    val ts = @{thm HOL.sym} OF [t]
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   168
  in
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   169
    MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_def}] ts
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   170
  end
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   171
*}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   172
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   173
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   174
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   175
ML {* val abs = findabs rty (prop_of (atomize_thm @{thm plus_sym_pre})) *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   176
ML {* val simp_lam_prs_thms = map (make_simp_lam_prs_thm @{context} quot) abs *}
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   177
thm HOL.sym[OF lambda_prs_mn_b,simplified]
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   178
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   179
ML {*
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   180
  fun simp_lam_prs lthy thm =
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   181
    simp_lam_prs lthy (eqsubst_thm lthy
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   182
      @{thms HOL.sym[OF lambda_prs_mn_b,simplified]}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   183
    thm)
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   184
    handle _ => thm
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   185
*}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   186
ML {* t_t2 *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   187
ML {* val t_l = simp_lam_prs @{context} t_t2 *}
192
a296bf1a3b09 Simplifying code in int
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 191
diff changeset
   188
ML {* findabs rty (prop_of (atomize_thm @{thm plus_sym_pre})) *}
191
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   189
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   190
ML {*
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   191
  fun simp_allex_prs lthy thm =
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   192
    let
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   193
      val rwf = @{thm FORALL_PRS[OF QUOTIENT_my_int]};
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   194
      val rwfs = @{thm "HOL.sym"} OF [rwf];
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   195
      val rwe = @{thm EXISTS_PRS[OF QUOTIENT_my_int]};
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   196
      val rwes = @{thm "HOL.sym"} OF [rwe]
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   197
    in
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   198
      (simp_allex_prs lthy (eqsubst_thm lthy [rwfs, rwes] thm))
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   199
    end
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   200
    handle _ => thm
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   201
*}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   202
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   203
ML {* val t_a = simp_allex_prs @{context} t_l *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   204
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   205
ML {* val t_defs = @{thms PLUS_def} *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   206
ML {* val t_defs_sym = add_lower_defs @{context} t_defs *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   207
ML {* val t_d = MetaSimplifier.rewrite_rule t_defs_sym t_a *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   208
ML {* val t_r = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_my_int.REPS_same} t_d *}
b97f3f5fbc18 Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 184
diff changeset
   209
ML {* ObjectLogic.rulify t_r *}
181
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
lemma 
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  fixes i j k::"my_int"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  shows "(PLUS (PLUS i j) k) = (PLUS i (PLUS j k))"
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  apply(unfold PLUS_def)
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  apply(simp add: expand_fun_eq)
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  sorry
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
3e53081ad53a added another example file about integers (see HOL/Int.thy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218