Numerical tower
In Scheme, the numerical tower is a set of data types that represent numbers and a logic for their hierarchical organisation.[src] Each type in the tower conceptually "sits on" a more fundamental type, so an integer is a rational number and a number, but the converse is not necessarily true, i.e.[src] not every number is an integer.[src] This asymmetry implies that a language can safely allow implicit coercions of numerical types—without creating semantic problems—in only one direction: coercing an integer to a rational loses no information and will never influence the value returned by a function, but to coerce most reals to an integer would alter any relevant computation (e.g., the real 1/3 does not equal any integer) and is thus impermissible.[src]
In Scheme, the numerical tower is a set of data types that represent numbers and a logic for their hierarchical organisation.[src] Each type in the tower conceptually "sits on" a more fundamental type, so an integer is a rational number and a number, but the converse is not necessarily true, i.e.[src] not every number is an integer.[src] This asymmetry implies that a language can safely allow implicit coercions of numerical types—without creating semantic problems—in only one direction: coercing an integer to a rational loses no information and will never influence the value returned by a function, but to coerce most reals to an integer would alter any relevant computation (e.g., the real 1/3 does not equal any integer) and is thus impermissible.[src] 1 -2 +3 ⇒ 1 ⇒ -2 ⇒ 3 1/3 ⇒ 1/3 72/6+8/3i ⇒ 12+8/3i ; coercion: canonical form (+ 3+2i 2-2i) ⇒ 5 ; coercion: canonical form (- 3-62/32i 1+inf.0i) ⇒ 2-inf.0i ; coercion: infinite cardinality (> 3+0/2i 3) ⇒ #f ; coercion: 3 ≯ 3 While in the following Python examples we see: 1; -2; +3 ⇒ 1 ⇒ -2 ⇒ 3 1/3 ⇒ 0.3333333333333333 inf = float('inf') # infinity not first-class from fractions import Fraction x = Fraction(1, 3) y = Fraction(2, 3) x + y ⇒ Fraction(1, 1) # no coercion (3+2j) ⇒ (3+2j) complex(x, inf) ⇒ (0.3333333333333333+infj) # coercion: equality violated a = 1/3 b = Fraction(1, 3) caz = complex(a, 0) cbz = complex(b, 0) a == b ⇒ False caz == cbz ⇒ True # proof of equality violation complex(x + y, -inf) ⇒ (1-infj) # coercion: equality preserved (3+0j) > 3 ⇒ Traceback (most recent call last): ⇒ File " ", line 1, in # no coercion: type error ⇒ TypeError: '>' not supported between instances of 'complex' and 'int' In the Python examples, we can see that numerical issues freely arise with an inconsistent application of the semantics of its type coercion.[src] While 1 / 3 in Python is treated as a call to divide 1 by 3, yielding a float, the inclusion of rationals inside a complex number, though clearly permissible, implicitly coerces them from rationals into floats or ints, even in cases where this is incorrect.[src] Smalltalk is another programming language that follows this model, but it has ArithmeticValue and Magnitude as superclasses of Number.[src] The Numerical Tower of Scheme was inspired by the hierarchy of numeric types in Common Lisp.[src] Number / \ Real Complex / \ Rational Float / \ Integer Ratio ==References==[src]
13 sentences · 13 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Numerical tower." encyclopegia.org, 2024, https://encyclopegia.org/wiki/numerical-tower. Accessed 29 November 2026.
Chicago
"Numerical tower." encyclopegia.org. Accessed November 29, 2026. https://encyclopegia.org/wiki/numerical-tower.
APA
encyclopegia.org. (2024). Numerical tower. Retrieved November 29, 2026, from https://encyclopegia.org/wiki/numerical-tower
Accessed November 29, 2026 · CC BY-SA 4.0 · citation page · JSON