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.

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

e is the left-hand operand. For example, 0 is a left identity for the + operator on integers and the empty set is a left<br />

identity for the ∪ operator on sets.<br />

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

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

isRightIdentity():Boolean<br />

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

end<br />

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

e is the left-hand operand. For example, 0 is a right identity (as well as a left identity) for the + operator on integers<br />

and the empty set is a right identity (as well as a left identity) for the ∪ operator on sets. By way of contrast, 1 is a<br />

right identity for division of rationals but not a left identity.<br />

value object Identityopr ⊙ end<br />

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

extends { HasLeftIdentityT, ⊙, HasRightIdentityT, ⊙ }<br />

where { T coerces Identity⊙ }<br />

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

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

property ∀(a:T) a.isLeftIdentity() ↔ (a = Identity⊙)<br />

property ∀(a:T) a.isRightIdentity() ↔ (a = Identity⊙)<br />

end<br />

If the same value is both a left identity and a right identity for ⊙ , then it may be called simply an identity—in fact,<br />

the identity, for it is unique and may be obtained by coercing the object named Identity⊙ to type T .<br />

value object Zeroopr ⊗ end<br />

trait ApproximateZeroAnnihilation T extends ApproximateZeroAnnihilationT, ⊗, ≈,<br />

opr ⊗,opr ≈<br />

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

property ∀(a:T) (Zero⊗ ⊗ a) :≈: Zero⊗<br />

property ∀(a:T) (a ⊗ Zero⊗) :≈: Zero⊗<br />

end<br />

An operator ⊗ obeys approximate zero annihilation if and only if there is an element (call it z ) that when used as<br />

either operand of ⊗ causes the result to be “close enough” to z as determined by the specified ≈ predicate. This<br />

zero element may be obtained by coercing the object named Zero⊗ to type T .<br />

trait ZeroAnnihilationT extends ZeroAnnihilationT, ⊗,opr ⊗<br />

extends { ApproximateZeroAnnihilationT, ⊗, =, EquivalenceRelationT, = }<br />

end<br />

An operator ⊗ obeys zero annihilation if and only if there is an element (call it z ) that when used as either operand of<br />

⊗ causes the result to equal z . (It follows that z is both a left idempotent element and a right idempotent element for<br />

⊗ . However, the trait ZeroAnnihilationT, ⊗ intentionally does not extend the traits HasLeftZeroesT, ⊗,name<br />

and HasRightZeroesT, ⊗,name because there is not always a practical requirement for methods that determine<br />

whether any value is left idempotent or right idempotent; sometimes it suffices to know only that one particular<br />

element, produced by coercing Zero⊗ to type T , has that property.)<br />

trait UnaryOperatorSubstitutionLawsT extends UnaryOperatorSubstitutionLawsT, ⊙, =,<br />

opr ⊙,opr ≃<br />

255

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

Saved successfully!

Ooh no, something went wrong!