Quot/Examples/IntEx2.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 10 Dec 2009 01:48:39 +0100
changeset 678 569f0e286400
parent 677 35fbace8d48d
parent 676 0668d218bfa5
child 679 fe64784b38c3
permissions -rw-r--r--
merged
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
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
     2
imports "../QuotMain" Nat Presburger
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
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
quotient 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
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
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
    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
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
    21
quotient_def
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
    22
  zero_int::"0 :: int"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
where
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
    24
  "(0::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
    25
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
    26
quotient_def
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
    27
  one_int::"1 :: int"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
where
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
    29
  "(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
    30
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
fun
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 :: "(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
    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
  "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
    35
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
    36
quotient_def
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
    37
  plus_int::"(op +) :: (int \<Rightarrow> int \<Rightarrow> int)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
where
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
    39
  "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
    40
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
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
    42
  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
    43
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
    44
  "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
    45
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
    46
quotient_def
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
    47
  uminus_int::"(uminus :: (int \<Rightarrow> int))"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
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
    49
  "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
    50
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
definition
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
    52
  minus_int_def [code del]:  "z - w = z + (-w::int)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
fun
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
    55
  times_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
    56
where
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
    57
  "times_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
    58
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
    59
quotient_def
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
    60
  times_int::"(op *) :: (int \<Rightarrow> int \<Rightarrow> int)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
where
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
    62
  "times_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
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
    64
(* PROBLEM: this should be called le_int and le_raw / or odd *)
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
fun
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
    66
  less_eq_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
    67
where
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
    68
  "less_eq_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
    69
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
    70
quotient_def
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
    71
  less_eq_int :: "(op \<le>) :: int \<Rightarrow> int \<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
    72
where
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
    73
  "less_eq_raw"
568
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
definition
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
    76
  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
    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
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
    79
  abs_int_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
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
    80
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
definition
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    82
  sgn_int_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
    83
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
instance ..
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
end
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
    88
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
    89
  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
    90
by auto
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
    92
lemma minus_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
    93
  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
    94
  by auto
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
    95
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    96
lemma times_raw_fst:
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    97
  assumes a: "x \<approx> z"
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    98
  shows "times_raw x y \<approx> times_raw z y"
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
    99
using a
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   100
apply(cases x, cases y, cases z)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   101
apply(auto simp add: times_raw.simps intrel.simps)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   102
apply(rename_tac u v w x y z)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   103
apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   104
apply(simp add: mult_ac)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   105
apply(simp add: add_mult_distrib [symmetric])
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   106
done
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   107
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   108
lemma times_raw_snd:
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   109
  assumes a: "x \<approx> z"
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   110
  shows "times_raw y x \<approx> times_raw y z"
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   111
using a
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   112
apply(cases x, cases y, cases z)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   113
apply(auto simp add: times_raw.simps intrel.simps)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   114
apply(rename_tac u v w x y z)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   115
apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   116
apply(simp add: mult_ac)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   117
apply(simp add: add_mult_distrib [symmetric])
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   118
done
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   119
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
   120
lemma times_raw_rsp[quot_respect]:
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
   121
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) times_raw times_raw"
672
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   122
apply(simp only: fun_rel.simps)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   123
apply(rule allI | rule impI)+
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   124
apply(rule equivp_transp[OF int_equivp])
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   125
apply(rule times_raw_fst)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   126
apply(assumption)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   127
apply(rule times_raw_snd)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   128
apply(assumption)
c63685837706 proved (with a lot of pain) that times_raw is respectful
Christian Urban <urbanc@in.tum.de>
parents: 663
diff changeset
   129
done
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
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
   131
lemma less_eq_raw_rsp[quot_respect]:
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
   132
  shows "(op \<approx> ===> op \<approx> ===> op =) less_eq_raw less_eq_raw"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   133
by auto
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   134
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
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
   136
  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
   137
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
   138
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
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
   140
  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
   141
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
   142
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
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
   144
  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
   145
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
   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 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
   148
  shows "plus_raw (uminus_raw i) i \<approx> (0, 0)"
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
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
   150
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
   151
lemma times_assoc_raw:
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
   152
  shows "times_raw (times_raw i j) k \<approx> times_raw i (times_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
   153
by (cases i, cases j, cases k) 
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   154
   (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
   155
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
   156
lemma times_sym_raw:
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
   157
  shows "times_raw i j \<approx> times_raw j i"
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   158
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
   159
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
   160
lemma times_one_raw:
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
   161
  shows "times_raw  (1, 0) i \<approx> i"
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 (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
   163
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
   164
lemma times_plus_comm_raw:
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
   165
  shows "times_raw (plus_raw i j) k \<approx> plus_raw (times_raw i k) (times_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
   166
by (cases i, cases j, cases k) 
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   167
   (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
   168
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
lemma one_zero_distinct:
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   170
  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
   171
  by simp
579
eac2662a21ec Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 570
diff changeset
   172
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   173
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
   174
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
   175
ML {* qconsts_lookup @{theory} @{term "op + :: int \<Rightarrow> int \<Rightarrow> int"} *}
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
ML {* dest_Type (snd (dest_Const @{term "0 :: int"})) *}
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
   177
ML {* @{term "0 :: int"} *}
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
568
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
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
   180
proof
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  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
   182
  show "(i + j) + k = i + (j + k)"
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   183
    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
   184
  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
   185
    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
   186
  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
   187
    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
   188
  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
   189
    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
   190
  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
   191
    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
   192
  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
   193
    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
   194
  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
   195
    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
   196
  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
   197
    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
   198
  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
   199
    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
   200
  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
   201
    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
   202
qed
0384e039b7f2 added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   204
lemma plus_raw_rsp_aux:
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   205
  assumes a: "a \<approx> b" "c \<approx> d"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   206
  shows "plus_raw a c \<approx> plus_raw b d"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   207
using a
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   208
by (cases a, cases b, cases c, cases d) 
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   209
   (simp)
674
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   210
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   211
lemma add:
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   212
     "(ABS_int (x,y)) + (ABS_int (u,v)) =
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   213
      (ABS_int (x + u, y + v))"
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   214
apply(simp add: plus_int_def)
674
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   215
apply(fold plus_raw.simps)
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   216
apply(rule Quotient_rel_abs[OF Quotient_int])
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   217
apply(rule plus_raw_rsp_aux)
674
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   218
apply(simp_all add: rep_abs_rsp_left[OF Quotient_int])
bb276771d85c Finished one proof in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 673
diff changeset
   219
done
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   220
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   221
lemma int_def: 
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   222
  shows "of_nat m = ABS_int (m, 0)"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   223
by (induct m) (simp_all add: zero_int_def one_int_def add)
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_antisym_raw:
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
   226
  shows "less_eq_raw i j \<Longrightarrow> less_eq_raw j i \<Longrightarrow> i \<approx> j"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   227
by (cases i, cases j) (simp)
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_refl_raw:
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
   230
  shows "less_eq_raw i i"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   231
by (cases i) (simp)
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_trans_raw:
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
   234
  shows "less_eq_raw i j \<Longrightarrow> less_eq_raw j k \<Longrightarrow> less_eq_raw i k"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   235
by (cases i, cases j, cases k) (simp)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   236
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   237
lemma le_cases_raw:
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
   238
  shows "less_eq_raw i j \<or> less_eq_raw j i"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   239
by (cases i, cases j) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   240
   (simp add: linorder_linear)
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   241
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   242
instance int :: linorder
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   243
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   244
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   245
  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
   246
    by (lifting le_antisym_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   247
  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
   248
    by (auto simp add: less_int_def dest: antisym) 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   249
  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
   250
    by (lifting le_refl_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   251
  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
   252
    by (lifting le_trans_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   253
  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
   254
    by (lifting le_cases_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   255
qed
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
instantiation int :: distrib_lattice
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   258
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   259
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   260
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   261
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
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
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   264
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
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
instance
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   267
  by intro_classes
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   268
    (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
   269
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   270
end
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   271
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   272
lemma le_plus_raw:
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
   273
  shows "less_eq_raw i j \<Longrightarrow> less_eq_raw (plus_raw k i) (plus_raw k j)"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   274
by (cases i, cases j, cases k) (simp)
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
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   277
instance int :: pordered_cancel_ab_semigroup_add
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   278
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   279
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   280
  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
   281
    by (lifting le_plus_raw)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   282
qed
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   283
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   284
abbreviation
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   285
  "less_raw i j \<equiv> less_eq_raw i j \<and> \<not>(i \<approx> j)"
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   286
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   287
lemma zmult_zless_mono2_lemma:
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   288
  fixes i j::int
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   289
  and   k::nat
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   290
  shows "i < j \<Longrightarrow> 0 < k \<Longrightarrow> of_nat k * i < of_nat k * j"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   291
apply(induct "k")
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   292
apply(simp)
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   293
apply(case_tac "k = 0")
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   294
apply(simp_all add: left_distrib add_strict_mono)
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   295
done
673
217db3103f6a slightly more on IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 672
diff changeset
   296
676
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   297
lemma int_induct_raw:
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   298
  assumes a: "P (0::nat, 0)"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   299
  and     b: "\<And>i. P i \<Longrightarrow> P (plus_raw i (1,0))"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   300
  and     c: "\<And>i. P i \<Longrightarrow> P (plus_raw i (minus_raw (1,0)))"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   301
  shows      "P x"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   302
apply(case_tac x) apply(simp)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   303
apply(rule_tac x="b" in spec)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   304
apply(rule_tac Nat.induct)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   305
apply(rule allI)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   306
apply(rule_tac Nat.induct)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   307
using a b c apply(auto)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   308
done
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   309
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   310
lemma int_induct:
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   311
  assumes a: "P (0::int)"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   312
  and     b: "\<And>i. P i \<Longrightarrow> P (i + 1)"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   313
  and     c: "\<And>i. P i \<Longrightarrow> P (i + (- 1))"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   314
  shows      "P x"
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   315
using a b c by (lifting int_induct_raw)
0668d218bfa5 Lifted some kind of induction.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 675
diff changeset
   316
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   317
lemma zero_le_imp_eq_int: 
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   318
  fixes k::int
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   319
  shows "0 < k \<Longrightarrow> \<exists>n > 0. k = of_nat n"
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   320
sorry
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   321
675
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   322
lemma zmult_zless_mono2: 
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   323
  fixes i j k::int
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   324
  assumes a: "i < j" "0 < k"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   325
  shows "k * i < k * j"
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   326
using a
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   327
apply(drule_tac zero_le_imp_eq_int)
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   328
apply(auto simp add: zmult_zless_mono2_lemma)
94d6d29459c9 more proofs in IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 674
diff changeset
   329
done
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   330
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   331
text{*The integers form an ordered integral domain*}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   332
instance int :: ordered_idom
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   333
proof
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   334
  fix i j k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   335
  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
   336
    by (rule zmult_zless_mono2)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   337
  show "\<bar>i\<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
   338
    by (simp only: abs_int_def)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   339
  show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
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
   340
    by (simp only: sgn_int_def)
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   341
qed
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
instance int :: lordered_ring
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   344
proof  
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   345
  fix k :: int
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   346
  show "abs k = sup k (- 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
   347
    by (auto simp add: sup_int_def abs_int_def less_minus_self_iff [symmetric])
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   348
qed
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
lemmas int_distrib =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   351
  left_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   352
  right_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   353
  left_diff_distrib [of "z1::int" "z2" "w", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   354
  right_diff_distrib [of "w::int" "z1" "z2", standard]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   355
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   356
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   357
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
   358
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   359
(*
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   360
context ring_1
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   361
begin
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   362
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   363
 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   364
definition 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   365
  of_int :: "int \<Rightarrow> 'a" 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   366
where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   367
  "of_int 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   368
*)
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
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   371
subsection {* Binary representation *}
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
text {*
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   374
  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
   375
  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
   376
  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
   377
  int_of_binary}, for the numerical interpretation.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   378
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   379
  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
   380
  even if m is negative;
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   381
  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
   382
  @{text "-5 = (-3)*2 + 1"}.
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
  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
   385
  "An Efficient Representation of Arithmetic for Term Rewriting" by
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   386
  Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   387
  Springer LNCS 488 (240-251), 1991.
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   388
*}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   389
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   390
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
   391
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   392
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   393
  Pls :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   394
  [code del]: "Pls = 0"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   395
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   396
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   397
  Min :: int where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   398
  [code del]: "Min = - 1"
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
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   401
  Bit0 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   402
  [code del]: "Bit0 k = k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   403
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   404
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   405
  Bit1 :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   406
  [code del]: "Bit1 k = 1 + k + k"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   407
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   408
class number = -- {* for numeric types: nat, int, real, \dots *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   409
  fixes number_of :: "int \<Rightarrow> 'a"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   410
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   411
(*use "~~/src/HOL/Tools/numeral.ML"
570
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
syntax
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   414
  "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   415
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   416
use "~~/src/HOL/Tools/numeral_syntax.ML"
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   417
570
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   418
setup NumeralSyntax.setup
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   419
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   420
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   421
  "Numeral0 \<equiv> number_of Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   422
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   423
abbreviation
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   424
  "Numeral1 \<equiv> number_of (Bit1 Pls)"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   425
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   426
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
   427
  -- {* Unfold all @{text let}s involving constants *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   428
  unfolding Let_def ..
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   429
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   430
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   431
  succ :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   432
  [code del]: "succ k = k + 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   433
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   434
definition
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   435
  pred :: "int \<Rightarrow> int" where
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   436
  [code del]: "pred k = k - 1"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   437
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   438
lemmas
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   439
  max_number_of [simp] = max_def
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   440
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   441
and
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   442
  min_number_of [simp] = min_def 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   443
    [of "number_of u" "number_of v", standard, simp]
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   444
  -- {* unfolding @{text minx} and @{text max} on numerals *}
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   445
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   446
lemmas numeral_simps = 
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   447
  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
   448
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   449
text {* Removal of leading zeroes *}
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
lemma Bit0_Pls [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   452
  "Bit0 Pls = Pls"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   453
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   454
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   455
lemma Bit1_Min [simp, code_post]:
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   456
  "Bit1 Min = Min"
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   457
  unfolding numeral_simps by simp
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   458
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   459
lemmas normalize_bin_simps =
6a031829319a added more to IntEx2
Christian Urban <urbanc@in.tum.de>
parents: 568
diff changeset
   460
  Bit0_Pls Bit1_Min
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
   461
*)
601
81f40b8bde7b added "end" to each example theory
Christian Urban <urbanc@in.tum.de>
parents: 600
diff changeset
   462
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
   463
end