First time here? Check out the FAQ!

Ask Your Question
3

simplify_full() and symbolic vectors

asked 13 years ago

__jacques__ gravatar image

updated 13 years ago

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.)

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
1

answered 13 years ago

parzan gravatar image

updated 13 years ago

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'>
Preview: (hide)
link

Comments

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.

__jacques__ gravatar image__jacques__ ( 13 years ago )

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.

kcrisman gravatar imagekcrisman ( 13 years ago )
1

answered 13 years ago

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.

Preview: (hide)
link

Comments

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

__jacques__ gravatar image__jacques__ ( 13 years ago )
1

answered 13 years ago

kcrisman gravatar image

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.

Preview: (hide)
link

Comments

Thanks; makes sense!

__jacques__ gravatar image__jacques__ ( 13 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 3,094 times

Last updated: Sep 21 '11