Tropical algebra overloading: Difference between revisions

m
clarify exp
mNo edit summary
m (clarify exp)
Line 14:
Show that 2 ⊗ -2 is 0, -0.001 ⊕ -Inf is -0.001, 0 ⊗ -Inf is -Inf, 1.5 ⊕ -1 is 1.5, and -0.5 ⊗ 0 is -0.5.
 
* Define exponentiation as serial ⊗, and in general that a to the power of b is a * b, where a is a real number and b must be a positive integer. Use either ↑ or similar up arrow or the carat ^, as an exponentiation operator if this can be used to overload such "exponentiation" in the language being used. ShowCalculate what5 your program calculates for (-1)(1/2) by7 theusing abovethis definition.
 
* Max tropical algebra is distributive, so that
Line 52:
 
def __pow__(self, other):
assert other.x // 1 == other.x and other.x > 1, "Invalid Operation"
return MaxTropical(self.x * other.x)
 
Line 78 ⟶ 79:
print("1.5 + -1 == ", h + b)
print("-0.5 * 0 == ", c * e)
print("(-1)5**(1/2)7 == ", bj**fk)
print("5 * (8 + 7)) == ", j * (l + k))
print("5 * 8 + 5 * 7 == ", j * l + j * k)
Line 90 ⟶ 91:
1.5 + -1 == 1.5
-0.5 * 0 == -0.5
(-1)5 **(1/2) 7 == -0.535
5 * (8 + 7)) == 13
5 * 8 + 5 * 7 == 13
4,106

edits