src/HOL/Decision_Procs/Rat_Pair.thy
author wenzelm
Fri, 14 Feb 2014 22:03:48 +0100
changeset 55498 cf829d10d1d4
parent 54230 b1d955791529
child 56410 a14831ac3023
permissions -rw-r--r--
proper signature; removed dead code;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54220
0e6645622f22 more convenient place for a theory in solitariness
haftmann
parents: 50282
diff changeset
     1
(*  Title:      HOL/Decision_Procs/Rat_Pair.thy
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
     2
    Author:     Amine Chaieb
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
     3
*)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
     4
54220
0e6645622f22 more convenient place for a theory in solitariness
haftmann
parents: 50282
diff changeset
     5
header {* Rational numbers as pairs *}
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
     6
54220
0e6645622f22 more convenient place for a theory in solitariness
haftmann
parents: 50282
diff changeset
     7
theory Rat_Pair
36411
4cd87067791e canonical import
haftmann
parents: 36409
diff changeset
     8
imports Complex_Main
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
     9
begin
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    10
42463
f270e3e18be5 modernized specifications;
wenzelm
parents: 41528
diff changeset
    11
type_synonym Num = "int \<times> int"
25005
60e5516c7b06 replaced syntax/translations by abbreviation;
wenzelm
parents: 24197
diff changeset
    12
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    13
abbreviation Num0_syn :: Num  ("0\<^sub>N")
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    14
  where "0\<^sub>N \<equiv> (0, 0)"
25005
60e5516c7b06 replaced syntax/translations by abbreviation;
wenzelm
parents: 24197
diff changeset
    15
50282
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
    16
abbreviation Numi_syn :: "int \<Rightarrow> Num"  ("'((_)')\<^sub>N")
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
    17
  where "(i)\<^sub>N \<equiv> (i, 1)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    18
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    19
definition isnormNum :: "Num \<Rightarrow> bool" where
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
    20
  "isnormNum = (\<lambda>(a,b). (if a = 0 then b = 0 else b > 0 \<and> gcd a b = 1))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    21
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    22
definition normNum :: "Num \<Rightarrow> Num" where
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    23
  "normNum = (\<lambda>(a,b).
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    24
    (if a=0 \<or> b = 0 then (0,0) else
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    25
      (let g = gcd a b
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    26
       in if b > 0 then (a div g, b div g) else (- (a div g), - (b div g)))))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    27
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    28
declare gcd_dvd1_int[presburger] gcd_dvd2_int[presburger]
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    29
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    30
lemma normNum_isnormNum [simp]: "isnormNum (normNum x)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    31
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    32
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    33
  { assume "a=0 \<or> b = 0" hence ?thesis by (simp add: x normNum_def isnormNum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    34
  moreover
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    35
  { assume anz: "a \<noteq> 0" and bnz: "b \<noteq> 0"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
    36
    let ?g = "gcd a b"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    37
    let ?a' = "a div ?g"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    38
    let ?b' = "b div ?g"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
    39
    let ?g' = "gcd ?a' ?b'"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    40
    from anz bnz have "?g \<noteq> 0" by simp  with gcd_ge_0_int[of a b]
41528
276078f01ada eliminated global prems;
wenzelm
parents: 36411
diff changeset
    41
    have gpos: "?g > 0" by arith
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    42
    have gdvd: "?g dvd a" "?g dvd b" by arith+
47162
9d7d919b9fd8 remove redundant lemma
huffman
parents: 44780
diff changeset
    43
    from dvd_mult_div_cancel[OF gdvd(1)] dvd_mult_div_cancel[OF gdvd(2)] anz bnz
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    44
    have nz': "?a' \<noteq> 0" "?b' \<noteq> 0" by - (rule notI, simp)+
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    45
    from anz bnz have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by arith
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31706
diff changeset
    46
    from div_gcd_coprime_int[OF stupid] have gp1: "?g' = 1" .
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    47
    from bnz have "b < 0 \<or> b > 0" by arith
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    48
    moreover
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    49
    { assume b: "b > 0"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    50
      from b have "?b' \<ge> 0"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    51
        by (presburger add: pos_imp_zdiv_nonneg_iff[OF gpos])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    52
      with nz' have b': "?b' > 0" by arith
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    53
      from b b' anz bnz nz' gp1 have ?thesis
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    54
        by (simp add: x isnormNum_def normNum_def Let_def split_def) }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    55
    moreover {
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    56
      assume b: "b < 0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    57
      { assume b': "?b' \<ge> 0"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
    58
        from gpos have th: "?g \<ge> 0" by arith
47162
9d7d919b9fd8 remove redundant lemma
huffman
parents: 44780
diff changeset
    59
        from mult_nonneg_nonneg[OF th b'] dvd_mult_div_cancel[OF gdvd(2)]
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
    60
        have False using b by arith }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    61
      hence b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    62
      from anz bnz nz' b b' gp1 have ?thesis
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    63
        by (simp add: x isnormNum_def normNum_def Let_def split_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    64
    ultimately have ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    65
  }
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    66
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    67
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    68
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    69
text {* Arithmetic over Num *}
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    70
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    71
definition Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl "+\<^sub>N" 60) where
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    72
  "Nadd = (\<lambda>(a,b) (a',b'). if a = 0 \<or> b = 0 then normNum(a',b')
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    73
    else if a'=0 \<or> b' = 0 then normNum(a,b)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    74
    else normNum(a*b' + b*a', b*b'))"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    75
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    76
definition Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl "*\<^sub>N" 60) where
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    77
  "Nmul = (\<lambda>(a,b) (a',b'). let g = gcd (a*a') (b*b')
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    78
    in (a*a' div g, b*b' div g))"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    79
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    80
definition Nneg :: "Num \<Rightarrow> Num" ("~\<^sub>N")
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    81
  where "Nneg \<equiv> (\<lambda>(a,b). (-a,b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    82
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    83
definition Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl "-\<^sub>N" 60)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    84
  where "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    85
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    86
definition Ninv :: "Num \<Rightarrow> Num"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    87
  where "Ninv = (\<lambda>(a,b). if a < 0 then (-b, \<bar>a\<bar>) else (b,a))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    88
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    89
definition Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl "\<div>\<^sub>N" 60)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    90
  where "Ndiv = (\<lambda>a b. a *\<^sub>N Ninv b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    91
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    92
lemma Nneg_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (~\<^sub>N x)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    93
  by (simp add: isnormNum_def Nneg_def split_def)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    94
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    95
lemma Nadd_normN[simp]: "isnormNum (x +\<^sub>N y)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    96
  by (simp add: Nadd_def split_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    97
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    98
lemma Nsub_normN[simp]: "\<lbrakk> isnormNum y\<rbrakk> \<Longrightarrow> isnormNum (x -\<^sub>N y)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    99
  by (simp add: Nsub_def split_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   100
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   101
lemma Nmul_normN[simp]:
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   102
  assumes xn: "isnormNum x" and yn: "isnormNum y"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   103
  shows "isnormNum (x *\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   104
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   105
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   106
  obtain a' b' where y: "y = (a', b')" by (cases y)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   107
  { assume "a = 0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   108
    hence ?thesis using xn x y
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   109
      by (simp add: isnormNum_def Let_def Nmul_def split_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   110
  moreover
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   111
  { assume "a' = 0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   112
    hence ?thesis using yn x y
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   113
      by (simp add: isnormNum_def Let_def Nmul_def split_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   114
  moreover
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   115
  { assume a: "a \<noteq>0" and a': "a'\<noteq>0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   116
    hence bp: "b > 0" "b' > 0" using xn yn x y by (simp_all add: isnormNum_def)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   117
    from mult_pos_pos[OF bp] have "x *\<^sub>N y = normNum (a * a', b * b')"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   118
      using x y a a' bp by (simp add: Nmul_def Let_def split_def normNum_def)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   119
    hence ?thesis by simp }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   120
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   121
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   122
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   123
lemma Ninv_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (Ninv x)"
25005
60e5516c7b06 replaced syntax/translations by abbreviation;
wenzelm
parents: 24197
diff changeset
   124
  by (simp add: Ninv_def isnormNum_def split_def)
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31706
diff changeset
   125
    (cases "fst x = 0", auto simp add: gcd_commute_int)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   126
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   127
lemma isnormNum_int[simp]:
50282
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
   128
  "isnormNum 0\<^sub>N" "isnormNum ((1::int)\<^sub>N)" "i \<noteq> 0 \<Longrightarrow> isnormNum (i)\<^sub>N"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
   129
  by (simp_all add: isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   130
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   131
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   132
text {* Relations over Num *}
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   133
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   134
definition Nlt0:: "Num \<Rightarrow> bool"  ("0>\<^sub>N")
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   135
  where "Nlt0 = (\<lambda>(a,b). a < 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   136
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   137
definition Nle0:: "Num \<Rightarrow> bool"  ("0\<ge>\<^sub>N")
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   138
  where "Nle0 = (\<lambda>(a,b). a \<le> 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   139
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   140
definition Ngt0:: "Num \<Rightarrow> bool"  ("0<\<^sub>N")
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   141
  where "Ngt0 = (\<lambda>(a,b). a > 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   142
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   143
definition Nge0:: "Num \<Rightarrow> bool"  ("0\<le>\<^sub>N")
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   144
  where "Nge0 = (\<lambda>(a,b). a \<ge> 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   145
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   146
definition Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool"  (infix "<\<^sub>N" 55)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   147
  where "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   148
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   149
definition Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool"  (infix "\<le>\<^sub>N" 55)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   150
  where "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   151
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   152
definition "INum = (\<lambda>(a,b). of_int a / of_int b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   153
50282
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
   154
lemma INum_int [simp]: "INum (i)\<^sub>N = ((of_int i) ::'a::field)" "INum 0\<^sub>N = (0::'a::field)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   155
  by (simp_all add: INum_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   156
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   157
lemma isnormNum_unique[simp]:
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   158
  assumes na: "isnormNum x" and nb: "isnormNum y"
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   159
  shows "((INum x ::'a::{field_char_0, field_inverse_zero}) = INum y) = (x = y)" (is "?lhs = ?rhs")
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   160
proof
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   161
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   162
  obtain a' b' where y: "y = (a', b')" by (cases y)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   163
  assume H: ?lhs
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   164
  { assume "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0"
32456
341c83339aeb tuned the simp rules for Int involving insert and intervals.
nipkow
parents: 31967
diff changeset
   165
    hence ?rhs using na nb H
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   166
      by (simp add: x y INum_def split_def isnormNum_def split: split_if_asm) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   167
  moreover
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   168
  { assume az: "a \<noteq> 0" and bz: "b \<noteq> 0" and a'z: "a'\<noteq>0" and b'z: "b'\<noteq>0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   169
    from az bz a'z b'z na nb have pos: "b > 0" "b' > 0" by (simp_all add: x y isnormNum_def)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   170
    from H bz b'z have eq: "a * b' = a'*b"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   171
      by (simp add: x y INum_def eq_divide_eq divide_eq_eq of_int_mult[symmetric] del: of_int_mult)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   172
    from az a'z na nb have gcd1: "gcd a b = 1" "gcd b a = 1" "gcd a' b' = 1" "gcd b' a' = 1"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   173
      by (simp_all add: x y isnormNum_def add: gcd_commute_int)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   174
    from eq have raw_dvd: "a dvd a' * b" "b dvd b' * a" "a' dvd a * b'" "b' dvd b * a'"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   175
      apply -
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27567
diff changeset
   176
      apply algebra
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27567
diff changeset
   177
      apply algebra
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27567
diff changeset
   178
      apply simp
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27567
diff changeset
   179
      apply algebra
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   180
      done
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 32960
diff changeset
   181
    from zdvd_antisym_abs[OF coprime_dvd_mult_int[OF gcd1(2) raw_dvd(2)]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   182
        coprime_dvd_mult_int[OF gcd1(4) raw_dvd(4)]]
41528
276078f01ada eliminated global prems;
wenzelm
parents: 36411
diff changeset
   183
      have eq1: "b = b'" using pos by arith
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   184
      with eq have "a = a'" using pos by simp
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   185
      with eq1 have ?rhs by (simp add: x y) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   186
  ultimately show ?rhs by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   187
next
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   188
  assume ?rhs thus ?lhs by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   189
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   190
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   191
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   192
lemma isnormNum0[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   193
    "isnormNum x \<Longrightarrow> (INum x = (0::'a::{field_char_0, field_inverse_zero})) = (x = 0\<^sub>N)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   194
  unfolding INum_int(2)[symmetric]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   195
  by (rule isnormNum_unique) simp_all
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   196
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   197
lemma of_int_div_aux: "d ~= 0 ==> ((of_int x)::'a::field_char_0) / (of_int d) =
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   198
    of_int (x div d) + (of_int (x mod d)) / ((of_int d)::'a)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   199
proof -
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   200
  assume "d ~= 0"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   201
  let ?t = "of_int (x div d) * ((of_int d)::'a) + of_int(x mod d)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   202
  let ?f = "\<lambda>x. x / of_int d"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   203
  have "x = (x div d) * d + x mod d"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   204
    by auto
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   205
  then have eq: "of_int x = ?t"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   206
    by (simp only: of_int_mult[symmetric] of_int_add [symmetric])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   207
  then have "of_int x / of_int d = ?t / of_int d"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   208
    using cong[OF refl[of ?f] eq] by simp
41528
276078f01ada eliminated global prems;
wenzelm
parents: 36411
diff changeset
   209
  then show ?thesis by (simp add: add_divide_distrib algebra_simps `d ~= 0`)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   210
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   211
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   212
lemma of_int_div: "(d::int) ~= 0 ==> d dvd n ==>
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   213
    (of_int(n div d)::'a::field_char_0) = of_int n / of_int d"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   214
  apply (frule of_int_div_aux [of d n, where ?'a = 'a])
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   215
  apply simp
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 29667
diff changeset
   216
  apply (simp add: dvd_eq_mod_eq_0)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   217
  done
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   218
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   219
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   220
lemma normNum[simp]: "INum (normNum x) = (INum x :: 'a::{field_char_0, field_inverse_zero})"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   221
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   222
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   223
  { assume "a = 0 \<or> b = 0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   224
    hence ?thesis by (simp add: x INum_def normNum_def split_def Let_def) }
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   225
  moreover
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   226
  { assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
   227
    let ?g = "gcd a b"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   228
    from a b have g: "?g \<noteq> 0"by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   229
    from of_int_div[OF g, where ?'a = 'a]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   230
    have ?thesis by (auto simp add: x INum_def normNum_def split_def Let_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   231
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   232
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   233
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   234
lemma INum_normNum_iff:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   235
  "(INum x ::'a::{field_char_0, field_inverse_zero}) = INum y \<longleftrightarrow> normNum x = normNum y"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   236
  (is "?lhs = ?rhs")
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   237
proof -
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   238
  have "normNum x = normNum y \<longleftrightarrow> (INum (normNum x) :: 'a) = INum (normNum y)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   239
    by (simp del: normNum)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   240
  also have "\<dots> = ?lhs" by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   241
  finally show ?thesis by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   242
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   243
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   244
lemma Nadd[simp]: "INum (x +\<^sub>N y) = INum x + (INum y :: 'a :: {field_char_0, field_inverse_zero})"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   245
proof -
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   246
  let ?z = "0:: 'a"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   247
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   248
  obtain a' b' where y: "y = (a', b')" by (cases y)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   249
  { assume "a=0 \<or> a'= 0 \<or> b =0 \<or> b' = 0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   250
    hence ?thesis
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   251
      apply (cases "a=0", simp_all add: x y Nadd_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   252
      apply (cases "b= 0", simp_all add: INum_def)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   253
       apply (cases "a'= 0", simp_all)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   254
       apply (cases "b'= 0", simp_all)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   255
       done }
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   256
  moreover
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   257
  { assume aa': "a \<noteq> 0" "a'\<noteq> 0" and bb': "b \<noteq> 0" "b' \<noteq> 0"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   258
    { assume z: "a * b' + b * a' = 0"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   259
      hence "of_int (a*b' + b*a') / (of_int b* of_int b') = ?z" by simp
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   260
      hence "of_int b' * of_int a / (of_int b * of_int b') +
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   261
          of_int b * of_int a' / (of_int b * of_int b') = ?z"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   262
        by (simp add:add_divide_distrib)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   263
      hence th: "of_int a / of_int b + of_int a' / of_int b' = ?z" using bb' aa'
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   264
        by simp
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   265
      from z aa' bb' have ?thesis
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   266
        by (simp add: x y th Nadd_def normNum_def INum_def split_def) }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   267
    moreover {
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   268
      assume z: "a * b' + b * a' \<noteq> 0"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 54220
diff changeset
   269
      let ?g = "gcd (a * b' + b * a') (b * b')"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   270
      have gz: "?g \<noteq> 0" using z by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   271
      have ?thesis using aa' bb' z gz
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   272
        of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a * b' + b * a'" and y="b*b'"]]
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   273
        of_int_div[where ?'a = 'a, OF gz gcd_dvd2_int[where x="a * b' + b * a'" and y="b*b'"]]
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 54220
diff changeset
   274
        by (simp add: x y Nadd_def INum_def normNum_def Let_def) (simp add: field_simps)
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 54220
diff changeset
   275
    }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   276
    ultimately have ?thesis using aa' bb'
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   277
      by (simp add: x y Nadd_def INum_def normNum_def Let_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   278
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   279
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   280
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   281
lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a :: {field_char_0, field_inverse_zero})"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   282
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   283
  let ?z = "0::'a"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   284
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   285
  obtain a' b' where y: "y = (a', b')" by (cases y)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   286
  { assume "a=0 \<or> a'= 0 \<or> b = 0 \<or> b' = 0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   287
    hence ?thesis
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   288
      apply (cases "a=0", simp_all add: x y Nmul_def INum_def Let_def)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   289
      apply (cases "b=0", simp_all)
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   290
      apply (cases "a'=0", simp_all)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   291
      done }
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   292
  moreover
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   293
  { assume z: "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
   294
    let ?g="gcd (a*a') (b*b')"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   295
    have gz: "?g \<noteq> 0" using z by simp
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   296
    from z of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a*a'" and y="b*b'"]]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   297
      of_int_div[where ?'a = 'a , OF gz gcd_dvd2_int[where x="a*a'" and y="b*b'"]]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   298
    have ?thesis by (simp add: Nmul_def x y Let_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   299
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   300
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   301
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   302
lemma Nneg[simp]: "INum (~\<^sub>N x) = - (INum x ::'a:: field)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   303
  by (simp add: Nneg_def split_def INum_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   304
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   305
lemma Nsub[simp]: "INum (x -\<^sub>N y) = INum x - (INum y:: 'a :: {field_char_0, field_inverse_zero})"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   306
  by (simp add: Nsub_def split_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   307
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   308
lemma Ninv[simp]: "INum (Ninv x) = (1::'a :: field_inverse_zero) / (INum x)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   309
  by (simp add: Ninv_def INum_def split_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   310
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   311
lemma Ndiv[simp]: "INum (x \<div>\<^sub>N y) = INum x / (INum y ::'a :: {field_char_0, field_inverse_zero})"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   312
  by (simp add: Ndiv_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   313
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   314
lemma Nlt0_iff[simp]:
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   315
  assumes nx: "isnormNum x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   316
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})< 0) = 0>\<^sub>N x"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   317
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   318
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   319
  { assume "a = 0" hence ?thesis by (simp add: x Nlt0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   320
  moreover
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   321
  { assume a: "a \<noteq> 0" hence b: "(of_int b::'a) > 0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   322
      using nx by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   323
    from pos_divide_less_eq[OF b, where b="of_int a" and a="0::'a"]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   324
    have ?thesis by (simp add: x Nlt0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   325
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   326
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   327
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   328
lemma Nle0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   329
  assumes nx: "isnormNum x"
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   330
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) \<le> 0) = 0\<ge>\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   331
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   332
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   333
  { assume "a = 0" hence ?thesis by (simp add: x Nle0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   334
  moreover
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   335
  { assume a: "a \<noteq> 0" hence b: "(of_int b :: 'a) > 0"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   336
      using nx by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   337
    from pos_divide_le_eq[OF b, where b="of_int a" and a="0::'a"]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   338
    have ?thesis by (simp add: x Nle0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   339
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   340
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   341
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   342
lemma Ngt0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   343
  assumes nx: "isnormNum x"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   344
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})> 0) = 0<\<^sub>N x"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   345
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   346
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   347
  { assume "a = 0" hence ?thesis by (simp add: x Ngt0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   348
  moreover
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   349
  { assume a: "a \<noteq> 0" hence b: "(of_int b::'a) > 0" using nx
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   350
      by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   351
    from pos_less_divide_eq[OF b, where b="of_int a" and a="0::'a"]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   352
    have ?thesis by (simp add: x Ngt0_def INum_def) }
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   353
  ultimately show ?thesis by blast
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   354
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   355
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   356
lemma Nge0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   357
  assumes nx: "isnormNum x"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   358
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) \<ge> 0) = 0\<le>\<^sub>N x"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   359
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   360
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   361
  { assume "a = 0" hence ?thesis by (simp add: x Nge0_def INum_def) }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   362
  moreover
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   363
  { assume "a \<noteq> 0" hence b: "(of_int b::'a) > 0" using nx
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   364
      by (simp add: x isnormNum_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   365
    from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   366
    have ?thesis by (simp add: x Nge0_def INum_def) }
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   367
  ultimately show ?thesis by blast
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   368
qed
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   369
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   370
lemma Nlt_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   371
  assumes nx: "isnormNum x" and ny: "isnormNum y"
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   372
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) < INum y) = (x <\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   373
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   374
  let ?z = "0::'a"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   375
  have "((INum x ::'a) < INum y) = (INum (x -\<^sub>N y) < ?z)"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   376
    using nx ny by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   377
  also have "\<dots> = (0>\<^sub>N (x -\<^sub>N y))"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   378
    using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   379
  finally show ?thesis by (simp add: Nlt_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   380
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   381
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   382
lemma Nle_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   383
  assumes nx: "isnormNum x" and ny: "isnormNum y"
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   384
  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})\<le> INum y) = (x \<le>\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   385
proof -
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   386
  have "((INum x ::'a) \<le> INum y) = (INum (x -\<^sub>N y) \<le> (0::'a))"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   387
    using nx ny by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   388
  also have "\<dots> = (0\<ge>\<^sub>N (x -\<^sub>N y))"
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   389
    using Nle0_iff[OF Nsub_normN[OF ny]] by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   390
  finally show ?thesis by (simp add: Nle_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   391
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   392
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   393
lemma Nadd_commute:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   394
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   395
  shows "x +\<^sub>N y = y +\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   396
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   397
  have n: "isnormNum (x +\<^sub>N y)" "isnormNum (y +\<^sub>N x)" by simp_all
31964
chaieb
parents: 31963
diff changeset
   398
  have "(INum (x +\<^sub>N y)::'a) = INum (y +\<^sub>N x)" by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   399
  with isnormNum_unique[OF n] show ?thesis by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   400
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   401
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   402
lemma [simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   403
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   404
  shows "(0, b) +\<^sub>N y = normNum y"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   405
    and "(a, 0) +\<^sub>N y = normNum y"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   406
    and "x +\<^sub>N (0, b) = normNum x"
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   407
    and "x +\<^sub>N (a, 0) = normNum x"
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   408
  apply (simp add: Nadd_def split_def)
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   409
  apply (simp add: Nadd_def split_def)
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   410
  apply (subst Nadd_commute, simp add: Nadd_def split_def)
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   411
  apply (subst Nadd_commute, simp add: Nadd_def split_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   412
  done
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   413
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   414
lemma normNum_nilpotent_aux[simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   415
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   416
  assumes nx: "isnormNum x"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   417
  shows "normNum x = x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   418
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   419
  let ?a = "normNum x"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   420
  have n: "isnormNum ?a" by simp
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   421
  have th: "INum ?a = (INum x ::'a)" by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   422
  with isnormNum_unique[OF n nx] show ?thesis by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   423
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   424
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   425
lemma normNum_nilpotent[simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   426
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   427
  shows "normNum (normNum x) = normNum x"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   428
  by simp
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   429
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   430
lemma normNum0[simp]: "normNum (0,b) = 0\<^sub>N" "normNum (a,0) = 0\<^sub>N"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   431
  by (simp_all add: normNum_def)
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   432
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   433
lemma normNum_Nadd:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   434
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   435
  shows "normNum (x +\<^sub>N y) = x +\<^sub>N y" by simp
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   436
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   437
lemma Nadd_normNum1[simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   438
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   439
  shows "normNum x +\<^sub>N y = x +\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   440
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   441
  have n: "isnormNum (normNum x +\<^sub>N y)" "isnormNum (x +\<^sub>N y)" by simp_all
31964
chaieb
parents: 31963
diff changeset
   442
  have "INum (normNum x +\<^sub>N y) = INum x + (INum y :: 'a)" by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   443
  also have "\<dots> = INum (x +\<^sub>N y)" by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   444
  finally show ?thesis using isnormNum_unique[OF n] by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   445
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   446
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   447
lemma Nadd_normNum2[simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   448
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   449
  shows "x +\<^sub>N normNum y = x +\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   450
proof -
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   451
  have n: "isnormNum (x +\<^sub>N normNum y)" "isnormNum (x +\<^sub>N y)" by simp_all
31964
chaieb
parents: 31963
diff changeset
   452
  have "INum (x +\<^sub>N normNum y) = INum x + (INum y :: 'a)" by simp
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   453
  also have "\<dots> = INum (x +\<^sub>N y)" by simp
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   454
  finally show ?thesis using isnormNum_unique[OF n] by simp
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   455
qed
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   456
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   457
lemma Nadd_assoc:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   458
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   459
  shows "x +\<^sub>N y +\<^sub>N z = x +\<^sub>N (y +\<^sub>N z)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   460
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   461
  have n: "isnormNum (x +\<^sub>N y +\<^sub>N z)" "isnormNum (x +\<^sub>N (y +\<^sub>N z))" by simp_all
31964
chaieb
parents: 31963
diff changeset
   462
  have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)" by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   463
  with isnormNum_unique[OF n] show ?thesis by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   464
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   465
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   466
lemma Nmul_commute: "isnormNum x \<Longrightarrow> isnormNum y \<Longrightarrow> x *\<^sub>N y = y *\<^sub>N x"
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31706
diff changeset
   467
  by (simp add: Nmul_def split_def Let_def gcd_commute_int mult_commute)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   468
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   469
lemma Nmul_assoc:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   470
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   471
  assumes nx: "isnormNum x" and ny: "isnormNum y" and nz: "isnormNum z"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   472
  shows "x *\<^sub>N y *\<^sub>N z = x *\<^sub>N (y *\<^sub>N z)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   473
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   474
  from nx ny nz have n: "isnormNum (x *\<^sub>N y *\<^sub>N z)" "isnormNum (x *\<^sub>N (y *\<^sub>N z))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   475
    by simp_all
31964
chaieb
parents: 31963
diff changeset
   476
  have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)" by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   477
  with isnormNum_unique[OF n] show ?thesis by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   478
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   479
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   480
lemma Nsub0:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   481
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   482
  assumes x: "isnormNum x" and y: "isnormNum y"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   483
  shows "x -\<^sub>N y = 0\<^sub>N \<longleftrightarrow> x = y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   484
proof -
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   485
  fix h :: 'a
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   486
  from isnormNum_unique[where 'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   487
  have "(x -\<^sub>N y = 0\<^sub>N) = (INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)) " by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   488
  also have "\<dots> = (INum x = (INum y :: 'a))" by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   489
  also have "\<dots> = (x = y)" using x y by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   490
  finally show ?thesis .
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   491
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   492
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   493
lemma Nmul0[simp]: "c *\<^sub>N 0\<^sub>N = 0\<^sub>N" " 0\<^sub>N *\<^sub>N c = 0\<^sub>N"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   494
  by (simp_all add: Nmul_def Let_def split_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   495
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   496
lemma Nmul_eq0[simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
   497
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   498
  assumes nx: "isnormNum x" and ny: "isnormNum y"
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   499
  shows "x*\<^sub>N y = 0\<^sub>N \<longleftrightarrow> x = 0\<^sub>N \<or> y = 0\<^sub>N"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   500
proof -
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   501
  fix h :: 'a
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   502
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   503
  obtain a' b' where y: "y = (a', b')" by (cases y)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   504
  have n0: "isnormNum 0\<^sub>N" by simp
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   505
  show ?thesis using nx ny
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   506
    apply (simp only: isnormNum_unique[where ?'a = 'a, OF  Nmul_normN[OF nx ny] n0, symmetric]
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   507
      Nmul[where ?'a = 'a])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   508
    apply (simp add: x y INum_def split_def isnormNum_def split: split_if_asm)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   509
    done
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   510
qed
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   511
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   512
lemma Nneg_Nneg[simp]: "~\<^sub>N (~\<^sub>N c) = c"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   513
  by (simp add: Nneg_def split_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   514
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   515
lemma Nmul1[simp]:
50282
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
   516
    "isnormNum c \<Longrightarrow> (1)\<^sub>N *\<^sub>N c = c"
fe4d4bb9f4c2 more robust syntax that survives collapse of \<^isub> and \<^sub>;
wenzelm
parents: 47162
diff changeset
   517
    "isnormNum c \<Longrightarrow> c *\<^sub>N (1)\<^sub>N = c"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   518
  apply (simp_all add: Nmul_def Let_def split_def isnormNum_def)
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   519
  apply (cases "fst c = 0", simp_all, cases c, simp_all)+
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   520
  done
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   521
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   522
end