On Mar 8, 3:14 pm, compound eye <compound...@gmail.com> wrote:
> thank you john,
>
> it's early morning in australia
> and I just woke up realising
> i had forgotten that what i am entering into my notebook is python
> not mysterious sagese configuration script
>
> I think I need to go do some python tutorials, what you've said makes
> perfect sense, and is exactly the behaviour I would have expected,
> except that in the example:
>
> x = var('x')
> def splitAgain(n):
>
>     if n < 2:
>         return n
>     else:
>         return 2-n
>
> plot(splitAgain(x),0,4)
>
> the evaluation of splitAgain(x) passed to plot(),
> is neither a reference to splitAgain,
> or an evaluation of splitAgain(x) for some value of x,
> but 2-x, as this draws 2-x
>
> this is a behaviour pattern I haven't encountered before, I am a bit
> mystified by it and would like to understand it, is this a python
> feature to do with : x = var('x') , or is something specifically to do
> with plot()?

Well, again 'x<2' evaluates to false, so the function returns the
other option, which in this case is 2-x.  I think that since 'x' is a
variable, any expression in it becomes a symbolic expression and is
evaluated accordingly.  If a boolean symbolic expression (like 'x<2')
is not obviously true, then it returns False.  Then the function
substitutes x for n to get the symbolic expression 2-x.  Then this
gets plotted.

>From this:

sage: type(splitAgain)
<type 'function'>
sage: type(2-x)
<class 'sage.calculus.calculus.SymbolicArithmetic'>
sage: type(splitAgain(x))
<class 'sage.calculus.calculus.SymbolicArithmetic'>

you can see that symbolic expressions are a Sage thing, not a Python
thing.

It also doesn't have anything to do with plot().  Well, not much: plot
can accept a python function like splitAgain as an argument, and it
can also accept a symbolic expression like splitAgain(x) as an
argument.  In fact you can plot any of these objects, and more:

sage: type(sin(x))
<class 'sage.calculus.calculus.SymbolicComposition'>
sage: type(sin)
<class 'sage.calculus.calculus.Function_sin'>
sage: def f(y):
....:     return sin(y)
sage: type(f)
<type 'function'>

'plot(f, 0, 2*pi)', 'plot(sin, 0, 2*pi)', and 'plot(sin(x), 0, 2*pi)'
all produce the same picture.

--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to