PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 304 days

MaplePrimes Activity


These are replies submitted by PatrickT

@Preben Alsholm 

thanks a lot, that clarifies it all, many thanks.

I'm not sure what the purpose of "name" is in "X::name"

type/name says


An object is of type name if it is a symbol, or if it is of type indexed
and its root is of type name (that is, it is a recursive type).


If I remove the bit that says "::name" the proc still works.

Side remark, the call to select(has,indets(F(X),indexed),X); rules out non-indexed lists/Vectors/Matrices, right?

e.g. things like:

G2 := (x1,x2,x3) -> Vector([exp(x1)+x2,(x1-x2)^3]): G2(x1,x2,x3);
TaylorExpand(G2(x1,x2,x3),[x1,x2,x3],2);

These cases can be handled directly with mtaylor~() I believe, as you showed earlier. It would be easy to add an if statement inside the proc, as you did above, to deal with Vectors, Matrices, and lists all at once (should someone wish to do that). At any rate, for my current purpose, I have everything in Vector or Matrix form and don't use lists (rightly or wrongly), so I will use the proc exactly as you posted.

I consider the original question to be fully resolved. Here I am merely playing around with the stuff you showed me for the purpose of learning. Thanks again Preben.

I'm not sure what the purpose of "name" is in "X::name"

type/name says


An object is of type name if it is a symbol, or if it is of type indexed
and its root is of type name (that is, it is a recursive type).


If I remove the bit that says "::name" the proc still works.

Side remark, the call to select(has,indets(F(X),indexed),X); rules out non-indexed lists/Vectors/Matrices, right?

e.g. things like:

G2 := (x1,x2,x3) -> Vector([exp(x1)+x2,(x1-x2)^3]): G2(x1,x2,x3);
TaylorExpand(G2(x1,x2,x3),[x1,x2,x3],2);

These cases can be handled directly with mtaylor~() I believe, as you showed earlier. It would be easy to add an if statement inside the proc, as you did above, to deal with Vectors, Matrices, and lists all at once (should someone wish to do that). At any rate, for my current purpose, I have everything in Vector or Matrix form and don't use lists (rightly or wrongly), so I will use the proc exactly as you posted.

I consider the original question to be fully resolved. Here I am merely playing around with the stuff you showed me for the purpose of learning. Thanks again Preben.

@Preben Alsholm 

Well Preben, thank you very, very much. This is fantastically helpful.

Thanks to the following piece of reverse-engineering I've been able to understand your steps. Hopefully I can come up with something like that myself in the not too distant future!

Patrick.

the op()(op()) construction is a welcome addition to my slim arsenal of tricks.

subsop~(2=) construction: very nice, I'm only beginning to learn the tilde trick, and would never have thought of combining it with subsop in this way, nice.

op(0,F(X));
op(1,F(X));
op(0,F(X))(op(1,F(X)));
op(2,F(X));
op(3..-1,F(X));
subsop~(2=Xk,op(2,F(X)));
X1:=op(0,F(X))(op(1,F(X)),subsop~(2=[seq(X[k],k=1..5)],op(2,F(X))),op(3..-1,F(X)));

P.S. sadly your latest contribution does not have the "vote" button, it certainly gets all my votes.

@Preben Alsholm 

Well Preben, thank you very, very much. This is fantastically helpful.

Thanks to the following piece of reverse-engineering I've been able to understand your steps. Hopefully I can come up with something like that myself in the not too distant future!

Patrick.

the op()(op()) construction is a welcome addition to my slim arsenal of tricks.

subsop~(2=) construction: very nice, I'm only beginning to learn the tilde trick, and would never have thought of combining it with subsop in this way, nice.

op(0,F(X));
op(1,F(X));
op(0,F(X))(op(1,F(X)));
op(2,F(X));
op(3..-1,F(X));
subsop~(2=Xk,op(2,F(X)));
X1:=op(0,F(X))(op(1,F(X)),subsop~(2=[seq(X[k],k=1..5)],op(2,F(X))),op(3..-1,F(X)));

P.S. sadly your latest contribution does not have the "vote" button, it certainly gets all my votes.

Dear Dave,

This is the clearest and most didactic tutorial I've read!

I think your post (and additional remarks in the follow-up) should be promoted to the "tutorial" section, if there is one -- there was a talk a little while ago about creating a "databank" of didactic posts, a sort of complement to the Help files, your post belongs right there.

I have often found myself doing exactly the kind of inefficient garbage collection you describe. While I was aware of the problem, I had no idea how to begin addressing the problem. Now I've got a much better idea of what's at stake.

A small thing I have wondered about, whichever of these two is an appropriate gauge of "efficiency" (whatever that means)? kernelopts(bytesalloc) versus kernelopts(bytesused). Your code only computes bytesused. (P.S. the 4.5MB figure you refer to, is that the bytesalloc? Quote: "Maple only had to allocate about 4.5MB in total at any given moment")

A side remark, the syntax of  ArrayTools:-Copy(10000,V,3,1,C,0,1); is definitely something to be learned rather than guessed.

Thanks a lot,

Patrick.

@Preben Alsholm 

op(1,V) returns the dimension of a Column Vector V,

op(1,M)[1] returns the column-dimension of a Matrix M,

Same remark goes for LinearAlgebra:-Dimension(V) and LinearAlgebra:-Dimension(M)[1].

Is there a single command that would return the column-size of Vector and Matrix alike? to put it differently, code that would work whether one feeds in a column-Vector of size n or a Matrix of size n x 1.

Note: this question is not urgent at all, mere curiosity on my part. Thanks for your help so far.

@Preben Alsholm 

op(1,V) returns the dimension of a Column Vector V,

op(1,M)[1] returns the column-dimension of a Matrix M,

Same remark goes for LinearAlgebra:-Dimension(V) and LinearAlgebra:-Dimension(M)[1].

Is there a single command that would return the column-size of Vector and Matrix alike? to put it differently, code that would work whether one feeds in a column-Vector of size n or a Matrix of size n x 1.

Note: this question is not urgent at all, mere curiosity on my part. Thanks for your help so far.

@Preben Alsholm 

nice one Preben, that's exactly what I was looking for, thanks very much!

So, if I'm not mistaken, op(1,F(X)); essentially does what LinearAlgebra:-Dimension(F(X)); does. Any reason to prefer one over the other?

I don't know if this is what I want to look at, but if I compare performance, on the following:

st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
  TaylorExpand(F,X,2);
  TaylorExpand(G,X,4);
time()-st,kernelopts(bytesalloc)-ba,kernelopts(bytesused)-bu;

I get:

using op(1,):
0.15e-1, 131048, 144936

using LinearAlgebra:-Dimension():
0.16e-1, 65524, 145256

The only difference appears to be that the bytesalloc is less with LinearAlgebra:-Dimension(), but the bytesused are about the same, slightly less with op(1,).

@Preben Alsholm 

nice one Preben, that's exactly what I was looking for, thanks very much!

So, if I'm not mistaken, op(1,F(X)); essentially does what LinearAlgebra:-Dimension(F(X)); does. Any reason to prefer one over the other?

I don't know if this is what I want to look at, but if I compare performance, on the following:

st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
  TaylorExpand(F,X,2);
  TaylorExpand(G,X,4);
time()-st,kernelopts(bytesalloc)-ba,kernelopts(bytesused)-bu;

I get:

using op(1,):
0.15e-1, 131048, 144936

using LinearAlgebra:-Dimension():
0.16e-1, 65524, 145256

The only difference appears to be that the bytesalloc is less with LinearAlgebra:-Dimension(), but the bytesused are about the same, slightly less with op(1,).

@pagan 

thanks pagan, that's very interesting. There is too much information for me to process at once, but I've learned some very useful stuff. I'm trying to apply it to other problems, sometimes I can, sometimes I struggle. The following code is still mysterious, but I'll make sure to look up "ArrayTools" and this 'inplace' option. As a side question, are there any pros and cons to calling a package (here ArrayToolrs:-) in the middle of a proc? Does it slow/speed things down/up?

      ArrayTools:-Copy(p*q,B,0,1,CC,0,1);
map2[evalhf,'inplace'](`*`,A[i,j],CC);


If I'd paid closer attention I ought to have spotted the typo in KPKP. Thanks for your follow-up.

Applied to the 5X5 symbolic Matrix example, the bytesalloc/bytesused breakdown is the following:

LinearAlgebra:-KroneckerProduct:
28371892, 50558216

"Guts" KP Proc posted by Pagan
54647016, 54793504

Pagan's KPKP
32499904, 49778620

Acer's KroneckerProduct2
51960532, 56334612

DJ Keenan's KroneckerProd3
12580608, 62123776

I'm not sure how fair/unfair this comparison is though. I don't quite grasp the importance of "doing well" along the bytesalloc dimension versus the "bytesused" dimension...


As for Matrices of floats, the following example

A:= Matrix(100, 25, [seq(1e-10*rand(), i=1..100*25)]):
B:= Matrix(199, 199, [seq(1e-10*rand(), i=1..199*199)]):

yields:

LinearAlgebra:-KroneckerProduct:
792020000, 793221636

Pagan's KPKP8
792216572, 793377332

So KPKP8 looks basically just as good as the LinearAlgebra command.

@PatrickT 

Follow-up on bytesalloc. Thanks to one of Acer's posts, to which I was directed by googling for bytesalloc, I found this useful code below for comparing resource-use across different codes. I'll post it here for reference.

instead of:

t := time():
YOUR CODE HERE
time() - t;

use the following:


time()-st,kernelopts(bytesalloc)-ba,kernelopts(bytesused)-bu;
YOUR CODE HERE
st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):

By some amazing coincidence I wanted to look into this problem only a couple of days ago. The setup has some realism.

If I understand the statement of the problem correctly, the objective is to select the best applicant (assumption 8) irrespective of how likely that goal is to be realized. You will prefer to select the best candidate with probability 0.1 than to select the second-best candidate with probability 1. Do I understand correctly?

This may be the right objective if the secretarial positition is a lifetime positition, but if the contract is unlikely to last, an employer may prefer to maximize the expected value (taking probabilities into account) and settle for second or third best some of the time.

Anyhow, I will read Robert's explanations (below) before saying more.

Thanks Acer,

I was totally misunderstanding nops. I mean I read the help file at the speed of light, figured it was pretty much giving me the Vector size and proceeded accordingly. So big and silly mistake here.

Yes it would be rather useful to have a command return the dimension of Vectors, vectors, Lists, lists, etc.. Isn't that usually available in Matlab and other software?

So the workaround I have found is to use LinearAlgebra:-Dimension().

I don't know the pros and cons of calling a package, but it seems to work on the two examples I gave earlier:

TaylorExpand := (F,X,n) -> 
Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..100)],n),i=1..LinearAlgebra:-Dimension(F(X)))]):
TaylorExpand(F,X,3);
TaylorExpand(G,X,6);

You see, I start my worksheet by inputting Vectors of a certain size, between 2 and 5, and experiment with different inputs, so I don't want to have to keep changing, e.g. manually change this:

TaylorExpand( F([X[1],X[2]), [X[1],X[2]], 3);

into this:

TaylorExpand( F([X[1],X[2],X[3]), [X[1],X[2],X[3]], 3);

everytime I experiment with Vectors of different sizes.

So thanks to both of you, Preben and Acer. I think I've got it to work now. If I run into trouble again with this same issue, I'll report back.

Patrick.

Thanks Acer,

I was totally misunderstanding nops. I mean I read the help file at the speed of light, figured it was pretty much giving me the Vector size and proceeded accordingly. So big and silly mistake here.

Yes it would be rather useful to have a command return the dimension of Vectors, vectors, Lists, lists, etc.. Isn't that usually available in Matlab and other software?

So the workaround I have found is to use LinearAlgebra:-Dimension().

I don't know the pros and cons of calling a package, but it seems to work on the two examples I gave earlier:

TaylorExpand := (F,X,n) -> 
Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..100)],n),i=1..LinearAlgebra:-Dimension(F(X)))]):
TaylorExpand(F,X,3);
TaylorExpand(G,X,6);

You see, I start my worksheet by inputting Vectors of a certain size, between 2 and 5, and experiment with different inputs, so I don't want to have to keep changing, e.g. manually change this:

TaylorExpand( F([X[1],X[2]), [X[1],X[2]], 3);

into this:

TaylorExpand( F([X[1],X[2],X[3]), [X[1],X[2],X[3]], 3);

everytime I experiment with Vectors of different sizes.

So thanks to both of you, Preben and Acer. I think I've got it to work now. If I run into trouble again with this same issue, I'll report back.

Patrick.

First 54 55 56 57 58 59 60 Last Page 56 of 93