src/HOL/Real/Float.thy
author wenzelm
Fri Jun 02 23:22:29 2006 +0200 (2006-06-02)
changeset 19765 dfe940911617
parent 16890 c4e5afaba440
child 20217 25b068a99d2b
permissions -rw-r--r--
misc cleanup;
obua@16782
     1
(*  Title: HOL/Real/Float.thy
obua@16782
     2
    ID:    $Id$
obua@16782
     3
    Author: Steven Obua
obua@16782
     4
*)
obua@16782
     5
wenzelm@16890
     6
theory Float imports Real begin
obua@16782
     7
wenzelm@19765
     8
definition
obua@16782
     9
  pow2 :: "int \<Rightarrow> real"
wenzelm@19765
    10
  "pow2 a = (if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (-a)))))"
obua@16782
    11
  float :: "int * int \<Rightarrow> real"
wenzelm@19765
    12
  "float x = real (fst x) * pow2 (snd x)"
obua@16782
    13
obua@16782
    14
lemma pow2_0[simp]: "pow2 0 = 1"
obua@16782
    15
by (simp add: pow2_def)
obua@16782
    16
obua@16782
    17
lemma pow2_1[simp]: "pow2 1 = 2"
obua@16782
    18
by (simp add: pow2_def)
obua@16782
    19
obua@16782
    20
lemma pow2_neg: "pow2 x = inverse (pow2 (-x))"
obua@16782
    21
by (simp add: pow2_def)
obua@16782
    22
wenzelm@19765
    23
lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
obua@16782
    24
proof -
obua@16782
    25
  have h: "! n. nat (2 + int n) - Suc 0 = nat (1 + int n)" by arith
obua@16782
    26
  have g: "! a b. a - -1 = a + (1::int)" by arith
obua@16782
    27
  have pos: "! n. pow2 (int n + 1) = 2 * pow2 (int n)"
obua@16782
    28
    apply (auto, induct_tac n)
obua@16782
    29
    apply (simp_all add: pow2_def)
obua@16782
    30
    apply (rule_tac m1="2" and n1="nat (2 + int na)" in ssubst[OF realpow_num_eq_if])
obua@16782
    31
    apply (auto simp add: h)
obua@16782
    32
    apply arith
wenzelm@19765
    33
    done
obua@16782
    34
  show ?thesis
obua@16782
    35
  proof (induct a)
obua@16782
    36
    case (1 n)
obua@16782
    37
    from pos show ?case by (simp add: ring_eq_simps)
obua@16782
    38
  next
obua@16782
    39
    case (2 n)
obua@16782
    40
    show ?case
obua@16782
    41
      apply (auto)
obua@16782
    42
      apply (subst pow2_neg[of "- int n"])
obua@16782
    43
      apply (subst pow2_neg[of "-1 - int n"])
obua@16782
    44
      apply (auto simp add: g pos)
obua@16782
    45
      done
wenzelm@19765
    46
  qed
obua@16782
    47
qed
wenzelm@19765
    48
obua@16782
    49
lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)"
obua@16782
    50
proof (induct b)
wenzelm@19765
    51
  case (1 n)
obua@16782
    52
  show ?case
obua@16782
    53
  proof (induct n)
obua@16782
    54
    case 0
obua@16782
    55
    show ?case by simp
obua@16782
    56
  next
obua@16782
    57
    case (Suc m)
obua@16782
    58
    show ?case by (auto simp add: ring_eq_simps pow2_add1 prems)
obua@16782
    59
  qed
obua@16782
    60
next
obua@16782
    61
  case (2 n)
wenzelm@19765
    62
  show ?case
obua@16782
    63
  proof (induct n)
obua@16782
    64
    case 0
wenzelm@19765
    65
    show ?case
obua@16782
    66
      apply (auto)
obua@16782
    67
      apply (subst pow2_neg[of "a + -1"])
obua@16782
    68
      apply (subst pow2_neg[of "-1"])
obua@16782
    69
      apply (simp)
obua@16782
    70
      apply (insert pow2_add1[of "-a"])
obua@16782
    71
      apply (simp add: ring_eq_simps)
obua@16782
    72
      apply (subst pow2_neg[of "-a"])
obua@16782
    73
      apply (simp)
obua@16782
    74
      done
obua@16782
    75
    case (Suc m)
wenzelm@19765
    76
    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith
obua@16782
    77
    have b: "int m - -2 = 1 + (int m + 1)" by arith
obua@16782
    78
    show ?case
obua@16782
    79
      apply (auto)
obua@16782
    80
      apply (subst pow2_neg[of "a + (-2 - int m)"])
obua@16782
    81
      apply (subst pow2_neg[of "-2 - int m"])
obua@16782
    82
      apply (auto simp add: ring_eq_simps)
obua@16782
    83
      apply (subst a)
obua@16782
    84
      apply (subst b)
obua@16782
    85
      apply (simp only: pow2_add1)
obua@16782
    86
      apply (subst pow2_neg[of "int m - a + 1"])
obua@16782
    87
      apply (subst pow2_neg[of "int m + 1"])
obua@16782
    88
      apply auto
obua@16782
    89
      apply (insert prems)
obua@16782
    90
      apply (auto simp add: ring_eq_simps)
obua@16782
    91
      done
obua@16782
    92
  qed
obua@16782
    93
qed
obua@16782
    94
wenzelm@19765
    95
lemma "float (a, e) + float (b, e) = float (a + b, e)"
obua@16782
    96
by (simp add: float_def ring_eq_simps)
obua@16782
    97
wenzelm@19765
    98
definition
obua@16782
    99
  int_of_real :: "real \<Rightarrow> int"
wenzelm@19765
   100
  "int_of_real x = (SOME y. real y = x)"
obua@16782
   101
  real_is_int :: "real \<Rightarrow> bool"
wenzelm@19765
   102
  "real_is_int x = (EX (u::int). x = real u)"
obua@16782
   103
obua@16782
   104
lemma real_is_int_def2: "real_is_int x = (x = real (int_of_real x))"
obua@16782
   105
by (auto simp add: real_is_int_def int_of_real_def)
obua@16782
   106
obua@16782
   107
lemma float_transfer: "real_is_int ((real a)*(pow2 c)) \<Longrightarrow> float (a, b) = float (int_of_real ((real a)*(pow2 c)), b - c)"
obua@16782
   108
by (simp add: float_def real_is_int_def2 pow2_add[symmetric])
obua@16782
   109
obua@16782
   110
lemma pow2_int: "pow2 (int c) = (2::real)^c"
obua@16782
   111
by (simp add: pow2_def)
obua@16782
   112
wenzelm@19765
   113
lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b - int c)"
obua@16782
   114
by (simp add: float_def pow2_int[symmetric] pow2_add[symmetric])
obua@16782
   115
obua@16782
   116
lemma real_is_int_real[simp]: "real_is_int (real (x::int))"
obua@16782
   117
by (auto simp add: real_is_int_def int_of_real_def)
obua@16782
   118
obua@16782
   119
lemma int_of_real_real[simp]: "int_of_real (real x) = x"
obua@16782
   120
by (simp add: int_of_real_def)
obua@16782
   121
obua@16782
   122
lemma real_int_of_real[simp]: "real_is_int x \<Longrightarrow> real (int_of_real x) = x"
obua@16782
   123
by (auto simp add: int_of_real_def real_is_int_def)
obua@16782
   124
obua@16782
   125
lemma real_is_int_add_int_of_real: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> (int_of_real (a+b)) = (int_of_real a) + (int_of_real b)"
obua@16782
   126
by (auto simp add: int_of_real_def real_is_int_def)
obua@16782
   127
obua@16782
   128
lemma real_is_int_add[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a+b)"
obua@16782
   129
apply (subst real_is_int_def2)
obua@16782
   130
apply (simp add: real_is_int_add_int_of_real real_int_of_real)
obua@16782
   131
done
obua@16782
   132
obua@16782
   133
lemma int_of_real_sub: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> (int_of_real (a-b)) = (int_of_real a) - (int_of_real b)"
obua@16782
   134
by (auto simp add: int_of_real_def real_is_int_def)
obua@16782
   135
obua@16782
   136
lemma real_is_int_sub[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a-b)"
obua@16782
   137
apply (subst real_is_int_def2)
obua@16782
   138
apply (simp add: int_of_real_sub real_int_of_real)
obua@16782
   139
done
obua@16782
   140
obua@16782
   141
lemma real_is_int_rep: "real_is_int x \<Longrightarrow> ?! (a::int). real a = x"
obua@16782
   142
by (auto simp add: real_is_int_def)
obua@16782
   143
wenzelm@19765
   144
lemma int_of_real_mult:
obua@16782
   145
  assumes "real_is_int a" "real_is_int b"
obua@16782
   146
  shows "(int_of_real (a*b)) = (int_of_real a) * (int_of_real b)"
obua@16782
   147
proof -
obua@16782
   148
  from prems have a: "?! (a'::int). real a' = a" by (rule_tac real_is_int_rep, auto)
obua@16782
   149
  from prems have b: "?! (b'::int). real b' = b" by (rule_tac real_is_int_rep, auto)
obua@16782
   150
  from a obtain a'::int where a':"a = real a'" by auto
obua@16782
   151
  from b obtain b'::int where b':"b = real b'" by auto
obua@16782
   152
  have r: "real a' * real b' = real (a' * b')" by auto
obua@16782
   153
  show ?thesis
obua@16782
   154
    apply (simp add: a' b')
obua@16782
   155
    apply (subst r)
obua@16782
   156
    apply (simp only: int_of_real_real)
obua@16782
   157
    done
obua@16782
   158
qed
obua@16782
   159
obua@16782
   160
lemma real_is_int_mult[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a*b)"
obua@16782
   161
apply (subst real_is_int_def2)
obua@16782
   162
apply (simp add: int_of_real_mult)
obua@16782
   163
done
obua@16782
   164
obua@16782
   165
lemma real_is_int_0[simp]: "real_is_int (0::real)"
obua@16782
   166
by (simp add: real_is_int_def int_of_real_def)
obua@16782
   167
obua@16782
   168
lemma real_is_int_1[simp]: "real_is_int (1::real)"
obua@16782
   169
proof -
obua@16782
   170
  have "real_is_int (1::real) = real_is_int(real (1::int))" by auto
obua@16782
   171
  also have "\<dots> = True" by (simp only: real_is_int_real)
obua@16782
   172
  ultimately show ?thesis by auto
obua@16782
   173
qed
obua@16782
   174
obua@16782
   175
lemma real_is_int_n1: "real_is_int (-1::real)"
obua@16782
   176
proof -
obua@16782
   177
  have "real_is_int (-1::real) = real_is_int(real (-1::int))" by auto
obua@16782
   178
  also have "\<dots> = True" by (simp only: real_is_int_real)
obua@16782
   179
  ultimately show ?thesis by auto
obua@16782
   180
qed
obua@16782
   181
obua@16782
   182
lemma real_is_int_number_of[simp]: "real_is_int ((number_of::bin\<Rightarrow>real) x)"
obua@16782
   183
proof -
obua@16782
   184
  have neg1: "real_is_int (-1::real)"
obua@16782
   185
  proof -
obua@16782
   186
    have "real_is_int (-1::real) = real_is_int(real (-1::int))" by auto
obua@16782
   187
    also have "\<dots> = True" by (simp only: real_is_int_real)
obua@16782
   188
    ultimately show ?thesis by auto
obua@16782
   189
  qed
wenzelm@19765
   190
wenzelm@19765
   191
  {
obua@16782
   192
    fix x::int
obua@16782
   193
    have "!! y. real_is_int ((number_of::bin\<Rightarrow>real) (Abs_Bin x))"
obua@16782
   194
      apply (simp add: number_of_eq)
obua@16782
   195
      apply (subst Abs_Bin_inverse)
obua@16782
   196
      apply (simp add: Bin_def)
obua@16782
   197
      apply (induct x)
obua@16782
   198
      apply (induct_tac n)
obua@16782
   199
      apply (simp)
obua@16782
   200
      apply (simp)
obua@16782
   201
      apply (induct_tac n)
obua@16782
   202
      apply (simp add: neg1)
obua@16782
   203
    proof -
obua@16782
   204
      fix n :: nat
obua@16782
   205
      assume rn: "(real_is_int (of_int (- (int (Suc n)))))"
obua@16782
   206
      have s: "-(int (Suc (Suc n))) = -1 + - (int (Suc n))" by simp
obua@16782
   207
      show "real_is_int (of_int (- (int (Suc (Suc n)))))"
wenzelm@19765
   208
        apply (simp only: s of_int_add)
wenzelm@19765
   209
        apply (rule real_is_int_add)
wenzelm@19765
   210
        apply (simp add: neg1)
wenzelm@19765
   211
        apply (simp only: rn)
wenzelm@19765
   212
        done
obua@16782
   213
    qed
obua@16782
   214
  }
obua@16782
   215
  note Abs_Bin = this
obua@16782
   216
  {
obua@16782
   217
    fix x :: bin
obua@16782
   218
    have "? u. x = Abs_Bin u"
obua@16782
   219
      apply (rule exI[where x = "Rep_Bin x"])
obua@16782
   220
      apply (simp add: Rep_Bin_inverse)
obua@16782
   221
      done
obua@16782
   222
  }
obua@16782
   223
  then obtain u::int where "x = Abs_Bin u" by auto
obua@16782
   224
  with Abs_Bin show ?thesis by auto
obua@16782
   225
qed
obua@16782
   226
obua@16782
   227
lemma int_of_real_0[simp]: "int_of_real (0::real) = (0::int)"
obua@16782
   228
by (simp add: int_of_real_def)
obua@16782
   229
obua@16782
   230
lemma int_of_real_1[simp]: "int_of_real (1::real) = (1::int)"
wenzelm@19765
   231
proof -
obua@16782
   232
  have 1: "(1::real) = real (1::int)" by auto
obua@16782
   233
  show ?thesis by (simp only: 1 int_of_real_real)
obua@16782
   234
qed
obua@16782
   235
obua@16782
   236
lemma int_of_real_number_of[simp]: "int_of_real (number_of b) = number_of b"
obua@16782
   237
proof -
obua@16782
   238
  have "real_is_int (number_of b)" by simp
obua@16782
   239
  then have uu: "?! u::int. number_of b = real u" by (auto simp add: real_is_int_rep)
obua@16782
   240
  then obtain u::int where u:"number_of b = real u" by auto
wenzelm@19765
   241
  have "number_of b = real ((number_of b)::int)"
obua@16782
   242
    by (simp add: number_of_eq real_of_int_def)
wenzelm@19765
   243
  have ub: "number_of b = real ((number_of b)::int)"
obua@16782
   244
    by (simp add: number_of_eq real_of_int_def)
obua@16782
   245
  from uu u ub have unb: "u = number_of b"
obua@16782
   246
    by blast
obua@16782
   247
  have "int_of_real (number_of b) = u" by (simp add: u)
obua@16782
   248
  with unb show ?thesis by simp
obua@16782
   249
qed
obua@16782
   250
obua@16782
   251
lemma float_transfer_even: "even a \<Longrightarrow> float (a, b) = float (a div 2, b+1)"
obua@16782
   252
  apply (subst float_transfer[where a="a" and b="b" and c="-1", simplified])
obua@16782
   253
  apply (simp_all add: pow2_def even_def real_is_int_def ring_eq_simps)
obua@16782
   254
  apply (auto)
obua@16782
   255
proof -
obua@16782
   256
  fix q::int
obua@16782
   257
  have a:"b - (-1\<Colon>int) = (1\<Colon>int) + b" by arith
wenzelm@19765
   258
  show "(float (q, (b - (-1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))"
obua@16782
   259
    by (simp add: a)
obua@16782
   260
qed
wenzelm@19765
   261
obua@16782
   262
consts
obua@16782
   263
  norm_float :: "int*int \<Rightarrow> int*int"
obua@16782
   264
obua@16782
   265
lemma int_div_zdiv: "int (a div b) = (int a) div (int b)"
obua@16782
   266
apply (subst split_div, auto)
obua@16782
   267
apply (subst split_zdiv, auto)
obua@16782
   268
apply (rule_tac a="int (b * i) + int j" and b="int b" and r="int j" and r'=ja in IntDiv.unique_quotient)
obua@16782
   269
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat)
obua@16782
   270
done
obua@16782
   271
obua@16782
   272
lemma int_mod_zmod: "int (a mod b) = (int a) mod (int b)"
obua@16782
   273
apply (subst split_mod, auto)
obua@16782
   274
apply (subst split_zmod, auto)
obua@16782
   275
apply (rule_tac a="int (b * i) + int j" and b="int b" and q="int i" and q'=ia in IntDiv.unique_remainder)
obua@16782
   276
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat)
obua@16782
   277
done
obua@16782
   278
obua@16782
   279
lemma abs_div_2_less: "a \<noteq> 0 \<Longrightarrow> a \<noteq> -1 \<Longrightarrow> abs((a::int) div 2) < abs a"
obua@16782
   280
by arith
obua@16782
   281
obua@16782
   282
lemma terminating_norm_float: "\<forall>a. (a::int) \<noteq> 0 \<and> even a \<longrightarrow> a \<noteq> 0 \<and> \<bar>a div 2\<bar> < \<bar>a\<bar>"
obua@16782
   283
apply (auto)
obua@16782
   284
apply (rule abs_div_2_less)
obua@16782
   285
apply (auto)
obua@16782
   286
done
obua@16782
   287
wenzelm@19765
   288
ML {* simp_depth_limit := 2 *}
obua@16782
   289
recdef norm_float "measure (% (a,b). nat (abs a))"
obua@16782
   290
  "norm_float (a,b) = (if (a \<noteq> 0) & (even a) then norm_float (a div 2, b+1) else (if a=0 then (0,0) else (a,b)))"
obua@16782
   291
(hints simp: terminating_norm_float)
obua@16782
   292
ML {* simp_depth_limit := 1000 *}
obua@16782
   293
obua@16782
   294
lemma norm_float: "float x = float (norm_float x)"
obua@16782
   295
proof -
obua@16782
   296
  {
wenzelm@19765
   297
    fix a b :: int
wenzelm@19765
   298
    have norm_float_pair: "float (a,b) = float (norm_float (a,b))"
obua@16782
   299
    proof (induct a b rule: norm_float.induct)
obua@16782
   300
      case (1 u v)
wenzelm@19765
   301
      show ?case
obua@16782
   302
      proof cases
wenzelm@19765
   303
        assume u: "u \<noteq> 0 \<and> even u"
wenzelm@19765
   304
        with prems have ind: "float (u div 2, v + 1) = float (norm_float (u div 2, v + 1))" by auto
wenzelm@19765
   305
        with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even)
wenzelm@19765
   306
        then show ?thesis
wenzelm@19765
   307
          apply (subst norm_float.simps)
wenzelm@19765
   308
          apply (simp add: ind)
wenzelm@19765
   309
          done
obua@16782
   310
      next
wenzelm@19765
   311
        assume "~(u \<noteq> 0 \<and> even u)"
wenzelm@19765
   312
        then show ?thesis
wenzelm@19765
   313
          by (simp add: prems float_def)
obua@16782
   314
      qed
obua@16782
   315
    qed
obua@16782
   316
  }
obua@16782
   317
  note helper = this
obua@16782
   318
  have "? a b. x = (a,b)" by auto
obua@16782
   319
  then obtain a b where "x = (a, b)" by blast
obua@16782
   320
  then show ?thesis by (simp only: helper)
obua@16782
   321
qed
obua@16782
   322
obua@16782
   323
lemma pow2_int: "pow2 (int n) = 2^n"
obua@16782
   324
  by (simp add: pow2_def)
obua@16782
   325
wenzelm@19765
   326
lemma float_add:
wenzelm@19765
   327
  "float (a1, e1) + float (a2, e2) =
wenzelm@19765
   328
  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1)
obua@16782
   329
  else float (a1*2^(nat (e1-e2))+a2, e2))"
obua@16782
   330
  apply (simp add: float_def ring_eq_simps)
obua@16782
   331
  apply (auto simp add: pow2_int[symmetric] pow2_add[symmetric])
obua@16782
   332
  done
obua@16782
   333
obua@16782
   334
lemma float_mult:
wenzelm@19765
   335
  "float (a1, e1) * float (a2, e2) =
obua@16782
   336
  (float (a1 * a2, e1 + e2))"
obua@16782
   337
  by (simp add: float_def pow2_add)
obua@16782
   338
obua@16782
   339
lemma float_minus:
obua@16782
   340
  "- (float (a,b)) = float (-a, b)"
obua@16782
   341
  by (simp add: float_def)
obua@16782
   342
obua@16782
   343
lemma zero_less_pow2:
obua@16782
   344
  "0 < pow2 x"
obua@16782
   345
proof -
obua@16782
   346
  {
obua@16782
   347
    fix y
wenzelm@19765
   348
    have "0 <= y \<Longrightarrow> 0 < pow2 y"
obua@16782
   349
      by (induct y, induct_tac n, simp_all add: pow2_add)
obua@16782
   350
  }
obua@16782
   351
  note helper=this
obua@16782
   352
  show ?thesis
obua@16782
   353
    apply (case_tac "0 <= x")
obua@16782
   354
    apply (simp add: helper)
obua@16782
   355
    apply (subst pow2_neg)
obua@16782
   356
    apply (simp add: helper)
obua@16782
   357
    done
obua@16782
   358
qed
obua@16782
   359
obua@16782
   360
lemma zero_le_float:
obua@16782
   361
  "(0 <= float (a,b)) = (0 <= a)"
obua@16782
   362
  apply (auto simp add: float_def)
wenzelm@19765
   363
  apply (auto simp add: zero_le_mult_iff zero_less_pow2)
obua@16782
   364
  apply (insert zero_less_pow2[of b])
obua@16782
   365
  apply (simp_all)
obua@16782
   366
  done
obua@16782
   367
obua@16782
   368
lemma float_le_zero:
obua@16782
   369
  "(float (a,b) <= 0) = (a <= 0)"
obua@16782
   370
  apply (auto simp add: float_def)
obua@16782
   371
  apply (auto simp add: mult_le_0_iff)
obua@16782
   372
  apply (insert zero_less_pow2[of b])
obua@16782
   373
  apply auto
obua@16782
   374
  done
obua@16782
   375
obua@16782
   376
lemma float_abs:
obua@16782
   377
  "abs (float (a,b)) = (if 0 <= a then (float (a,b)) else (float (-a,b)))"
obua@16782
   378
  apply (auto simp add: abs_if)
obua@16782
   379
  apply (simp_all add: zero_le_float[symmetric, of a b] float_minus)
obua@16782
   380
  done
obua@16782
   381
obua@16782
   382
lemma float_zero:
obua@16782
   383
  "float (0, b) = 0"
obua@16782
   384
  by (simp add: float_def)
obua@16782
   385
obua@16782
   386
lemma float_pprt:
obua@16782
   387
  "pprt (float (a, b)) = (if 0 <= a then (float (a,b)) else (float (0, b)))"
obua@16782
   388
  by (auto simp add: zero_le_float float_le_zero float_zero)
obua@16782
   389
obua@16782
   390
lemma float_nprt:
obua@16782
   391
  "nprt (float (a, b)) = (if 0 <= a then (float (0,b)) else (float (a, b)))"
obua@16782
   392
  by (auto simp add: zero_le_float float_le_zero float_zero)
obua@16782
   393
obua@16782
   394
lemma norm_0_1: "(0::_::number_ring) = Numeral0 & (1::_::number_ring) = Numeral1"
obua@16782
   395
  by auto
wenzelm@19765
   396
obua@16782
   397
lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)"
obua@16782
   398
  by simp
obua@16782
   399
obua@16782
   400
lemma add_right_zero: "a + 0 = (a::'a::comm_monoid_add)"
obua@16782
   401
  by simp
obua@16782
   402
obua@16782
   403
lemma mult_left_one: "1 * a = (a::'a::semiring_1)"
obua@16782
   404
  by simp
obua@16782
   405
obua@16782
   406
lemma mult_right_one: "a * 1 = (a::'a::semiring_1)"
obua@16782
   407
  by simp
obua@16782
   408
obua@16782
   409
lemma int_pow_0: "(a::int)^(Numeral0) = 1"
obua@16782
   410
  by simp
obua@16782
   411
obua@16782
   412
lemma int_pow_1: "(a::int)^(Numeral1) = a"
obua@16782
   413
  by simp
obua@16782
   414
obua@16782
   415
lemma zero_eq_Numeral0_nring: "(0::'a::number_ring) = Numeral0"
obua@16782
   416
  by simp
obua@16782
   417
obua@16782
   418
lemma one_eq_Numeral1_nring: "(1::'a::number_ring) = Numeral1"
obua@16782
   419
  by simp
obua@16782
   420
obua@16782
   421
lemma zero_eq_Numeral0_nat: "(0::nat) = Numeral0"
obua@16782
   422
  by simp
obua@16782
   423
obua@16782
   424
lemma one_eq_Numeral1_nat: "(1::nat) = Numeral1"
obua@16782
   425
  by simp
obua@16782
   426
obua@16782
   427
lemma zpower_Pls: "(z::int)^Numeral0 = Numeral1"
obua@16782
   428
  by simp
obua@16782
   429
obua@16782
   430
lemma zpower_Min: "(z::int)^((-1)::nat) = Numeral1"
obua@16782
   431
proof -
obua@16782
   432
  have 1:"((-1)::nat) = 0"
obua@16782
   433
    by simp
obua@16782
   434
  show ?thesis by (simp add: 1)
obua@16782
   435
qed
obua@16782
   436
obua@16782
   437
lemma fst_cong: "a=a' \<Longrightarrow> fst (a,b) = fst (a',b)"
obua@16782
   438
  by simp
obua@16782
   439
obua@16782
   440
lemma snd_cong: "b=b' \<Longrightarrow> snd (a,b) = snd (a,b')"
obua@16782
   441
  by simp
obua@16782
   442
obua@16782
   443
lemma lift_bool: "x \<Longrightarrow> x=True"
obua@16782
   444
  by simp
obua@16782
   445
obua@16782
   446
lemma nlift_bool: "~x \<Longrightarrow> x=False"
obua@16782
   447
  by simp
obua@16782
   448
obua@16782
   449
lemma not_false_eq_true: "(~ False) = True" by simp
obua@16782
   450
obua@16782
   451
lemma not_true_eq_false: "(~ True) = False" by simp
obua@16782
   452
obua@16782
   453
wenzelm@19765
   454
lemmas binarith =
obua@16782
   455
  Pls_0_eq Min_1_eq
wenzelm@19765
   456
  bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0
obua@16782
   457
  bin_succ_Pls bin_succ_Min bin_succ_1 bin_succ_0
obua@16782
   458
  bin_add_Pls bin_add_Min bin_add_BIT_0 bin_add_BIT_10
wenzelm@19765
   459
  bin_add_BIT_11 bin_minus_Pls bin_minus_Min bin_minus_1
wenzelm@19765
   460
  bin_minus_0 bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0
obua@16782
   461
  bin_add_Pls_right bin_add_Min_right
obua@16782
   462
obua@16782
   463
lemma int_eq_number_of_eq: "(((number_of v)::int)=(number_of w)) = iszero ((number_of (bin_add v (bin_minus w)))::int)"
obua@16782
   464
  by simp
obua@16782
   465
wenzelm@19765
   466
lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)"
obua@16782
   467
  by (simp only: iszero_number_of_Pls)
obua@16782
   468
obua@16782
   469
lemma int_nonzero_number_of_Min: "~(iszero ((-1)::int))"
obua@16782
   470
  by simp
obua@16782
   471
obua@16782
   472
lemma int_iszero_number_of_0: "iszero ((number_of (w BIT bit.B0))::int) = iszero ((number_of w)::int)"
obua@16782
   473
  by simp
obua@16782
   474
wenzelm@19765
   475
lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)"
obua@16782
   476
  by simp
obua@16782
   477
obua@16782
   478
lemma int_less_number_of_eq_neg: "(((number_of x)::int) < number_of y) = neg ((number_of (bin_add x (bin_minus y)))::int)"
obua@16782
   479
  by simp
obua@16782
   480
wenzelm@19765
   481
lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))"
obua@16782
   482
  by simp
obua@16782
   483
obua@16782
   484
lemma int_neg_number_of_Min: "neg (-1::int)"
obua@16782
   485
  by simp
obua@16782
   486
obua@16782
   487
lemma int_neg_number_of_BIT: "neg ((number_of (w BIT x))::int) = neg ((number_of w)::int)"
obua@16782
   488
  by simp
obua@16782
   489
obua@16782
   490
lemma int_le_number_of_eq: "(((number_of x)::int) \<le> number_of y) = (\<not> neg ((number_of (bin_add y (bin_minus x)))::int))"
obua@16782
   491
  by simp
obua@16782
   492
wenzelm@19765
   493
lemmas intarithrel =
wenzelm@19765
   494
  int_eq_number_of_eq
wenzelm@19765
   495
  lift_bool[OF int_iszero_number_of_Pls] nlift_bool[OF int_nonzero_number_of_Min] int_iszero_number_of_0
obua@16782
   496
  lift_bool[OF int_iszero_number_of_1] int_less_number_of_eq_neg nlift_bool[OF int_not_neg_number_of_Pls] lift_bool[OF int_neg_number_of_Min]
obua@16782
   497
  int_neg_number_of_BIT int_le_number_of_eq
obua@16782
   498
obua@16782
   499
lemma int_number_of_add_sym: "((number_of v)::int) + number_of w = number_of (bin_add v w)"
obua@16782
   500
  by simp
obua@16782
   501
obua@16782
   502
lemma int_number_of_diff_sym: "((number_of v)::int) - number_of w = number_of (bin_add v (bin_minus w))"
obua@16782
   503
  by simp
obua@16782
   504
obua@16782
   505
lemma int_number_of_mult_sym: "((number_of v)::int) * number_of w = number_of (bin_mult v w)"
obua@16782
   506
  by simp
obua@16782
   507
obua@16782
   508
lemma int_number_of_minus_sym: "- ((number_of v)::int) = number_of (bin_minus v)"
obua@16782
   509
  by simp
obua@16782
   510
obua@16782
   511
lemmas intarith = int_number_of_add_sym int_number_of_minus_sym int_number_of_diff_sym int_number_of_mult_sym
obua@16782
   512
obua@16782
   513
lemmas natarith = add_nat_number_of diff_nat_number_of mult_nat_number_of eq_nat_number_of less_nat_number_of
obua@16782
   514
wenzelm@19765
   515
lemmas powerarith = nat_number_of zpower_number_of_even
wenzelm@19765
   516
  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
obua@16782
   517
  zpower_Pls zpower_Min
obua@16782
   518
obua@16782
   519
lemmas floatarith[simplified norm_0_1] = float_add float_mult float_minus float_abs zero_le_float float_pprt float_nprt
obua@16782
   520
obua@16782
   521
(* for use with the compute oracle *)
obua@16782
   522
lemmas arith = binarith intarith intarithrel natarith powerarith floatarith not_false_eq_true not_true_eq_false
obua@16782
   523
obua@16782
   524
end