tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are replies submitted by tomleslie

As well as Carl's comment, I think you should check your parentheses. You start with

Find the numerical (decimal) value of

f (ln (5π) + 2e5 + √ 4 + sin (4)

which should probably be

ln(5*Pi)+2*exp(5)+sqrt(4)+sin(4)

rather than

ln(5*Pi)+2*exp(5)+sqrt(4+sin(4))

Agree with everything Acer says - if you are planning on changing entries - don't use lists. It's OK if they are "small", but if you get into this habit then (one day) you will either write some horrendous inefficient code (say changing the entries in a small list a gazillion tmess), or run into the error message you reported above.

Note that this applies to changing entries - not initialisation, so when I try your original problem, (with the typo corrected)

L :=[seq(0, n=1..N)]:

Then this works on Maple 2015.2 (win7 64-bit, 16GB) for N=10000, 100000, 1000000 -provided that the list 'L' does not pre-exist this command. If the list 'L' preexists this command then you are going to run into the error message for the reason previously mentioned

How to actually structure your problem??

Inefficient way:

Create a single 1D array and then create the "sub"-1D-arrays using the ArrayTools:-Copy() command: toy example

A :=Array([seq(n, n=1..100)]):
B:=Array(1..50):
ArrayTools:-Copy(A[51..100], B);

This is inefficient because you end up with two copies of everything

Efficient way

Create the multiple (smaller) arrays as a first step. Many ways to do this: toy example

restart;
nsub:=50:
seq( assign( A||j, Array( 1..nsub, [seq(i, i=j*nsub+1..nsub*(j+1))])), j=0..9);

will create 10 Arrays called 'A0'..'A9'. You can refer to these sequentially (say in a for loop) by using the concatenation operator '||', so in your code, you would have something like

for ProcNumber from 0 to Grid:-NumProc() do

   StartFrom := ...      # depends on N, ProcNumber and NumProc()
   Goto         := ...      # depends on N, ProcNumber and NumProc()

   Grid:-Run(ProcNumber, F( A||ProcNumber ):

end do:

 

 

 

If I use the code I posted earlier on this "example" list then it perfoms the required operation in ~0.1secs. I notice that you claimed earlier that you thought your list might contain 250000 elements. The example you provide only has 21809 (see appended code). I suspect that with even bigger lists, one would become even more dominated by the time to read the lists

Just how much faster are you hoping to get?

I renamed your example1.mw file to ldata.mpl using my standard editor - since your data isn't (technically) in .mw format.

TImings for the following code is actually dominated by the time to read the data (~1.6secs on my machine), but the time taken to perform your required operation varies between 90mS and 180mS. The former is obtained by my code and the latter is obtained with Carl's original solution.

Now which part of this operation exactly are you trying to speed up and why - I mean can you read/generate this data in comparable time

Code for this comparison/test follows:

#
# Start a timer for the read operation
#
   t1:=time():
#
# Read the data file - obviously OP will have to adjust
# file name and path. But the file ldata.mpl is identical
# to the OP's example.mw: just renamed and stored somewhere
# convenient on my machine
#
   read("D:/Users/TomLeslie/MyMaple/ldata.mpl"):
#
# Return the time just to read the file
#
   readTime:=time()-t1;
#
# Idle curiosity - just how many elements are in this list??
#
   NumberOfElementsInList:=numelems(gb1);
#
# Define the procedure which actually does all the work
# (Copied from my earlier post)
#
   myProc2:= proc( l )
                           local j,
                           A:=table([seq((j)=NULL, j in convert(l, set))]):
                           for j from 1 to numelems(l) do
                               A[l[j]]:=A[l[j]],j;
                           od;
                           entries(A);
                   end proc:
#
# Time how long it takes to solve the OP's original problem -
# ie return the indices of repeated elements
#
   r1:=CodeTools:-Usage(myProc2(gb1)):
#
# Compare with Carl's original solution for this problem
#
   r2:= CodeTools:-Usage
          (
            { entries(((x-> x[2])~)~(ListTools:-Classify(x-> x[1], `[]`~(gb1, [$1..nops(gb1)]))), nolist)}
         ):
#
# Verify that my results and Carl's are indeed the same
# By default Carl has a set of sets and I have a list of
# lists so a little manipulation is necessary - but the
# results would seem to be identical
#
   evalb(map(convert, {r1}, set)=r2);

 

Leaving aside my original quick/dirty/inefficient, but simple/understandable solution, a summary of results posted so far (with one addition from me) would be the following. Have to confess I can't get very excited about the timing discrepancies

   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
#
# Carl's original
#
   CodeTools:-Usage
   (
     {entries(((x-> x[2])~)~(ListTools:-Classify(x-> x[1], `[]`~(L, [$1..nops(L)]))), nolist)}
   ):
   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
#
# VV's original
#
  ff:=proc(a)
           local aa,sa:=convert(a,set),T,u;
           aa:=zip(`[]`,a,[$1..nops(a)]);
           for u in sa do
               T[u]:=NULL
           od;
           for u in aa do
               T[u[1]]:=T[u[1]],u[2]
           od;
           [seq([T[u]],u=sa)];
   end:
   CodeTools:-Usage(ff(L)):
#
# Others posted by VV
#
   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:

   f4:= proc(a)
                  local T, u;
                  for  u in `[]`~(a, [$1..nops(a)]) do
                        T[u[1]][u[2]]:= ()  #use NULL instead of () in math 2D
                  od;
                 {indices}~({entries(T, nolist)}, nolist)
           end proc:
   CodeTools:-Usage(f4(L)):

   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
   fff:=proc(a)
                local aa,T,u;
                aa:=zip(`[]`,a,[$1..nops(a)]);
                for u in aa do
                    T[u[1]][u[2]]:=NULL
                od;
                [indices]~([entries(T, nolist)], nolist)
        end:
   CodeTools:-Usage(fff(L)):
#
# Carl's "improvements" to VV solutions
#
   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
   f5:= proc(L::list)
                  local T, k;
                  for  k to nops(L) do
                        T[L[k]][k]:= ()
                  od;
                  [indices]~([entries(T, nolist)], nolist)
           end proc:
   CodeTools:-Usage(f5(L)):
#
# My first attempt at an "efficient" solution (previously posted)
#
   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
   myProc:= proc( l )
                         local j,
                         p:=ListTools:-Enumerate(l),
                         A:=table([seq((j)=NULL, j in convert(l, set))]):
                         for j in p do
                             A[j[2]]:=A[j[2]],j[1];
                         od;
                         entries(A);
                 end proc:
   CodeTools:-Usage(myProc(L)):
#
# My second attempt  - ie improving the above, although I think
# it may be "morphing" into one of VV's solutions
#
   restart:
   R:= rand(1..999):
   L:= ['R()' $ 99999]:
   myProc2:= proc( l )
                           local j,
                                  A:=table([seq((j)=NULL, j in convert(l, set))]):
                           for j from 1 to numelems(l) do
                                A[l[j]]:=A[l[j]],j;
                           od;
                           entries(A);
                   end proc:
    CodeTools:-Usage(myProc2(L)):
#
# Answers
#
memory used=34.53MiB, alloc change=47.02MiB, cpu time=343.00ms, real time=345.00ms, gc time=46.80ms
memory used=57.42MiB, alloc change=111.78MiB, cpu time=327.00ms, real time=301.00ms, gc time=78.00ms
memory used=25.97MiB, alloc change=47.02MiB, cpu time=234.00ms, real time=232.00ms, gc time=62.40ms
memory used=24.44MiB, alloc change=47.02MiB, cpu time=203.00ms, real time=214.00ms, gc time=31.20ms
memory used=15.26MiB, alloc change=46.01MiB, cpu time=109.00ms, real time=110.00ms, gc time=0ns
memory used=52.85MiB, alloc change=110.01MiB, cpu time=312.00ms, real time=270.00ms, gc time=109.20ms
memory used=48.26MiB, alloc change=98.00MiB, cpu time=188.00ms, real time=164.00ms, gc time=46.80ms

I freely admit my original was 'quick and dirty', where 'quick' refers to how long it took to write, rather than execution speed/efficiency.

Since this seem to have turned into a bit of programming competition, my entry is submitted below

restart;
myProc:=proc( l )
                        local j,
                                p:=ListTools:-Enumerate(l),
                                A:=table([seq((j)=NULL, j in convert(l, set))]):
                        for j in p do
                             A[j[2]]:=A[j[2]], j[1];
                        od;
                        entries(A);
               end proc:

R:= rand(1..999):
L:= ['R()' $ 9999]:
r1:= CodeTools:-Usage(myProc(L)):
r2:= CodeTools:-Usage( {entries(((x-> x[2])~)~(ListTools:-Classify(x-> x[1], `[]`~(L, [$1..nops(L)]))), nolist)}):

evalb(map(convert, {r1}, set)=r2);

memory used=1.97MiB, alloc change=0 bytes, cpu time=16.00ms, real time=19.00ms, gc time=0ns
memory used=5.59MiB, alloc change=34.00MiB, cpu time=47.00ms, real time=38.00ms, gc time=15.60ms
                              true

You could also probably do something with the ListTools:-FindRepetitions() command, although everything I tried came out a little more compicated than my previous post

@Carl Love 

Never claimed any of these commands were threadsafe - I merely observed that if one changes solve() to fsolve(),  then the resultant time-saving means that a threaded calculation seems pretty pointless, so I didn't investigate further

For the OP's benefit

?Threadsafe

will load the help page which lists all threadsafe functions:

neither solve() nor fsolve() is included (as of Maple 2016.1) :-(

Logically there are three possibilities

  1. Maple worksheet files are corrupt, but Maple software installation OK
  2. Maple worksheet files are OK, but Maple software installation is corrupt
  3. Both worksheet files and installation are corrupt

Easiest path is probably that suggested by vv. Upload to here (using the big green up-arrow in the aove toolbar) a couple of the files which you can't open, and someone here will check them.

Or (assuming you have your Maple installation file(s), maybe in a 'Downloads' directory) - just do a clean install: should only take aboout 10mins.

It migth also be helpful if you posted the Maple version you have (and your OS)

@Preben Alsholm 

Don't have a problem with this suggestion - my only thought was that plotting the three curves

[ t, B[1](t) ],

[ t, B[2](t)] and

[ t, C(T) ]

was useful in itself and was actually helpful in visualising the meaning of plotting the triple[ B[1](t), B[2](t), C(t) ], as a function of t

I freely admit that it was only after I plotted the first of these, that the second of these made much sense. I guess I'm just bad at 3D-visualization

There is a lot of stuff in this code that I don't understand, so my response is pretty much guesswork. However see if the attached does anything for you

trickSums.mw

The code you supply does not generate an error message (win7, 64-bit MAple 2016.1)

Specify OS, Maple version where your code does generate an error message

According the help page  (always a helpful read), the syntax for differentiating a function, say g(), wrt to a variable, say X, and doing n times, would be

 diff( g(X), X$n)

Now you can, if you want, write the above in the equivalent syntax

diff( g(X), `$`(X, n)),

but why bother, unless you like the extra typing?

Somewhat to my surprise, Maple does not even mind if you make the second argument a single-element list as in

diff( g(X), [`$`(X, n)]),

although why you would want/need to completely escapes me.

So now we get to the basic question, why might a differential such as

diff(1/(ln(X)-Psi(1-f(X))-Psi(f(X))), [`$`(X, n-k[1]-k[2])])

fail

Since OP provides no information on 'n', 'k[1]', 'k[2]', 'f(X)', then one is reduced to mere speculation. So some entriely speculative thoughts

  1. The argument n-k[1]-k[2] does not evaluate to a positive integer. NOw I have run a very light check on this and Maple does something 'plausible' in all the case I have tried. Basically if the argument is <1 (including real and/or negative numbers), then Maple does nothing, other than return the first argument from the diff() command. For positive, non-integer, second arguments for the diff() command Maple appears to  apply a 'floor' function to the second argument and return the appropriate differential
  2. Since the second argument to the diff() function *seems* not to cause problems on my limited tests, then maybe attention should be focussed on the first argument. The in-built digamma function, Psi(x), is differentiable to any order, so I'd have to guess that the problem arises with the OP's unspecified function 'f(X)'
  3. Perhaps if the OP provided definitions of 'f(X)', 'n', 'k[1]', 'k[2]' etc, his/her problems might be easier to debug. However based on this (and previous) post(s) OP is somewhat more interested in throwing toys from pram rather than obtaining solutions

 

 

@vv 

Would that maxima bear any relation to macsyma - so beloved of geriatrics like me?

I may have interpreted the intent of your second summation incorrectly - but no way can my original code produce 'if' in the output.

Attached is a worksheet with my original code, plus another interpretation of you second sum statement. Generating such sums is trivial - it is your responsibility to specify exactly and precisely what sums you want

trickSums.mw

 

So far as I am aware there is no solution for the general quintic - I believe this is known as the Abel-Ruffini Theorem/Proposition/Assertion whatever

Some, but not all, quintics can be generally solved: I think when they can be factorised into, say, a cubic multiplied by a quadratic, or even linear multiplied by a quadratic.

Similarly, polynomials above quintic can only really be solved (I think) if they can be written in terms on products of linear, cubic and quartic terms. So solving your final polynomial of degree 29 - I mean c'mon

By some miraculous coincidence, Maple will solve your quartic and quintic (with no Rootof) with a slight code modification, as in

with(CurveFitting):
f := PolynomialInterpolation([[0, x0],[1, x1],[2, x2],[3, x3],[4, x4]], x):
f2 := solve(f=y,x, explicit=true):
area1 := int(f, x=0..1);
with(student):
area2 := trapezoid(f2[1], x = 0..1);

with(CurveFitting):
f := PolynomialInterpolation([[0, x0],[1, x1],[2, x2],[3, x3]], x);
f2 := solve(f=y,x, explicit=true);
area1 := int(f, x=0..1);
with(student):
area2 := trapezoid(f2[1], x = 0..1);

BUt your final example - a 29-th order polynomial - I mean, get real!

Read carefully the wikipedia page at https://en.wikipedia.org/wiki/Quintic_function

First 141 142 143 144 145 146 147 Last Page 143 of 207