ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Oct 2018 17:04:18 +0200substitution of ideal generators of a free algebrahttps://ask.sagemath.org/question/43903/substitution-of-ideal-generators-of-a-free-algebra/I'm trying to map the generators of an ideal $I$ of a free $k$-algebra $A = k \\{ x, y \\}$ to a different free $k$-algebra $B = k \\{ u, v \\}$ (really I'm trying something more complicated, but the failure occurs in even this simplified example). I was attempting to do this via `subs` by creating a dictionary taking $x$ to $u$ and $y$ to $v$, but this is not working.
sage: A.<x, y> = FreeAlgebra(QQ, 2)
sage: I = A*[x*y - y*x - 1]*A
sage: B.<u, v> = FreeAlgebra(QQ, 2)
sage: genMap = {'x':'u', 'y':'v'}
sage: I.gen(0).subs(genMap)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-9d969fff6a4a> in <module>()
----> 1 I.gen(Integer(0)).subs(genMap)
sage/structure/element.pyx in sage.structure.element.Element.subs (build/cythonized/sage/structure/element.c:7572)()
/usr/lib/python2.7/dist-packages/sage/algebras/free_algebra_element.pyc in __call__(self, *x, **kwds)
176 for m, c in six.iteritems(self._monomial_coefficients):
177 if result is None:
--> 178 result = c*m(x)
179 else:
180 result += c*m(x)
sage/rings/rational.pyx in sage.rings.rational.Rational.__mul__ (build/cythonized/sage/rings/rational.c:21325)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:10686)()
TypeError: unsupported operand parent(s) for *: 'Rational Field' and 'Free monoid on 2 generators (x, y)'
This error seems strange to me; is it not understanding elements of $\mathbb{Q}$ and $\\{ x, y \\}$ as elements of $\mathbb{Q} \\{ x, y \\}$? I also tried to do this via a homomorphism $A \to B$ but I could not get this to work, as it seems they are not fully implemented yet for free algebras, from what I could tell. Any help or alternatives would be very appreciated.
**EDIT**: I got a slight work-around, by converting the elements to strings, replacing the variables as characters, and the evaluating the string in the target. However, I feel like this is way more costly than a substitution would be, so I am still interested in a solution.rhoadskjWed, 10 Oct 2018 17:04:18 +0200https://ask.sagemath.org/question/43903/dictionary substitution for elements of ExteriorAlgebrahttps://ask.sagemath.org/question/25464/dictionary-substitution-for-elements-of-exterioralgebra/As a newbie for sage, I don't understand how to perform substitution for elements in, e.g., an ExteriorAlgebra.
For example, i'm trying:
E.<x,y>=ExteriorAlgebra(SR)
x.substitute({x:y})
and i'd expect "y", instead getting "x". It seems substitution in this case is not possible... So, where am i getting wrong, and what is the correct way to perform such an operation?
thanksdanieleSun, 11 Jan 2015 15:10:29 +0100https://ask.sagemath.org/question/25464/Defining and manipulating vector equations with cross and dot productshttps://ask.sagemath.org/question/24421/defining-and-manipulating-vector-equations-with-cross-and-dot-products/Hello, I have been experimenting with Sage to see what it can or can't do. Consider the following simple problem.
Show $[ \mathbf{A} \times (\mathbf{B} \times \mathbf{C}) ] + [ \mathbf{B} \times (\mathbf{C} \times \mathbf{A}) ] + [ \mathbf{C} \times (\mathbf{A} \times \mathbf{B}) ] = 0 $ where $\mathbf{A}, \mathbf{B}, \mathbf{C} \in \mathbb{R}^3$. In Sage I can do this in one line
eqn = A.cross_product(B.cross_product(C)) + B.cross_product(C.cross_product(A)) + C.cross_product(A.cross_product(B))
where A,B and C are elements of $SR^3$. Now I can show component wise `eqn[0].expand()` `eqn[1].expand()` `eqn[2].expand()` that it's zero.
A much simpler way is to use the identity $\mathbf{A} \times ( \mathbf{B} \times \mathbf{C} ) = \mathbf{B}( \mathbf{A} \cdot \mathbf{C} ) - \mathbf{C}( \mathbf{A} \cdot \mathbf{B} )$ and plug it in. Yet this is easier done by hand than by computer.
My question is can Sage do this? Can I define a vector equation in sage, and sub in vector identities to manipulate or simplify the equation?
Thanks
NahsiNTue, 07 Oct 2014 22:58:01 +0200https://ask.sagemath.org/question/24421/Substitute and evaluatehttps://ask.sagemath.org/question/11357/substitute-and-evaluate/Hello, I would like to ask a really easy question:
How can I substitute a variable into an equation and have it evaluated simultaneously? If I have $f = a + b$ and would it to return $5$ if $a=2$ and $b=3$, how shall I proceed?
I've tried the following
a, b = var('a, b');
f = a + b;
a = 2; b = 3; f
But it returned `a+b`, which is not what I had in mind. Thanks for the help in advance!BlackadderWed, 16 Apr 2014 06:47:55 +0200https://ask.sagemath.org/question/11357/Substitution using Dictionary with Matrix as Valuehttps://ask.sagemath.org/question/9075/substitution-using-dictionary-with-matrix-as-value/As a newcomer to SAGE, trying to use it to do symbolic linear algebra, I am wondering why substitution of a variable using a dictionary doesn't work in this case:
sage: aMatrix = matrix(SR,1,1)
sage: var('aVariable')
aVariable
sage: aDict = {}
sage: aDict[aVariable] = aMatrix
sage: aDict[aVariable]
[0]
but:
sage: aVariable.subs(aDict)
....
/Applications/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:16025)()
/Applications/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.coerce_in (sage/symbolic/expression.cpp:11265)()
/Applications/sage/local/lib/python2.7/site-packages/sage/structure/parent_old.so in sage.structure.parent_old.Parent._coerce_ (sage/structure/parent_old.c:3369)()
/Applications/sage/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.coerce (sage/structure/parent.c:8912)()
TypeError: no canonical coercion from Full MatrixSpace of 1 by 1 dense matrices over Symbolic Ring to Symbolic Ring
Functionality to substitute matrices for variables seems to be indispensable to doing symbolic linear algebra, so I am sure there is a proper way to do this.
heatkernelThu, 14 Jun 2012 17:58:48 +0200https://ask.sagemath.org/question/9075/Simplification of expression with exponentials.https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/Hello,
I am looking at expanding the product:
(a+b\*g+c\*g^2+d\*g^3)\*(a+b\*g^2+c\*g^4+d\*g)\*(a+b\*g^3+c\*g+d\*g^4)\*(a+b\*g^4+c\*g^3+d\*g^2)
where $g=e^{2\pi i /5}$ is a fifth root of unity. The problem is, after expanding, and telling sage the value of $g$, it does not collect terms according to the rule $1+g+g^2+g^3+g^4=0$ so there are over 5 times too many terms.
Is there any way to make this simplification automatic? For degrees higher then $5$ going through manually will not be an option. (It is almost faster to multiply everything myself then figure out the collection of the terms)
Thank you very much for any help on this, I have been stuck for the last whileEric NaslundMon, 26 Sep 2011 14:31:17 +0200https://ask.sagemath.org/question/8344/