Carl Love

Carl Love

28100 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@tomleslie I wasn't claiming that you were claiming that any commands were threadsafe. Rather, I was addressing the following comment of yours:

Of course your original calculation should run multithreaded. At the moment I can't figure out why it doesn't....

@tomleslie The commands solve, fsolve, and int---like the vast majority of more-complicated Maple commands---aren't "thread safe". They can't be used with Threads. See ?index,threadsafe.

@taro There's no problem with the accuracy of your use of eval. The problem is with efficiency. Like I said, it forces the recomputation of the symbolic derivative every time that it's used. In other words, every time that you use eval(g(x), x= a), Maple does these steps:

x^2 is converted to 2*x, then a is substituted for x.

Using D, the conversion x^2 to 2*x is done only once, at the time g is defined, and it's only the substitution step that's done for every invocation of g.

Here's an example showing the timing difference for a complicated function:

f:= unapply(randpoly([exp,sin,cos,arctan](x), degree= 23, dense), x):
g:= x-> diff(f(x),x):
gD:= D(f):
time(eval(g(x), x= 2));

     0.218

gc(); time(gD(2));

     0.109

gc(); time(eval(g(x), x= 3));

     0.234

gc(); time(gD(3));

     0.109

By "pre-subscript", do you mean the x in x[1] or x__1? By "pre-superscript", do you mean the x in x^2?

@taro Your use of eval isn't a good way to do this. I almost consider it an accident or a coincidence that it works at all. The biggest problem with it is that it forces the re-computation of the symbolic derivative every time it is used.

It can be done without D by using unapply:

f:= x-> x^2:
g:= unapply(diff(f(x),x), x);
g(2);

Indeed, D is essentially just a combination of unapply and diff.

@alfarunner The back quotes used on the `if` are an essential part of Maple syntax, and they're used in a great many commands other than `if`. My guess is that you're not using the correct quote. The correct one is (on a standard US keyboard) the key on the upper left, the leftmost key in the second row, under ESC.

The piecewise is an appropriate alternative to `if` in this case, but that won't always be true.

You can always substitute ifelse (without quotes) for `if`. This is a purely syntactic substitution that will always work. But there are other situations where the back quotes (also called "name" quotes in Maple) will be needed.

 

@nidojan To show you appreciation for my help, you can click on the Thumb icon and/or the Trophy Cup icon in the upper right corner of my Answer.

Please don't ever---on any forum---delete a legitimate question that already has a legitimate answer. To do so is incredibly disrespectful to the person who took the time to answer.

@vv Only a computer or a person with a very limited imagination and no understanding of recursion would give 31 as the answer. If it's a "puzzle", not just a problem, I think that an answer based on a first-order recursion would always be preferable to one that's not.

@emendes No problem. Let's name the procedure P.

P:= proc(f::list, vars::And(list, satisfies(vars-> nops(vars) = nops(f))))
     #...statements...
end proc:

There's no need for the parameter of the satisfies procedure to have the same name as the corresponding parameter of P, so that can be shortened to

P:= proc(f::list, vars::And(list, satisfies(v-> nops(v) = nops(f))))
     #...statements...
end proc:

Here's a third way, completely different:

P:= proc(f::list, vars::depends([anything $ nops(f)]))
     #...statements...
end proc:

In this way, it's the square brackets that force vars to be a list, the $ nops(f) that forces it to be a certain length, the anything is a primitive type that matches any single thing, and the depends is a keyword that signals that the type check for vars depends on f. For reasons that I don't understand, the depends isn't needed when the dependency is inside a satisfies.

Please let me know if you have any more questions.

@nidojan Okay, now we're getting somewhere. However, the errors are not quite the same. If you want me to take your question seriously, please point out how the two error messages are different. In the process, you may begin to understand the fundamental problem. Hint: It is a purely mathematical error; it has nothing to do with computer coding.

@nidojan Please post the corrected file. I don't feel like retyping your equation.

@nidojan Another problem is that in PDE, you take derivatives with respect to y; whereas the independent variables are x and t. Do you really need me to point that out?

@Carl Love Continuing from above, items 1 and 2 are handled by the list({name, name= anything}). Note that a disjunction of types is expressed with {...}. A conjunction of types is handled by And.

To check if the elements of a list are distinct, we construct the corresponding set and check if it has the same number of elements as the list. If v is a list, then nops(v) is its number of elements, and {v[]} is the corresponding set. Some members of v may be equations. From these, we to extract the left sides. The other members, we want to leave alone. A procedure that does this is (x-> `if`(x::name, x, lhs(x))). This mapped over the set is (x-> `if`(x::name, x, lhs(x)))~({v[]}), and the number of elements of that is nops((x-> `if`(x::name, x, lhs(x)))~({v[]})).

In the expression (n-> n=nops(f) and n=nops((x-> `if`(x::name, x, lhs(x)))~({v[]})))(nops(v)), the nops(v) is the argument that corresponds to the parameter n.

Please let me know if you have more questions.

@acer Just to make it absolutely clear for the other readers, by "Java garbage collector" you mean something distinct from the much-more-familiar kernel garbage collector, right? And one doesn't seem to have much control over this Java garbage collector, by, say, deleting visible objects like plots from worksheets.

Firefox (where I currently have 35 tabs open) is usually the number one memory hog on my computer, and Maple's Java GUI is usually number two.

@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.

 

 

First 390 391 392 393 394 395 396 Last Page 392 of 709