Tropical algebra overloading: Difference between revisions

Content added Content deleted
(add RPL)
Line 1,010: Line 1,010:
max tropical comparison of 5 (x) with (+)(8,7) compared to
max tropical comparison of 5 (x) with (+)(8,7) compared to
(x)(5,8) with (+) (x)(5,7) ───► true
(x)(5,8) with (+) (x)(5,7) ───► true
</pre>

RPL does not support operator overloading so we need to use functions instead. As all stack-driven languages, RPL requires the user to deal with operator precedence.
MAXR EVAL ''''Inf'''' STO
≪ 1 3 '''START''' ROT EVAL '''NEXT'''
'''IF''' DUP ABS '''Inf''' == '''THEN''' SIGN ''''Inf'''' * '''END'''
≫ ‘'''TropOp'''’ STO
≪ ≪ MAX ≫ '''TropOp''' ≫ ‘'''TPLUS'''’ STO
≪ ≪ + ≫ '''TropOp''' ≫ ‘'''TMULT'''’ STO
≪ ≪ * ≫ '''TropOp''' ≫ ‘'''TPOWR'''’ STO

2 -2 '''TMULT'''
-0.001 '-'''Inf'''' '''TPLUS'''
0 '-'''Inf'''' '''TMULT'''
1.5 -1 '''TPLUS'''
0.5 0 '''TMULT'''
8 7 '''TPLUS''' 5 '''TMULT'''
5 8 '''TMULT''' 5 7 '''TMULT TPLUS'''

{{out}}
<pre>
7: 0
6: -0.001
5: '-Inf'
4: 1.5
3: -0.5
2: 13
1: 13
</pre>
</pre>