Ask Your Question
3

simplify_full() and symbolic vectors

asked 2011-09-20 17:37:30 +0100

__jacques__ gravatar image

updated 2011-09-20 17:38:22 +0100

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2011-09-20 19:39:42 +0100

parzan gravatar image

updated 2011-09-20 19:41:40 +0100

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'>
edit flag offensive delete link more

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__ ( 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.

kcrisman gravatar imagekcrisman ( 2011-09-21 09:29:42 +0100 )edit
1

answered 2011-09-21 17:00:39 +0100

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.

edit flag offensive delete link more

Comments

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

__jacques__ gravatar image__jacques__ ( 2011-09-24 06:34:32 +0100 )edit
1

answered 2011-09-20 18:14:26 +0100

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.

edit flag offensive delete link more

Comments

Thanks; makes sense!

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

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: 2011-09-20 17:37:30 +0100

Seen: 2,972 times

Last updated: Sep 21 '11