On Saturday, March 15, 2014 8:23:47 PM UTC-7, Nils Bruin wrote:
>
> On Thursday, March 13, 2014 3:05:22 PM UTC-7, Lee Worden wrote:
>>
>> sage: s = symbolic_expression( 'a(x)' ) 
>> sage: s.substitute_function( 
>> sage.symbolic.function_factory.function('a'), 
>> sage.symbolic.function_factory.function('A') ) 
>> A(x) 
>> sage: t = deepcopy( s ) 
>>
>
> Since symbolic expressions are not mutable, you shouldn't have a need to 
> make deep copies of them. The behaviour does seem problematic, though.
>

Thank you for responding!

This came up because I'm using deepcopy on a python object that includes 
some symbolic expressions as members.  If I'm not mistaken it uses deepcopy 
to copy all its members.  To avoid using deepcopy on those expressions, I'd 
have to write a custom deepcopy for each class that uses symbolic 
expressions (which is what I've done to work around this problem).

The problem you are seeing stems from:
>
> sage: sage.symbolic.function_factory.function('a') == s.operator()
> True
> sage: sage.symbolic.function_factory.function('a') == t.operator()
> False
>
> It looks like deep copy is a little too eager: it shouldn't make a copy of 
> the function 'a', but it does. You end up with a different function 
> (accessible via t.operator() ) which also prints as 'a' but isn't equal to 
> the function 'a' you can create via 
> sage.symbolic.function_factory.function. Basically, you got what you asked 
> for: a COPY of the function, not the function itself.
>

I think that we agree that this is buggy behavior.  If repeated calls to 
function('a') return the same object, the one in t should also be the same 
object.

Something fishy is going on, though, because
>
> sage: a=s.operator()
> sage: deepcopy(a)
> a
> sage: deepcopy(a) == a
> True
> sage: deepcopy(a) is a
> False
> sage: deepcopy(a)(x).substitute_function(
> ....: sage.symbolic.function_factory.function('a'),
> ....: sage.symbolic.function_factory.function('A') ) 
> A(x)
>
> so a function object by itself does get "deepcopied" correctly, but when 
> it's sitting in an expression it is not.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to