187 Reputation

8 Badges

4 years, 325 days

MaplePrimes Activity

These are replies submitted by Gillee


Thanks for your response.

One more try at speeding it up. Write procedure and compile it to native code. The compiled procedure is faster than any of the previous attempts found in



restart; kernelopts(version)

`Maple 2021.1, X86 64 WINDOWS, May 19 2021, Build ID 1539851`


datLoop := proc (i_high::integer, j_high::integer, X::(Vector(datatype = float[8])), Y::(Vector(datatype = float[8])), Z::(Vector(datatype = float[8]))) local i::integer, j::integer, k::integer, di::(float[8]), dj::(float[8]); k := 1; di := 1.0/i_high; dj := 1.0/j_high; for j to j_high do for i to i_high do X[k] := i*di; Y[k] := j*dj; Z[k] := X[k]^2+Y[k]^2; k := k+1 end do end do end proc


If you can compile a Maple procedure to native code, then it runs fast. There are only small number of mathematical functions in the run-time library, see help on Compiler.  


cdatLoop := Compiler:-Compile(datLoop)

proc () options call_external, define_external(_mf85e7835c3fc2354c4b104b43e721728, MAPLE, IN_MEM = 2379591451296); call_external(0, 2379591451296, true, false, args) end proc



Initialize variables:


i_high := 1000; j_high := 1000; X := Vector(1 .. i_high*j_high, datatype = float[8]); Y := Vector(1 .. i_high*j_high, datatype = float[8]); Z := Vector(1 .. i_high*j_high, datatype = float[8])


Run datLoop procedure


CodeTools:-Usage(datLoop(i_high, j_high, X, Y, Z))

memory used=480.47MiB, alloc change=8.00MiB, cpu time=5.44s, real time=5.49s, gc time=1.94s



Display the first ten data points


X[1 .. 10], Y[1 .. 10], Z[1 .. 10]

Vector[column](%id = 36893490527006812148), Vector[column](%id = 36893490527006812268), Vector[column](%id = 36893490527006812388)



Run compiled datLoop procedure: cdatLoop


CodeTools:-Usage(cdatLoop(i_high, j_high, X, Y, Z))

memory used=1.06KiB, alloc change=0 bytes, cpu time=16.00ms, real time=17.00ms, gc time=0ns


X[1 .. 10], Y[1 .. 10], Z[1 .. 10]

Vector[column](%id = 36893490527006802756), Vector[column](%id = 36893490527006802876), Vector[column](%id = 36893490527006802996)


"n:=3: f(x,y):=x^(~2)+y^(~2): data := CodeTools:-Usage([seq([seq([i/10^(n), j/10^(n), f(i/10^(n), j/10^(n))], i = 1 .. 10^(n))], j = 1 .. 10^(n))]): "

memory used=0.99GiB, alloc change=225.29MiB, cpu time=6.73s, real time=5.95s, gc time=1.75s


data[1][1 .. 2][1 .. 2]

[[1/1000, 1/1000, 1/500000], [1/500, 1/1000, 1/200000]]






I realized I should have shown that zeta = xi - beta * I.

I added negative signs to the following two lines of code:

soln1:=select(s->Re(s)>0 and -Im(s)>0, soln);



It is a nice solution.


Thank you


@Carl Love Two thumbs up.

@Carl Love Your improvements did make it run faster by 20 to 30 percent on my computer. Using the original script before it was modified for Grid Map and your M values, I calculated values for the Array A and found the results from both methods identical - element by element.  Thanks again for your great insight to this problem. 

@Carl Love The efficiency of your code is wonderful. Your lesson is greatly appreciated. I am in the process of verifying the results. Thanks again.

@acer The added the datatype declaration to local A in LArip showed some improvements. This line is amazing:

Grid:-Map(subs(rr = r, MM = M, eval(k -> LArip(k, rr, MM))), [$ (1 .. r)])

Thanks again.  

Thank you for your insightfulness and quick response.


I noticed your additional conditions: g is not a square of an integer number and your limits for b, d, and f. I incorporate these new conditions to Again there many solutions and the real time is less than 5 minutes to complete the search. Please see new script.


@Carl Love This problem was prosed by a user a year ago on Mapleprime: looking for a fast way to find 6 integer roots. I suggested a solution at that time. I am revisting it to see if I can speedup my original solution. I enjoyed reviewing your script. It will take me much time to understand it.

You appear to have found more than 2 possible 6 integer root solutions. I may be wrong, but I substituted the values for the 7 coefficients from Sols into the equation: abs(a*x + b) + abs(c*x + d) - t*x^2 + m*x - n and calculated the equation for the various roots (x). The results were not always zero. Please see script.

I hope I understood your question correctly about the possibilities of 8 integer roots instead of 6. It never occurred to me that there will be 8 integer roots. I modified the script called found in my original question. I changed the statement if nops(X) = 6 to if nops(X) = 8 and added and frac(X[7]) = 0 and frac(X[8]) = 0 in Procedure 2. I was not able to come up solution with 8 roots. Please show me how to get 8.

Thanks again for your help, I throughly enjoyed it.

@Carl Love I would never have come up your three methods to handle multiple agruements. You are right they did required as much time to complete as my old method. Thanks.

@dharr I like the Profile function. I will implement your the seq method and see what happens.

Thanks again. 

1 2 3 Page 1 of 3