acer

33014 Reputation

29 Badges

20 years, 168 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Every instance of a() will produce a new call to the random generating proc that you assigned to `a`. So the instance of a() in the while-condition is not the same as the instance in the print. The generator gets called separately for those.

I've seen similar questions asked about this sort of thing:

> a:=rand(1..10):

> evalb(a()=a());
                                     false
 
> is(a()=a());
                                     false
 
> a()=a();
                                     4 = 6
The explanation is pretty much the same, as hopefully the last line shows.

acer

It's not really strange at all. `while` is part of the to-from-while-do-for statement group, and so ?while gets to that "Repetition Statement" help-page.

acer

It's not really strange at all. `while` is part of the to-from-while-do-for statement group, and so ?while gets to that "Repetition Statement" help-page.

acer

The search facility of MaplePrimes is broken. A simple query for the word rocket does not currently find this.

I usually do like Patrick suggests, and use google.

acer

You could assign them to something (as table entries, or whatever), then wait until the loop is finished, and then use the seq command.

Or if you wanted the results displayed as they get computed and in a single row then you could use printf (and omit the \n for newline after each entry, then printf a single newline when the loop finishes.)

acer

You could assign them to something (as table entries, or whatever), then wait until the loop is finished, and then use the seq command.

Or if you wanted the results displayed as they get computed and in a single row then you could use printf (and omit the \n for newline after each entry, then printf a single newline when the loop finishes.)

acer

It wasn't clear whether Alex meant that the floats would be of the form xxx.000... or not.

But if he did in fact mean that they are merely the floating-point representation of some integers then conversion of very many of them might be faster using the kernel builtin routine trunc than using round (or floor).

acer

It wasn't clear whether Alex meant that the floats would be of the form xxx.000... or not.

But if he did in fact mean that they are merely the floating-point representation of some integers then conversion of very many of them might be faster using the kernel builtin routine trunc than using round (or floor).

acer

It seems uninstructive to demand use of do-loops if the data is already in list or listlist form. The following may not be optimally efficient (versus using an Array initializer), but it might be more instructive.

> MyA := Array(1 .. 5):
> MyA[1]:=1:
> for i from 2 to 5 do
>   MyA[i]:=5*(i-1);
> end do:
> MyA;
                              [1, 5, 10, 15, 20]

> MyA := Array(1 .. 4, 1..4):
> for i from 1 to 4 do
>   for j from 1 to 4 do
>     MyA[i,j]:=i*3^(j-1);
>   end do:
> end do:
> MyA;
                            [1     3     9     27]
                            [                    ]
                            [2     6    18     54]
                            [                    ]
                            [3     9    27     81]
                            [                    ]
                            [4    12    36    108]

acer

It seems uninstructive to demand use of do-loops if the data is already in list or listlist form. The following may not be optimally efficient (versus using an Array initializer), but it might be more instructive.

> MyA := Array(1 .. 5):
> MyA[1]:=1:
> for i from 2 to 5 do
>   MyA[i]:=5*(i-1);
> end do:
> MyA;
                              [1, 5, 10, 15, 20]

> MyA := Array(1 .. 4, 1..4):
> for i from 1 to 4 do
>   for j from 1 to 4 do
>     MyA[i,j]:=i*3^(j-1);
>   end do:
> end do:
> MyA;
                            [1     3     9     27]
                            [                    ]
                            [2     6    18     54]
                            [                    ]
                            [3     9    27     81]
                            [                    ]
                            [4    12    36    108]

acer

To be able to save the worksheet with some stored results (rtables, plots, etc) likely entails the underlying kernel being in a safe state. And if the kernel had "gone away" while doing gc while swapped out or what have you, then that might not be possible as an immediate action.

A middle ground might be to forcibly and immediately kill the underlying kernel and to be prompted to save any worksheets (open and using that kernel instance) without their output and stored rtable or plot or other embedded data. What might be novel might be for this to be offered without having the entire application quit.

I can imagine that it gets tricky if the GUI is waiting on Typesetting before completing a partial redraw of 2D Math output. If the kernel is not safely finished doing gc or other stuff, while inside Typesetting...  And there could well be other tricky scenarios.

acer

When Maple's too tied up and busy to abort the current computation, I will usually close the whole application (corner button on Maple's main window). This usually results in being queried about saving the open worksheet. That's fine.

But, as you put it, why cannot Maple's GUI be told to forcibly kill the kernel and close that worksheet, without having to quit the entire application.

A stable GUI, that allows forced closure of worksheets individually (even when running unresponsive kernel instances), would be useful. That would allow us to keep the Standard GUI up longer. That would make Standard's launch time less important, and so alleviate a difference w.r.t Classic.

acer

Upon a moment's reflection, it is not at all a good to suggest Matrix(Ans^%T,shape=antisymmetric) as that is the very sort of inefficiency we're trying to avoid. It creates two whole new large Matrices. Sorry.

Instead, the line in the autocompiled proc,

     A[i,j]:=Xmean/Xstdev;

could be followed immediately by,

     A[j,i] := -A[i,j];

acer

Upon a moment's reflection, it is not at all a good to suggest Matrix(Ans^%T,shape=antisymmetric) as that is the very sort of inefficiency we're trying to avoid. It creates two whole new large Matrices. Sorry.

Instead, the line in the autocompiled proc,

     A[i,j]:=Xmean/Xstdev;

could be followed immediately by,

     A[j,i] := -A[i,j];

acer

Inside the Sharpe procedure, there is a double loop over i and j. As I wrote it, the inner such loop goes from 1 to i. If you instead made j go from 1 to NSTOCK then it would compute all NSTOCK^2 entries.

But the results are antisymmetric. So there is no need to make twice the computational effort. If you want the Result Matrix to actually be contain all the full antisymmetric results then you can keep the `for j from 1 to i` (or make it `to i-1`) and instead have outerproc return an antisymmetric copy of Ans. That is to say, the last line in outerproc could be,

   Matrix(Ans^%T,shape=antisymmetric);

Indenting my code does not make it faster. I hope that it makes it more legible. Ideally, it would also have more comments.

yes, it's a big deal that there are many ways to implement an algorithm in Maple, some of which might be very fast and some of which might be very slow, with no 100% crystal clear characterization of what causes that.

If you want just the top 20 items, write a for-loop to walk the Results 20 times, storing the next greatest with each sweep. That can be much faster than sorting the whole thing.

acer

First 479 480 481 482 483 484 485 Last Page 481 of 605