# simplify_full() and symbolic vectors

First, the question:

Suppose I've constructed some vectors with symbolic entries, call them P0 and P1. Calling simplify_full on them will -- apparently by changes introduced in the latest version (#11335 and #11381)! -- do an elementwise simplification. Great!

Suppose I construct a new symbolic vector by, say, interpolating between P0 and P1:

Pt = (1-t)*P0 + t*P1


Now

Pt.simplify_full()


produces

Traceback (click to the left of this block for traceback)
...
AttributeError:
'sage.modules.free_module_element.FreeModuleElement_generic_dense'
object has no attribute 'simplify_full'


whereas

P0.simplify_full()


and

P1.simplify_full()


work just fine. Somehow the symbolic vector-ness is forgotten in the construction of Pt.

Am I doing something wrong?

Then, the disclaimer:

A friend pointed me to Sage today, and this is the first thing I'm trying to do with it -- I do have background in some other symbolic tools, but this may just be a Stupid User Error despite giving this my best shot and looking at documentation.

Anyway, I'm very impressed with what I'm seeing when I look at Sage.

(For completeness' sake, here's a full example:

var('x,w,C0,C1,t')
P0=vector([0, C1*w/(C1*w+C0) - w/(w+C0/C1)])
P1=vector([cos(x)/sin(x)*tan(x)-1, 0])


Now both

P0.simplify_full()
P1.simplify_full()


return (0,0) as they should. But

Pt=(1-t)*P0+t*P1
Pt.simplify_full()


returns the above error.)

edit retag close merge delete

Sort by ยป oldest newest most voted

Here is a workaround:

vector(list((1-t)*P0+t*P1)).simplify_full()


It seems that the Vector_symbolic_dense class is quite new (judging by the content of vector_symbolic_dense.py). Even basic operations are not yet implemented:

sage: type(P0)
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
sage: type(P0+P0)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
sage: type(2*P0)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>


(I think addition and scalar multiplication are desirable for a class implementing vectors). For some reason vector needs a list as input (or a tuple, but not a symbolic vector) in order to produce a symbolic vector:

sage: type(vector(P0+P0))
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
sage: type(vector(list(P0+P0)))
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>

more

That indeed works. Awesome, thanks a lot! Judging from what you're saying, this could be worth a feature request. I'll dig around for where I can file one.

( 2011-09-21 04:56:36 +0100 )edit

See http://trac.sagemath.org/sage_trac for this. Yes, please do file this - and as a BUG, not an enhancement, since it is certainly a bug that this doesn't work.

( 2011-09-21 09:29:42 +0100 )edit

This was fixed by #11549. The fix will be available in Sage 4.7.2.

You can apply the changes on that ticket to your copy of Sage using these instructions from the developer guide.

more

Awesome, thanks for the pointer. For some reason this didn't come up in my original search.

( 2011-09-24 06:34:32 +0100 )edit

Here is the problem.

sage: type(P0)
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
sage: Pt=(1-t)*P0+t*P1
sage: type(P1)
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
sage: type(Pt)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>


I don't have time to look for a workaround now, but this is why you get that AttributeError. I don't know how easy it would be to make Pt get back in the vector type.

more

Thanks; makes sense!

( 2011-09-21 04:56:15 +0100 )edit