equal
deleted
inserted
replaced
71 DO IF a<b THEN (b := b-a; x := x+y) ELSE (a := a-b; y := y+x) FI OD |
71 DO IF a<b THEN (b := b-a; x := x+y) ELSE (a := a-b; y := y+x) FI OD |
72 {a = gcd A B & 2*A*B = a*(x+y)}" |
72 {a = gcd A B & 2*A*B = a*(x+y)}" |
73 apply vcg |
73 apply vcg |
74 apply simp |
74 apply simp |
75 apply(simp add: distribs gcd_diff_r not_less_iff_le gcd_diff_l) |
75 apply(simp add: distribs gcd_diff_r not_less_iff_le gcd_diff_l) |
76 apply arith |
|
77 apply(simp add: distribs gcd_nnn) |
76 apply(simp add: distribs gcd_nnn) |
78 done |
77 done |
79 |
78 |
80 (** Power by iterated squaring and multiplication **) |
79 (** Power by iterated squaring and multiplication **) |
81 |
80 |
134 WHILE (r+1)*(r+1) <= x |
133 WHILE (r+1)*(r+1) <= x |
135 INV {r*r <= x & x=X} |
134 INV {r*r <= x & x=X} |
136 DO r := r+1 OD |
135 DO r := r+1 OD |
137 {r*r <= X & X < (r+1)*(r+1)}" |
136 {r*r <= X & X < (r+1)*(r+1)}" |
138 apply vcg_simp |
137 apply vcg_simp |
139 apply auto |
|
140 done |
138 done |
141 |
139 |
142 (* without multiplication *) |
140 (* without multiplication *) |
143 |
141 |
144 lemma sqrt_without_multiplication: "VARS u w r x |
142 lemma sqrt_without_multiplication: "VARS u w r x |
147 WHILE w <= x |
145 WHILE w <= x |
148 INV {u = r+r+1 & w = (r+1)*(r+1) & r*r <= x & x=X} |
146 INV {u = r+r+1 & w = (r+1)*(r+1) & r*r <= x & x=X} |
149 DO r := r + 1; w := w + u + 2; u := u + 2 OD |
147 DO r := r + 1; w := w + u + 2; u := u + 2 OD |
150 {r*r <= X & X < (r+1)*(r+1)}" |
148 {r*r <= X & X < (r+1)*(r+1)}" |
151 apply vcg_simp |
149 apply vcg_simp |
152 apply auto |
|
153 done |
150 done |
154 |
151 |
155 |
152 |
156 (*** LISTS ***) |
153 (*** LISTS ***) |
157 |
154 |
229 {leq A u & (!k. u<k & k<l --> A!k = pivot) & geq A l}" |
226 {leq A u & (!k. u<k & k<l --> A!k = pivot) & geq A l}" |
230 (* expand and delete abbreviations first *) |
227 (* expand and delete abbreviations first *) |
231 apply (simp); |
228 apply (simp); |
232 apply (erule thin_rl)+ |
229 apply (erule thin_rl)+ |
233 apply vcg_simp |
230 apply vcg_simp |
234 apply (force simp: neq_Nil_conv) |
231 apply (force simp: neq_Nil_conv) |
235 apply (blast elim!: less_SucE intro: Suc_leI) |
232 apply (blast elim!: less_SucE intro: Suc_leI) |
236 apply (blast elim!: less_SucE intro: less_imp_diff_less dest: lem) |
233 apply (blast elim!: less_SucE intro: less_imp_diff_less dest: lem) |
237 apply (force simp: nth_list_update) |
234 apply (force simp: nth_list_update) |
238 apply (auto intro: order_antisym) |
|
239 done |
235 done |
240 |
236 |
241 end |
237 end |