# an uncomprehensible "max"

hi! i dontunderstand the way this code runs :

ddom(x,y)=max(abs(x-0.5),abs(y-0.5))-0.5
catox(x,y)=abs(x-0.5)
catoy(x,y)=abs(y-0.5)
show(catox(10,20),";",catoy(10,20))
show(max(catox(10,20),catoy(10,20))-0.5)#19
show(max(catoy(10,20),catox(10,20))-0.5)#19
show("ddom=",ddom(10,20))#9???? <--- here
show("ddom=",ddom(20,10))#19


why 9 ???????????

edit retag close merge delete

Sort by ยป oldest newest most voted

Hint:

sage: ddom(x,y)
abs(x - 0.500000000000000) - 0.500000000000000


This shows that SageMath (or rather, Python) didn't catch your intended meaning when you wrote max. If you want to work with symbolic expressions involving the maximum, then you should use the symbolic maximum:

sage: ddom(x,y)=max_symbolic(abs(x-0.5),abs(y-0.5))-0.5
sage: ddom(x,y)
max(abs(x - 0.500000000000000), abs(y - 0.500000000000000)) - 0.500000000000000
sage: ddom(10,20)
19.0000000000000


If you don't need symbolic expressions, then you can also define a Python function instead:

sage: ddom2 = lambda x,y: max(abs(x-0.5),abs(y-0.5))-0.5
sage: ddom2(10,20)
19.0000000000000

more

ok thanks very much

now, i have understood how to ; fine, works very well

concerning the why, i have not everything but the following point is now clearer for me thnaks to your answer :

ddom(x,y)=...


defines a SageMaths functions whereas

ddom(x,y)= lambda something
def ddom(x,y): something


define both a Python function

what i have not understood yet is the logical way SageMaths has taken to produce this "9"

( 2022-03-06 20:38:52 +0200 )edit