On Dec 11, 2007 9:48 PM, William Stein <[EMAIL PROTECTED]> wrote:
>
> On Dec 11, 2007 12:17 PM, Robert Bradshaw <[EMAIL PROTECTED]> wrote:
> >
> > On Dec 11, 2007, at 8:53 AM, William Stein wrote:
> >
> > > One possible solution would be to call simplify before
> > > doing float(...) -- but that could greatly slow symbolic calculus
> > > down in some cases.
> >
> > This could be attempted only on failure, which wouldn't have a
> > performance impact in most cases.
> >
> > > Another possibility would be to change
> > > the definition of variables() to return all variables, even the ones
> > > that are simplified away:
> > >
> > > sage: (x - x).variables()   # fake
> > > (x,)
> > >
> > > That would be very confusing.
> > >
> > > A third possibility would be to make implicit calling use variables
> > > in the unsimplified expression if the simplified expression has
> > > no variables.  This would cleanly deal with your case above.
> >
> > Anther option would to make zero-variable expressions ignore the
> > (single) input value, and return itself (behaving as the constant
> > function) or itself evaluated on that value (e.g. if it were an un-
> > evaluated trig, sqrt, etc.). This might be a way to remedy the confusing
> >
> > sage: f = sin + cos
> > sage: f(3)
> > sin + cos
> >
> > too.
>
> Keep in mind
>       http://trac.sagemath.org/sage_trac/ticket/553
> I.e., students who forget to put a * in get very confused by this:
>
>   sage: (5 + 2^(1/3))(x^2 + 1)
>   2^(1/3) + 5
>
> ?!  It would be better to get an error...

Exactly. That's why I don't like all this playing with (). And why I
don't like with playing with .subs(x=2), because .subs(x**2=2) gives
confusing error too. Using .subs(x==2) is ok to me though. (even
though I still prefer .subs(x, 2), but I know I am in minority here)


> Maybe it is.   I've been thinking about removing the f(1) syntax,
> *unless* something is
> a "callable symbolic expression", e.g.,
>
> sage: f(t) = t*sin(0)
> sage: f(1)
> 0
> sage: float(f(1))
> 0.0
>
> A drawback though is that if we do this then all of the following break, which
> will confuse new users:
>
> sage: f = x^2 + x + 1
> sage: f(5)
> 31
> sage: show(plot(f, -2, 2))
> sage: show(plot(sin(x)*cos(x^2), -pi, 3*pi))

I don't think so, e.g. in SymPy you can do:

In [1]: f = x**2 +x +1

In [3]: Plot(f, -2, 2)
Out[3]: [0]: 1 + x + x**2, -2, 2, 'mode=parametric'

(Currently the plot of this seems kind of broken - as to plotting, I
don't like devising our new plotting library, I'd rather reuse
something existing, but we didn't find anything useful, mathplotlib 3D
stuff is very bad - but maybe we could integrate our pyglet plotting
stuff into matplotlib)

Here is a relevant part from the Plot docstring:

    Variable Intervals
    ==================

    The basic format is [var, min, max, steps], but the
    syntax is flexible and arguments left out are taken
    from the defaults for the current coordinate mode:

    >>> Plot(x**2) # implies [x,-5,5,100]
    >>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
    >>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
    >>> Plot(x**2, [x,-13,13,100])
    >>> Plot(x**2, [-13,13]) # [x,-13,13,100]
    >>> Plot(x**2, [x,-13,13]) # [x,-13,13,100]
    >>> Plot(1*x, [], [x], mode='cylindrical')
    ... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]



>
> For the first, you just suggest in the error message to do either
> f(x=5) or f(x,5) or
> f(x) = ...;  for the second, we can modify plot to optionally work like this:
>
>
> sage: show(plot(f, x, -2, 2))
>
> (actually the above already works)
>
> or
>
>
> sage: show(plot(f,  (x, -2, 2)))

Either that, or just use the same way as in SymPy, see above, or actually both.

Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to