Quot/Examples/IntEx2.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 09 Dec 2009 00:03:18 +0100
changeset 654 02fd9de9d45e
parent 636 520a4084d064
child 663 0dd10a900cae
permissions -rw-r--r--
tuned the examples and flagged the problematic cleaning lemmas in FSet
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory IntEx2
597
8a1c8dc72b5c directory re-arrangement
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
     2
imports "../QuotMain"
604
0cf166548856 isabelle make tests all examples
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
     3
(*uses
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  ("Tools/numeral.ML")
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  ("Tools/numeral_syntax.ML")
604
0cf166548856 isabelle make tests all examples
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
     6
  ("Tools/int_arith.ML")*)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
begin
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
578
070161f1996a updated Isabelle and deleted mono rules
Christian Urban <urbanc@in.tum.de>
parents: 570
diff changeset
     9
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" (infix "\<approx>" 50)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  "intrel (x, y) (u, v) = (x + v = u + y)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
quotient int = "nat \<times> nat" / intrel
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  apply(unfold equivp_def)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  apply(auto simp add: mem_def expand_fun_eq)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  done
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
instantiation int :: "{zero, one, plus, minus, uminus, times, ord, abs, sgn}"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
begin
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
quotient_def 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  zero_qnt::"int"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  "zero_qnt \<equiv> (0::nat, 0::nat)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
definition  Zero_int_def[code del]: 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  "0 = zero_qnt"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
quotient_def 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  one_qnt::"int"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  "one_qnt \<equiv> (1::nat, 0::nat)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
definition One_int_def[code del]:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  "1 = one_qnt"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  plus_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  "plus_raw (x, y) (u, v) = (x + u, y + v)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
quotient_def 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  plus_qnt::"int \<Rightarrow> int \<Rightarrow> int"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  "plus_qnt \<equiv> plus_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
definition add_int_def[code del]:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  "z + w = plus_qnt z w"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  minus_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  "minus_raw (x, y) = (y, x)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
    57
quotient_def
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  minus_qnt::"int \<Rightarrow> int"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  "minus_qnt \<equiv> minus_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
definition minus_int_def [code del]:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    "- z = minus_qnt z"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
definition
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  diff_int_def [code del]:  "z - w = z + (-w::int)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  mult_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  "mult_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
quotient_def 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  mult_qnt::"int \<Rightarrow> int \<Rightarrow> int"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  "mult_qnt \<equiv> mult_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
definition
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  mult_int_def [code del]: "z * w = mult_qnt z w"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  le_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  "le_raw (x, y) (u, v) = (x+v \<le> u+y)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
quotient_def 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  le_qnt :: "int \<Rightarrow> int \<Rightarrow> bool"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  "le_qnt \<equiv> le_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
definition
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  le_int_def [code del]:
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
    93
   "z \<le> w = le_qnt z w"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
definition
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
    96
  less_int_def [code del]: "(z\<Colon>int) < w = (z \<le> w \<and> z \<noteq> w)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
definition
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
definition
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  zsgn_def: "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
instance ..
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
end
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
   108
lemma plus_raw_rsp[quot_respect]:
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) plus_raw plus_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
by auto
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
   112
lemma minus_raw_rsp[quot_respect]:
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   113
  shows "(op \<approx> ===> op \<approx>) minus_raw minus_raw"
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   114
  by auto
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   115
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
   116
lemma mult_raw_rsp[quot_respect]:
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) mult_raw mult_raw"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
apply(auto)
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   119
apply(simp add: algebra_simps)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
sorry
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
   122
lemma le_raw_rsp[quot_respect]:
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   123
  shows "(op \<approx> ===> op \<approx> ===> op =) le_raw le_raw"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   124
by auto
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   125
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
lemma plus_assoc_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  shows "plus_raw (plus_raw i j) k \<approx> plus_raw i (plus_raw j k)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
by (cases i, cases j, cases k) (simp)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
lemma plus_sym_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  shows "plus_raw i j \<approx> plus_raw j i"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
by (cases i, cases j) (simp)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
lemma plus_zero_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  shows "plus_raw  (0, 0) i \<approx> i"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
by (cases i) (simp)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
lemma plus_minus_zero_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  shows "plus_raw (minus_raw i) i \<approx> (0, 0)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
by (cases i) (simp)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
lemma mult_assoc_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  shows "mult_raw (mult_raw i j) k \<approx> mult_raw i (mult_raw j k)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
by (cases i, cases j, cases k) 
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   145
   (simp add: algebra_simps)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
lemma mult_sym_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  shows "mult_raw i j \<approx> mult_raw j i"
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   149
by (cases i, cases j) (simp add: algebra_simps)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
lemma mult_one_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
  shows "mult_raw  (1, 0) i \<approx> i"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
by (cases i) (simp)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
lemma mult_plus_comm_raw:
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  shows "mult_raw (plus_raw i j) k \<approx> plus_raw (mult_raw i k) (mult_raw j k)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
by (cases i, cases j, cases k) 
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   158
   (simp add: algebra_simps)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
lemma one_zero_distinct:
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   161
  shows "\<not> (0, 0) \<approx> ((1::nat), (0::nat))"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  by simp
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   163
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
text{*The integers form a @{text comm_ring_1}*}
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
instance int :: comm_ring_1
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
proof
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  fix i j k :: int
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
  show "(i + j) + k = i + (j + k)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
    unfolding add_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   172
    by (lifting plus_assoc_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  show "i + j = j + i" 
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
    unfolding add_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   175
    by (lifting plus_sym_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  show "0 + i = (i::int)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
    unfolding add_int_def Zero_int_def 
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   178
    by (lifting plus_zero_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  show "- i + i = 0"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
    unfolding add_int_def minus_int_def Zero_int_def 
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   181
    by (lifting plus_minus_zero_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  show "i - j = i + - j"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
    by (simp add: diff_int_def)
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  show "(i * j) * k = i * (j * k)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
    unfolding mult_int_def 
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   186
    by (lifting mult_assoc_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  show "i * j = j * i"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
    unfolding mult_int_def 
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   189
    by (lifting mult_sym_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  show "1 * i = i"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
    unfolding mult_int_def One_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   192
    by (lifting mult_one_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  show "(i + j) * k = i * k + j * k"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
    unfolding mult_int_def add_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   195
    by (lifting mult_plus_comm_raw)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  show "0 \<noteq> (1::int)"
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
    unfolding Zero_int_def One_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   198
    by (lifting one_zero_distinct)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
qed
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   201
term of_nat
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   202
thm of_nat_def
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   203
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   204
lemma int_def: "of_nat m = ABS_int (m, 0)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   205
apply(induct m) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   206
apply(simp add: Zero_int_def zero_qnt_def)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   207
apply(simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   208
apply(simp add: add_int_def One_int_def)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   209
apply(simp add: plus_qnt_def one_qnt_def)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   210
oops
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   211
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   212
lemma le_antisym_raw:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   213
  shows "le_raw i j \<Longrightarrow> le_raw j i \<Longrightarrow> i \<approx> j"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   214
by (cases i, cases j) (simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   215
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   216
lemma le_refl_raw:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   217
  shows "le_raw i i"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   218
by (cases i) (simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   219
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   220
lemma le_trans_raw:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   221
  shows "le_raw i j \<Longrightarrow> le_raw j k \<Longrightarrow> le_raw i k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   222
by (cases i, cases j, cases k) (simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   223
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   224
lemma le_cases_raw:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   225
  shows "le_raw i j \<or> le_raw j i"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   226
by (cases i, cases j) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   227
   (simp add: linorder_linear)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   228
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   229
instance int :: linorder
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   230
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   231
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   232
  show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   233
    unfolding le_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   234
    by (lifting le_antisym_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   235
  show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   236
    by (auto simp add: less_int_def dest: antisym) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   237
  show "i \<le> i"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   238
    unfolding le_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   239
    by (lifting le_refl_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   240
  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   241
    unfolding le_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   242
    by (lifting le_trans_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   243
  show "i \<le> j \<or> j \<le> i"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   244
    unfolding le_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   245
    by (lifting le_cases_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   246
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   247
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   248
instantiation int :: distrib_lattice
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   249
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   250
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   251
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   252
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   253
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   254
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   255
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   256
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   257
instance
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   258
  by intro_classes
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   259
    (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   260
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   261
end
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   262
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   263
lemma le_plus_raw:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   264
  shows "le_raw i j \<Longrightarrow> le_raw (plus_raw k i) (plus_raw k j)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   265
by (cases i, cases j, cases k) (simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   266
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   267
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   268
instance int :: pordered_cancel_ab_semigroup_add
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   269
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   270
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   271
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   272
    unfolding le_int_def add_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   273
    by (lifting le_plus_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   274
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   275
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   276
lemma test:
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   277
  "\<lbrakk>le_raw i j \<and> \<not>i \<approx> j; le_raw (0, 0) k \<and> \<not>(0, 0) \<approx> k\<rbrakk>
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   278
    \<Longrightarrow> le_raw (mult_raw k i) (mult_raw k j) \<and> \<not>mult_raw k i \<approx> mult_raw k j"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   279
apply(cases i, cases j, cases k)
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   280
apply(auto simp add: algebra_simps)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   281
sorry
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   282
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   283
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   284
text{*The integers form an ordered integral domain*}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   285
instance int :: ordered_idom
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   286
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   287
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   288
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   289
    unfolding mult_int_def le_int_def less_int_def Zero_int_def
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   290
    by (lifting test)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   291
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   292
    by (simp only: zabs_def)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   293
  show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   294
    by (simp only: zsgn_def)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   295
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   296
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   297
instance int :: lordered_ring
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   298
proof  
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   299
  fix k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   300
  show "abs k = sup k (- k)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   301
    by (auto simp add: sup_int_def zabs_def less_minus_self_iff [symmetric])
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   302
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   303
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   304
lemmas int_distrib =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   305
  left_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   306
  right_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   307
  left_diff_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   308
  right_diff_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   309
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   310
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   311
subsection {* Embedding of the Integers into any @{text ring_1}: @{text of_int}*}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   312
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   313
(*
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   314
context ring_1
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   315
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   316
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   317
 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   318
definition 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   319
  of_int :: "int \<Rightarrow> 'a" 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   320
where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   321
  "of_int 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   322
*)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   323
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   324
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   325
subsection {* Binary representation *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   326
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   327
text {*
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   328
  This formalization defines binary arithmetic in terms of the integers
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   329
  rather than using a datatype. This avoids multiple representations (leading
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   330
  zeroes, etc.)  See @{text "ZF/Tools/twos-compl.ML"}, function @{text
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   331
  int_of_binary}, for the numerical interpretation.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   332
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   333
  The representation expects that @{text "(m mod 2)"} is 0 or 1,
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   334
  even if m is negative;
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   335
  For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   336
  @{text "-5 = (-3)*2 + 1"}.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   337
  
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   338
  This two's complement binary representation derives from the paper 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   339
  "An Efficient Representation of Arithmetic for Term Rewriting" by
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   340
  Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   341
  Springer LNCS 488 (240-251), 1991.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   342
*}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   343
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   344
subsubsection {* The constructors @{term Bit0}, @{term Bit1}, @{term Pls} and @{term Min} *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   345
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   346
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   347
  Pls :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   348
  [code del]: "Pls = 0"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   349
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   350
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   351
  Min :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   352
  [code del]: "Min = - 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   353
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   354
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   355
  Bit0 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   356
  [code del]: "Bit0 k = k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   357
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   358
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   359
  Bit1 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   360
  [code del]: "Bit1 k = 1 + k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   361
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   362
class number = -- {* for numeric types: nat, int, real, \dots *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   363
  fixes number_of :: "int \<Rightarrow> 'a"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   364
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   365
(*use "~~/src/HOL/Tools/numeral.ML"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   366
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   367
syntax
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   368
  "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   369
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   370
use "~~/src/HOL/Tools/numeral_syntax.ML"
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   371
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   372
setup NumeralSyntax.setup
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   373
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   374
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   375
  "Numeral0 \<equiv> number_of Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   376
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   377
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   378
  "Numeral1 \<equiv> number_of (Bit1 Pls)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   379
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   380
lemma Let_number_of [simp]: "Let (number_of v) f = f (number_of v)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   381
  -- {* Unfold all @{text let}s involving constants *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   382
  unfolding Let_def ..
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   383
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   384
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   385
  succ :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   386
  [code del]: "succ k = k + 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   387
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   388
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   389
  pred :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   390
  [code del]: "pred k = k - 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   391
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   392
lemmas
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   393
  max_number_of [simp] = max_def
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   394
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   395
and
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   396
  min_number_of [simp] = min_def 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   397
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   398
  -- {* unfolding @{text minx} and @{text max} on numerals *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   399
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   400
lemmas numeral_simps = 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   401
  succ_def pred_def Pls_def Min_def Bit0_def Bit1_def
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   402
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   403
text {* Removal of leading zeroes *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   404
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   405
lemma Bit0_Pls [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   406
  "Bit0 Pls = Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   407
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   408
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   409
lemma Bit1_Min [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   410
  "Bit1 Min = Min"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   411
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   412
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   413
lemmas normalize_bin_simps =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   414
  Bit0_Pls Bit1_Min
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   415
*)
601
81f40b8bde7b added "end" to each example theory
Christian Urban <urbanc@in.tum.de>
parents: 600
diff changeset
   416
81f40b8bde7b added "end" to each example theory
Christian Urban <urbanc@in.tum.de>
parents: 600
diff changeset
   417
end