Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

getting a specific Coefficient of a non-commuting monomial in multiple variables

asked 0 years ago

levav gravatar image

updated 0 years ago

Example:

A.<a,b> = FreeAlgebra(QQ, 2)
f = a + a * b - b * a
f.coefficient(a*b)

Throws:

AssertionError: a*b should be an element of Free monoid on 2 generators (a, b)

After some investigation:

c = f.monomial_coefficients()
type(list(c.keys())[0])
<class 'sage.monoids.free_monoid.FreeMonoid_with_category.element_class'>

But:

type(a*b)
<class 'sage.algebras.free_algebra.FreeAlgebra_generic_with_category.element_class'>

This might be a bug? I'm not sure. For now, the only 'solution' I have is something like this:

mon_keys = list(c.keys())
str_keys = [str(k) for k in c.keys()]
i = str_keys.index(str(a*b))
print(f[mon_keys[i]])

Which prints:

1

as expected.

Note that this is a playground example, in practice I need to get this result from a Lyndon word in the generators, hence some of the generalities that would otherwise seem slightly unneeded. Anyhow, Is there a way to avoid this ugly hack?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

FrédéricC gravatar image

like this

A.<a,b> = FreeAlgebra(QQ, 2)
f = a + a * b - b * a
aa,bb=A.monoid().gens()
f.coefficient(aa*bb)
Preview: (hide)
link

Comments

Thank you very much! this worked perfectly. Should I open a bug about this in git, or is this expected behavior?

levav gravatar imagelevav ( 0 years ago )
1

Well, this is expected, but maybe things can be enhanced.

FrédéricC gravatar imageFrédéricC ( 0 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

1 follower

Stats

Asked: 0 years ago

Seen: 50 times

Last updated: Jan 07