Attic/Quot/Examples/IntEx2.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 23 Apr 2010 10:21:34 +0200
changeset 1939 19f296e757c5
parent 1260 9df6144e281b
child 1974 13298f4b212b
permissions -rw-r--r--
Minor cleaning of IntEx
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
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 913
diff changeset
     2
imports "../Quotient" "../Quotient_Product" Nat
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
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  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
    11
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  "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
    13
766
df053507edba renamed "quotient" command to "quotient_type"; needs new keyword file to be installed
Christian Urban <urbanc@in.tum.de>
parents: 719
diff changeset
    14
quotient_type int = "nat \<times> nat" / intrel
677
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
    15
  unfolding equivp_def
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
    16
  by (auto simp add: mem_def expand_fun_eq)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
715
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents: 711
diff changeset
    18
instantiation int :: "{zero, one, plus, uminus, minus, times, ord, abs, sgn}"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
begin
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
    21
ML {* @{term "0 \<Colon> int"} *}
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    23
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    24
  "0 \<Colon> int" is "(0\<Colon>nat, 0\<Colon>nat)"
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 692
diff changeset
    25
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    26
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    27
  "1 \<Colon> int" is "(1\<Colon>nat, 0\<Colon>nat)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
fun
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  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
    31
where
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  "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
    33
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    34
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    35
  "(op +) \<Colon> (int \<Rightarrow> int \<Rightarrow> int)" is "plus_raw"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
fun
677
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
    38
  uminus_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
where
677
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
    40
  "uminus_raw (x, y) = (y, x)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    42
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    43
  "(uminus \<Colon> (int \<Rightarrow> int))" is "uminus_raw"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
definition
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
    46
  minus_int_def [code del]:  "z - w = z + (-w\<Colon>int)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
fun
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    49
  mult_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
where
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    51
  "mult_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    53
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    54
  mult_int_def: "(op *) :: (int \<Rightarrow> int \<Rightarrow> int)" is "mult_raw"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
fun
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    57
  le_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
where
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    59
  "le_raw (x, y) (u, v) = (x+v \<le> u+y)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    61
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
    62
  le_int_def: "(op \<le>) :: int \<Rightarrow> int \<Rightarrow> bool" is "le_raw"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
definition
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
    65
  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
    66
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
definition
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
    68
  zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
    69
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
definition
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
    71
  zsgn_def: "sgn (i\<Colon>int) = (if i = 0 then 0 else if 0 < i then 1 else - 1)"
568
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
instance ..
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
end
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
    77
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
    78
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) plus_raw plus_raw"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    79
  by auto
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
691
cc3c55f56116 Removed 'Presburger' as it introduces int & other minor cleaning in Int2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 682
diff changeset
    81
lemma uminus_raw_rsp[quot_respect]:
677
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
    82
  shows "(op \<approx> ===> op \<approx>) uminus_raw uminus_raw"
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
    83
  by auto
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
    84
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    85
lemma mult_raw_fst:
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    86
  assumes a: "x \<approx> z"
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    87
  shows "mult_raw x y \<approx> mult_raw z y"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    88
  using a
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    89
  apply(cases x, cases y, cases z)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    90
  apply(auto simp add: mult_raw.simps intrel.simps)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    91
  apply(rename_tac u v w x y z)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    92
  apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    93
  apply(simp add: mult_ac)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    94
  apply(simp add: add_mult_distrib [symmetric])
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
    95
  done
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    96
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    97
lemma mult_raw_snd:
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    98
  assumes a: "x \<approx> z"
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    99
  shows "mult_raw y x \<approx> mult_raw y z"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   100
  using a
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   101
  apply(cases x, cases y, cases z)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   102
  apply(auto simp add: mult_raw.simps intrel.simps)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   103
  apply(rename_tac u v w x y z)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   104
  apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   105
  apply(simp add: mult_ac)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   106
  apply(simp add: add_mult_distrib [symmetric])
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   107
  done
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   108
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   109
lemma mult_raw_rsp[quot_respect]:
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   110
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) mult_raw mult_raw"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   111
  apply(simp only: fun_rel_def)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   112
  apply(rule allI | rule impI)+
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   113
  apply(rule equivp_transp[OF int_equivp])
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   114
  apply(rule mult_raw_fst)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   115
  apply(assumption)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   116
  apply(rule mult_raw_snd)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   117
  apply(assumption)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   118
  done
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   120
lemma le_raw_rsp[quot_respect]:
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   121
  shows "(op \<approx> ===> op \<approx> ===> op =) le_raw le_raw"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   122
  by auto
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   123
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
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
   125
  shows "plus_raw (plus_raw i j) k \<approx> plus_raw i (plus_raw j k)"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   126
  by (cases i, cases j, cases k) (simp)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
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
   129
  shows "plus_raw i j \<approx> plus_raw j i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   130
  by (cases i, cases j) (simp)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
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
   133
  shows "plus_raw  (0, 0) i \<approx> i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   134
  by (cases i) (simp)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
lemma plus_minus_zero_raw:
677
35fbace8d48d naming in this file cannot be made to agree to the original (PROBLEM?)
Christian Urban <urbanc@in.tum.de>
parents: 675
diff changeset
   137
  shows "plus_raw (uminus_raw i) i \<approx> (0, 0)"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   138
  by (cases i) (simp)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   140
lemma times_assoc_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   141
  shows "mult_raw (mult_raw i j) k \<approx> mult_raw i (mult_raw j k)"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   142
  by (cases i, cases j, cases k) 
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   143
     (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
   144
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   145
lemma times_sym_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   146
  shows "mult_raw i j \<approx> mult_raw j i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   147
  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
   148
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   149
lemma times_one_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   150
  shows "mult_raw  (1, 0) i \<approx> i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   151
  by (cases i) (simp)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   153
lemma times_plus_comm_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   154
  shows "mult_raw (plus_raw i j) k \<approx> plus_raw (mult_raw i k) (mult_raw j k)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
by (cases i, cases j, cases k) 
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   156
   (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
   157
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
lemma one_zero_distinct:
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   159
  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
   160
  by simp
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   161
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   162
text{* The integers form a @{text comm_ring_1}*}
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
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
   165
proof
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  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
   167
  show "(i + j) + k = i + (j + k)"
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   168
    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
   169
  show "i + j = j + i" 
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   170
    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
   171
  show "0 + i = (i::int)"
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_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
   173
  show "- i + i = 0"
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   174
    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
   175
  show "i - j = i + - j"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   176
    by (simp add: minus_int_def)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
  show "(i * j) * k = i * (j * k)"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   178
    by (lifting times_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
   179
  show "i * j = j * i"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   180
    by (lifting times_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
   181
  show "1 * i = i"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   182
    by (lifting times_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
   183
  show "(i + j) * k = i * k + j * k"
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   184
    by (lifting times_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
   185
  show "0 \<noteq> (1::int)"
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 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
   187
qed
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   189
lemma plus_raw_rsp_aux:
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   190
  assumes a: "a \<approx> b" "c \<approx> d"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   191
  shows "plus_raw a c \<approx> plus_raw b d"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   192
  using a
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   193
  by (cases a, cases b, cases c, cases d)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   194
     (simp)
674
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   195
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   196
lemma add:
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   197
  "(abs_int (x,y)) + (abs_int (u,v)) =
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   198
   (abs_int (x + u, y + v))"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   199
  apply(simp add: plus_int_def id_simps)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   200
  apply(fold plus_raw.simps)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   201
  apply(rule Quotient_rel_abs[OF Quotient_int])
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   202
  apply(rule plus_raw_rsp_aux)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   203
  apply(simp_all add: rep_abs_rsp_left[OF Quotient_int])
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   204
  done
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   205
682
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   206
definition int_of_nat_raw: 
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   207
  "int_of_nat_raw m = (m :: nat, 0 :: nat)"
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   208
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
   209
quotient_definition
1139
c4001cda9da3 renamed 'as' to 'is' everywhere.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1136
diff changeset
   210
  "int_of_nat :: nat \<Rightarrow> int" is "int_of_nat_raw"
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   211
682
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   212
lemma[quot_respect]: 
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   213
  shows "(op = ===> op \<approx>) int_of_nat_raw int_of_nat_raw"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   214
  by (simp add: equivp_reflp[OF int_equivp])
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   215
692
c9231c2903bc Moved 'int_induct' to IntEx to keep IntEx2 being just theory of integers in order.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 691
diff changeset
   216
lemma int_of_nat:
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   217
  shows "of_nat m = int_of_nat m"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   218
  by (induct m)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   219
    (simp_all add: zero_int_def one_int_def int_of_nat_def int_of_nat_raw add)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   220
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   221
lemma le_antisym_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   222
  shows "le_raw i j \<Longrightarrow> le_raw j i \<Longrightarrow> i \<approx> j"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   223
  by (cases i, cases j) (simp)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   224
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   225
lemma le_refl_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   226
  shows "le_raw i i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   227
  by (cases i) (simp)
570
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
lemma le_trans_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   230
  shows "le_raw i j \<Longrightarrow> le_raw j k \<Longrightarrow> le_raw i k"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   231
  by (cases i, cases j, cases k) (simp)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   232
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   233
lemma le_cases_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   234
  shows "le_raw i j \<or> le_raw j i"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   235
  by (cases i, cases j)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   236
     (simp add: linorder_linear)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   237
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   238
instance int :: linorder
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   239
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   240
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   241
  show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
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_antisym_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   243
  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
   244
    by (auto simp add: less_int_def dest: antisym) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   245
  show "i \<le> i"
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   246
    by (lifting le_refl_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   247
  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   248
    by (lifting le_trans_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   249
  show "i \<le> j \<or> j \<le> i"
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   250
    by (lifting le_cases_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   251
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   252
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   253
instantiation int :: distrib_lattice
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   254
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   255
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   256
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   257
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   258
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   259
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   260
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   261
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   262
instance
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   263
  by intro_classes
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   264
    (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
   265
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   266
end
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
lemma le_plus_raw:
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   269
  shows "le_raw i j \<Longrightarrow> le_raw (plus_raw k i) (plus_raw k j)"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   270
  by (cases i, cases j, cases k) (simp)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   271
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 913
diff changeset
   272
instance int :: ordered_cancel_ab_semigroup_add
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   273
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   274
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   275
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
654
02fd9de9d45e tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   276
    by (lifting le_plus_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   277
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   278
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   279
abbreviation
710
add8f7f311cd Renamed theorems in IntEx2 to conform to names in Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
   280
  "less_raw i j \<equiv> le_raw i j \<and> \<not>(i \<approx> j)"
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   281
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   282
lemma zmult_zless_mono2_lemma:
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   283
  fixes i j::int
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   284
  and   k::nat
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   285
  shows "i < j \<Longrightarrow> 0 < k \<Longrightarrow> of_nat k * i < of_nat k * j"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   286
  apply(induct "k")
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   287
  apply(simp)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   288
  apply(case_tac "k = 0")
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   289
  apply(simp_all add: left_distrib add_strict_mono)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   290
  done
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   291
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   292
lemma zero_le_imp_eq_int_raw:
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   293
  fixes k::"(nat \<times> nat)"
682
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   294
  shows "less_raw (0, 0) k \<Longrightarrow> (\<exists>n > 0. k \<approx> int_of_nat_raw n)"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   295
  apply(cases k)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   296
  apply(simp add:int_of_nat_raw)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   297
  apply(auto)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   298
  apply(rule_tac i="b" and j="a" in less_Suc_induct)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   299
  apply(auto)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   300
  done
679
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   301
fe64784b38c3 With int_of_nat as a quotient_def, lemmas about it can be easily lifted.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 678
diff changeset
   302
lemma zero_le_imp_eq_int:
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   303
  fixes k::int
692
c9231c2903bc Moved 'int_induct' to IntEx to keep IntEx2 being just theory of integers in order.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 691
diff changeset
   304
  shows "0 < k \<Longrightarrow> \<exists>n > 0. k = of_nat n"
c9231c2903bc Moved 'int_induct' to IntEx to keep IntEx2 being just theory of integers in order.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 691
diff changeset
   305
  unfolding less_int_def int_of_nat
682
Christian Urban <urbanc@in.tum.de>
parents: 679
diff changeset
   306
  by (lifting zero_le_imp_eq_int_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   307
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   308
lemma zmult_zless_mono2: 
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   309
  fixes i j k::int
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   310
  assumes a: "i < j" "0 < k"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   311
  shows "k * i < k * j"
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   312
  using a
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   313
  by (drule_tac zero_le_imp_eq_int) (auto simp add: zmult_zless_mono2_lemma)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   314
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   315
text{*The integers form an ordered integral domain*}
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 913
diff changeset
   316
instance int :: linordered_idom
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   317
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   318
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   319
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   320
    by (rule zmult_zless_mono2)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   321
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
   322
    by (simp only: zabs_def)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   323
  show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
711
810d59a3d9b0 More theorem renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 710
diff changeset
   324
    by (simp only: zsgn_def)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   325
qed
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
lemmas int_distrib =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   328
  left_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   329
  right_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   330
  left_diff_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   331
  right_diff_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   332
1939
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   333
lemma int_induct_raw:
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   334
  assumes a: "P (0::nat, 0)"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   335
  and     b: "\<And>i. P i \<Longrightarrow> P (plus_raw i (1, 0))"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   336
  and     c: "\<And>i. P i \<Longrightarrow> P (plus_raw i (uminus_raw (1, 0)))"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   337
  shows      "P x"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   338
proof (cases x, clarify)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   339
  fix a b
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   340
  show "P (a, b)"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   341
  proof (induct a arbitrary: b rule: Nat.induct)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   342
    case zero
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   343
    show "P (0, b)" using assms by (induct b) auto
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   344
  next
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   345
    case (Suc n)
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   346
    then show ?case using assms by auto
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   347
  qed
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   348
qed
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   349
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   350
lemma int_induct:
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   351
  fixes x :: int
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   352
  assumes a: "P 0"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   353
  and     b: "\<And>i. P i \<Longrightarrow> P (i + 1)"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   354
  and     c: "\<And>i. P i \<Longrightarrow> P (i - 1)"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   355
  shows      "P x"
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   356
  using a b c unfolding minus_int_def
19f296e757c5 Minor cleaning of IntEx
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1260
diff changeset
   357
  by (lifting int_induct_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   358
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   359
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
   360
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
context ring_1
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   363
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   364
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   365
 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   366
definition 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   367
  of_int :: "int \<Rightarrow> 'a" 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   368
where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   369
  "of_int 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   370
*)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   371
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   372
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   373
subsection {* Binary representation *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   374
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   375
text {*
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   376
  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
   377
  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
   378
  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
   379
  int_of_binary}, for the numerical interpretation.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   380
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   381
  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
   382
  even if m is negative;
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   383
  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
   384
  @{text "-5 = (-3)*2 + 1"}.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   385
  
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   386
  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
   387
  "An Efficient Representation of Arithmetic for Term Rewriting" by
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   388
  Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   389
  Springer LNCS 488 (240-251), 1991.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   390
*}
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
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
   393
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   394
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   395
  Pls :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   396
  [code del]: "Pls = 0"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   397
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   398
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   399
  Min :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   400
  [code del]: "Min = - 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   401
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   402
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   403
  Bit0 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   404
  [code del]: "Bit0 k = k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   405
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   406
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   407
  Bit1 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   408
  [code del]: "Bit1 k = 1 + k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   409
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   410
class number = -- {* for numeric types: nat, int, real, \dots *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   411
  fixes number_of :: "int \<Rightarrow> 'a"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   412
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   413
(*use "~~/src/HOL/Tools/numeral.ML"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   414
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   415
syntax
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   416
  "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   417
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   418
use "~~/src/HOL/Tools/numeral_syntax.ML"
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   419
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   420
setup NumeralSyntax.setup
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   421
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   422
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   423
  "Numeral0 \<equiv> number_of Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   424
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   425
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   426
  "Numeral1 \<equiv> number_of (Bit1 Pls)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   427
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   428
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
   429
  -- {* Unfold all @{text let}s involving constants *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   430
  unfolding Let_def ..
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   431
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   432
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   433
  succ :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   434
  [code del]: "succ k = k + 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   435
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   436
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   437
  pred :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   438
  [code del]: "pred k = k - 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   439
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   440
lemmas
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   441
  max_number_of [simp] = max_def
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   442
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   443
and
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   444
  min_number_of [simp] = min_def 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   445
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   446
  -- {* unfolding @{text minx} and @{text max} on numerals *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   447
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   448
lemmas numeral_simps = 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   449
  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
   450
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   451
text {* Removal of leading zeroes *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   452
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   453
lemma Bit0_Pls [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   454
  "Bit0 Pls = Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   455
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   456
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   457
lemma Bit1_Min [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   458
  "Bit1 Min = Min"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   459
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   460
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   461
lemmas normalize_bin_simps =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   462
  Bit0_Pls Bit1_Min
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   463
*)
601
81f40b8bde7b added "end" to each example theory
Christian Urban <urbanc@in.tum.de>
parents: 600
diff changeset
   464
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 654
diff changeset
   465
end