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