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, 17 Feb 2021 02:00:44 +0100Sagemath 9.2 Product function Bughttps://ask.sagemath.org/question/55750/sagemath-92-product-function-bug/In sagemath 9.2 the product function have a bug in multiplication.
var('q')
var('jt')
((q^(2/3)+q**(2/5))*(product(1 -q**jt, jt, 1 , 31) * q**(1 /24 ))).expand()
returned a result with leading series to be (Both wrong in the powers and the coefficients )
...+ 2*q^(121/24) - 2*q^(49/24) - 2*q^(25/24) + 2*q^(1/24)
while
((q^(2/3)+q**(2/5))*(product(1 -q**jt, jt, 1 , 31) * q**(1 /24 )).expand()).expand()
returned a result with leading series to be
...+ q^(653/120) - q^(65/24) - q^(293/120) - q^(41/24) - q^(173/120) + q^(17/24) + q^(53/120)
Notice that both
((q^(2/3)+q**(2/5))*(product(1 -q**jt, jt, 1 , 30) * q**(1 /24 ))).expand()
((q^(2/3)+q**(2/5))*(product(1 -q**jt, jt, 1 , 30) * q**(1 /24 )).expand()).expand()
returned a result with leading series to be
...+ q^(653/120) - q^(65/24) - q^(293/120) - q^(41/24) - q^(173/120) + q^(17/24) + q^(53/120)ShoutOutAndCalculateWed, 17 Feb 2021 02:00:44 +0100https://ask.sagemath.org/question/55750/Simplify symbolic producthttps://ask.sagemath.org/question/55471/simplify-symbolic-product/As per the title, I want to simplify this product somehow.
var('i,r')
exp = product(1-2**(-i), i, 1, r)
This can be also expressed as
q_pochhammer(r, 2, 2)
However, the latest expression does not accept the symbolic variable `r`, but only a real integer.
The main problem is that the actual computation (f.e. `exp.unhold().subs({r: 12345})` takes a huge amount of time. Is there any way to simplify this product in sage or accelerate this computation somehow? I've already tried all the simplify/expand methods, but also the `combsimp` method of `sympy`.
As a side question, is there any way to use the `q_pochhammer` function symbolically? Maybe I can use the hypergeometric simplifications on it.tigerjackWed, 27 Jan 2021 15:21:13 +0100https://ask.sagemath.org/question/55471/Sage symbolic math simplification errorhttps://ask.sagemath.org/question/53345/sage-symbolic-math-simplification-error/In sagemath version 9.1, the code
product(1-q^x, x, 1, N)
returned
-(-1)^N*product(q^x - 1, x, 1, N)
while the correct result ought to be
(-1)^N*product(q^x - 1, x, 1, N)
What went wrong? Where did this sign change come from?ShoutOutAndCalculateMon, 07 Sep 2020 03:21:09 +0200https://ask.sagemath.org/question/53345/Multiplying a vector to a listhttps://ask.sagemath.org/question/52213/multiplying-a-vector-to-a-list/Let's say I have a list of forms given by
U = Manifold(4, 'U')
X.<x, y, z, w> = U.chart()
f = U.diff_form(3, 'f')
f[0, 1, 2] = x^2
g = U.diff_form(3, 'g')
g[0, 1, 2] = y^2
h = U.diff_form(3, 'g')
h[0, 1, 2] = z^3
List = [f, g, h]
So I have a list of 3 elements, each a 3-form.
Let's assume I have a list of vectors given by
ListofVectors = [(0, 1, 1), (0, 2, 1), (1, 2, 3)]
I want to do a dot product but the problem is Sage won't
let me make `List` into a vector so I can do like
List.dot_product(ListofVectors[i]) for i < len(ListforVectors)
Basically, I want a new list with `[g + h, 2*h + g, f + 2*g + 3*h]`. Is there a way to dot product a list of forms with a list of vectors? Again, I think the main issue is I can't turn List into a vector for the dot product function to make sense.whatupmattThu, 25 Jun 2020 02:16:50 +0200https://ask.sagemath.org/question/52213/Symbolic product in Sage?https://ask.sagemath.org/question/9047/symbolic-product-in-sage/Suppose I'd like to compute
prod(1/x^4, x, 1, oo)
How can this be done?
I found an old [thread](https://groups.google.com/forum/?fromgroups#!topic/sage-support/ZLfVooTBLvw), but with no answers.bk322Fri, 08 Jun 2012 14:13:32 +0200https://ask.sagemath.org/question/9047/Is there an easy way to get the matrix of coefficients from a product of a matrix and a vector?https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/I have a matrix multiplication of the form
$$ B = A x $$
or
$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\\
a_{21} & a_{22} & a_{23}\\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\\
x_2 \\\
x_3
\end{pmatrix}
$$
Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?
Edited from a question posted by someone else at the Mathematica StackexchangenikolaussucherFri, 08 Feb 2019 20:40:39 +0100https://ask.sagemath.org/question/45376/Working with sums/products of listshttps://ask.sagemath.org/question/44905/working-with-sumsproducts-of-lists/I need to work symbolically with expressions such as this
$L(x; a,b) = \prod_{i=1}^n{abx_i^{a-1}(1-x_i^a)^{b-1}}$
where $x$ would be a random sample of size $n$.
I don't know of any way to express the indexing of the sample $x$ by each element...
The closest I got was defining the variables $n$ and $i$ and representing $x$ as a function
var('a','b','x','n','i')
assume(x>0,a>0,b>0,i>0,n>0)
X = function('X',nargs=1)
L = product(a*b*X(i)^(a-1)*(1-X(i)^a)^(b-1), i, 1, n)
But this seems to inmediately assume that $X(i) = i$ and $L$ is represented as:
$-\frac{\left(-1\right)^{n} a^{n} b^{n} X\left(0\right) X\left(-1\right) X\left(-2\right) X\left(-3\right) X\left(-4\right) X\left(-5\right) X\left(-6\right) X\left(-7\right) X\left(-8\right) X\left(-9\right) {\prod_{i=1}^{n} {\left(-X\left(i\right)^{a} + 1\right)}^{b}} {\prod_{i=1}^{n} X\left(i\right)^{a}}}{X\left(n - 1\right) X\left(n - 2\right) X\left(n - 3\right) X\left(n - 4\right) X\left(n - 5\right) X\left(n - 6\right) X\left(n - 7\right) X\left(n - 8\right) X\left(n - 9\right) X\left(n\right) {\prod_{i=1}^{n} X\left(i\right)^{a} - 1} {\prod_{i=1}^{n} X\left(i - 10\right)}}$
I don't know how to deal with this expression, and it seems to me like it should be straight forward.galioSat, 05 Jan 2019 15:20:32 +0100https://ask.sagemath.org/question/44905/How to make "zip" work faster?https://ask.sagemath.org/question/26790/how-to-make-zip-work-faster/ I have these two finite sets $A$ and $B$ where the size of $A$ is typically much larger than the size of $B$. (typically $|A| is 200-500$ and $|B| is 10-50$) I am trying to enumerate all possible maps from $B$ to $A$ using the following idea - but this turns out to be very slow.
- Is there a way to speed this up?
- Without the over all "for i" loop can I access any one of the "k"s?
(for every i each $l$ is a list of tuples)
How can I just pick out any one such "k" list without wanting to wait for the whole code to run.
S = []
from itertools import product
for i in product(A,repeat = len (B)):
k = zip(B,i)
S.append(k)
show(S)PhoenixSun, 10 May 2015 23:42:04 +0200https://ask.sagemath.org/question/26790/define new vectorhttps://ask.sagemath.org/question/26198/define-new-vector/ hi i'm new in sage , I have two vectors
v1=vector([8,-10,12]) <br>
v2=vector([9,4,-6])
i want to create a third one which is parallel with v1 and also the scalar product of v2 and v3 is equal to 1440
(x,y,z)=var('x,y,z') <br>
v3=vector([x,y,z])
solve([v1.dot_product(v3)==1440,v2.cross_product(v3)==0],x,y,z)
i want to get something like this: [x= , y= , z= ] <br>
but the result: []
dan6252Mon, 16 Mar 2015 03:15:30 +0100https://ask.sagemath.org/question/26198/how to get two modules tensor_prduct()https://ask.sagemath.org/question/23430/how-to-get-two-modules-tensor_prduct/ u = vector(QQ, [1/2, 1/3, 1/4, 1/5])
v = vector(ZZ, [60, 180, 600])
u.outer_product(v),v.outer_product(u),u.tensor_product(v),v.tensor_product(u)
(
[ 30 90 300] [ 30 90 300]
[ 20 60 200] [ 30 20 15 12] [ 20 60 200] [ 30 20 15 12]
[ 15 45 150] [ 90 60 45 36] [ 15 45 150] [ 90 60 45 36]
[ 12 36 120], [300 200 150 120], [ 12 36 120], [300 200 150 120]
)
above are two vectors'tensor_product,but when use two mudules,cannot run....
M=FreeModule(ZZ,3);M
N=FreeModule(ZZ,7);N
M.outer_product(N),M.tensor_product(N)
AttributeError Traceback (most recent call last)
<ipython-input-1-ad4483c60043> in <module>()
1 M=FreeModule(ZZ,Integer(3));M
2 N=FreeModule(ZZ,Integer(7));N
----> 3 M.outer_product(N),M.tensor_product(N)
/home/sageserver/sage/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__getattr__ (build/cythonized/sage/structure/parent.c:7367)()
/home/sageserver/sage/local/lib/python2.7/site-packages/sage/structure/misc.so in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1687)()
AttributeError: 'FreeModule_ambient_pid_with_category' object has no attribute 'outer_product'
cjshWed, 16 Jul 2014 09:05:27 +0200https://ask.sagemath.org/question/23430/Categorical product of simplicial complexeshttps://ask.sagemath.org/question/23170/categorical-product-of-simplicial-complexes/Does Sage have some function that takes the *categorical* product of two finite simplicial complexes? I see that the SimplicialComplex library has a product() function that appears to take the *topological* product of two complexes (details here: http://www.sagemath.org/doc/reference/homology/sage/homology/simplicial_complex.html), but this isn't what I'm looking for.
The example given on the linked webpage is Simplex(1).product(Simplex(1)), which returns [('L0R0', 'L0R1', 'L1R1'), ('L0R0', 'L1R0', 'L1R1')], or a square with a diagonal through it. This is what I would expect from a topological product, since the product of two lines is a square. However, the *categorical* product of two complexes is different and is in general not homeomorphic to their topological product. The categorical product of two edges (1-simplexes) should be a tetrahedron and not a square.
Is there a Sage function that will do this for me? I'm not familiar with the markdown syntax on this forum so sorry about the poor formatting.Vikram SaraphThu, 03 Jul 2014 00:25:08 +0200https://ask.sagemath.org/question/23170/construction of product rings Z/nZ x Z/mZhttps://ask.sagemath.org/question/10347/construction-of-product-rings-znz-x-zmz/Hello,
is it possible in Sage to construct a product ring of two integer modulo rings?
When just creating an cartesian_product,
it is for example not possible to add its elements:
R5=Integers(5)
R3=Integers(3)
CR=R5.cartesian_product(R3)
elem=CR((3,2)) # ok, element construction
elem*elem # ok
elem+elem # fails
CR.list() # not implemented
CR.list_of_elements_of_multiplicative_group # not implemented
jack77Thu, 11 Jul 2013 18:46:09 +0200https://ask.sagemath.org/question/10347/How to compute an iterated product in Sagehttps://ask.sagemath.org/question/10219/how-to-compute-an-iterated-product-in-sage/I am wondering about how to define a function `f(n, k, i)` that will take inputs `n`, `k`, `i` and give me the following product:
$$
\prod_{\ell = 1}^i {n + k - \ell \choose k}
$$
So for $i = 2$, this would look like ${n + k - 1 \choose k}\cdot {n + k - 2 \choose k}$. Would I use a for loop to iteratively add to the product until all `i` terms were accounted for?JoshIzzardMon, 10 Jun 2013 17:58:24 +0200https://ask.sagemath.org/question/10219/How to do mul(function, i=1..n); like in Maple?https://ask.sagemath.org/question/8564/how-to-do-mulfunction-i1n-like-in-maple/I want to a product of polynomials which I define in Maple as
f := n->mul((1+x^k),k=1..n);
The obvious choice, mimicking Sage's 'sum' command does not work. I can't do
def f(n):
return mul((1+x^k),k,1,n)
Instead I had to use
def S(n,k):
return mul(1+x^(k+1) for k in range(n))
Maybe my problem is another, so I'll post my whole problem and traceback:
def S(n,k):
s = mul(1+x^(i+1) for i in range(n))
return s.expand().coeff(x^k)
def H(n,k):
return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
H(121,4)
Traceback (most recent call last): return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
File "", line 1, in <module>
File "/tmp/tmpKvQFbK/___code___.py", line 10, in <module>
exec compile(u'H(_sage_const_121 ,_sage_const_4 )
File "", line 1, in <module>
File "/tmp/tmpKvQFbK/___code___.py", line 9, in H
return sum(sum( S(_sage_const_2 *i+_sage_const_1 ,b)*S(n-_sage_const_2 *i-_sage_const_3 ,k-(_sage_const_2 *i+_sage_const_2 )-b),b,_sage_const_0 ,k-(_sage_const_2 *i+_sage_const_2 )),i,_sage_const_0 ,floor((n-_sage_const_5 )/_sage_const_4 ))
File "/tmp/tmpKvQFbK/___code___.py", line 4, in S
s = mul(_sage_const_1 +x**(i+_sage_const_1 ) for i in range(n))
TypeError: range() integer end argument expected, got sage.symbolic.expression.Expression.
All advice is welcome.alejandroericksonWed, 04 Jan 2012 00:00:17 +0100https://ask.sagemath.org/question/8564/