acer

32343 Reputation

29 Badges

19 years, 327 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Can you provide an example of f,g,h for which this occurs?

What is the OSX version?

Does it happen if libname is not augemted by the user, and if no initialization file is used?

Are there extra packages (eg. Gym) loaded of in libname?

@tomleslie Your latter workaround can also be adapted for plot3d with style=point, which allows for multiple, differing symbols and symbolsizes. Eg,

restart;
with(geom3d):
point(A, [1, 2, 3]):
point(B, [-2, 3, -1]):
point(C, [0,-3, 1]):
plot3d( [ coordinates(A),
          coordinates(B), coordinates(C)
        ], style=point,
           color=[red, blue, green],
           symbolsize=[34,24,30],
           symbol=[soliddiamond,solidsphere,asterisk],
           axes=none
       );

@greatpet That is the same issue as in my example: a module export declaration following an assignment statement.

And your workaround is the same approach as in one (of the pair) that I gave.

@Oktopus If one of the alternatives that I suggested does not work for you then perhaps it's because you are using an older version. If that's so then you ought to provide us with the details.

Even better would be if you uploaded and attached an actual worksheet that showed exactly what you have done.

If the desired tickmarks are to be spaced evenly then a terser solution (in Maple 2020.1 at least), is something like:

   plot(x, x = 0 .. Pi/2, xtickmarks=spacing(Pi/10));

I've changed your Post to a Question.

(This is the second time I've done that for your queries. Please submit Questions rather than Posts, for queries, thank you.)

@paulor Look at the Praw plot, which consists of all the roots of H(k,i) for each horizontal "k" value, ie. vertically appear the various "i" values of the roots.

The plottools:-transform command returns a procedure which may then be applied to a plot in order to transform it.

My plot tranformation applies your formula to all the (k,i) points, ie. roots. In my Answer, the parameter names x and y appearing in the construction of the plot-transforming procedure transf are arbitrary dummy names that I happened to pick. But perhaps it might be a little more clear to you if I had constructed it instead with these procedural parameter names,

transf := plottools:-transform((k, i) -> [k, ln((w(k) - i)*(A*alpha)^beta*(p(i)*i)^(alpha*beta))]):

For every point (k,i) on the curves in a plot, that transformer transf obtains the new horizontal component as simply k itself, and obtains the new vertical component by using the k and i values in your formula.

By restricting the vertical range of the implicitplot one can restrict the range of the roots found, which happens to also allow you to "separate" them for this example. I did that in my followup Comment.

Let us know if that doesn't make it clear.

The same very fast approach is easily adapted to get, say, only a few of the portions plotted separately. Eg,

str := time[real]();
P[1] := plots:-implicitplot(H(k, i), k = 1 .. 2, i = 6 .. 7, color = red);
P[2] := plots:-implicitplot(H(k, i), k = 1 .. 2, i = 7 .. 15, color = blue);

(time[real]() - str)*'seconds';

                 0.008 seconds

plots:-display(seq(transf(P[i]), i = 1 .. 2));

(For comparison, using vv's rootfinding technique took my machine 532 seconds to produce the separate plots of just the portions n=2..4, whereas the above implicitplot approach takes only a fraction of a second.

For fun, here's another coarse rootfinding jab at it, taking about 70 seconds. I used default adaptive plotting, so the memoization is not a big help. With some twiddles it could be sped up, but likely not nearly as fast as the implicit plot, so I didn't put in the effort. Worksheet_1_implicit_ac.mw)

@lcz Here's the %P format that I meant, for printf. I believe it was added in Maple 2019.

If you use fprintf then you could have it write out directly to file.

restart;
kernelopts(version);
   Maple 2021.1, X86 64 LINUX, May 19 2021, Build ID 1539851

printf("%P", eval(GraphTheory:-PlaneDual));
proc(G::{GRAPHLN, listlist})
    local F, E, i, f, k, j, n, e, S;
    if type(G, GRAPHLN) and not IsPlanar(G, 'F') then
        error "1st argument must be a planar graph or a list of faces o\
            f a planar graph.";
    elif type(G, 'listlist') then
        F := G;
    end if;
    n := nops(F);
    if n < 2 then
        return Graph(n);
    end if;
    E := table();
    for i to n do
        f := F[i];
        k := nops(f);
        for j to k - 1 do
            e := {f[j + 1], f[j]};
            if assigned(E[e]) then
                E[e] := E[e] union {i};
            else
                E[e] := {i};
            end if;
        end do;
        e := {f[1], f[k]};
        if assigned(E[e]) then
            E[e] := E[e] union {i};
        else
            E[e] := {i};
        end if;
    end do;
    S := {entries(E, 'nolist')};
    if map(nops, S) <> {2} then
        error "list of faces is inconsistent.";
    end if;
    Graph(nops(F), S);
end proc

As for showstat, there are situations in which revealing the line numbers is desirable, eg. using stopat.

@The function One of your images has the correct syntax. One does not.

It looks like the book's correct syntax was incorrectly transcribed.

You claimed that your input was the same. The two images shown have different inputs.

I can't tell whether the book's own bundled example .mw files don't match its actual text (their mistake),  or whether you incorrectly transcribed some example.

@Detlef Hoyer What I stated is true. I wrote that a number applied to an argument evaluates to that number.

In 2D Input the parser interpets your last example as multiplication. In 1D plaintext input it gets interpreted as function application.

My statement (to which you have objected) was not about what is typed or entered. My statement was about the parsed meaning. I made a statement about a number applied to an argument, not about a number positioned next to an opening bracket. You have mistakenly conflated the two, in your claim that what I wrote was not true.

What I wrote is also the central part of what went awry in your original Question's example, where adjacent bracketing was parsed as function application.

@GunnerMunk Your last comment's expectation is mistaken. You have the order of assignment back-to-front.

If you assign A:=3*a only after some assignment to `a`` then reassigning to `a` will not (by itself) update A.

If you assign A:=3*a prior to any assingment to `a` the you can get A updated automatically upon each new, subsequent assignment to `a`.

You've confused assigning three times "the current value of `a`" with assigning three times "a reference to `a`".

This behaviour is not directly related to this Question's original topic of re-execution flow of embedded context-menu actions on 2D Input.

@tomleslie That is a neat use of the nested seq for the indexing on the LHS of the prArr assignment statement, instead of a (uncompiled) nested loop. I suppose the inner seq can't be under a conditional because the entries aren't yet updated.

note: the only part of procedure Eratosthenes2 that was due to me was the single line,
   seq(`if`(L[n]=true,n,NULL), n=2..N);
as a replacement for the iterated list augmentation, because that was one inefficiency. The rest of that algorithm and choice of coding was due to the OP. I did revise the algorithm and do later modifications as procedures with other names, though.

@Ziaahmed812 

Last for me, fun as it was. This skips, dealing with the odd numbers only in the first stage. I didn't bother to reduce the Array size.

On my machine this does the N=2^20 case in 0.167 seconds, compared to the original which took 35.8 seconds.

restart;
Eratosthenes4 := module() local cstage1, stage1, ModuleApply;
  ModuleApply := proc(N::posint)
    local L, n, k;
    L := Array(1 .. N, 1, datatype=integer[4]);
    cstage1(N, L);
    2,seq(`if`(L[n]=1,n,NULL), n=3..N, 2);
  end proc;
  stage1 := proc(N, L::Array(datatype=integer[4]));
    local n, k;
    for n from 3 to trunc(sqrt(N)) by 2 do 
      if L[n] = 1 then 
        for k from n^2 to N by 2*n do 
          L[k] := 0;
        end do;
      end if; 
    end do;
    NULL; 
  end proc:
  cstage1 := Compiler:-Compile(stage1);
end module:

CodeTools:-Usage(Eratosthenes4(2^20)):
memory used=21.25MiB, alloc change=8.00MiB,
cpu time=167.00ms, real time=167.00ms, gc time=0ns

nops([%]);

                 82025

If you'd be willing to accept the results in an Array instead of a sequence (or list) then the second stage might be sped up too.

For fun,

restart;
Eratosthenes3 := module() local cstage1, stage1, ModuleApply;
  ModuleApply := proc(N::posint)
    local L, n, k;
    L := Array(1 .. N, 1, datatype=integer[4]);
    cstage1(N, L);
    seq(`if`(L[n]=1,n,NULL), n=2..N);
  end proc;
  stage1 := proc(N, L::Array(datatype=integer[4]));
    local n, k;
    for n from 2 to trunc(sqrt(N)) do 
      if L[n] = 1 then 
        for k from n^2 to N by n do 
          L[k] := 0;
        end do;
      end if; 
    end do;
    NULL; 
  end proc:
  cstage1 := Compiler:-Compile(stage1);
end module:

CodeTools:-Usage(Eratosthenes3(2^20)):
memory used=36.63MiB, alloc change=12.00MiB,
cpu time=319.00ms, real time=320.00ms, gc time=0ns

nops([%]);

                 82025

I have not implemented the refinement to work with only the odd numbers (and adjusting the increment accordinly).

The above is over 100 times faster than the (corrected) original posting, on my machine, for N=2^20. And it's slightly over twice as fast as the sieve routine that Tom's supplied in his Answer, on my machine, for N=2^20. But it is limited by the hardware integer size of N=2^32=4294967296.

First 125 126 127 128 129 130 131 Last Page 127 of 592