Ask Your Question
1

an uncomprehensible "max"

asked 2022-03-06 19:30:46 +0200

ErWinz gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-06 20:05:30 +0200

rburing gravatar image

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
edit flag offensive delete link more

Comments

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"

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-03-06 19:30:46 +0200

Seen: 137 times

Last updated: Mar 06 '22