src/HOL/Decision_Procs/Rat_Pair.thy
author paulson <lp15@cam.ac.uk>
Mon, 15 Apr 2024 22:23:40 +0100
changeset 80105 2fa018321400
parent 69597 ff784d5a5bfb
permissions -rw-r--r--
Streamlining of many more archaic proofs
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
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
     5
section \<open>Rational numbers as pairs\<close>
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
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 67051
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
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    13
abbreviation Num0_syn :: Num  (\<open>0\<^sub>N\<close>)
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
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    16
abbreviation Numi_syn :: "int \<Rightarrow> Num"  (\<open>'((_)')\<^sub>N\<close>)
50282
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
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    19
definition isnormNum :: "Num \<Rightarrow> bool"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    20
  where "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
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    22
definition normNum :: "Num \<Rightarrow> Num"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 67051
diff changeset
    23
  where "normNum = (\<lambda>(a,b).
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    24
    (if a = 0 \<or> b = 0 then (0, 0)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    25
     else
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    26
      (let g = gcd a b
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    27
       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
    28
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 60698
diff changeset
    29
declare gcd_dvd1[presburger] gcd_dvd2[presburger]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    30
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    31
lemma normNum_isnormNum [simp]: "isnormNum (normNum x)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    32
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    33
  obtain a b where x: "x = (a, b)" by (cases x)
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    34
  consider "a = 0 \<or> b = 0" | "a \<noteq> 0" "b \<noteq> 0"
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    35
    by blast
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    36
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    37
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    38
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    39
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    40
      by (simp add: x normNum_def isnormNum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    41
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    42
    case ab: 2
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
    43
    let ?g = "gcd a b"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    44
    let ?a' = "a div ?g"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    45
    let ?b' = "b div ?g"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
    46
    let ?g' = "gcd ?a' ?b'"
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    47
    from ab have "?g \<noteq> 0" by simp
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    48
    with gcd_ge_0_int[of a b] have gpos: "?g > 0" by arith
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    49
    have gdvd: "?g dvd a" "?g dvd b" by arith+
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    50
    from dvd_mult_div_cancel[OF gdvd(1)] dvd_mult_div_cancel[OF gdvd(2)] ab
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    51
    have nz': "?a' \<noteq> 0" "?b' \<noteq> 0" by - (rule notI, simp)+
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    52
    from ab have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by arith
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
    53
    from div_gcd_coprime[OF stupid] have gp1: "?g' = 1"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
    54
      by simp
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    55
    from ab consider "b < 0" | "b > 0" by arith
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    56
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    57
    proof cases
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    58
      case b: 1
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    59
      have False if b': "?b' \<ge> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    60
      proof -
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    61
        from gpos have th: "?g \<ge> 0" by arith
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    62
        from mult_nonneg_nonneg[OF th b'] dvd_mult_div_cancel[OF gdvd(2)]
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    63
        show ?thesis using b by arith
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    64
      qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    65
      then have b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    66
      from ab(1) nz' b b' gp1 show ?thesis
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    67
        by (simp add: x isnormNum_def normNum_def Let_def split_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    68
    next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    69
      case b: 2
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    70
      then have "?b' \<ge> 0"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    71
        by (presburger add: pos_imp_zdiv_nonneg_iff[OF gpos])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
    72
      with nz' have b': "?b' > 0" by arith
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
    73
      from b b' ab(1) nz' gp1 show ?thesis
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    74
        by (simp add: x isnormNum_def normNum_def Let_def split_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    75
    qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    76
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    77
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    78
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
    79
text \<open>Arithmetic over Num\<close>
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    80
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    81
definition Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl \<open>+\<^sub>N\<close> 60)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    82
where
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    83
  "Nadd = (\<lambda>(a, b) (a', b').
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    84
    if a = 0 \<or> b = 0 then normNum (a', b')
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    85
    else if a' = 0 \<or> b' = 0 then normNum (a, b)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    86
    else normNum (a * b' + b * a', b * b'))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    87
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    88
definition Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl \<open>*\<^sub>N\<close> 60)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    89
where
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    90
  "Nmul = (\<lambda>(a, b) (a', b').
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    91
    let g = gcd (a * a') (b * b')
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    92
    in (a * a' div g, b * b' div g))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    93
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    94
definition Nneg :: "Num \<Rightarrow> Num" (\<open>~\<^sub>N\<close>)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
    95
  where "Nneg = (\<lambda>(a, b). (- a, b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    96
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
    97
definition Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl \<open>-\<^sub>N\<close> 60)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
    98
  where "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
    99
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   100
definition Ninv :: "Num \<Rightarrow> Num"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   101
  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
   102
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   103
definition Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num"  (infixl \<open>\<div>\<^sub>N\<close> 60)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   104
  where "Ndiv = (\<lambda>a b. a *\<^sub>N Ninv b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   105
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   106
lemma Nneg_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (~\<^sub>N x)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   107
  by (simp add: isnormNum_def Nneg_def split_def)
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   108
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   109
lemma Nadd_normN[simp]: "isnormNum (x +\<^sub>N y)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   110
  by (simp add: Nadd_def split_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   111
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   112
lemma Nsub_normN[simp]: "isnormNum y \<Longrightarrow> isnormNum (x -\<^sub>N y)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   113
  by (simp add: Nsub_def split_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   114
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   115
lemma Nmul_normN[simp]:
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   116
  assumes xn: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   117
    and yn: "isnormNum y"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   118
  shows "isnormNum (x *\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   119
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   120
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   121
  obtain a' b' where y: "y = (a', b')" by (cases y)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   122
  consider "a = 0" | "a' = 0" | "a \<noteq> 0" "a' \<noteq> 0" by blast
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   123
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   124
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   125
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   126
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   127
      using xn x y by (simp add: isnormNum_def Let_def Nmul_def split_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   128
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   129
    case 2
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   130
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   131
      using yn x y by (simp add: isnormNum_def Let_def Nmul_def split_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   132
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   133
    case aa': 3
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   134
    then have bp: "b > 0" "b' > 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   135
      using xn yn x y by (simp_all add: isnormNum_def)
56544
b60d5d119489 made mult_pos_pos a simp rule
nipkow
parents: 56479
diff changeset
   136
    from bp have "x *\<^sub>N y = normNum (a * a', b * b')"
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   137
      using x y aa' bp by (simp add: Nmul_def Let_def split_def normNum_def)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   138
    then show ?thesis by simp
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   139
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   140
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   141
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   142
lemma Ninv_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (Ninv x)"
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   143
  by (simp add: Ninv_def isnormNum_def split_def gcd.commute split: if_split_asm)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   144
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   145
lemma isnormNum_int[simp]: "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
   146
  by (simp_all add: isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   147
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   148
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   149
text \<open>Relations over Num\<close>
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   150
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   151
definition Nlt0:: "Num \<Rightarrow> bool"  (\<open>0>\<^sub>N\<close>)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   152
  where "Nlt0 = (\<lambda>(a, b). a < 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   153
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   154
definition Nle0:: "Num \<Rightarrow> bool"  (\<open>0\<ge>\<^sub>N\<close>)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   155
  where "Nle0 = (\<lambda>(a, b). a \<le> 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   156
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   157
definition Ngt0:: "Num \<Rightarrow> bool"  (\<open>0<\<^sub>N\<close>)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   158
  where "Ngt0 = (\<lambda>(a, b). a > 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   159
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   160
definition Nge0:: "Num \<Rightarrow> bool"  (\<open>0\<le>\<^sub>N\<close>)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   161
  where "Nge0 = (\<lambda>(a, b). a \<ge> 0)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   162
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   163
definition Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool"  (infix \<open><\<^sub>N\<close> 55)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   164
  where "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   165
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68442
diff changeset
   166
definition Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool"  (infix \<open>\<le>\<^sub>N\<close> 55)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   167
  where "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   168
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   169
definition "INum = (\<lambda>(a, b). of_int a / of_int b)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   170
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   171
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
   172
  by (simp_all add: INum_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   173
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   174
lemma isnormNum_unique[simp]:
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   175
  assumes na: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   176
    and nb: "isnormNum y"
68442
nipkow
parents: 67123
diff changeset
   177
  shows "(INum x ::'a::field_char_0) = INum y \<longleftrightarrow> x = y"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   178
  (is "?lhs = ?rhs")
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   179
proof
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   180
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   181
  obtain a' b' where y: "y = (a', b')" by (cases y)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   182
  consider "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0" | "a \<noteq> 0" "b \<noteq> 0" "a' \<noteq> 0" "b' \<noteq> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   183
    by blast
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   184
  then show ?rhs if H: ?lhs
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   185
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   186
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   187
    then show ?thesis
62390
842917225d56 more canonical names
nipkow
parents: 62348
diff changeset
   188
      using na nb H by (simp add: x y INum_def split_def isnormNum_def split: if_split_asm)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   189
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   190
    case 2
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   191
    with na nb have pos: "b > 0" "b' > 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   192
      by (simp_all add: x y isnormNum_def)
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   193
    from H \<open>b \<noteq> 0\<close> \<open>b' \<noteq> 0\<close> have eq: "a * b' = a' * b"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   194
      by (simp add: x y INum_def eq_divide_eq divide_eq_eq of_int_mult[symmetric] del: of_int_mult)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   195
    from \<open>a \<noteq> 0\<close> \<open>a' \<noteq> 0\<close> na nb
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   196
    have gcd1: "gcd a b = 1" "gcd b a = 1" "gcd a' b' = 1" "gcd b' a' = 1"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 60698
diff changeset
   197
      by (simp_all add: x y isnormNum_def add: gcd.commute)
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   198
    then have "coprime a b" "coprime b a" "coprime a' b'" "coprime b' a'"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   199
      by (simp_all add: coprime_iff_gcd_eq_1)
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   200
    from eq have raw_dvd: "a dvd a' * b" "b dvd b' * a" "a' dvd a * b'" "b' dvd b * a'"
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   201
      by (algebra|simp)+
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   202
    then have eq1: "b = b'"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   203
      using pos \<open>coprime b a\<close> \<open>coprime b' a'\<close>
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   204
      by (auto simp add: coprime_dvd_mult_left_iff intro: associated_eqI)
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   205
    with eq have "a = a'" using pos by simp
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 62390
diff changeset
   206
    with \<open>b = b'\<close> show ?thesis by (simp add: x y)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   207
  qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   208
  show ?lhs if ?rhs
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   209
    using that by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   210
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   211
68442
nipkow
parents: 67123
diff changeset
   212
lemma isnormNum0[simp]: "isnormNum x \<Longrightarrow> INum x = (0::'a::field_char_0) \<longleftrightarrow> x = 0\<^sub>N"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   213
  unfolding INum_int(2)[symmetric]
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   214
  by (rule isnormNum_unique) simp_all
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   215
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   216
lemma of_int_div_aux:
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   217
  assumes "d \<noteq> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   218
  shows "(of_int x ::'a::field_char_0) / of_int d =
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   219
    of_int (x div d) + (of_int (x mod d)) / of_int d"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   220
proof -
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   221
  let ?t = "of_int (x div d) * (of_int d ::'a) + of_int (x mod d)"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   222
  let ?f = "\<lambda>x. x / of_int d"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   223
  have "x = (x div d) * d + x mod d"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   224
    by auto
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   225
  then have eq: "of_int x = ?t"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   226
    by (simp only: of_int_mult[symmetric] of_int_add [symmetric])
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   227
  then have "of_int x / of_int d = ?t / of_int d"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   228
    using cong[OF refl[of ?f] eq] by simp
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   229
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   230
    by (simp add: add_divide_distrib algebra_simps \<open>d \<noteq> 0\<close>)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   231
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   232
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   233
lemma of_int_div:
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   234
  fixes d :: int
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   235
  assumes "d \<noteq> 0" "d dvd n"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   236
  shows "(of_int (n div d) ::'a::field_char_0) = of_int n / of_int d"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   237
  using assms of_int_div_aux [of d n, where ?'a = 'a] by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   238
68442
nipkow
parents: 67123
diff changeset
   239
lemma normNum[simp]: "INum (normNum x) = (INum x :: 'a::field_char_0)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   240
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   241
  obtain a b where x: "x = (a, b)" by (cases x)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   242
  consider "a = 0 \<or> b = 0" | "a \<noteq> 0" "b \<noteq> 0" by blast
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   243
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   244
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   245
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   246
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   247
      by (simp add: x INum_def normNum_def split_def Let_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   248
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   249
    case ab: 2
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30663
diff changeset
   250
    let ?g = "gcd a b"
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   251
    from ab have g: "?g \<noteq> 0"by simp
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   252
    from of_int_div[OF g, where ?'a = 'a] show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   253
      by (auto simp add: x INum_def normNum_def split_def Let_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   254
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   255
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   256
68442
nipkow
parents: 67123
diff changeset
   257
lemma INum_normNum_iff: "(INum x ::'a::field_char_0) = INum y \<longleftrightarrow> normNum x = normNum y"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   258
  (is "?lhs \<longleftrightarrow> _")
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   259
proof -
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   260
  have "normNum x = normNum y \<longleftrightarrow> (INum (normNum x) :: 'a) = INum (normNum y)"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   261
    by (simp del: normNum)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   262
  also have "\<dots> = ?lhs" by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   263
  finally show ?thesis by simp
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   264
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   265
68442
nipkow
parents: 67123
diff changeset
   266
lemma Nadd[simp]: "INum (x +\<^sub>N y) = INum x + (INum y :: 'a :: field_char_0)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   267
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   268
  let ?z = "0::'a"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   269
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   270
  obtain a' b' where y: "y = (a', b')" by (cases y)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   271
  consider "a = 0 \<or> a'= 0 \<or> b =0 \<or> b' = 0" | "a \<noteq> 0" "a'\<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   272
    by blast
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   273
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   274
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   275
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   276
    then show ?thesis
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   277
      by (auto simp: x y INum_def Nadd_def normNum_def Let_def of_int_div)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   278
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   279
    case neq: 2
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   280
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   281
    proof (cases "a * b' + b * a' = 0")
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   282
      case True
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   283
      then have "of_int (a * b' + b * a') / (of_int b * of_int b') = ?z"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   284
        by simp
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   285
      then have "of_int b' * of_int a / (of_int b * of_int b') +
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   286
          of_int b * of_int a' / (of_int b * of_int b') = ?z"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   287
        by (simp add: add_divide_distrib)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   288
      then have th: "of_int a / of_int b + of_int a' / of_int b' = ?z"
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   289
        using neq by simp
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   290
      from True neq show ?thesis
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   291
        by (simp add: x y th Nadd_def normNum_def INum_def split_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   292
    next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   293
      case False
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   294
      let ?g = "gcd (a * b' + b * a') (b * b')"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   295
      have gz: "?g \<noteq> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   296
        using False by simp
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   297
      show ?thesis
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   298
        using neq False gz
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   299
          of_int_div [where ?'a = 'a, OF gz gcd_dvd1 [of "a * b' + b * a'" "b * b'"]]
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   300
          of_int_div [where ?'a = 'a, OF gz gcd_dvd2 [of "a * b' + b * a'" "b * b'"]]
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   301
        by (simp add: x y Nadd_def INum_def normNum_def Let_def) (simp add: field_simps)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   302
    qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   303
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   304
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   305
68442
nipkow
parents: 67123
diff changeset
   306
lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a::field_char_0)"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   307
proof -
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   308
  let ?z = "0::'a"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   309
  obtain a b where x: "x = (a, b)" by (cases x)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   310
  obtain a' b' where y: "y = (a', b')" by (cases y)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   311
  consider "a = 0 \<or> a' = 0 \<or> b = 0 \<or> b' = 0" | "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   312
    by blast
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   313
  then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   314
  proof cases
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   315
    case 1
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   316
    then show ?thesis
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   317
      by (auto simp add: x y Nmul_def INum_def)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   318
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   319
    case neq: 2
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   320
    let ?g = "gcd (a * a') (b * b')"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   321
    have gz: "?g \<noteq> 0"
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   322
      using neq by simp
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60538
diff changeset
   323
    from neq of_int_div [where ?'a = 'a, OF gz gcd_dvd1 [of "a * a'" "b * b'"]]
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   324
      of_int_div [where ?'a = 'a , OF gz gcd_dvd2 [of "a * a'" "b * b'"]]
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   325
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   326
      by (simp add: Nmul_def x y Let_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   327
  qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   328
qed
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   329
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   330
lemma Nneg[simp]: "INum (~\<^sub>N x) = - (INum x :: 'a::field)"
56479
91958d4b30f7 revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
hoelzl
parents: 56410
diff changeset
   331
  by (simp add: Nneg_def split_def INum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   332
68442
nipkow
parents: 67123
diff changeset
   333
lemma Nsub[simp]: "INum (x -\<^sub>N y) = INum x - (INum y:: 'a::field_char_0)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   334
  by (simp add: Nsub_def split_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   335
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   336
lemma Ninv[simp]: "INum (Ninv x) = (1 :: 'a::field) / INum x"
56479
91958d4b30f7 revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
hoelzl
parents: 56410
diff changeset
   337
  by (simp add: Ninv_def INum_def split_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   338
68442
nipkow
parents: 67123
diff changeset
   339
lemma Ndiv[simp]: "INum (x \<div>\<^sub>N y) = INum x / (INum y :: 'a::field_char_0)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   340
  by (simp add: Ndiv_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   341
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   342
lemma Nlt0_iff[simp]:
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   343
  assumes nx: "isnormNum x"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   344
  shows "((INum x :: 'a::{field_char_0,linordered_field}) < 0) = 0>\<^sub>N x"
44779
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)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   347
  show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   348
  proof (cases "a = 0")
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   349
    case True
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   350
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   351
      by (simp add: x Nlt0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   352
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   353
    case False
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   354
    then have b: "(of_int b::'a) > 0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   355
      using nx by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   356
    from pos_divide_less_eq[OF b, where b="of_int a" and a="0::'a"]
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   357
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   358
      by (simp add: x Nlt0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   359
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   360
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   361
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   362
lemma Nle0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   363
  assumes nx: "isnormNum x"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   364
  shows "((INum x :: 'a::{field_char_0,linordered_field}) \<le> 0) = 0\<ge>\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   365
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   366
  obtain a b where x: "x = (a, b)" by (cases x)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   367
  show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   368
  proof (cases "a = 0")
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   369
    case True
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   370
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   371
      by (simp add: x Nle0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   372
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   373
    case False
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   374
    then have b: "(of_int b :: 'a) > 0"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   375
      using nx by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   376
    from pos_divide_le_eq[OF b, where b="of_int a" and a="0::'a"]
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   377
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   378
      by (simp add: x Nle0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   379
  qed
24197
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 Ngt0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   383
  assumes nx: "isnormNum x"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   384
  shows "((INum x :: 'a::{field_char_0,linordered_field}) > 0) = 0<\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   385
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   386
  obtain a b where x: "x = (a, b)" by (cases x)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   387
  show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   388
  proof (cases "a = 0")
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   389
    case True
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   390
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   391
      by (simp add: x Ngt0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   392
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   393
    case False
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   394
    then have b: "(of_int b::'a) > 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   395
      using nx by (simp add: x isnormNum_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   396
    from pos_less_divide_eq[OF b, where b="of_int a" and a="0::'a"]
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   397
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   398
      by (simp add: x Ngt0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   399
  qed
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   400
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   401
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   402
lemma Nge0_iff[simp]:
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   403
  assumes nx: "isnormNum x"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   404
  shows "(INum x :: 'a::{field_char_0,linordered_field}) \<ge> 0 \<longleftrightarrow> 0\<le>\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   405
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   406
  obtain a b where x: "x = (a, b)" by (cases x)
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   407
  show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   408
  proof (cases "a = 0")
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   409
    case True
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   410
    then show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   411
      by (simp add: x Nge0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   412
  next
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   413
    case False
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   414
    then have b: "(of_int b::'a) > 0"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   415
      using nx by (simp add: x isnormNum_def)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   416
    from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   417
    show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   418
      by (simp add: x Nge0_def INum_def)
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   419
  qed
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   420
qed
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   421
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   422
lemma Nlt_iff[simp]:
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   423
  assumes nx: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   424
    and ny: "isnormNum y"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   425
  shows "((INum x :: 'a::{field_char_0,linordered_field}) < INum y) \<longleftrightarrow> x <\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   426
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   427
  let ?z = "0::'a"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   428
  have "((INum x ::'a) < INum y) \<longleftrightarrow> INum (x -\<^sub>N y) < ?z"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   429
    using nx ny by simp
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   430
  also have "\<dots> \<longleftrightarrow> 0>\<^sub>N (x -\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   431
    using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   432
  finally show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   433
    by (simp add: Nlt_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   434
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   435
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   436
lemma Nle_iff[simp]:
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   437
  assumes nx: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   438
    and ny: "isnormNum y"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   439
  shows "((INum x :: 'a::{field_char_0,linordered_field}) \<le> INum y) \<longleftrightarrow> x \<le>\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   440
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   441
  have "((INum x ::'a) \<le> INum y) \<longleftrightarrow> INum (x -\<^sub>N y) \<le> (0::'a)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   442
    using nx ny by simp
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   443
  also have "\<dots> \<longleftrightarrow> 0\<ge>\<^sub>N (x -\<^sub>N y)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   444
    using Nle0_iff[OF Nsub_normN[OF ny]] by simp
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   445
  finally show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   446
    by (simp add: Nle_def)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   447
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   448
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   449
lemma Nadd_commute:
68442
nipkow
parents: 67123
diff changeset
   450
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   451
  shows "x +\<^sub>N y = y +\<^sub>N x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   452
proof -
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   453
  have n: "isnormNum (x +\<^sub>N y)" "isnormNum (y +\<^sub>N x)"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   454
    by simp_all
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   455
  have "(INum (x +\<^sub>N y)::'a) = INum (y +\<^sub>N x)"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   456
    by simp
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   457
  with isnormNum_unique[OF n] show ?thesis
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   458
    by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   459
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   460
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   461
lemma [simp]:
68442
nipkow
parents: 67123
diff changeset
   462
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   463
  shows "(0, b) +\<^sub>N y = normNum y"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   464
    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
   465
    and "x +\<^sub>N (0, b) = normNum x"
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   466
    and "x +\<^sub>N (a, 0) = normNum x"
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   467
  by (simp_all add: Nadd_def normNum_def split_def)
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 normNum_nilpotent_aux[simp]:
68442
nipkow
parents: 67123
diff changeset
   470
  assumes "SORT_CONSTRAINT('a::field_char_0)"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   471
  assumes nx: "isnormNum x"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   472
  shows "normNum x = x"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   473
proof -
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   474
  let ?a = "normNum x"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   475
  have n: "isnormNum ?a" by simp
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   476
  have th: "INum ?a = (INum x ::'a)" by simp
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   477
  with isnormNum_unique[OF n nx] show ?thesis by simp
24197
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 normNum_nilpotent[simp]:
68442
nipkow
parents: 67123
diff changeset
   481
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   482
  shows "normNum (normNum x) = normNum x"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   483
  by simp
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   484
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   485
lemma normNum0[simp]: "normNum (0, b) = 0\<^sub>N" "normNum (a, 0) = 0\<^sub>N"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   486
  by (simp_all add: normNum_def)
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   487
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   488
lemma normNum_Nadd:
68442
nipkow
parents: 67123
diff changeset
   489
  assumes "SORT_CONSTRAINT('a::field_char_0)"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   490
  shows "normNum (x +\<^sub>N y) = x +\<^sub>N y"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   491
  by simp
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   492
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   493
lemma Nadd_normNum1[simp]:
68442
nipkow
parents: 67123
diff changeset
   494
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   495
  shows "normNum x +\<^sub>N y = x +\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   496
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   497
  have n: "isnormNum (normNum x +\<^sub>N y)" "isnormNum (x +\<^sub>N y)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   498
    by simp_all
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   499
  have "INum (normNum x +\<^sub>N y) = INum x + (INum y :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   500
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   501
  also have "\<dots> = INum (x +\<^sub>N y)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   502
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   503
  finally show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   504
    using isnormNum_unique[OF n] by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   505
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   506
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   507
lemma Nadd_normNum2[simp]:
68442
nipkow
parents: 67123
diff changeset
   508
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   509
  shows "x +\<^sub>N normNum y = x +\<^sub>N y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   510
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   511
  have n: "isnormNum (x +\<^sub>N normNum y)" "isnormNum (x +\<^sub>N y)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   512
    by simp_all
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   513
  have "INum (x +\<^sub>N normNum y) = INum x + (INum y :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   514
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   515
  also have "\<dots> = INum (x +\<^sub>N y)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   516
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   517
  finally show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   518
    using isnormNum_unique[OF n] by simp
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   519
qed
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   520
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   521
lemma Nadd_assoc:
68442
nipkow
parents: 67123
diff changeset
   522
  assumes "SORT_CONSTRAINT('a::field_char_0)"
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   523
  shows "x +\<^sub>N y +\<^sub>N z = x +\<^sub>N (y +\<^sub>N z)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   524
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   525
  have n: "isnormNum (x +\<^sub>N y +\<^sub>N z)" "isnormNum (x +\<^sub>N (y +\<^sub>N z))"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   526
    by simp_all
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   527
  have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   528
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   529
  with isnormNum_unique[OF n] show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   530
    by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   531
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   532
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   533
lemma Nmul_commute: "isnormNum x \<Longrightarrow> isnormNum y \<Longrightarrow> x *\<^sub>N y = y *\<^sub>N x"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 60698
diff changeset
   534
  by (simp add: Nmul_def split_def Let_def gcd.commute mult.commute)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   535
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   536
lemma Nmul_assoc:
68442
nipkow
parents: 67123
diff changeset
   537
  assumes "SORT_CONSTRAINT('a::field_char_0)"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   538
  assumes nx: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   539
    and ny: "isnormNum y"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   540
    and nz: "isnormNum z"
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   541
  shows "x *\<^sub>N y *\<^sub>N z = x *\<^sub>N (y *\<^sub>N z)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   542
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   543
  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
   544
    by simp_all
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   545
  have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   546
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   547
  with isnormNum_unique[OF n] show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   548
    by simp
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   549
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   550
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   551
lemma Nsub0:
68442
nipkow
parents: 67123
diff changeset
   552
  assumes "SORT_CONSTRAINT('a::field_char_0)"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   553
  assumes x: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   554
    and y: "isnormNum y"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   555
  shows "x -\<^sub>N y = 0\<^sub>N \<longleftrightarrow> x = y"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   556
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   557
  from isnormNum_unique[where 'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   558
  have "x -\<^sub>N y = 0\<^sub>N \<longleftrightarrow> INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   559
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   560
  also have "\<dots> \<longleftrightarrow> INum x = (INum y :: 'a)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   561
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   562
  also have "\<dots> \<longleftrightarrow> x = y"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60567
diff changeset
   563
    using x y by simp
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   564
  finally show ?thesis .
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   565
qed
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   566
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   567
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
   568
  by (simp_all add: Nmul_def Let_def split_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   569
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   570
lemma Nmul_eq0[simp]:
68442
nipkow
parents: 67123
diff changeset
   571
  assumes "SORT_CONSTRAINT('a::field_char_0)"
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   572
  assumes nx: "isnormNum x"
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   573
    and ny: "isnormNum y"
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   574
  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
   575
proof -
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   576
  obtain a b where x: "x = (a, b)" by (cases x)
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   577
  obtain a' b' where y: "y = (a', b')" by (cases y)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   578
  have n0: "isnormNum 0\<^sub>N" by simp
44780
a13cdb1e9e08 tuned/simplified proofs;
wenzelm
parents: 44779
diff changeset
   579
  show ?thesis using nx ny
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   580
    by (metis (no_types, opaque_lifting) INum_int(2) Nmul Nmul0(1) Nmul0(2) isnormNum0 mult_eq_0_iff)
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   581
qed
44779
98d597c4193d tuned proofs;
wenzelm
parents: 42463
diff changeset
   582
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   583
lemma Nneg_Nneg[simp]: "~\<^sub>N (~\<^sub>N c) = c"
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   584
  by (simp add: Nneg_def split_def)
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   585
60538
b9add7665d7a tuned proofs;
wenzelm
parents: 60533
diff changeset
   586
lemma Nmul1[simp]: "isnormNum c \<Longrightarrow> (1)\<^sub>N *\<^sub>N c = c" "isnormNum c \<Longrightarrow> c *\<^sub>N (1)\<^sub>N = c"
80105
2fa018321400 Streamlining of many more archaic proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   587
  by (simp add: Nmul_def Let_def split_def isnormNum_def, metis div_0 div_by_1 surjective_pairing)+
24197
c9e3cb5e5681 proper implementation of rational numbers
haftmann
parents:
diff changeset
   588
28615
4c8fa015ec7f explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
wenzelm
parents: 27668
diff changeset
   589
end