Tropical algebra overloading: Difference between revisions

Content added Content deleted
m (→‎{{header|R}}: use cat)
mNo edit summary
Line 30: Line 30:
:;*[[https://en.wikipedia.org/wiki/Operator_overloading Operator overloading]]
:;*[[https://en.wikipedia.org/wiki/Operator_overloading Operator overloading]]



=={{header|Julia}}==
<lang julia>⊕(x, y) = max(x, y)
⊗(x, y) = x + y
↑(x, y) = x * y

@show 2 ⊗ -2
@show -0.001 ⊕ -Inf
@show 0 ⊗ -Inf
@show 1.5 ⊕ -1
@show -0.5 ⊗ 0
@show (-1)↑(1/2)
@show 5 ⊗ (8 ⊕ 7)
@show 5 ⊗ 8 ⊕ 5 ⊗ 7
@show 5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7
</lang>{{out}}
<pre>
2 ⊗ -2 = 0
-0.001 ⊕ -Inf = -0.001
0 ⊗ -Inf = -Inf
1.5 ⊕ -1 = 1.5
-0.5 ⊗ 0 = -0.5
(-1) ↑ (1 / 2) = -0.5
5 ⊗ (8 ⊕ 7) = 13
5 ⊗ 8 ⊕ 5 ⊗ 7 = 13
5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7 = true
</pre>


=={{header|Python}}==
=={{header|Python}}==
Line 96: Line 123:
5 * (8 + 7) == 5 * 8 + 5 * 7 True
5 * (8 + 7) == 5 * 8 + 5 * 7 True
</pre>
</pre>



=={{header|R}}==
=={{header|R}}==