On Dec 11, 2007 5:53 PM, William Stein <[EMAIL PROTECTED]> wrote:
>
> On Dec 11, 2007 8:39 AM, Joel B. Mohler <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I've noticed a very recent regression -- it worked 2 months ago.
> >
> > sage: t=var('t')
> > sage: f=t*cos(0)
> > sage: float(f(1))
> > 1.0
> > sage: f=t*sin(0)
> > sage: float(f(1))
> > Traceback...
> > <type 'exceptions.TypeError'>: float() argument must be a string or a number
> >
> > --
>
> It is actually hard to decide how to fix this.   This is a result of
> several significant fixes
> and optimizations recently.  What is happening is that for t*sin(0)
> the simplified
> form is 0, so (t*sin(0)).variables() is [].
>
> sage: t=var('t')
> sage: f = t*cos(0)
> sage: f.variables()
> (t,)
> sage: g = t*sin(0)
> sage: g.variables()
> ()
> sage: float(f(1))
> 1.0
> sage: float(g(t=1))
> 0.0
>
> Both f(1) and g(1) are formal products.  However:
>
> sage: g(1)._operands
> [t, 0]
> sage: f(1)._operands
> [1, 1]
>
> Notice the [t, 0].
>
> One possible solution would be to call simplify before
> doing float(...) -- but that could greatly slow symbolic calculus
> down in some 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.
>
> Thoughts?

First I cannot reproduce it on 2.8.14 (so it's probably only a bug in 2.8.15?):

$ ./sage
----------------------------------------------------------------------
| SAGE Version 2.8.14, Release Date: 2007-11-24                      |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------

sage: t = var("t")
sage: f = t*cos(0)
sage: f
t
sage: f(1)
1
sage: f = t*sin(0)
sage: f
0
sage: f(1)
0
sage: float(f(1))
0.0
sage: (t*sin(0)).variables()
()


Second, I find the f(1) syntax very confusing. Exactly because it's
not clear what is substituted for. Why isn't the syntax:

f.subs(t, 1) enough?

sage: f.subs(t, 1)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/ondra/ext/sage-2.8.13-i686-Linux/<ipython console> in <module>()

/home/ondra/ext/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py
in subs(self, *args, **kwds)
   2506
   2507     def subs(self, *args, **kwds):
-> 2508         return self.substitute(*args, **kwds)
   2509
   2510     def _recursive_sub(self, kwds):

<type 'exceptions.TypeError'>: substitute() takes at most 2 arguments (3 given)
sage: f.subs(t=1)
0


Yeah, I mean f.subs(t=1), I am going to write a separate email about
this problem.

Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
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