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.Sun, 05 Apr 2020 17:46:08 +0200How to factorise a quantity obtained after summing?https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/ list=[]
for n in range(2,20,2):
s = sum(1/k^n,k,1,oo)/(pi)^n
print(s)
list.append(s.factor())
print(list)
My code is given above I'm not able to use the .factor() function, I understand that this is due to the type of s in the above code which is sage.symbolic.expression.Expression . My question is how to convert it into 𝚜𝚊𝚐𝚎.𝚛𝚒𝚗𝚐𝚜.𝚛𝚊𝚝𝚒𝚘𝚗𝚊𝚕.𝚁𝚊𝚝𝚒𝚘𝚗𝚊𝚕 or something else so that I can factorise it. In the end I want to make a list of these numbers factorized.Sun, 05 Apr 2020 09:38:08 +0200https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/Answer by vdelecroix for <pre><code>list=[]
for n in range(2,20,2):
s = sum(1/k^n,k,1,oo)/(pi)^n
print(s)
list.append(s.factor())
print(list)
</code></pre>
<p>My code is given above I'm not able to use the .factor() function, I understand that this is due to the type of s in the above code which is sage.symbolic.expression.Expression . My question is how to convert it into 𝚜𝚊𝚐𝚎.𝚛𝚒𝚗𝚐𝚜.𝚛𝚊𝚝𝚒𝚘𝚗𝚊𝚕.𝚁𝚊𝚝𝚒𝚘𝚗𝚊𝚕 or something else so that I can factorise it. In the end I want to make a list of these numbers factorized.</p>
https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/?answer=50549#post-id-50549For your problem, since `zeta(2n)` has an explicit expression in terms of Bernoulli number I would rather go with
sage: [((-1)**(1+n//2)*2**(n-1) * bernoulli(n)/factorial(n)).factor() for n in range(2,20,2)]
[2^-1 * 3^-1,
2^-1 * 3^-2 * 5^-1,
3^-3 * 5^-1 * 7^-1,
2^-1 * 3^-3 * 5^-2 * 7^-1,
3^-5 * 5^-1 * 7^-1 * 11^-1,
3^-6 * 5^-3 * 7^-2 * 11^-1 * 13^-1 * 691,
2 * 3^-6 * 5^-2 * 7^-1 * 11^-1 * 13^-1,
2^-1 * 3^-7 * 5^-4 * 7^-2 * 11^-1 * 13^-1 * 17^-1 * 3617,
3^-9 * 5^-3 * 7^-3 * 11^-1 * 13^-1 * 17^-1 * 19^-1 * 43867]
Sun, 05 Apr 2020 17:46:08 +0200https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/?answer=50549#post-id-50549Answer by rburing for <pre><code>list=[]
for n in range(2,20,2):
s = sum(1/k^n,k,1,oo)/(pi)^n
print(s)
list.append(s.factor())
print(list)
</code></pre>
<p>My code is given above I'm not able to use the .factor() function, I understand that this is due to the type of s in the above code which is sage.symbolic.expression.Expression . My question is how to convert it into 𝚜𝚊𝚐𝚎.𝚛𝚒𝚗𝚐𝚜.𝚛𝚊𝚝𝚒𝚘𝚗𝚊𝚕.𝚁𝚊𝚝𝚒𝚘𝚗𝚊𝚕 or something else so that I can factorise it. In the end I want to make a list of these numbers factorized.</p>
https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/?answer=50545#post-id-50545Replace `s.factor()` by `QQ(s).factor()` to convert the symbolic expression to a rational and to factor that rational. Indeed, `SR(1/6).factor()` yields `1/6` while `QQ(1/6).factor()` yields `2^-1 * 3^-1`.Sun, 05 Apr 2020 15:30:32 +0200https://ask.sagemath.org/question/50537/how-to-factorise-a-quantity-obtained-after-summing/?answer=50545#post-id-50545