Ask Your Question

Quinten87's profile - activity

2024-01-20 22:08:57 +0200 received badge  Notable Question (source)
2024-01-20 22:08:57 +0200 received badge  Popular Question (source)
2023-11-21 06:05:58 +0200 commented answer Is there a bug with the "parts" input in VectorPartitions?

Thanks! Manually inputting the minimum vector to be zeros does appear to work in some further examples I tried. As you i

2023-11-21 06:00:49 +0200 commented answer Is there a bug with the "parts" input in VectorPartitions?

Thanks! Manually inputting the minimum vector to be zeros does appear to work in some further examples I tried. As you i

2023-11-21 02:55:33 +0200 asked a question Is there a bug with the "parts" input in VectorPartitions?

Is there a bug with the "parts" input in VectorPartitions? Using Sagemath 10.1 if I run the code: VectorPartitions([2,2

2023-11-13 21:22:55 +0200 marked best answer Efficient way to compute all possible permutations that sort a list

I'm looking for a good way to compute all the possible permutations that sort a list. For example, if the list is [3,4,3,2,4] I would want the permutations to be: [4,1,3,2,5], [4,1,3,5,2], [4,3,1,2,5], [4,3,1,5,2]. I'm well aware of how to get a permutation that sorts the list, one can use argsort or standard_permutation(), but neither of these will return all such permutations.

I can also, of course, come up with something stupid myself, but I worry it won't be efficient and I wish to do this for a largeish number of arrays.

Edit: Here is my best attempt to code this. Essentially, I find one permutation using the standard 'sorted' python function, and then find all permutations that preserve the sorted list, and then multiply the two permutations. I just feel like this is a really stupid way to do this that will slow my program down. Especially if the list is long, this is going to involve checking a bunch of unnecessary permutations.

dP = [3,4,3,2,4]
sorted_enumerate_dP = sorted(enumerate(dP,1), key=lambda x: x[1])
sorted_dP = [pair[1] for pair in sorted_enumerate_dP]
initial_perm = Permutation([pair[0] for pair in sorted_enumerate_dP])
further_perms = []
for p in Permutations(len(sorted_dP)):
    new_dP=[sorted_dP[i-1] for i in p]
    if new_dP == sorted_dP:
        further_perms+=[p]
perms = []
for p in further_perms:
    perms += [Permutation([initial_perm[i-1] for i in p])]
print(perms)

The output is indeed [[4, 1, 3, 2, 5], [4, 1, 3, 5, 2], [4, 3, 1, 2, 5], [4, 3, 1, 5, 2]], as I want.

2023-11-13 21:22:51 +0200 commented answer Efficient way to compute all possible permutations that sort a list

Yep, looks like it works now; I'll accept this answer. Thanks for helping me out.

2023-11-13 20:29:04 +0200 edited answer Efficient way to compute all possible permutations that sort a list

This is a corrected version of the thought process provided by Max Alekseyev (it copies some of his code as well). I did

2023-11-13 20:22:49 +0200 commented answer Efficient way to compute all possible permutations that sort a list

After looking it up, I realised I missed the most obvious set of generators, namely (1 2), (2 3),...(n-1 n). I edited it

2023-11-13 20:21:55 +0200 edited answer Efficient way to compute all possible permutations that sort a list

This is a corrected version of the thought process provided by Max Alekseyev (it copies some of his code as well). I did

2023-11-13 19:50:25 +0200 commented answer Efficient way to compute all possible permutations that sort a list

After looking it up, I realised I missed the most obvious set of generators, namely (1 2), (2 3),...(n-1 n). I'll edit t

2023-11-13 18:58:05 +0200 commented answer Efficient way to compute all possible permutations that sort a list

I'm not overly comfortable with itertools.groupby() (hence I didn't use it), but I agree it seems more elegant. The pr

2023-11-13 18:55:09 +0200 commented answer Efficient way to compute all possible permutations that sort a list

I'm not overly comfortable with itertools.groupby() (hence I didn't use it), but I agree it seems more elegant. The pr

2023-11-13 01:14:04 +0200 answered a question Efficient way to compute all possible permutations that sort a list

This is a corrected version of the thought process provided by Max Alekseyev (it copies some of his code as well). I did

2023-11-13 01:14:02 +0200 commented answer Efficient way to compute all possible permutations that sort a list

Thanks for the reply! However, this algorithm does not work. For example, one can choose dP = [1,1,1] and it will only g

2023-11-11 00:39:32 +0200 commented answer Efficient way to compute all possible permutations that sort a list

Thanks a lot! This is (in concept) similar to what I was thinking in my code, but it is vastly superior in execution. In

2023-11-10 22:31:55 +0200 edited question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 22:31:26 +0200 edited question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 22:30:12 +0200 edited question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 22:29:51 +0200 edited question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 21:08:48 +0200 edited question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 21:08:20 +0200 asked a question Efficient way to compute all possible permutations that sort a list

Efficient way to compute all possible permutations that sort a list I'm looking for a good way to compute all the possib

2023-11-10 20:54:41 +0200 received badge  Notable Question (source)
2022-11-28 00:09:58 +0200 edited question Cryptic Cython Error Message

Cryptic Cython Error Message I have been coding a basic algorithm to compute infinite dimensional path integrals in cyth

2022-11-27 23:41:56 +0200 edited question Cryptic Cython Error Message

Cryptic Cython Error Message I have been coding a basic algorithm to compute infinite dimensional path integrals in cyth

2022-11-27 23:41:02 +0200 edited question Cryptic Cython Error Message

Cryptic Cython Error Message I have been coding a basic algorithm to compute infinite dimensional path integrals in cyth

2022-11-27 23:41:02 +0200 received badge  Editor (source)
2022-11-27 23:40:19 +0200 asked a question Cryptic Cython Error Message

Cryptic Cython Error Message I have been coding a basic algorithm to compute infinite dimensional path integrals in cyth

2022-11-27 23:05:44 +0200 received badge  Popular Question (source)
2020-04-30 23:08:28 +0200 asked a question ode_solver throwing ValueError: error solving

So I've been trying to solve a system of ode's with the class ode_solver. My code looks something like this:

#Set up ode solver
OS=ode_solver() #Create instance of ode solver
OS.algorithm='bsimp' #Choose algorithm
OS.error_abs=10^(-12) #Set absolute error
OS.error_rel=10^(-12) #Set relative error

#Parameters
n=1 
eta=1 
e=1 
R=200 #Estimate for "infinity"

#System to solve
def F(r, y):
       return [y[2], y[3],
               y[0]/(R-r)^2+y[2]/(R-r)+e^2*(y[0]-1/(R-r))*y[1]^2,
               y[3]/(R-r)+y[1]*(n^2*(y[0]-1/(R-r))^2+e^2*(y[1]^2-eta^2))]

#Jacobian
def J(r,y):
       return [[0, 0, 1, 0],
               [0, 0, 0, 1],
               [1/(R-r)^2+e^2*y[1]^2, 2*e^2*y[1]*(y[0]-1/(R-r)), 1/(R-r), 0],
               [2*y[1]*n^2*(y[0]-1/(R-r)), n^2*(y[0]-1/(R-r))^2+e^2*(y[1]^2-eta^2)+2*e^2*y[1]^2, 0, 1/(R-r)]]

#Solve the ode
OS.function=F
OS.jacobian=J
OS.ode_solve(y_0=[1/R, eta, -1/R^2, -e*eta*exp(-e*eta*R)], t_span=[0,R])

#Plot the solution
y_0=OS.interpolate_solution(i=0)
y_1=OS.interpolate_solution(i=1)
var('r')
show(plot(y_1(r),(r,0,R))+plot(y_0(r),(r,0,R)))

Whenever I try to run it sage throws me the very unhelpful error of ValueError: error solving. I'm just not sure what could going wrong? It throws me the same error even if I reduce to t_span to only go to [0,1] so it has nothing to do with dividing by zero in the jacobian.

For reference the error thrown is:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-ff7d0ba0b2e5> in <module>()
    29 OS.function=F
    30 OS.jacobian=J
---> 31 OS.ode_solve(y_0=[Integer(1)/R, eta, -Integer(1)/R**Integer(2), -e*eta*exp(-e*eta*R)], t_span=[Integer(0),R])
    32 
    33 #Plot the solution

/opt/sagemath-8.2/local/lib/python2.7/site-packages/sage/calculus/ode.pyx in sage.calculus.ode.ode_solver.ode_solve (build/cythonized/sage/calculus/ode.c:7242)()
   587                         sig_free(y)
   588                         sig_free(scale_abs_array)
--> 589                         raise ValueError("error solving")
   590 
   591                 for j from 0<=j<dim:

ValueError: error solving
2018-06-08 21:20:34 +0200 received badge  Scholar (source)
2018-06-08 21:20:20 +0200 commented answer Computing Roots of Large Polynomials

Thanks a lot! That's closer to what I was expecting when I went out to code the graph. I should have figured dividing by all those really huge numbers and then using numerical algorithms to pinpoint the roots would result in some massive errors.

2018-06-08 18:18:51 +0200 received badge  Supporter (source)
2018-06-08 18:18:42 +0200 commented answer Computing Roots of Large Polynomials

Thanks for the reply. I tried CDF and like you said it was a lot faster but a bunch of the roots also disappeared. The trouble is I'm not getting the picture I think I should. I think I should see one root converging to 1 and all the other ones going to infinity as for large N the series becomes increasingly close to z*exp(-z). I would be interested to see the picture you get using exact computation to see if it would be closer to my intuition but your code seems to give me the error 'Algebraic Field is not a valid variable'.

2018-06-08 11:13:10 +0200 received badge  Good Question (source)
2018-06-07 08:48:33 +0200 received badge  Nice Question (source)
2018-06-07 08:04:58 +0200 received badge  Student (source)
2018-06-07 07:57:28 +0200 asked a question Computing Roots of Large Polynomials

Hey, I'm looking to compute the roots of very large polynomials (as in polynomials of degree 500+) and am looking for the most efficient method to do so. This my code so far (I tried a different method with the commented out code) and it works great for about anything with N<=200ish and then starts to take a really long time:

#var('x')
x=PolynomialRing(ComplexField(),'x').gen()
N=500
s=0
for m in range (N+1):
    n=N+1-m
    s+=(-1)^n*(n+1)*x^n/factorial(n)
    #s+=[(-1)^n*(n+1)/factorial(n)]
#sols=(s==0).roots(x,ring=CC,multiplicities=False)
sols=s.roots()
solsPlot=[]
for n in range(len(sols)):
    solsPlot+=[[sols[n][0].real(),sols[n][0].imag()]]
    #solsPlot+=[[sols[n].real(),sols[n].imag()]]
scatter_plot(solsPlot)

Thanks.