Ada SPARK | 2. Proof

Laufzeitfehlererkennung

procedure Increment(X:in out Integer)
	with Pre => (x < Integer'Last)
is 
begin
	X:=X+1;
end Increment;

Grundlegende Routine-Oriented Contracts

Pre- und Postconditions

procedure Turn_on(speed: in out Integer) with 
	Pre => speed = 0;
	Post => speed < 200;

Spezielle Attribute

  • Old-Attribute
procedure Increment(x: in out Integer)
	with Pre => x < Integer'Last,
		Post => x = x'Old + 1;
  • Result-Attribute
function Euclid (A, B : Integer) return Integer
	with Pre => A > 0 and B > 0,
		Post => IS_GCD(A, B, Euclid'Result)

Quantified Expressions

Pre => (for some a of age => a > 25)
Pre => (for all a of age => a > 25)

Conditional Expression

with Post => (if K in List'Range then X(K) = 0)

Contract Cases

function Sqrt (X: Float) return Float with
	Post =>
	(if x > 1.0 then Sqrt'Result <= X) or 
	(if x = 1.0 then Sqrt'Result = X) // =, not ==

Schleifen beweisen

procedure Increment_Loop(X: in out Integer; N: Natural ) with
	Pre => X <= Integer'Last - N,
	Post => X = X'Old + N
is 
begin
	for K in 1 .. N loop
		X := X + 1;
		prama Loop_Invariant(X = X'Loop_Entry + K);
	end loop;
end Increment_Loop;

Loop_Variant

Y : Natural;
begin 
	Y := 0;
	while X - Y >= 3 loop
		 Y := Y + 3;
		 pragma Loop_Variant(Increases => Y);
	end loop;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值