Carl Love

Carl Love

28100 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Joe Riel 

Thank you for the example. Yes, I already understood what "return an unevaluated call to a constructor" meant. What I am asking for is an example of a practical use of the parsing of that unevaluated call. (I guess that I emphasized the wrong sentence.)

@Prashanth Please post code as plaintext, not pictures.

I'm not sure, but I don't think that parametric and piecewise can be used together.

You do not have any Array. Your f is a table. An Array must be explicitly created or declared. Making assignments to subscripted entries of an undeclared variable creates a table. Whether it's a table or an Array, the number of elements can be found with numelems.

@Kitonum You raise an important point. For the case of polynomial systems (your first counterexample), the problem can still be handled by a single call to solve (but multiple calls to eval), if you use the parametric option, which returns a piecewise solution. Thus:

solve({b*x+y=1, x+b*y=1}, {x,y}, parametric= full);

     piecewise(b-1 = 0, [{x = -y+1, y = y}], b+1 = 0, [],
     And(b-1 <> 0, b+1 <> 0), [{x = 1/(b+1), y = 1/(b+1)}])

Thus, a solution of this form can be sequenced by 

{b=j, 'eval'(solve({b*x+y=1, x+b*y=1}, {x,y}, parametric= full), b= j)[][]} $ j= -2..2;

     {b = -2, x = -1, y = -1}, {b = -1},
     {b = 0, x = 1, y = 1}, {b = 1, x = -y+1, y = y}, {b = 2, x = 1/3, y = 1/3}

The absence of and y in the b=-1 term indicates that there's no solution for b=-1. And, of course, note the special form of the b=1 term. The unevaluation quotes around eval force it to be evaluated for every value of j.

@yader

There are much easier and better ways to make a procedure distribute over container classes (lists, sets, tables, rtables (Vectors, Matrices, Arrays)). The easiest way is to use the elementwise operator ~ (see ?elementwise). So, for example, if is a Vector, do

Cancel10s~(A);

If isn't a container, then the above command behaves just like Cancel10s(A).

The command map is more general in its definition of "container" (see ?map):

map(Candel10s, A);

There is an inplace option for map so that it operates on rtables (Vectors, Matrices, and Arrays) without making a copy:

map[inplace](Cancel10s, A);

The above command alters itself, so there's no need to assign the result to a variable.

Regarding copy-and-paste of plaintext code: The preservation of indentation seems browser dependent. My experience is that it is preserved in Firefox and lines are left-justified in Chrome. My most common use modality is to use Chrome and manually re-add the indentation (because, on my favorite computer, I can't post at all with Firefox). Regardless, it is nearly worthless to your readers to post Maple input as a picture unless you also attach a worksheet.

@Markiyan Hirnyk The resolution (or granularity) of the Maple clock is so large that CPU times less than about 0.05 sec can't accurately be measured directly. That resolution is system dependent, but on every system that I've ever used (mostly Windows), it's been exactly 1/64 = 0.015625 seconds. To measure small times more accurately, use the iterations option to CodeTools:-Usage. This will execute the code multiple times and report the average time.

You can verify what I say about the resolution by measuring a variety of small times with kernelopts(cputime). For example, you can execute the following:

st:= kernelopts(cputime):
for k do t:= kernelopts(cputime); if t > st then break end if end do:
t-st, k;

     0.015625, 9731

That means that for the first 9730 iterations of the loop, the measured time was exactly zero. You can repeat this code any number of times. The number of iterations will vary wildly, but the first number---the first nonzero time measured---will be constant.

@yader 

Yes, I said that it wouldn't work with nested floats. Here's an improvement using frontend (which prevents it from seeing anything inside a function call, such as sin) that will work:

Cancel10s:= proc(E::algebraic)
local T,P,N,D;
     T:= And(float,Not(identical(0.)));
     if not frontend(hastype, [E], [{`+`,`*`}, {}], T) then return E end if;
     P:= 10^ilog10~(frontend(indets, [E], [{`+`, `*`}, {}], T)[1]);
     N:= numer(E)/P;
     D:= denom(E)/P;
     N/D
end proc:

I can't explain the error that you got earlier except to say that the big "1/" in your prettyprinted output is suspicious.

@yader 

I used Maple 18. I wonder if there has been an unintentional fundamental syntax change in Maple 2015. It'd be a very bad thing if so. The big "1/" in the prettyprinted version of the procedure in your Reply is very suspciious. Or, I wonder if it's a 1-D / 2-D difference. Try the following bloated version of the procedure:

Cancel10s:= proc(E::algebraic)
local T,P,N,D;
     T:= And(float,Not(identical(0.)));
     if not hastype(E, T) then return E end if;
     P:= 10^ilog10~(indets(E, T))[1];
     N:= numer(E)/P;
     D:= denom(E)/P;
     N/D
end proc:

@Al86 The u example that I used satisfies that PDE, so the identity still doesn't hold.

@Kitonum It means the same thing as does NaN (Not a Number) in the IEEE 754 standard for (double-precision) floating-point arithmetic that Maple uses. See the Wikipedia page on NaN. In this case, I suspect that it comes from computing the difference of two very large positive numbers whose difference is very small. If you increase Digits to 15, the problem will go away.

@ 

Changing int to Int should substantially reduce the computation time. I don't have time to test it right now. As it is, it is attempting a symbolic integration every time YFD is called with numeric input.

@Markiyan Hirnyk Replace your map with map[inplace, evalhf] and you should get about a factor-of-10 time reduction.

@tomleslie 

  • Yes, I meant assign (original Answer corrected).
  • Yes, AFAIK, all of Maple's solving commands treat algebraic expressions as equations equated to 0.
  • The process you describe is esentially equivalent to using eliminate, where one can clearly see that the reduced equations (the second returned set) are inconsistent.

@Bendesarts The embedded semicolons make this problem more difficult than something that can be handled with some simple StringTools commands. Maple does have it's own Matlab-to-Maple translator: Matlab:-FromMFile (see ?Matlab,FromMFile). It does have some limitations on the complexity of the Matlab code that it can handle, but I think that it can handle what you've presented above. 

I believe that the embedded prompt (>) symbols on copy-and-paste are due to a bug in Maple 2015 that's already been corrected in Maple 2015.1. I'm not sure about that. Hopefully someone else here will comment on that. It that's not the problem, I can come up with a StringTools solution for that problem.

@erik10 Adding an icosahedrom wireframe is much easier than your Reply suggests. Starting with Kitonum's PlotFootball, do

FB:= PlotFootball([red,yellow]);
plots:-display(
     FB,
     geom3d:-draw(geom3d:-icosahedron(Icosa, C, 1.2), style= wireframe, thickness= 4)
);

First 470 471 472 473 474 475 476 Last Page 472 of 709