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.Thu, 16 Sep 2021 02:48:15 +0200ValueError: Cannot pickle code objects from closureshttps://ask.sagemath.org/question/59044/valueerror-cannot-pickle-code-objects-from-closures/The following code produces a strange error `ValueError: Cannot pickle code objects from closures` in Sage 9.4. It does not happen at SageCell, and also disappears if I remove `if set(v)&S` condition. What's wrong?
def mytestproc(n,G,S):
V = [v for v in G.vertices() if set(v)&S]
return n*len(V)
def test(n):
G = DiGraph()
return sum( val for _,val in sage.parallel.multiprocessing_sage.parallel_iter(2, mytestproc, [((n,G,S),{}) for S in Subsets(1..n)]) )
test(2)
Max AlekseyevThu, 16 Sep 2021 02:48:15 +0200https://ask.sagemath.org/question/59044/Factoring a polynomial over algebraic numbers?https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/ Actually, what I want is to be able to factor a polynomial over the quadratic closure of the rationals, so that I could factor `x^2-3` say, as `(x+sqrt(3)*(x-sqrt(3))`. I don't know enough about factoring algorithms to know whether this is easy or not, but is this at all possible in Sage?
I know I can build an extension field of the rationals by the use of an irreducible quadratic, but that just gives me access to one square root. So if I added `sqrt(3)` then I could factorize the example above, but not `x^2-5`. Is it possible to include all square roots - in other words, can Sage work with the the field of [constructible numbers](https://en.wikipedia.org/wiki/Constructible_number)?AlasdairThu, 21 Jan 2016 11:12:09 +0100https://ask.sagemath.org/question/32308/Type error in recursionhttps://ask.sagemath.org/question/8765/type-error-in-recursion/Consider the following function:
<pre>
def f(n) :
def retfunc(x) :
return 1 if n == 0 else x*add(f(n-k) for k in (1..n))
return retfunc
</pre>
The test
<pre>
w = f(9); print w, type(w)
</pre>
gives
<pre>
"function retfunc at 0x43d3de8" "type 'function'"
</pre>
which looks fine to me. However an evaluation w(3) gives
<pre>
TypeError: unsupported operand type(s) for +: 'int' and 'function'
</pre>
How can I get around this error?
EDIT: One solution is, as indicated by DSM,
<pre>
def f(n):
retfunc(x) = 1 if n == 0 else add(x*f(n-k) for k in (1..n))
return retfunc
</pre>
What I am trying to do here? Let's see:
<pre>
for i in [1..8] : [c[0] for c in expand(f(i)(x)).coeffs()]
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]
</pre>
petropolisSat, 03 Mar 2012 02:32:30 +0100https://ask.sagemath.org/question/8765/