Carl Love

Carl Love

28015 Reputation

25 Badges

12 years, 292 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

Your Question has been received! Please don't repost it to new threads. If you want to add additional information (you're welcome to do so), put it in this thread.

@Suryakanth The code in your Reply seems extremely familiar to me. I'm certain that this exact same Question or one extremely close to it has been asked, and Answered, here on MaplePrimes within the last year or so. Perhaps both you and the other person who asked it obtained that worksheet from the same source. Anyway, perhaps someone who is better at searching MaplePrimes than I am can find that other thread.

@imparter seems to be an index variable, especially since the code refers to m+1. Thus, the m:= 7.44, 7.88 from your 1st line doesn't make sense.

@imparter Your code assigns values in the 3D arrays (or tables) eq1, ..., eq4. But nothing sets any values in the 3D arrays (or tables) U, V, T, or C; not even any initial values.

@sursumCorda Here is your lexical-vs-dynamic example, which I've indented to improve readability:

:-CompSeq:= -1:
proc($) local CompSeq; 
    convert(
        [x = a + b, i = a*b, j = x + i, y = a + sin(x)], 
        'procedure', 
        'locals' = [i, j], 'globals' = [x, y], 'params' = [a, b]
     ) 
end proc();
Error, (in convert/list) too many levels of recursion

You've used CompSeq as a variable here in two different ways, as a global and as a local. There's nothing at all wrong with doing that; I just need to point out for the following discussion that Maple considers these as two completely separate variables that only coincidentally have names that are spelled the same. I think that most other languages would consider it the same way, regardless of whether they're purported to be lexically or dynamically scoped (since I'm only guessing about other languages, it'd be worth checking whether this is true).

I do not have a thorough knowledge of the precise formal definitions of lexically scoped language and dynamically scoped language. Do you agree with the definitions given by Ming-Ho Yee in the blog post that I linked earlier? (Read the whole post, because Yee expresses some skepticism about his definitions.) If no, what definitions are you using? According to Yee, both concepts are about how a single variable is viewed at various places in a program---in which places is it evaluated and in which is it viewed as a "free" variable. Since, your example has two separate variables named CompSeq, it can't be used to discriminate between the two types of scoping under the given definitions.

Now, to be fair, your "local CompSeq" has no affect at all on the outcome. So, we might as well remove it and reconsider the scoping question. The same error occurs. This time I can't raise the two-variable objection from the previous paragraph. Could the result be considered evidence of lexical scoping, dynamic scoping, or neither? I'm not sure. The keyword CompSeq is used in three different ways in `convert/procedure` and `convert/CompSeq`. In `convert/procedure`, it's used as a type name on line 1 and as a kind of conversion for the convert command on line 26. In `convert/CompSeq`, it's used as a function name on line 45. In this last usage, it's used without unevaluation quotes. I think that this is the source of the error, and, regardless, it should be considered a bug.

Consider the following variation of your code, which runs without error. I use local CompSeq, but this could be replaced by any symbol.

:-CompSeq:= -1:
proc($) local CompSeq:= :-CompSeq, P;
    :-CompSeq:= ':-CompSeq'; 
    P:= convert(
        [x = a + b, i = a*b, j = x + i, y = a + sin(x)], 
        'procedure', 
        'locals' = [i, j], 'globals' = [x, y], 'params' = [a, b]
    );
    :-CompSeq:= CompSeq;
    eval(P) 
end proc();
 proc (a, b) local i, j; global x, y; x := a+b; i := b*a; j := 
    x+i; y := a+sin(x) end proc

Is this now evidence of one of the scoping methods? I don't have an opinion on that yet.

@C_R You wrote

  • The fact that the rendering is as expected after a restart (of Maple or the whole system?) indicates that the system starts Maple in a correct way with all involved software and hardware components configured correctly. 

The required "restart" in this case is of the Maple GUI (user interface), which necessitates the closure of all open worksheets. Thus, a system "reboot" (restart of the operating system) works also but is more than is necessary.

To avoid confusion. readers should note that the usage of the word "restart" in this discussion has nothing to do with Maple's restart command.

@Ronan For any procedure keyword option X, passing alone is equivalent to passing X= true, even if true isn't a valid value for X.

@Jesús Guillera You're welcome. There are many notations commonly used for pochhammer and related functions. Maple's Typesetting package allows the display (only) of many MathML formulae that are beyond the usual Maple displays. Let me know if you'd like something different. 

@mmcdara Thank you. I didn't expect my technique to be the fastest possible, just brief and reasonably fast and intuitive.

I realize that your Maple version may not have the command convert(M, list, dimension= 1). If is a matrix, this makes a list of the rows, but the rows themselves are still rtables. I haven't tested, but I suspect that that is more efficient than convert(M, listlist) or its modern replacement convert(M, list, nested); and I suspect it'd be even more efficient if has order= C_order.

If you care to rerun your test, I think that my code using ArrayTools:-Alias in the Reply immediately above will work in Maple 2015.

@sursumCorda You wrote:

  • Maybe such functionalities can be built into the underlying core so that Maple can sort rows of the rtable in-place.

The following pretty much does that. It does create a "dope vector" (i.e., vector of pointers/addresses) with number-of-rows elements, but that's much less effort than copying the whole rtable. This also requires that the sub-rtables being sorted (the rows in this case) are each stored in contiguous memory locations, which is why I used order= C_order.

M:= rtable(<4, 1, 1 | 0, 5, 2 | 7, 8, 9>, order= C_order):  
(r,c):= op(1, M):
M[sort[inplace](
    rtable(1..r, i-> ArrayTools:-Alias(M, c*(i-1), [1..c])),
    key= (R-> [seq](R[[1,3,2]])), 
    output= permutation
)];

If doesn't have order= C_order, the above won't give an error message, but the results won't be meaningful.

There are no files attached to your Question. Please try attaching them again.

@Joe Riel It's frustrating that the expository section of help page ?object,create has 8 paragraphs devoted to "Inheritance", but the "Examples" section doesn't have a single example of it.

@sursumCorda The specific example that you show can be done by

M:= <4, 1, 1 | 0, 5, 2 | 7, 8, 9>:
<sort(convert(M, list, dimension= 1), key= (R-> [seq](R[[1,3,2]])))[]>;

Higher dimensions can also be accomodated.

@Mike Mc Dermott Okay, here's an example verifying real-time enhancement on both integer and hardware-float data:

nV:= 6:  V:= [x||(1..nV)]:
P0:= codegen:-makeproc(randpoly(V, dense, degree= nV), V):
P1:= codegen:-optimize(P0):
P2:= codegen:-optimize(P0, tryhard):
(lprint@codegen:-cost)~([P0, P1, P2]):
918*additions+4727*multiplications
221*storage+221*assignments+1827*multiplications+918*additions
108*storage+108*assignments+855*multiplications+917*additions

DataInt:= 
    'rtable(1..2^13, random(-9..9), datatype= integer[4], subtype= Vector[row])' 
    $ nV
:
for k from 0 to 2 do gc(); R[k]:= CodeTools:-Usage((P||k)~(DataInt)) od:
memory used=375.70MiB, alloc change=0 bytes, 
cpu time=1.95s, real time=1.96s, gc time=0ns

memory used=72.91MiB, alloc change=0 bytes, 
cpu time=844.00ms, real time=847.00ms, gc time=0ns

memory used=39.18MiB, alloc change=0 bytes, 
cpu time=469.00ms, real time=473.00ms, gc time=0ns

#Verify accuracy:
LinearAlgebra:-Norm~([R[0]-R[1], R[1]-R[2], R[0]-R[2]], infinity);
                           [0, 0, 0]
DataHF:=
    'rtable(1..2^13, frandom(-2..2), datatype= hfloat, subtype= Vector[row])' 
    $ nV
:
for k from 0 to 2 do gc(); R[k]:= CodeTools:-Usage((P||k)~(DataHF)) od:
memory used=404.77MiB, alloc change=0 bytes, 
cpu time=7.02s, real time=4.07s, gc time=3.53s

memory used=195.47MiB, alloc change=0 bytes, 
cpu time=1.38s, real time=1.38s, gc time=0ns

memory used=92.04MiB, alloc change=0 bytes,
cpu time=563.00ms, real time=558.00ms, gc time=0ns

#Verify accuracy:
(lprint@LinearAlgebra:-Norm)~([R[0]-R[1], R[1]-R[2], R[0]-R[2]], infinity):
.123691279441118240e-9
.436557456851005554e-10
.130967237055301666e-9

 

I was rushed when I wrote the Answer above. Here's a more-complete example:

Statistics:-ColumnGraph(
    [1,2,3,4], #column heights
    width= 2, distance= 1,
    axis[1]= [
        tickmarks= [
            [seq](k+1 = sprintf("%a - %a", k, k+2), k= 0..11, 3), 
            rotation= Pi/4
        ]
    ],
    axesfont= ["Arial", 18]
);

 

First 33 34 35 36 37 38 39 Last Page 35 of 708