The unsigned infinity “ring” is the set of two elements
The rules for arithmetic are that the unsigned infinity ring does not canonically coerce to any other ring, and all other rings canonically coerce to the unsigned infinity ring, sending all elements to the single element “a number less than infinity” of the unsigned infinity ring. Arithmetic and comparisons then take place in the unsigned infinity ring, where all arithmetic operations that are well-defined are defined.
The infinity “ring” is the set of five elements
The infinity ring coerces to the unsigned infinity ring, sending the infinite elements to infinity and the non-infinite elements to “a number less than infinity.” Any ordered ring coerces to the infinity ring in the obvious way.
Note: the shorthand oo is predefined in Sage to be the same as +Infinity in the infinity ring. It is considered equal to, but not the same as Infinity in the UnsignedInfinityRing:
sage: oo
+Infinity
sage: oo is InfinityRing.0
True
sage: oo is UnsignedInfinityRing.0
False
sage: oo == UnsignedInfinityRing.0
True
EXAMPLES:
We fetch the unsigned infinity ring and create some elements:
sage: P = UnsignedInfinityRing; P
The Unsigned Infinity Ring
sage: P(5)
A number less than infinity
sage: P.ngens()
1
sage: unsigned_oo = P.0; unsigned_oo
Infinity
We compare finite numbers with infinity:
sage: 5 < unsigned_oo
True
sage: 5 > unsigned_oo
False
sage: unsigned_oo < 5
False
sage: unsigned_oo > 5
True
We do arithmetic:
sage: unsigned_oo + 5
Infinity
We make 1 / unsigned_oo return the integer 0 so that arithmetic of the following type works:
sage: (1/unsigned_oo) + 2
2
sage: 32/5 - (2.439/unsigned_oo)
32/5
Note that many operations are not defined, since the result is not well-defined:
sage: unsigned_oo/0
...
ValueError: unsigned oo times smaller number not defined
What happened above is that 0 is canonically coerced to “a number less than infinity” in the unsigned infinity ring, and the quotient is then not well-defined.
sage: 0/unsigned_oo
0
sage: unsigned_oo * 0
...
ValueError: unsigned oo times smaller number not defined
sage: unsigned_oo/unsigned_oo
...
ValueError: unsigned oo times smaller number not defined
In the infinity ring, we can negate infinity, multiply positive numbers by infinity, etc.
sage: P = InfinityRing; P
The Infinity Ring
sage: P(5)
A positive finite number
The symbol oo is predefined as a shorthand for +Infinity:
sage: oo
+Infinity
We compare finite and infinite elements:
sage: 5 < oo
True
sage: P(-5) < P(5)
True
sage: P(2) < P(3)
False
sage: -oo < oo
True
We can do more arithmetic than in the unsigned infinity ring:
sage: 2 * oo
+Infinity
sage: -2 * oo
-Infinity
sage: 1 - oo
-Infinity
sage: 1 / oo
0
sage: -1 / oo
0
We make 1 / oo and 1 / -oo return the integer 0 instead of the infinity ring Zero so that arithmetic of the following type works:
sage: (1/oo) + 2
2
sage: 32/5 - (2.439/-oo)
32/5
If we try to subtract infinities or multiply infinity by zero we still get an error:
sage: oo - oo
...
SignError: cannot add infinity to minus infinity
sage: 0 * oo
...
SignError: cannot multiply infinity by zero
sage: P(2) + P(-3)
...
SignError: cannot add positive finite value to negative finite value
TESTS:
sage: P = InfinityRing
sage: P == loads(dumps(P))
True
sage: P(2) == loads(dumps(P(2)))
True
The following is assumed in a lot of code (i.e., “is” is used for testing whether something is infinity), so make sure it is satisfied:
sage: loads(dumps(infinity)) is infinity
True
EXAMPLES:
sage: [abs(x) for x in [UnsignedInfinityRing.gen(), oo, -oo]]
[Infinity, +Infinity, +Infinity]
EXAMPLES:
sage: oo == oo
True
sage: oo < oo
False
sage: -oo < oo
True
sage: -oo < 3 < oo
True
sage: unsigned_infinity == 3
False
sage: unsigned_infinity == unsigned_infinity
True
sage: unsigned_infinity == oo
True
Generate a floating-point infinity. The printing of floating-point infinity varies across platforms.
EXAMPLES:
sage: RDF(infinity)
+infinity
sage: float(infinity) # random
+infinity
sage: CDF(infinity)
+infinity
sage: infinity.__float__() # random
+infinity
sage: RDF(-infinity)
-infinity
sage: float(-infinity) # random
-inf
sage: CDF(-infinity)
-infinity
sage: (-infinity).__float__() # random
-inf
EXAMPLES:
sage: -oo + -oo
-Infinity
sage: -oo + 3
-Infinity
sage: oo + -100
+Infinity
sage: oo + -oo
...
SignError: cannot add infinity to minus infinity
sage: unsigned_infinity = UnsignedInfinityRing.gen()
sage: unsigned_infinity + unsigned_infinity
Infinity
sage: unsigned_infinity + 88/3
Infinity
EXAMPLES:
sage: 1.5 / oo
0
sage: oo / -4
-Infinity
sage: oo / oo
...
SignError: cannot multiply infinity by zero
EXAMPLES:
latex(oo)
+\infty
sage: [x._latex_() for x in [unsigned_infinity, oo, -oo]]
['\infty', '+\infty', '-\infty']
TESTS:
maxima(-oo)
minf
sage: [x._maxima_init_() for x in [unsigned_infinity, oo, -oo]]
['inf', 'inf', 'minf']
EXAMPLES:
sage: oo * 19
+Infinity
sage: oo * oo
+Infinity
sage: -oo * oo
-Infinity
sage: -oo * 4
-Infinity
sage: -oo * -2/3
+Infinity
sage: -oo * 0
...
SignError: cannot multiply infinity by zero
TESTS:
sage: [x._repr_() for x in [unsigned_infinity, oo, -oo]]
['Infinity', '+Infinity', '-Infinity']
EXAMPLES:
sage: -oo - oo
-Infinity
sage: oo - -oo
+Infinity
sage: oo - 4
+Infinity
sage: -oo - 1
-Infinity
sage: oo - oo
...
SignError: cannot add infinity to minus infinity
sage: unsigned_infinity - 4
Infinity
sage: unsigned_infinity - unsigned_infinity
...
ValueError: oo - oo not defined
Return the least common multiple of oo and x, which is by definition oo unless x is 0.
EXAMPLES:
sage: oo.lcm(0)
0
sage: oo.lcm(oo)
+Infinity
sage: oo.lcm(-oo)
+Infinity
sage: oo.lcm(10)
+Infinity
sage: (-oo).lcm(10)
+Infinity
EXAMPLES:
sage: abs(InfinityRing(-3))
A positive finite number
sage: abs(InfinityRing(3))
A positive finite number
sage: abs(InfinityRing(0))
Zero
EXAMPLES:
sage: P = InfinityRing
sage: -oo < P(-5) < P(0) < P(1.5) < oo
True
sage: P(1) < P(100)
False
sage: P(-1) == P(-100)
True
TESTS:
sage: sage.rings.infinity.FiniteNumber(InfinityRing, 1)
A positive finite number
sage: sage.rings.infinity.FiniteNumber(InfinityRing, -1)
A negative finite number
sage: sage.rings.infinity.FiniteNumber(InfinityRing, 0)
Zero
EXAMPLES:
sage: P = InfinityRing
sage: ~P(2)
A positive finite number
sage: ~P(-7)
A negative finite number
sage: ~P(0)
...
ZeroDivisionError: Cannot divide by zero
EXAMPLES:
sage: P = InfinityRing
sage: 4 + oo
+Infinity
sage: P(4) + P(2)
A positive finite number
sage: P(-1) + P(1)
...
SignError: cannot add positive finite value to negative finite value
EXAMPLES:
sage: P = InfinityRing
sage: 1 / oo
0
sage: oo / 4
+Infinity
sage: oo / -4
-Infinity
sage: P(1) / P(-4)
A negative finite number
TESTS:
sage: a = InfinityRing(pi); a
A positive finite number
sage: a._latex_()
'A positive finite number'
sage: [latex(InfinityRing(a)) for a in [-2..2]]
[A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number]
EXAMPLES:
sage: P = InfinityRing
sage: 0 * oo
...
SignError: cannot multiply infinity by zero
sage: -1 * oo
-Infinity
sage: -2 * oo
-Infinity
sage: 3 * oo
+Infinity
sage: -oo * oo
-Infinity
sage: P(0) * 3
0
sage: P(-3) * P(2/3)
A negative finite number
EXAMPLES:
sage: a = InfinityRing(5); a
A positive finite number
sage: -a
A negative finite number
sage: -(-a) == a
True
sage: -InfinityRing(0)
Zero
EXAMPLES:
sage: InfinityRing(-2)._repr_()
'A negative finite number'
sage: InfinityRing(7)._repr_()
'A positive finite number'
sage: InfinityRing(0)._repr_()
'Zero'
EXAMPLES:
sage: P = InfinityRing
sage: 4 - oo
-Infinity
sage: 5 - -oo
+Infinity
sage: P(44) - P(4)
...
SignError: cannot add positive finite value to negative finite value
sage: P(44) - P(-1)
A positive finite number
EXAMPLES:
sage: InfinityRing(7).sqrt()
A positive finite number
sage: InfinityRing(0).sqrt()
Zero
sage: InfinityRing(-.001).sqrt()
...
SignError: cannot take square root of a negative number
TESTS:
sage: InfinityRing == InfinityRing
True
sage: InfinityRing == UnsignedInfinityRing
False
TEST:
sage: sage.rings.infinity.InfinityRing_class() is sage.rings.infinity.InfinityRing_class() is InfinityRing
True
There is a coercion from anything that has a coercion into the reals.
EXAMPLES:
sage: InfinityRing.has_coerce_map_from(int)
True
sage: InfinityRing.has_coerce_map_from(AA)
True
sage: InfinityRing.has_coerce_map_from(RDF)
True
sage: InfinityRing.has_coerce_map_from(CC)
False
TESTS:
sage: InfinityRing(-oo)
-Infinity
sage: InfinityRing(3)
A positive finite number
sage: InfinityRing(-1.5)
A negative finite number
sage: [InfinityRing(a) for a in [-2..2]]
[A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number]
sage: K.<a> = QuadraticField(3)
sage: InfinityRing(a)
A positive finite number
sage: InfinityRing(a - 2)
A negative finite number
TEST:
sage: InfinityRing._repr_()
'The Infinity Ring'
This isn’t really a ring, let alone an integral domain.
TEST:
sage: InfinityRing.fraction_field()
...
TypeError: infinity 'ring' has no fraction field
The two generators are plus and minus infinity.
EXAMPLES:
sage: InfinityRing.gen(0)
+Infinity
sage: InfinityRing.gen(1)
-Infinity
sage: InfinityRing.gen(2)
...
IndexError: n must be 0 or 1
The two generators are plus and minus infinity.
EXAMPLES:
sage: InfinityRing.gens()
[+Infinity, -Infinity]
The two generators are plus and minus infinity.
EXAMPLES:
sage: InfinityRing.ngens()
2
sage: len(InfinityRing.gens())
2
EXAMPLES:
sage: 1 == unsigned_infinity
False
EXAMPLES:
sage: sage.rings.infinity.LessThanInfinity() is UnsignedInfinityRing(5)
True
EXAMPLES:
sage: UnsignedInfinityRing(5) + UnsignedInfinityRing(-3)
A number less than infinity
sage: UnsignedInfinityRing(5) + unsigned_infinity
Infinity
Can’t eliminate possibility of zero division....
EXAMPLES:
sage: UnsignedInfinityRing(2) / UnsignedInfinityRing(5)
...
ValueError: quotient of number < oo by number < oo not defined
sage: 1 / unsigned_infinity
0
EXAMPLES:
sage: UnsignedInfinityRing(5)._latex_()
'(<\infty)'
EXAMPLES:
sage: UnsignedInfinityRing(4) * UnsignedInfinityRing(-3)
A number less than infinity
sage: 5 * unsigned_infinity
...
ValueError: oo times number < oo not defined
sage: unsigned_infinity * unsigned_infinity
Infinity
EXAMPLES:
sage: UnsignedInfinityRing(5)._repr_()
'A number less than infinity'
EXAMPLES:
sage: UnsignedInfinityRing(5) - UnsignedInfinityRing(-3)
A number less than infinity
sage: UnsignedInfinityRing(5) - unsigned_infinity
Infinity
TESTS:
sage: sage.rings.infinity.MinusInfinity() is sage.rings.infinity.MinusInfinity() is -oo
True
EXAMPLES:
sage: -(-oo)
+Infinity
EXAMPLES:
sage: (-oo).sqrt()
...
SignError: cannot take square root of negative infinity
TESTS:
sage: sage.rings.infinity.PlusInfinity() is sage.rings.infinity.PlusInfinity() is oo
True
TESTS:
sage: -oo
-Infinity
Converts oo to sympy oo.
Then you don’t have to worry which oo you use, like in these examples:
EXAMPLE:
sage: import sympy
sage: bool(oo == sympy.oo) # indirect doctest
True
sage: bool(SR(oo) == sympy.oo)
True
EXAMPLES:
sage: oo.sqrt()
+Infinity
TESTS:
sage: sage.rings.infinity.UnsignedInfinity() is sage.rings.infinity.UnsignedInfinity() is unsigned_infinity
True
Can’t rule out an attempt at multiplication by 0.
EXAMPLES:
sage: unsigned_infinity * unsigned_infinity
Infinity
sage: unsigned_infinity * 0
...
ValueError: unsigned oo times smaller number not defined
sage: unsigned_infinity * 3
...
ValueError: unsigned oo times smaller number not defined
TESTS:
sage: infinity == UnsignedInfinityRing.gen()
True
sage: UnsignedInfinityRing(3) == UnsignedInfinityRing(-19.5)
True
TESTS:
sage: sage.rings.infinity.UnsignedInfinityRing_class() is sage.rings.infinity.UnsignedInfinityRing_class() is UnsignedInfinityRing
True
EXAMPLES:
sage: UnsignedInfinityRing.has_coerce_map_from(int)
True
sage: UnsignedInfinityRing.has_coerce_map_from(CC)
True
sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a'))
True
sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3)
False
sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13))
False
TESTS:
sage: UnsignedInfinityRing(2)
A number less than infinity
sage: UnsignedInfinityRing(I)
A number less than infinity
sage: UnsignedInfinityRing(infinity)
Infinity
TESTS:
sage: UnsignedInfinityRing._repr_()
'The Unsigned Infinity Ring'
The unsigned infinity ring isn’t an integral domain.
EXAMPLES:
sage: UnsignedInfinityRing.fraction_field()
...
TypeError: infinity 'ring' has no fraction field
The “generator” of self is the infinity object.
EXAMPLES:
sage: UnsignedInfinityRing.gen()
Infinity
sage: UnsignedInfinityRing.gen(1)
...
IndexError: UnsignedInfinityRing only has one generator
The “generator” of self is the infinity object.
EXAMPLES:
sage: UnsignedInfinityRing.gens()
[Infinity]
This is the element that represents a finite value.
EXAMPLES:
sage: UnsignedInfinityRing.less_than_infinity()
A number less than infinity
sage: UnsignedInfinityRing(5) is UnsignedInfinityRing.less_than_infinity()
True
The unsigned infinity ring has one “generator.”
EXAMPLES:
sage: UnsignedInfinityRing.ngens()
1
sage: len(UnsignedInfinityRing.gens())
1
This ensures uniqueness of these objects.
EXAMPLE:
sage: sage.rings.infinity.UnsignedInfinityRing_class() is sage.rings.infinity.UnsignedInfinityRing_class()
True
This is a type check for infinity elements.
EXAMPLES:
sage: sage.rings.infinity.is_Infinite(oo)
True
sage: sage.rings.infinity.is_Infinite(-oo)
True
sage: sage.rings.infinity.is_Infinite(unsigned_infinity)
True
sage: sage.rings.infinity.is_Infinite(3)
False
sage: sage.rings.infinity.is_Infinite(RR(infinity))
False
sage: sage.rings.infinity.is_Infinite(ZZ)
False