pagan

5147 Reputation

23 Badges

17 years, 121 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are replies submitted by pagan

It's a little hard to figure out from your original post (only) that you're using MS-Windows.

It's a little hard to figure out from your original post (only) that you're using MS-Windows.

Yes, thanks. I realized too late that that ceil call was not good.

The IsPalindrome routine is written entirely in some compiled language (likely C), so it's hard to compete at the Maple language level. It would be foolish to compare an illustrative Library level implementation with a dedicated StringTools routine (they are usually very, very good). I wasn't suggesting that my routine was super efficient. I was only illustrating the point about whether the top and bottom halfs get compared once or twice.

> kernelopts(printbytes=false):
>
> F := proc(n)
> local a, m, r, t;
>  a := length(n);
>  if type(a,odd) then
>    m := (a-1)/2;
>    t := irem(n,10^(m+1));
>    irem(n,10^m,'r');
>  else # a is even
>    m := a/2;
>    t := irem(n,10^m,'r');
>  end if;
>  evalb(parse(StringTools:-Reverse(convert(r,string))) = t);
> end proc:
>
> low := 1: hi := 10000:
>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  StringTools:-IsPalindrome(""||n);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.076

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  F(N);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.520

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  StringTools:-IsPalindrome(""||n);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.060

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  F(N);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.604

I'd be surprised if IsPalindrome did not also check each half against the other only once, like F does. Of course, F is also taking a hit (time, memory) due to the parsing back from string to number. The string reversed inside F will be collectible garbage, while StringTools may do its own external memory management without needing to call Maple's global `gc`.

It may be faster to work with repeated irem calls, and not do any string conversion at all. Can Maple's Compile routine be used with irem? But it's tricky since Maple's own quirks can affect the efficiency of the algorithm implementations. So, general advice such as, "don't walk the number more than once" has to be offset against the degree to which several mapping tasks can be melded together.

This might also be a fun problem on which to use the Threads package (once that package's own efficieny concerns are ironed out).

Another thing to consider is that there might be quite different best algorithms, depending on whether the goal is to detect non-palindromes, to confirm suspected palindromes, or to sweep over many mixed inputs. The nature of the goal can affect how, say, a fast fail-detection gets built into it.

Yes, thanks. I realized too late that that ceil call was not good.

The IsPalindrome routine is written entirely in some compiled language (likely C), so it's hard to compete at the Maple language level. It would be foolish to compare an illustrative Library level implementation with a dedicated StringTools routine (they are usually very, very good). I wasn't suggesting that my routine was super efficient. I was only illustrating the point about whether the top and bottom halfs get compared once or twice.

> kernelopts(printbytes=false):
>
> F := proc(n)
> local a, m, r, t;
>  a := length(n);
>  if type(a,odd) then
>    m := (a-1)/2;
>    t := irem(n,10^(m+1));
>    irem(n,10^m,'r');
>  else # a is even
>    m := a/2;
>    t := irem(n,10^m,'r');
>  end if;
>  evalb(parse(StringTools:-Reverse(convert(r,string))) = t);
> end proc:
>
> low := 1: hi := 10000:
>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  StringTools:-IsPalindrome(""||n);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.076

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  F(N);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.520

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  StringTools:-IsPalindrome(""||n);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.060

>
> tot:=0:
> for N from low to hi do
>  gc():
>  st:=time():
>  F(N);
>  tot := tot+time()-st;
> od:
> tot;
                                     0.604

I'd be surprised if IsPalindrome did not also check each half against the other only once, like F does. Of course, F is also taking a hit (time, memory) due to the parsing back from string to number. The string reversed inside F will be collectible garbage, while StringTools may do its own external memory management without needing to call Maple's global `gc`.

It may be faster to work with repeated irem calls, and not do any string conversion at all. Can Maple's Compile routine be used with irem? But it's tricky since Maple's own quirks can affect the efficiency of the algorithm implementations. So, general advice such as, "don't walk the number more than once" has to be offset against the degree to which several mapping tasks can be melded together.

This might also be a fun problem on which to use the Threads package (once that package's own efficieny concerns are ironed out).

Another thing to consider is that there might be quite different best algorithms, depending on whether the goal is to detect non-palindromes, to confirm suspected palindromes, or to sweep over many mixed inputs. The nature of the goal can affect how, say, a fast fail-detection gets built into it.

The Standard GUI of Maple first appeared in Maple 9, released in June 2003. It had serious performance problems then and, four major releases and five years later, it is still underperforming.

 

The Standard GUI of Maple first appeared in Maple 9, released in June 2003. It had serious performance problems then and, four major releases and five years later, it is still underperforming.

 

Even though Robert I. and A.Jakubi showed two alternative ways to get it, I found this one quirkily interesting.

expr:=Ei(1,1/2*Pi*(1+2*k)):
eval(subs(Int=int,convert(convert(Ei(1,x),Int),Sum)));

For this example the frontend call is not necessary, is it?

> polinom:= (a*x^2+b*x*sin(y)+c*sin(y))^2+(a*sin(x)^2+b*x)^3:
> t := collect(polinom, [x, sin(y)], recursive):
> coeff(frontend(coeff, [t, sin(y), 2]), x, 1);
                                     2 c b
> coeff(coeff(t, sin(y), 2) , x, 1);
                                     2 c b

Perhaps it's not an interesting question, but can it be done with a single (unnested) coeff call along with frontend?

For this example the frontend call is not necessary, is it?

> polinom:= (a*x^2+b*x*sin(y)+c*sin(y))^2+(a*sin(x)^2+b*x)^3:
> t := collect(polinom, [x, sin(y)], recursive):
> coeff(frontend(coeff, [t, sin(y), 2]), x, 1);
                                     2 c b
> coeff(coeff(t, sin(y), 2) , x, 1);
                                     2 c b

Perhaps it's not an interesting question, but can it be done with a single (unnested) coeff call along with frontend?

Did you have any evidence that vandalism against your wiki was coming from the blocked maplesoft address?

Did you have any evidence that vandalism against your wiki was coming from the blocked maplesoft address?

I guess we differ in opinion about what is an excerpt, and what is more than that. Reproducing seven of ten (or so) "paragraphs" is more than an excerpt where the purpose seems to be to support a point, I think.

You do give the citation, which is nice. Indicating [deleted] or some such, to indicate the missing bits, might be nicer still.

I guess we differ in opinion about what is an excerpt, and what is more than that. Reproducing seven of ten (or so) "paragraphs" is more than an excerpt where the purpose seems to be to support a point, I think.

You do give the citation, which is nice. Indicating [deleted] or some such, to indicate the missing bits, might be nicer still.

censorship does necessarily mean editing or removal. Blocking an entire site or IP range (in this case, Maplesoft's), even if only temporarily, means censorship to me.

censorship does necessarily mean editing or removal. Blocking an entire site or IP range (in this case, Maplesoft's), even if only temporarily, means censorship to me.

First 70 71 72 73 74 75 76 Last Page 72 of 81