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