Professional Documents
Culture Documents
Bài giải môn đặc tả hình thức từ câu 41-47
Bài giải môn đặc tả hình thức từ câu 41-47
insert_pos (x : R, A : R*) B: R*
pre
post: ( len A = 0 ^ B = cons (x, A)) V (len A > 0 ^ ((hd A
> x ^ B = cons(hd A, insert_pos(x, lt A))))
post: (len A = 0 ^ B = cons( x, A)) v ( len A > 0 ^ ((abs (hd A) abs (x) ^ B = cons ( x,
A) ) v (abs (hd A) < abs (x) ^ B = cons ( hd A, insert_pos( x, lt A))))
---------------------------------------------------------------------------------------43. Hy c t hm sp xp mng s thc A theo quy lut sau:
sort ( A : R*) B: R*
pre:
post: (len A
x ^ hd A
0) v hd A < 0) ^ B
x) v
x ^ B = cons
(x, A)) v ( ( (is_odd(hd A) ^ hd A > x) v is_even (hd A))^ B = cons ( hd A, insert_odd (x,
lt A))))
-----------------------------------------------------------------------------------------46. Hy c t hm kim tra mt chui s c phi l chui con ca chui t hay khng?
post: r = (
Tng minh:
is_child : String String B
is_child (s,t) = if(len t < len s) then FALSE
else if(s = subseq (t, 1, len s) then TRUE
else is_child(s, lt( t ))
----------------------------------------------------------------------------
1 ^ r = s) v (
Tng minh:
hd A)
reverse_String: String
String
reverse_String(s) = if (len s
1) then r
r
hd A
r = standard_String( s(1, len s 1))) v ( i inds s s(i) = ^ s(i+1) = ^ r =
r
standard_String(s(1, i) s(i+2, len s))) v (r = s))
Tng minh:
standard_String: String
String