Kitonum

21845 Reputation

26 Badges

17 years, 235 days

MaplePrimes Activity


These are replies submitted by Kitonum

@Markiyan Hirnyk 

1) Why was the combinat package called, if in the code it is not used?  

2) Your procedure s does not work in the classic interface, as left single quotes should be used: print(`Invalid input`) . In standard interface s works - Maple interprets a blank as multiplication.    

3) A simple exhaustive search program more effective (running at least 10 times faster)

s1:=proc(L::list)

local n, N, i, j;

n:=nops(L);

if nops(convert(L,set))=n then

N:=0;

for i to n-1 do

for j from i+1 to n do

if L[i]>L[j] then N:=N+1; fi;

od; od;

else print(`Invalid input`); fi;

(-1)^N;

end proc;

 

Examples:

L:=combinat[randperm](1000):

st:=time():

s1(L), time()-st;

    1,  0.967

 

st:=time():

s(L), time()-st;

    1,  11.981

s([1, 2, 3, 4]);

             -1

No comments!

s([1, 2, 3, 4]);

             -1

No comments!

Many thanks to all for the detailed comments and answers!

Mathematica immediately finds the correct answer:

N[FractionalPart[10^9*Exp[1]], 10]

0.4590452354

The coordinates of T and E are the rational numbers, what you would like!

The coordinates of T and E are the rational numbers, what you would like!

To toandhsp! I solved your problem by Classic Worksheet Maple 13  (time about 6 min).

To Markiyan Hirnyk! Your solving found only 98 solutions (and accurate of them will be 50). Therefore, I believe that the application of DirectSearch package for these tasks is inefficient. It is interesting your comment on this.

To toandhsp! I solved your problem by Classic Worksheet Maple 13  (time about 6 min).

To Markiyan Hirnyk! Your solving found only 98 solutions (and accurate of them will be 50). Therefore, I believe that the application of DirectSearch package for these tasks is inefficient. It is interesting your comment on this.

Dear Markiyan! Thank you for finding error in my code. I did not notice the coefficients 2, 3 and so on before x_2, x_3, and so on. The corrected code:

P:=proc(k, i)

local L, s, M, K, m;

if not (k>=2*i and 2*i>=4) then

error `should be k>=2*i>=4` fi;

if not type(k, posint) or not type(i, posint) then

error `should be k is integer and i is integer` fi;

L:=[];

for s from k-2*i to k-i do

M:=combinat[composition](s+i, i);

K:=[seq([seq(M[j,l]-1, l=1..i)], j=1..nops(M))];

for m from 1 to nops(M) do

if convert([seq(type(K[m,t]/t, integer), t=2..i)], `and`) then

L:=[op(L), [K[m,1],seq(K[m,t]/t, t=2..i)]]; fi; od;

od;

L;

end proc;

Dear Markiyan! Thank you for finding error in my code. I did not notice the coefficients 2, 3 and so on before x_2, x_3, and so on. The corrected code:

P:=proc(k, i)

local L, s, M, K, m;

if not (k>=2*i and 2*i>=4) then

error `should be k>=2*i>=4` fi;

if not type(k, posint) or not type(i, posint) then

error `should be k is integer and i is integer` fi;

L:=[];

for s from k-2*i to k-i do

M:=combinat[composition](s+i, i);

K:=[seq([seq(M[j,l]-1, l=1..i)], j=1..nops(M))];

for m from 1 to nops(M) do

if convert([seq(type(K[m,t]/t, integer), t=2..i)], `and`) then

L:=[op(L), [K[m,1],seq(K[m,t]/t, t=2..i)]]; fi; od;

od;

L;

end proc;

@Markiyan Hirnyk 

Unfortunately, there is a limit in Maple on the length of the list. Run the following code (all permutations of 10 elements):

combinat[permute](10);

There are ways around this restriction, for example, dividing the list into several parts.

@Markiyan Hirnyk 

Unfortunately, there is a limit in Maple on the length of the list. Run the following code (all permutations of 10 elements):

combinat[permute](10);

There are ways around this restriction, for example, dividing the list into several parts.

That's right!

That's right!

First 126 127 128 129 130 131 132 Page 128 of 134