author  obua 
Tue, 12 Jul 2005 21:49:38 +0200  
changeset 16782  b214f21ae396 
child 16890  c4e5afaba440 
permissions  rwrr 
16782
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

1 
(* Title: HOL/Real/Float.thy 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

2 
ID: $Id$ 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

3 
Author: Steven Obua 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

4 
*) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

5 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

6 
theory Float = Real: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

7 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

8 
constdefs 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

9 
pow2 :: "int \<Rightarrow> real" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

10 
"pow2 a == if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (a))))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

11 
float :: "int * int \<Rightarrow> real" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

12 
"float x == (real (fst x)) * (pow2 (snd x))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

13 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

14 
lemma pow2_0[simp]: "pow2 0 = 1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

15 
by (simp add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

16 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

17 
lemma pow2_1[simp]: "pow2 1 = 2" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

18 
by (simp add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

19 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

20 
lemma pow2_neg: "pow2 x = inverse (pow2 (x))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

21 
by (simp add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

22 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

23 
lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

24 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

25 
have h: "! n. nat (2 + int n)  Suc 0 = nat (1 + int n)" by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

26 
have g: "! a b. a  1 = a + (1::int)" by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

27 
have pos: "! n. pow2 (int n + 1) = 2 * pow2 (int n)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

28 
apply (auto, induct_tac n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

29 
apply (simp_all add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

30 
apply (rule_tac m1="2" and n1="nat (2 + int na)" in ssubst[OF realpow_num_eq_if]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

31 
apply (auto simp add: h) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

32 
apply arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

33 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

34 
show ?thesis 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

35 
proof (induct a) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

36 
case (1 n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

37 
from pos show ?case by (simp add: ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

38 
next 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

39 
case (2 n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

40 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

41 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

42 
apply (subst pow2_neg[of " int n"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

43 
apply (subst pow2_neg[of "1  int n"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

44 
apply (auto simp add: g pos) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

45 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

46 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

47 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

48 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

49 
lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

50 
proof (induct b) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

51 
case (1 n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

52 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

53 
proof (induct n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

54 
case 0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

55 
show ?case by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

56 
next 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

57 
case (Suc m) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

58 
show ?case by (auto simp add: ring_eq_simps pow2_add1 prems) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

59 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

60 
next 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

61 
case (2 n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

62 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

63 
proof (induct n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

64 
case 0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

65 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

66 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

67 
apply (subst pow2_neg[of "a + 1"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

68 
apply (subst pow2_neg[of "1"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

69 
apply (simp) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

70 
apply (insert pow2_add1[of "a"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

71 
apply (simp add: ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

72 
apply (subst pow2_neg[of "a"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

73 
apply (simp) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

74 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

75 
case (Suc m) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

76 
have a: "int m  (a + 2) = 1 + (int m  a + 1)" by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

77 
have b: "int m  2 = 1 + (int m + 1)" by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

78 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

79 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

80 
apply (subst pow2_neg[of "a + (2  int m)"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

81 
apply (subst pow2_neg[of "2  int m"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

82 
apply (auto simp add: ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

83 
apply (subst a) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

84 
apply (subst b) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

85 
apply (simp only: pow2_add1) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

86 
apply (subst pow2_neg[of "int m  a + 1"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

87 
apply (subst pow2_neg[of "int m + 1"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

88 
apply auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

89 
apply (insert prems) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

90 
apply (auto simp add: ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

91 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

92 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

93 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

94 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

95 
lemma "float (a, e) + float (b, e) = float (a + b, e)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

96 
by (simp add: float_def ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

97 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

98 
constdefs 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

99 
int_of_real :: "real \<Rightarrow> int" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

100 
"int_of_real x == SOME y. real y = x" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

101 
real_is_int :: "real \<Rightarrow> bool" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

102 
"real_is_int x == ? (u::int). x = real u" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

103 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

104 
lemma real_is_int_def2: "real_is_int x = (x = real (int_of_real x))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

105 
by (auto simp add: real_is_int_def int_of_real_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

106 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

108 
by (simp add: float_def real_is_int_def2 pow2_add[symmetric]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

109 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

110 
lemma pow2_int: "pow2 (int c) = (2::real)^c" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

111 
by (simp add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

112 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

113 
lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b  int c)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

114 
by (simp add: float_def pow2_int[symmetric] pow2_add[symmetric]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

115 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

116 
lemma real_is_int_real[simp]: "real_is_int (real (x::int))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

117 
by (auto simp add: real_is_int_def int_of_real_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

118 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

119 
lemma int_of_real_real[simp]: "int_of_real (real x) = x" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

120 
by (simp add: int_of_real_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

121 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

122 
lemma real_int_of_real[simp]: "real_is_int x \<Longrightarrow> real (int_of_real x) = x" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

123 
by (auto simp add: int_of_real_def real_is_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

124 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

126 
by (auto simp add: int_of_real_def real_is_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

127 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

128 
lemma real_is_int_add[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a+b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

129 
apply (subst real_is_int_def2) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

130 
apply (simp add: real_is_int_add_int_of_real real_int_of_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

131 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

132 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

133 
lemma int_of_real_sub: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> (int_of_real (ab)) = (int_of_real a)  (int_of_real b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

134 
by (auto simp add: int_of_real_def real_is_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

135 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

136 
lemma real_is_int_sub[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (ab)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

137 
apply (subst real_is_int_def2) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

138 
apply (simp add: int_of_real_sub real_int_of_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

139 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

140 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

141 
lemma real_is_int_rep: "real_is_int x \<Longrightarrow> ?! (a::int). real a = x" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

142 
by (auto simp add: real_is_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

143 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

144 
lemma int_of_real_mult: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

145 
assumes "real_is_int a" "real_is_int b" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

146 
shows "(int_of_real (a*b)) = (int_of_real a) * (int_of_real b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

147 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

148 
from prems have a: "?! (a'::int). real a' = a" by (rule_tac real_is_int_rep, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

149 
from prems have b: "?! (b'::int). real b' = b" by (rule_tac real_is_int_rep, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

150 
from a obtain a'::int where a':"a = real a'" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

151 
from b obtain b'::int where b':"b = real b'" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

152 
have r: "real a' * real b' = real (a' * b')" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

153 
show ?thesis 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

154 
apply (simp add: a' b') 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

155 
apply (subst r) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

156 
apply (simp only: int_of_real_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

157 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

158 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

159 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

160 
lemma real_is_int_mult[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a*b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

161 
apply (subst real_is_int_def2) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

162 
apply (simp add: int_of_real_mult) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

163 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

164 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

165 
lemma real_is_int_0[simp]: "real_is_int (0::real)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

166 
by (simp add: real_is_int_def int_of_real_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

167 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

168 
lemma real_is_int_1[simp]: "real_is_int (1::real)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

169 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

170 
have "real_is_int (1::real) = real_is_int(real (1::int))" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

171 
also have "\<dots> = True" by (simp only: real_is_int_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

172 
ultimately show ?thesis by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

173 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

174 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

175 
lemma real_is_int_n1: "real_is_int (1::real)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

176 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

177 
have "real_is_int (1::real) = real_is_int(real (1::int))" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

178 
also have "\<dots> = True" by (simp only: real_is_int_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

179 
ultimately show ?thesis by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

180 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

181 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

182 
lemma real_is_int_number_of[simp]: "real_is_int ((number_of::bin\<Rightarrow>real) x)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

183 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

184 
have neg1: "real_is_int (1::real)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

185 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

186 
have "real_is_int (1::real) = real_is_int(real (1::int))" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

187 
also have "\<dots> = True" by (simp only: real_is_int_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

188 
ultimately show ?thesis by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

189 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

190 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

191 
{ 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

192 
fix x::int 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

193 
have "!! y. real_is_int ((number_of::bin\<Rightarrow>real) (Abs_Bin x))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

194 
apply (simp add: number_of_eq) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

195 
apply (subst Abs_Bin_inverse) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

196 
apply (simp add: Bin_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

197 
apply (induct x) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

198 
apply (induct_tac n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

199 
apply (simp) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

200 
apply (simp) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

201 
apply (induct_tac n) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

202 
apply (simp add: neg1) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

203 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

204 
fix n :: nat 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

205 
assume rn: "(real_is_int (of_int ( (int (Suc n)))))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

206 
have s: "(int (Suc (Suc n))) = 1 +  (int (Suc n))" by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

207 
show "real_is_int (of_int ( (int (Suc (Suc n)))))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

208 
apply (simp only: s of_int_add) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

209 
apply (rule real_is_int_add) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

210 
apply (simp add: neg1) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

211 
apply (simp only: rn) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

212 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

213 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

214 
} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

215 
note Abs_Bin = this 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

216 
{ 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

217 
fix x :: bin 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

218 
have "? u. x = Abs_Bin u" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

219 
apply (rule exI[where x = "Rep_Bin x"]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

220 
apply (simp add: Rep_Bin_inverse) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

221 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

222 
} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

223 
then obtain u::int where "x = Abs_Bin u" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

224 
with Abs_Bin show ?thesis by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

225 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

226 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

227 
lemma int_of_real_0[simp]: "int_of_real (0::real) = (0::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

228 
by (simp add: int_of_real_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

229 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

230 
lemma int_of_real_1[simp]: "int_of_real (1::real) = (1::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

231 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

232 
have 1: "(1::real) = real (1::int)" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

233 
show ?thesis by (simp only: 1 int_of_real_real) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

234 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

235 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

236 
lemma int_of_real_number_of[simp]: "int_of_real (number_of b) = number_of b" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

237 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

238 
have "real_is_int (number_of b)" by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

239 
then have uu: "?! u::int. number_of b = real u" by (auto simp add: real_is_int_rep) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

240 
then obtain u::int where u:"number_of b = real u" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

241 
have "number_of b = real ((number_of b)::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

242 
by (simp add: number_of_eq real_of_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

243 
have ub: "number_of b = real ((number_of b)::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

244 
by (simp add: number_of_eq real_of_int_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

245 
from uu u ub have unb: "u = number_of b" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

246 
by blast 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

247 
have "int_of_real (number_of b) = u" by (simp add: u) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

248 
with unb show ?thesis by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

249 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

250 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

251 
lemma float_transfer_even: "even a \<Longrightarrow> float (a, b) = float (a div 2, b+1)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

252 
apply (subst float_transfer[where a="a" and b="b" and c="1", simplified]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

253 
apply (simp_all add: pow2_def even_def real_is_int_def ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

254 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

255 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

256 
fix q::int 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

257 
have a:"b  (1\<Colon>int) = (1\<Colon>int) + b" by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

258 
show "(float (q, (b  (1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

259 
by (simp add: a) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

260 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

261 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

262 
consts 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

263 
norm_float :: "int*int \<Rightarrow> int*int" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

264 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

265 
lemma int_div_zdiv: "int (a div b) = (int a) div (int b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

266 
apply (subst split_div, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

267 
apply (subst split_zdiv, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

269 
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

270 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

271 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

272 
lemma int_mod_zmod: "int (a mod b) = (int a) mod (int b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

273 
apply (subst split_mod, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

274 
apply (subst split_zmod, auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

276 
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

277 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

278 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

279 
lemma abs_div_2_less: "a \<noteq> 0 \<Longrightarrow> a \<noteq> 1 \<Longrightarrow> abs((a::int) div 2) < abs a" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

280 
by arith 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

281 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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>" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

283 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

284 
apply (rule abs_div_2_less) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

285 
apply (auto) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

286 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

287 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

288 
ML {* simp_depth_limit := 2 *} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

289 
recdef norm_float "measure (% (a,b). nat (abs a))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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)))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

291 
(hints simp: terminating_norm_float) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

292 
ML {* simp_depth_limit := 1000 *} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

293 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

294 
lemma norm_float: "float x = float (norm_float x)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

295 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

296 
{ 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

297 
fix a b :: int 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

298 
have norm_float_pair: "float (a,b) = float (norm_float (a,b))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

299 
proof (induct a b rule: norm_float.induct) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

300 
case (1 u v) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

301 
show ?case 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

302 
proof cases 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

303 
assume u: "u \<noteq> 0 \<and> even u" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

304 
with prems have ind: "float (u div 2, v + 1) = float (norm_float (u div 2, v + 1))" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

305 
with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

306 
then show ?thesis 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

307 
apply (subst norm_float.simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

308 
apply (simp add: ind) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

309 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

310 
next 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

311 
assume "~(u \<noteq> 0 \<and> even u)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

312 
then show ?thesis 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

313 
by (simp add: prems float_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

314 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

315 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

316 
} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

317 
note helper = this 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

318 
have "? a b. x = (a,b)" by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

319 
then obtain a b where "x = (a, b)" by blast 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

320 
then show ?thesis by (simp only: helper) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

321 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

322 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

323 
lemma pow2_int: "pow2 (int n) = 2^n" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

324 
by (simp add: pow2_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

325 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

326 
lemma float_add: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

327 
"float (a1, e1) + float (a2, e2) = 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

328 
(if e1<=e2 then float (a1+a2*2^(nat(e2e1)), e1) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

329 
else float (a1*2^(nat (e1e2))+a2, e2))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

330 
apply (simp add: float_def ring_eq_simps) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

331 
apply (auto simp add: pow2_int[symmetric] pow2_add[symmetric]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

332 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

333 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

334 
lemma float_mult: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

335 
"float (a1, e1) * float (a2, e2) = 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

336 
(float (a1 * a2, e1 + e2))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

337 
by (simp add: float_def pow2_add) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

338 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

339 
lemma float_minus: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

340 
" (float (a,b)) = float (a, b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

341 
by (simp add: float_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

342 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

343 
lemma zero_less_pow2: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

344 
"0 < pow2 x" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

345 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

346 
{ 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

347 
fix y 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

348 
have "0 <= y \<Longrightarrow> 0 < pow2 y" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

349 
by (induct y, induct_tac n, simp_all add: pow2_add) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

350 
} 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

351 
note helper=this 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

352 
show ?thesis 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

353 
apply (case_tac "0 <= x") 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

354 
apply (simp add: helper) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

355 
apply (subst pow2_neg) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

356 
apply (simp add: helper) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

357 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

358 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

359 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

360 
lemma zero_le_float: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

361 
"(0 <= float (a,b)) = (0 <= a)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

362 
apply (auto simp add: float_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

363 
apply (auto simp add: zero_le_mult_iff zero_less_pow2) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

364 
apply (insert zero_less_pow2[of b]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

365 
apply (simp_all) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

366 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

367 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

368 
lemma float_le_zero: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

369 
"(float (a,b) <= 0) = (a <= 0)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

370 
apply (auto simp add: float_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

371 
apply (auto simp add: mult_le_0_iff) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

372 
apply (insert zero_less_pow2[of b]) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

373 
apply auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

374 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

375 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

376 
lemma float_abs: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

377 
"abs (float (a,b)) = (if 0 <= a then (float (a,b)) else (float (a,b)))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

378 
apply (auto simp add: abs_if) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

379 
apply (simp_all add: zero_le_float[symmetric, of a b] float_minus) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

380 
done 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

381 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

382 
lemma float_zero: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

383 
"float (0, b) = 0" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

384 
by (simp add: float_def) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

385 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

386 
lemma float_pprt: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

387 
"pprt (float (a, b)) = (if 0 <= a then (float (a,b)) else (float (0, b)))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

388 
by (auto simp add: zero_le_float float_le_zero float_zero) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

389 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

390 
lemma float_nprt: 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

391 
"nprt (float (a, b)) = (if 0 <= a then (float (0,b)) else (float (a, b)))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

392 
by (auto simp add: zero_le_float float_le_zero float_zero) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

393 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

394 
lemma norm_0_1: "(0::_::number_ring) = Numeral0 & (1::_::number_ring) = Numeral1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

395 
by auto 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

396 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

397 
lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

398 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

399 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

400 
lemma add_right_zero: "a + 0 = (a::'a::comm_monoid_add)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

401 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

402 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

403 
lemma mult_left_one: "1 * a = (a::'a::semiring_1)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

404 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

405 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

406 
lemma mult_right_one: "a * 1 = (a::'a::semiring_1)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

407 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

408 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

409 
lemma int_pow_0: "(a::int)^(Numeral0) = 1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

410 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

411 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

412 
lemma int_pow_1: "(a::int)^(Numeral1) = a" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

413 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

414 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

415 
lemma zero_eq_Numeral0_nring: "(0::'a::number_ring) = Numeral0" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

416 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

417 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

418 
lemma one_eq_Numeral1_nring: "(1::'a::number_ring) = Numeral1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

419 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

420 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

421 
lemma zero_eq_Numeral0_nat: "(0::nat) = Numeral0" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

422 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

423 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

424 
lemma one_eq_Numeral1_nat: "(1::nat) = Numeral1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

425 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

426 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

427 
lemma zpower_Pls: "(z::int)^Numeral0 = Numeral1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

428 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

429 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

430 
lemma zpower_Min: "(z::int)^((1)::nat) = Numeral1" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

431 
proof  
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

432 
have 1:"((1)::nat) = 0" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

433 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

434 
show ?thesis by (simp add: 1) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

435 
qed 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

436 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

437 
lemma fst_cong: "a=a' \<Longrightarrow> fst (a,b) = fst (a',b)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

438 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

439 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

440 
lemma snd_cong: "b=b' \<Longrightarrow> snd (a,b) = snd (a,b')" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

441 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

442 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

443 
lemma lift_bool: "x \<Longrightarrow> x=True" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

444 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

445 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

446 
lemma nlift_bool: "~x \<Longrightarrow> x=False" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

447 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

448 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

449 
lemma not_false_eq_true: "(~ False) = True" by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

450 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

451 
lemma not_true_eq_false: "(~ True) = False" by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

452 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

453 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

454 
lemmas binarith = 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

455 
Pls_0_eq Min_1_eq 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

456 
bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

457 
bin_succ_Pls bin_succ_Min bin_succ_1 bin_succ_0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

458 
bin_add_Pls bin_add_Min bin_add_BIT_0 bin_add_BIT_10 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

459 
bin_add_BIT_11 bin_minus_Pls bin_minus_Min bin_minus_1 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

460 
bin_minus_0 bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

461 
bin_add_Pls_right bin_add_Min_right 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

462 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

463 
lemma int_eq_number_of_eq: "(((number_of v)::int)=(number_of w)) = iszero ((number_of (bin_add v (bin_minus w)))::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

464 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

465 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

466 
lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

467 
by (simp only: iszero_number_of_Pls) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

468 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

469 
lemma int_nonzero_number_of_Min: "~(iszero ((1)::int))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

470 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

471 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

472 
lemma int_iszero_number_of_0: "iszero ((number_of (w BIT bit.B0))::int) = iszero ((number_of w)::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

473 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

474 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

475 
lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

476 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

477 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

479 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

480 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

481 
lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

482 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

483 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

484 
lemma int_neg_number_of_Min: "neg (1::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

485 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

486 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

487 
lemma int_neg_number_of_BIT: "neg ((number_of (w BIT x))::int) = neg ((number_of w)::int)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

488 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

489 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

491 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

492 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

493 
lemmas intarithrel = 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

494 
int_eq_number_of_eq 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

495 
lift_bool[OF int_iszero_number_of_Pls] nlift_bool[OF int_nonzero_number_of_Min] int_iszero_number_of_0 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

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] 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

497 
int_neg_number_of_BIT int_le_number_of_eq 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

498 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

499 
lemma int_number_of_add_sym: "((number_of v)::int) + number_of w = number_of (bin_add v w)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

500 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

501 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

502 
lemma int_number_of_diff_sym: "((number_of v)::int)  number_of w = number_of (bin_add v (bin_minus w))" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

503 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

504 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

505 
lemma int_number_of_mult_sym: "((number_of v)::int) * number_of w = number_of (bin_mult v w)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

506 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

507 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

508 
lemma int_number_of_minus_sym: " ((number_of v)::int) = number_of (bin_minus v)" 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

509 
by simp 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

510 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

511 
lemmas intarith = int_number_of_add_sym int_number_of_minus_sym int_number_of_diff_sym int_number_of_mult_sym 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

512 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

513 
lemmas natarith = add_nat_number_of diff_nat_number_of mult_nat_number_of eq_nat_number_of less_nat_number_of 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

514 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

515 
lemmas powerarith = nat_number_of zpower_number_of_even 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

516 
zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring] 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

517 
zpower_Pls zpower_Min 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

518 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

519 
lemmas floatarith[simplified norm_0_1] = float_add float_mult float_minus float_abs zero_le_float float_pprt float_nprt 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

520 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

521 
(* for use with the compute oracle *) 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

522 
lemmas arith = binarith intarith intarithrel natarith powerarith floatarith not_false_eq_true not_true_eq_false 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

523 

b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

524 
end 
b214f21ae396
 use TableFun instead of homebrew binary tree in am_interpreter.ML
obua
parents:
diff
changeset

525 