src/HOL/Quotient_Examples/Quotient_Int.thy
author paulson <lp15@cam.ac.uk>
Tue, 18 Mar 2025 18:11:58 +0000
changeset 82302 19ada02fa486
parent 80914 d97fdabd9e2b
permissions -rw-r--r--
Tidied old proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
(*  Title:      HOL/Quotient_Examples/Quotient_Int.thy
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
    Author:     Cezary Kaliszyk
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
    Author:     Christian Urban
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
41467
8fc17c5e11c0 tuned headers;
wenzelm
parents: 41413
diff changeset
     5
Integers based on Quotients, based on an older version by Larry
8fc17c5e11c0 tuned headers;
wenzelm
parents: 41413
diff changeset
     6
Paulson.
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
*)
41467
8fc17c5e11c0 tuned headers;
wenzelm
parents: 41413
diff changeset
     8
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
theory Quotient_Int
68660
4ce18f389f53 slightly more canonical imports
haftmann
parents: 67399
diff changeset
    10
imports "HOL-Library.Quotient_Product"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
begin
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
fun
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 69597
diff changeset
    14
  intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" (infix \<open>\<approx>\<close> 50)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
where
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
  "intrel (x, y) (u, v) = (x + v = u + y)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
quotient_type int = "nat \<times> nat" / intrel
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    19
  by (auto simp add: equivp_def fun_eq_iff)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
instantiation int :: "{zero, one, plus, uminus, minus, times, ord, abs, sgn}"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    22
begin
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
quotient_definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    25
  "0 :: int" is "(0::nat, 0::nat)" done
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
quotient_definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    28
  "1 :: int" is "(1::nat, 0::nat)" done
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
fun
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
  plus_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
where
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
  "plus_int_raw (x, y) (u, v) = (x + u, y + v)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
quotient_definition
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66453
diff changeset
    36
  "(+) :: (int \<Rightarrow> int \<Rightarrow> int)" is "plus_int_raw" by auto
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
fun
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
  uminus_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
where
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
  "uminus_int_raw (x, y) = (y, x)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
quotient_definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    44
  "(uminus :: (int \<Rightarrow> int))" is "uminus_int_raw" by auto
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    47
  minus_int_def:  "z - w = z + (-w::int)"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
fun
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
  times_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
where
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  "times_int_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    54
lemma times_int_raw:
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    55
  assumes "x \<approx> z"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    56
  shows "times_int_raw x y \<approx> times_int_raw z y \<and> times_int_raw y x \<approx> times_int_raw y z"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    57
proof (cases x, cases y, cases z)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    58
  fix a a' b b' c c'
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    59
  assume \<section>: "x = (a, a')" "y = (b, b')" "z = (c, c')"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    60
  then obtain "a*b + c'*b = c*b + a'*b" "a*b' + c'*b' = c*b' + a'*b'"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    61
    by (metis add_mult_distrib assms intrel.simps)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    62
  then show ?thesis
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    63
    by (simp add: \<section> algebra_simps)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    64
qed
47092
fa3538d6004b fix Quotient_Examples
kuncar
parents: 45605
diff changeset
    65
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
quotient_definition
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 68660
diff changeset
    67
  "((*)) :: (int \<Rightarrow> int \<Rightarrow> int)" is "times_int_raw"
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
    68
  by (metis Quotient_Int.int.abs_eq_iff times_int_raw)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
fun
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
  le_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
where
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
  "le_int_raw (x, y) (u, v) = (x+v \<le> u+y)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
quotient_definition
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66453
diff changeset
    76
  le_int_def: "(\<le>) :: int \<Rightarrow> int \<Rightarrow> bool" is "le_int_raw" by auto
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    79
  less_int_def: "(z::int) < w = (z \<le> w \<and> z \<noteq> w)"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    82
  zabs_def: "\<bar>i::int\<bar> = (if i < 0 then - i else i)"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
    85
  zsgn_def: "sgn (i::int) = (if i = 0 then 0 else if 0 < i then 1 else - 1)"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
instance ..
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
end
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 61169
diff changeset
    92
text\<open>The integers form a \<open>comm_ring_1\<close>\<close>
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
instance int :: comm_ring_1
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
proof
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
  fix i j k :: int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
  show "(i + j) + k = i + (j + k)"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
    98
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
  show "i + j = j + i"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   100
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  show "0 + i = (i::int)"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   102
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
  show "- i + i = 0"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   104
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
  show "i - j = i + - j"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
    by (simp add: minus_int_def)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
  show "(i * j) * k = i * (j * k)"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   108
    by (descending) (auto simp add: algebra_simps)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
  show "i * j = j * i"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   110
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
  show "1 * i = i"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   112
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
  show "(i + j) * k = i * k + j * k"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   114
    by (descending) (auto simp add: algebra_simps)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
  show "0 \<noteq> (1::int)"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   116
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
qed
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
lemma plus_int_raw_rsp_aux:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
  assumes a: "a \<approx> b" "c \<approx> d"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
  shows "plus_int_raw a c \<approx> plus_int_raw b d"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
  using a
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   123
  by (cases a, cases b, cases c, cases d)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   124
     (simp)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
lemma add_abs_int:
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   127
  "(abs_int (x,y)) + (abs_int (u,v)) = (abs_int (x + u, y + v))"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   128
proof -
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   129
  have "abs_int (plus_int_raw (rep_int (abs_int (x, y))) (rep_int (abs_int (u, v)))) 
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   130
     = abs_int (plus_int_raw (x, y) (u, v))"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   131
  by (meson Quotient3_abs_rep Quotient3_int int.abs_eq_iff plus_int_raw_rsp_aux)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   132
  then show ?thesis
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   133
    by (simp add: Quotient_Int.plus_int_def)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   134
qed
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
definition int_of_nat_raw:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
  "int_of_nat_raw m = (m :: nat, 0 :: nat)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
quotient_definition
47092
fa3538d6004b fix Quotient_Examples
kuncar
parents: 45605
diff changeset
   140
  "int_of_nat :: nat \<Rightarrow> int" is "int_of_nat_raw" done
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
lemma int_of_nat:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
  shows "of_nat m = int_of_nat m"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
  by (induct m)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
     (simp_all add: zero_int_def one_int_def int_of_nat_def int_of_nat_raw add_abs_int)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
instance int :: linorder
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
proof
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
  fix i j k :: int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
  show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   151
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   152
  show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
    by (auto simp add: less_int_def dest: antisym)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
  show "i \<le> i"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   155
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   157
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
  show "i \<le> j \<or> j \<le> i"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   159
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
qed
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
instantiation int :: distrib_lattice
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
begin
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
   166
  "(inf :: int \<Rightarrow> int \<Rightarrow> int) = min"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   167
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
definition
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
   169
  "(sup :: int \<Rightarrow> int \<Rightarrow> int) = max"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
instance
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 61076
diff changeset
   172
  by standard (auto simp add: inf_int_def sup_int_def max_min_distrib2)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
end
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
instance int :: ordered_cancel_ab_semigroup_add
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
proof
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
  fix i j k :: int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   180
    by (descending) (auto)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
qed
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
abbreviation
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
  "less_int_raw i j \<equiv> le_int_raw i j \<and> \<not>(i \<approx> j)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
lemma zmult_zless_mono2_lemma:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
  fixes i j::int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
  and   k::nat
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
  shows "i < j \<Longrightarrow> 0 < k \<Longrightarrow> of_nat k * i < of_nat k * j"
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   190
proof (induction "k")
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   191
  case 0
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   192
  then show ?case by simp
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   193
next
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   194
  case (Suc k)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   195
  then show ?case 
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   196
    by (cases "k = 0"; simp add: distrib_right add_strict_mono)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   197
qed
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
lemma zero_le_imp_eq_int_raw:
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   200
  assumes "less_int_raw (0, 0) u"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   201
  shows "(\<exists>n > 0. u \<approx> int_of_nat_raw n)"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   202
proof -
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   203
  have "\<And>a b::nat. \<lbrakk>b \<le> a; b \<noteq> a\<rbrakk> \<Longrightarrow> \<exists>n>0. a = n + b"
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   204
    by (metis add.comm_neutral add.commute gr0I le_iff_add)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   205
  with assms show ?thesis
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   206
    by (cases u) (simp add:int_of_nat_raw)
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   207
qed
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
lemma zero_le_imp_eq_int:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
  fixes k::int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
  shows "0 < k \<Longrightarrow> \<exists>n > 0. k = of_nat n"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   212
  unfolding less_int_def int_of_nat
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   213
  by (descending) (rule zero_le_imp_eq_int_raw)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
lemma zmult_zless_mono2:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
  fixes i j k::int
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   217
  assumes "i < j" "0 < k"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
  shows "k * i < k * j"
82302
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   219
  using assms zmult_zless_mono2_lemma [of i j]
19ada02fa486 Tidied old proofs
paulson <lp15@cam.ac.uk>
parents: 80914
diff changeset
   220
  using Quotient_Int.zero_le_imp_eq_int by blast
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 61169
diff changeset
   222
text\<open>The integers form an ordered integral domain\<close>
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
instance int :: linordered_idom
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
proof
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
  fix i j k :: int
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
    by (rule zmult_zless_mono2)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
    by (simp only: zabs_def)
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 57514
diff changeset
   231
  show "sgn (i::int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
    by (simp only: zsgn_def)
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
qed
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   234
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
lemmas int_distrib =
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 47308
diff changeset
   236
  distrib_right [of z1 z2 w]
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 47308
diff changeset
   237
  distrib_left [of w z1 z2]
45605
a89b4bc311a5 eliminated obsolete "standard";
wenzelm
parents: 41467
diff changeset
   238
  left_diff_distrib [of z1 z2 w]
a89b4bc311a5 eliminated obsolete "standard";
wenzelm
parents: 41467
diff changeset
   239
  right_diff_distrib [of w z1 z2]
a89b4bc311a5 eliminated obsolete "standard";
wenzelm
parents: 41467
diff changeset
   240
  minus_add_distrib[of z1 z2]
a89b4bc311a5 eliminated obsolete "standard";
wenzelm
parents: 41467
diff changeset
   241
  for z1 z2 w :: int
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
47304
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   243
lemma int_induct2:
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   244
  assumes "P 0 0"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   245
  and     "\<And>n m. P n m \<Longrightarrow> P (Suc n) m"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   246
  and     "\<And>n m. P n m \<Longrightarrow> P n (Suc m)"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   247
  shows   "P n m"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   248
using assms
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   249
by (induction_schema) (pat_completeness, lexicographic_order)
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   250
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
lemma int_induct:
47304
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   253
  fixes j :: int
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   254
  assumes a: "P 0"
47304
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   255
  and     b: "\<And>i::int. P i \<Longrightarrow> P (i + 1)"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   256
  and     c: "\<And>i::int. P i \<Longrightarrow> P (i - 1)"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   257
  shows      "P j"
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   258
using a b c 
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   259
unfolding minus_int_def
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   260
by (descending) (auto intro: int_induct2)
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   261
  
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   262
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
   263
text \<open>Magnitide of an Integer, as a Natural Number: \<^term>\<open>nat\<close>\<close>
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   264
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   265
definition
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   266
  "int_to_nat_raw \<equiv> \<lambda>(x, y).x - (y::nat)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   267
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   268
quotient_definition
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   269
  "int_to_nat::int \<Rightarrow> nat"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   270
is
47304
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   271
  "int_to_nat_raw" 
a0d97d919f01 tuned proofs
Christian Urban <urbanc@in.tum.de>
parents: 47092
diff changeset
   272
unfolding int_to_nat_raw_def by auto 
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   273
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   274
lemma nat_le_eq_zle:
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   275
  fixes w z::"int"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   276
  shows "0 < w \<or> 0 \<le> z \<Longrightarrow> (int_to_nat w \<le> int_to_nat z) = (w \<le> z)"
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   277
  unfolding less_int_def
37594
32ad67684ee7 cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents: 36524
diff changeset
   278
  by (descending) (auto simp add: int_to_nat_raw_def)
36524
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   279
3909002beca5 Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   280
end