[sage-support] Re: plot3d and expression evaluation

2010-03-12 Thread stefan
I think I've got a vague idea what happens here... The same thing also
happens when
I define the max() function myself:

sage: def my_max(x,y):
sage: if(x>y): return x
sage: else: return y

sage: fermi2(x,y,d,L) = 1 - 1/( exp( ( my_max(abs(x),abs(y))-L) /d)  +
1)

sage: fermi2
(x, y, d, L) |--> -1/(e^(-(L - abs(y))/d) + 1) + 1

This looks a bit like max(x,y) gets passed the the objects 'abs(x)'
and 'abs(y)'
and decides, for whatever reason, that 'abs(x)' is not greater than
'abs(y)', so
the else-clause gets executed and we are left with abs(y). Does this
make sense to
you? (I'm just thinking aloud, I got no idea how sage actually does
it)

Most likely the internal "max" function is defined in rather the same
way (it
just returns abs(x) instead of abs(y). )

The bottom line seems to be that it is a very dangerous game to mix
symbolic expressions and python functions. Is there some way to
control
when (and how) Sage evaluates expressions and invokes python
functions?
Something like saying "first evaluate abs(x) and abs(y) and then
invoke the
python function max() with the result of the evaluation"?


On Mar 12, 5:49 pm, Harald Schilly  wrote:
> Ah, I got it, the max function is evaluated during the definition of
> the function, look:
>
> sage: fermi(x,y,d,L) = 1 - 1/( exp( ( max(abs(x),abs(y))-L) /d)  + 1)
> sage: fermi
> (x, y, d, L) |--> -1/(e^(-(L - abs(x))/d) + 1) + 1
>
> especially:
> sage: max(abs(x),abs(y))
> abs(x)
>
> There is no y any more!
>
> H

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: plot3d and expression evaluation

2010-03-12 Thread stefan


On Mar 12, 5:47 pm, Harald Schilly  wrote:
> I'm not sure but there might be a bug or problem evaluating the
> expression. Anyways, going the "pure" python way works:
>
> sage: def fermi(x,y,d,L): return  1 - 1/( exp( ( max(abs(x),abs(y))-
> L) /d)  + 1)
>
> sage: plot3d(lambda x,y : fermi(x,y,0.2,1), (x,-2,2), (y,-2,2))
>
> Does this look fine?

Yes, the "pure python" way works. But defining the function that way,
I loose the ability to perform symbolic manipulations with it, don't I?

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: plot3d and expression evaluation

2010-03-12 Thread Harald Schilly
On Mar 12, 5:39 pm, stefan  wrote:
> I have encountered a somewhat strange problem ...

Ah, I got it, the max function is evaluated during the definition of
the function, look:

sage: fermi(x,y,d,L) = 1 - 1/( exp( ( max(abs(x),abs(y))-L) /d)  + 1)
sage: fermi
(x, y, d, L) |--> -1/(e^(-(L - abs(x))/d) + 1) + 1

especially:
sage: max(abs(x),abs(y))
abs(x)

There is no y any more!

H

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: plot3d and expression evaluation

2010-03-12 Thread Harald Schilly
On Mar 12, 5:39 pm, stefan  wrote:
> Basically, I am trying to plot this expression:
>
> #sage> fermi(x,y,d,L) = 1 - 1/( exp( ( max(abs(x),abs(y))-L) /d)  + 1)


I'm not sure but there might be a bug or problem evaluating the
expression. Anyways, going the "pure" python way works:

sage: def fermi(x,y,d,L): return  1 - 1/( exp( ( max(abs(x),abs(y))-
L) /d)  + 1)

sage: plot3d(lambda x,y : fermi(x,y,0.2,1), (x,-2,2), (y,-2,2))

Does this look fine?

H

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org