有没有人知道我可以去哪些教程来完全理解这种表示法的语法?
/* value definition */
abstract typedef <int, int> RATIONAL;
condition RATIONAL[1] != 0;
/* Operator definitions */
abstract equal( a, b ) /* written a == b */
RATIONAL a, b;
postcondition equal == ( a[0] * b[1] == b[0] * a[1] )
abstract RATIONAL makerational( a, b ) /* written [a, b] */
int a, b;
precondition b != 0;
postcondition makerational[0] * b == a * makerational[1]
abstract RATIONAL add( a, b ) /* written a + b */
RATIONAL a, b;
postcondition add == [ a[0] * b[1] + b[0] * a[1], a[1] * b[1] ]
abstract RATIONAL mult( a, b )
RATIONAL a, b;
postcondition mult == [ a[0] * b[0], a[1] * b[1] ]
答案 0 :(得分:0)
如果你知道有理数是什么,即一个整数除以另一个整数,那么就不难发现这个符号。
我之前从未见过它,但从有理数(分数)的属性来看,方括号索引很明显是一个表示为两个整数的向量。
然后,在普通的数学符号中,
upper( rational( a, b ) ) = a
lower( rational( a, b ) ) = b
equal( r1, r2 ) = (upper(r1)*lower(r2) eq upper(r2)*lower(r1) )
add( r1, r2 ) = rational(upper(r1)*lower(r2)+upper(r2)*lower(r1), lower(r1)*lower(r2))
mul( r1, r2 ) = rational(upper(r1)*upper(r2), lower(r1)*lower(r2))
干杯&amp; HTH,
答案 1 :(得分:-1)
postcondition makerational [0] == a; makerational [1] == b;
然后它讨论了1/2和2/4应被视为相等的事实,并修改了定义。我认为可以这样读: 得到的RATIONAL时间b的[0]元素必须等于得到的RATIONAL的[1]元素乘以