19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>The</strong> trait Commutative requires the operator ⊙ to be commutative; that is, reversing the operands produces an equal<br />

result.<br />

trait ApproximatelyAssociativeT extends ApproximatelyAssociativeT, ⊙, ≈,opr ⊙,opr ≈<br />

extends { BinaryOperatorT, ⊙, ReflexiveT, ≈, SymmetricT, ≈ }<br />

property ∀(a:T, b: T, c:T) ((a ⊙ b) ⊙ c) :≈: (a ⊙ (b ⊙ c))<br />

end<br />

<strong>The</strong> trait ApproximatelyAssociative requires the operator ⊙ to be approximately associative; that is, the expressions<br />

(a ⊙ b) ⊙ c and a ⊙ (b ⊙ c) always produce results that are “close enough” to each other as determined by the<br />

specified ≈ predicate.<br />

trait AssociativeT extends AssociativeT, ⊙,opr ⊙<br />

extends { ApproximatelyAssociativeT, ⊙, =, EquivalenceRelationT, = }<br />

end<br />

<strong>The</strong> trait Associative requires the operator ⊙ to be associative; that is, the expressions (a ⊙ b) ⊙ c and a ⊙ (b ⊙ c)<br />

always produce equal results.<br />

trait IdempotentBinaryOperatorT extends IdempotentBinaryOperatorT, ⊙,opr ⊙<br />

extends { BinaryOperatorT, ⊙, EquivalenceRelationT, = }<br />

property ∀(a:T) (a ⊙ a) :=: a<br />

end<br />

An idempotent binary operator has the property that if its two arguments are the same then the result is equal to each<br />

argument. For example, MAX and MIN are idempotent, as are ∧ and ∨ applied to boolean arguments and ∩ and ∪<br />

applied to sets; but + applied to integers is not idempotent because 1 + 1 does not produce 1 , and ⊕ applied to<br />

boolean arguments is not idempotent because true ⊕ true produces false . <strong>The</strong> property of idempotency is sometimes<br />

of interest when performing reductions such as MAX<br />

i←1:n a i .<br />

trait HasLeftZeroesT extends HasLeftZeroesT, ⊙,isLeftZero,opr ⊙,ident isLeftZero<br />

extends { BinaryOperatorT, ⊙ }<br />

isLeftZero():Boolean<br />

property ∀(a:T, b: T) a.isLeftZero() →: ((a ⊙ b) = a)<br />

end<br />

A value e is a left zero for a binary operator ⊙ if the result of ⊙ always equals e whenever e is the left-hand operand.<br />

For example, −∞ is a left zero for the MIN operator on floating-point values, and 7FFFFFFF 16 is a left zero for the<br />

MAX operator on values of type Z32 . <strong>The</strong> purpose of this trait is to specify a method that says whether a given element<br />

is a left zero for ⊙ .<br />

trait HasRightZeroesT extends HasRightZeroesT, ⊙,isRightZero,opr ⊙,ident isRightZero<br />

extends { BinaryOperatorT, ⊙ }<br />

isRightZero():Boolean<br />

property ∀(a:T, b: T) b.isRightZero() →: ((a ⊙ b) = b)<br />

end<br />

A value e is a right zero for a binary operator ⊙ if the result of ⊙ always equals e whenever e is the right-hand<br />

operand. For example, −∞ is a right zero (as well as a left zero) for the MIN operator on floating-point values, and<br />

7FFFFFFF 16 is a right zero (as well as a left zero) for the MAX operator on values of type Z32 . By way of contrast, 0<br />

is a left zero for the arithmetic shift operator on integers, but is not a right zero. <strong>The</strong> purpose of this trait is to specify<br />

a method that says whether a given element is a right zero for ⊙ .<br />

trait ApproximatelyLeftDistributiveT extends ApproximatelyLeftDistributiveT, ⊗, ⊕, ≈,<br />

253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!