William Stein wrote:

> Before voting, may I register some concerns?
> 
> 1. Recall your example:
> 
> sage: t = var('t')
> sage: r=vector([t,t^2])
> sage: f(x,y)=x^2+y
> sage: f(r)
> boom.
> 
> If we make f(r) work (as you propose), note that the following will
> still not work, and can never ever be made to work:
> 
> sage: t = var('t')
> sage: r=vector([t,t^2])
> sage: f=lambda x,y: x^2+y
> sage: f(r)
> boom!
> 
> and equally:
> 
> sage: def f(x,y): return x^2+y
> sage: f(r)
> boom.
> 
> There is already a lot of confusion that results from the difference
> between callable symbolic expressions ("symbolic functions") and
> Python functions.  I'm worried that Jason's proposal would add yet
> another point of confusion.


These are great examples.  Given these two examples, I think Nick (and 
you?) are right that the resulting confusion would be worse than 
teaching students that to pass a vector, they need to either "dismantle" 
the vector into components f(*r), or define the function to actually 
take a vector like f(v)=v[0]*2+v[1]^2 (once we have the necessary 
changes; see below).

So I officially withdraw my proposal.  Thanks for the discussion.


> 2. A second concern is that at some point we will enhance symbolic
> expressions to more naturally take vectors as input (I played with
> Bill Furnish's symbolics rewrite and remember it being good at this
> sort of thing, and it being natural for expressing certain things).
> Then the following will work:
> 
> sage: t=var('t')
> sage: f(x,y) = 2*x + 3*y
> sage: r=vector([t,t^2]); s = vector([t,sin(t)])
> sage: f(r,r)
> (5*t, 2*t^2 + 3*sin(t))


You can sort of manipulate this to get it to work, since you can convert 
a matrix to a symbolic expression:

sage: f(x,y) = 2*x + 3*y
sage: r=matrix([[t,t^2]]); s = matrix([[t,sin(t)]])
sage: f(SR(r), SR(r))
[  5*t 5*t^2]
sage: f(SR(r), SR(s))
[             5*t 2*t^2 + 3*sin(t)]

so it looks like all you need to do is

* Make vectors behave like matrices, so that SR(vector([1,2])) works

* automatically cast symbolic function arguments to SR

Thanks,

Jason


-- 
Jason Grout


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

Reply via email to