On Sep 12, 2007, at 2:00 PM, cwitty wrote:

> On Sep 12, 1:30 pm, Robert Bradshaw <[EMAIL PROTECTED]>
> wrote:
>> On Sep 12, 2007, at 1:06 PM, William Stein wrote:
>>>>> I have a few design questions that I would like to discuss and  
>>>>> they
>>>>> are relevant to both SymPy and SAGE, so I am posting to both
>>>>> mailinglists.
>>
>>> Thanks.   I want to preface my comments below by remarking that the
>>> design constraints in SAGE and SymPy are different so the best  
>>> answers
>>> in each case may be different.
>>
>>>>> We are currently redesigning the class hierarchy in SymPy so that:
>>>>> 1)
>>>>>   Add(sin, cos)
>>>>> and
>>>>>   Add(sin(1),cos(1))
>>
>>>>> are valid constructions. Here (Add(sin, cos))(1) will produce
>>>>> Add(sin(1), cos(1)). So that we can use both applied (sin(x)) and
>>>>> unapplied (sin) functions.
>>
>>> In SAGE the following happens.  Maybe this  is a design mistake in
>>> SAGE:
>>
>>> sage: f = sin + cos; f
>>> sin + cos
>>> sage: f(1)
>>> sin + cos         # design mistake?  should it be sin(1) + cos(1)?
>>> sage: sin(1)
>>> sin(1)
>>
>>> It definitely seems wrong from one point of view.  What's happening
>>> above is that f(1) does substitution on the variables in f, of which
>>> there are none.  In contrast sin(1) evaluates the function sin at 1.
>>
>>> If somebody agrees that the above should be considered a bug
>>> in SAGE, it should be added to trac.
>>
>> Seehttp://www.sagemath.org:9002/sage_trac/ticket/644
>
> Is this really a good thing?

I think so, but I welcome lots of discussion before it gets implemented.

> It seems like it might get a little
> confusing, especially when you get into some more complicated cases.
>
> Assume that sin and cos are 1-argument functions, and pow and atan2
> are 2-argument functions.  What do the following mean?
>
> (sin+cos)(1)

sin(1) + cos(1)

> (sin+1)(1)

sin(1) + 1

> (pow+atan2)(1, 2)

1 + atan(1,2)

> (sin+cos)(1, 2)

error, wrong number of args

> (pow+atan2)(1)

error, wrong number of args

> (pow+sin)(1)
> (pow+sin)(1, 2)
> (pow+sin+1)(1)

Coercion error, no common parent for '+' (CallableSR in 2 unnamed  
vars, CallableSR in 1 unnamed var) # due to ambiguity of where the  
1st var goes


That's assuming we go beyond 1-argument functions, which may or may  
not be a good idea (and is certainly less common).

Also, I would propose

sage: x, y = var('x y')
sage: f(x) = x^2 + 1
sage: f + sin
x^2 + 1 + sin(x)
sage: y + sin
y + sin(y)

BTW, I think this is a bug:

sage: f = x+y
sage: f
y + x
sage: f(4)
y + 4


- Robert


--~--~---------~--~----~------------~-------~--~----~
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