Carl Love

Carl Love

28110 Reputation

25 Badges

13 years, 123 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@emendes Naturally, you have selected the most complicated part of the whole thing. I'll need to explain this a little bit at a time.

First, let's distinguish arguments and parameters. In the following four code snippets, x is a parameter, and y is the argument that corresponds to x:

  1. f:= proc(x) x^2 end proc;  f(y);
  2. f:= x-> x^2;  f(y);
  3. proc(x) x^2 end proc(y);
  4. (x-> x^2)(y);

All four examples define a procedure, and then evaluate that procedure at argument y. To understand the code that you asked about, you must understand that the end result of 4 is y^2.

In a parameter declaration, the part after the :: is a type. For the parameter v, I want to check several things:

  1. That it is a list.
  2. That each member of that list is either a name or an equation whose left side is a name.
  3. That the length of the list is the same as the length of f.
  4. That the names that constitute the members of the list or the left sides of the equations are distinct.

Items 1 and 2 can be handled by Maple's vast collection of predefined types. For 3 and 4, an ad hoc type is specified by the keyword satisfies, whose argument is a boolean-valued procedure.

That's all that I have time to write right now. More later.

 

 

@tomleslie Changing some operators to prefix form is an unfortunate effect of converting 2D input to 1D, which happens when you copy-and-paste. So X$n always gets converted to `$`(X, n) without it being directly the fault of the OP.

The use of square brackets in the second argument of diff allows for the degenerate case of a zeroth-order derivative to be specified. For example:

d:= Diff(exp(x^2), [x$n]);
v:= value(d);

     v := x^(-n)*2^n*MeijerG([[0, 1/2], []], [[0], [1/2+(1/2)*n, (1/2)*n]], -x^2)

simplify(value(eval(d-v, n= 0)));

     0

The above's last line would be syntactically invalid without the square brackets in the first line.

@dsh1

Well you better check yourself before you go accusing people of being wrong, because if you copy-and-paste this input

geom3d:-point~([A,B,C], [[8,3,-9], [-6,-6,-2], [6,9,-3]]):
geom3d:-line(L1, [A,B]):
geom3d:-line(L2, [C, [2,4,-1]]):
geom3d:-distance(L1,L2);

you'll get 2*sqrt(5), not (388/545)*sqrt(545).

@Niek There is no problem with your pi because of the reason described by Preben Alsholm above. If you were to try using pi without menus and the mouse, then it would be a problem.

The syntax for assuming that an object has a property uses `::` rather than `=`. For example, Assume(rho::constant). I doubt that this type of assumption would have any effect on dsolve.

@emendes The only two things that I can recommend are the Maple Programming Guide and asking Questions here. The Guide is available in the onboard help system. Just enter ?ProgrammingGuide.

If there's any specific point of syntax that you'd like to ask about, I'd be glad to answer.

@omer Using recursion, it can be done as a one-liner in modern Maple (and even in older Maple):

SumToOneDigit:= (n::posint)-> `if`(ilog10(n) < 1, n, thisproc(add(convert(n, base, 10)))):

I just post this as an example to show how recursion is done in modern Maple. Acer's and Joe's very-well-known mod trick makes this procedure obsolete.

@firmaulana Tom Leslie's code works for me. Please post a worksheet so that I can see what you're doing wrong. It is impossible to use if as you show, without quotation marks, and not get an error message.

@emendes In the vast majority of cases, a procedure should use named parameters rather than relying on args. Yes, you should use proc(f::list, vars::list, samp:= T). This makes samp optional with a default value of T.

See my Answer below for a solution to the problem of iterating a multivariate function multiple times with simplification at each step.

@emendes 

I don't understand your use of T. Is it just a symbol?

@Vic Hmm. I haven't seen a full specification of your problem, but I'm going to guess that ListProcess will return NULL for the vast majority of cases. If that's not true, then you'll need a whole room full of disk drives just to store the cases for which it doesn't return NULL, and in that case, you might as well give up now. So, change the above line of code from Threads:-Map(ListProcess, LL) to LL:= Threads:-Map(ListProcess, LL). Thus the new LL will be much shorter than the old LL (NULL in a list takes no memory at all), which will be reclaimed by the automatic garbage collector. Then you write the new LL to disk.

I need to stop for the night.

@mmcdara Hmm, yes, of course. This was the first approach that I tried. I hope that you realize that my approach does linearize the problem automatically, uses exactly the same computational engine as yours, and produces exactly the same result. The reason that I didn't publish that first approach is that it requires manually taking apart the model function and re-entering parts of it into the code. The essence of elegance in programming is to reduce such redundancy. The goal is to enter the problem into the computer in as close a form as possible to its original statement and then to avoid, as much as possible, re-entering any subparts.

I do appreciate that your code shows a shortcut that I was previously unaware of: The tilde ~ can be placed after a function symbol (in prefix form) to zip that function as well as to map it. To wit: You used TX~(x,y) as a shortcut for zip(TX, x, y). I've already used that new knowledge twice in the few hours since I read your code.

@Vic It's often quite difficult to parallelize code, but in this case it's very easy, almost trivial. Make a list of lists LL such that each member of LL is one of the lists that you want to process and such that LL is as long as can comfortably fit in the memory of your computer. I'd guess that LL has on the order of a million members. Then simply do

Threads:-Map(ListProcess, LL);

@Adam Ledger Since you seem to like commands that are as short as possible, like I do, I thought that you'd appreciate that the pairing of the data could be done by `[]`~(X,Y)

Do you mean that you'd like a procedure that'd check whether the span of a set of vectors U is in the subspace spanned by a set of vectors V? What you're calling u and v are not usually thought of as single vectors as you are suggesting. Rather your u is the span of {<0,1,0>, <0,0,1>} and your v is the span of {<1,0,0>, <0,1,0>, <0,0,1>}. 

First 391 392 393 394 395 396 397 Last Page 393 of 710