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.

Chapter 25<br />

Numbers<br />

25.1 Rational Numbers<br />

<strong>The</strong> trait Q ( QQ ) encompasses all finite rational numbers, the result of dividing any integer by any nonzero integer.<br />

<strong>The</strong> trait Q ∗ ( QQ_star ) is Q with two extra elements, +∞ and −∞ . <strong>The</strong> trait Q # ( QQ_splat ) is Q ∗ with<br />

one additional element, the indefinite rational (written 0/0 ), which is used as the result of dividing zero by zero or of<br />

adding −∞ to +∞ .<br />

Often it is desirable to indicate that a variable ranges over only a subset of the rationals, such as only positive values<br />

or only nonnegative values or only nonzero values. Unfortunately, traditional notations such as Q + are not used<br />

consistently in the literature; one author may use Q + to mean the set of strictly positive rationals and another may<br />

use it to mean the set of nonnegative rationals. <strong>Fortress</strong> therefore uses a notation that is novel but unambiguous:<br />

Q ( QQ ) is the set of rationals (it is a subtype of R and Q ∗ ).<br />

Q < ( QQ_LT ) is the set of strictly negative rationals (it is a subtype of R < , Q ∗ < , Q , Q ≤ , and Q≠ ).<br />

Q ≤ ( QQ_LE ) is the set of nonpositive rationals, that is, Q < ∪ {0} (it is a subtype of R ≤ , Q ∗ ≤ , and Q ).<br />

Q ≥ ( QQ_GE ) is the set of nonnegative rationals, that is, Q > ∪ {0} (it is a subtype of R ≥ , Q ∗ ≥ , and Q ).<br />

Q > ( QQ_GT ) is the set of strictly positive rationals (it is a subtype of R > , Q ∗ > , Q , Q ≥ , and Q≠ ).<br />

Q≠ ( QQ_NE ) is the set of strictly nonzero rationals (that is, Q < ∪ Q > ) (it is a subtype of R≠ , Q ∗<br />

≠<br />

, and Q ).<br />

Q ∗ ( QQ_star ) is Q with extra elements +∞ and −∞ (it is a subtype of R ∗ and Q # ).<br />

Q ∗ < ( QQ_star_LT ) is Q < with extra element −∞ (it is a subtype of R ∗ < , Q # < , Q ∗ , Q ∗ ≤ , and Q∗ ≠ ).<br />

Q ∗ ≤ ( QQ_star_LE ) is Q ≤ with extra element −∞ (it is a subtype of R ∗ ≤ , Q# ≤ , and Q∗ ).<br />

Q ∗ ≥ ( QQ_star_GE ) is Q ≥ with extra element +∞ (it is a subtype of R ∗ ≥ , Q# ≥ , and Q∗ ).<br />

Q ∗ > ( QQ_star_GT ) is Q > with extra element +∞ (it is a subtype of R ∗ > , Q # > , Q ∗ , Q ∗ ≥ , and Q∗ ≠ ).<br />

Q ∗<br />

≠ ( QQ_star_NE ) is Q ≠ with extra elements +∞ and −∞ (it is a subtype of R ∗<br />

≠ , Q# ≠ , and Q∗ ).<br />

Q # ( QQ_splat ) is Q ∗ with extra element 0/0 (it is a subtype of R # ).<br />

Q # < ( QQ_splat_LT ) is Q ∗ < with extra element 0/0 (it is a subtype of R # < , Q # , Q # ≤<br />

, and Q#<br />

≠ ).<br />

Q # ≤ ( QQ_splat_LE ) is Q∗ ≤ with extra element 0/0 (it is a subtype of R# ≤ and Q# ).<br />

Q # ≥ ( QQ_splat_GE ) is Q∗ ≥ with extra element 0/0 (it is a subtype of R# ≥ and Q# ).<br />

Q # > ( QQ_splat_GT ) is Q ∗ > with extra element 0/0 (it is a subtype of R # > , Q # , Q # ≥<br />

, and Q#<br />

≠ ).<br />

Q #<br />

≠<br />

( QQ_splat_NE ) is Q∗ ≠<br />

with extra element 0/0 (it is a subtype of R#<br />

≠ and Q# ).<br />

<strong>The</strong> <strong>Fortress</strong> type system tracks these types closely through various arithmetic operations; for example, adding two<br />

values of type Q > produces a result of type Q > , and adding a value of type Q ∗ > and a value of type Q ≥ produces<br />

a value of type Q ∗ ≥ . 193

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

Saved successfully!

Ooh no, something went wrong!