Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 360 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Simwar You wrote:

  • I tried copying your improvements, but I seem to have a problem with the 'relation' in the end.

That was my fault. Sorry. Record needs to be with a capital R; I had record.

  • How exactly is double colon suposed to be understood? Not sure when it is used instead of definitions.

It is not used instead of definitions. When x::T appears as a parameter declaration, it means that the argument that is passed to x will be checked for its type (see ?type), and if it's not type T, an error will be issued. A parameter declaration can include a type, a default value (Is that what you mean by definition?), both, or neither.

  •  I don't quite understand how the satisfies command works and I couldn't find information regarding it.

It is not a command; it's a type (see ?type,satisfies).

  • Is it similar to satisfy or satisfiable?

It has no relation to Satisfy or Satisfiable, which are commands in the Logic package.

  • Why is "n->" needed?

The argument to satisfies must be a procedure that returns true or false. The n-> n >= x means exactly the same thing as proc(n) n >= x end proc, but is easier to type. 

  • Why are the forward quotes needed here on list, integer and range?

They aren't needed; the procedure will work without them. They are there to guard against the possibility that in some other code, perhaps totally unrelated code, you've globally set the value of integerlist, or range.

  •  Is it gonna show both the roll and the counter now? Are they both return values or how do I choose which one it is?

It'll show both. They are both part of the return value. If you want to separate them after calling sim, do

(roll, cnt):= sim(3, 12);

The first pair of parentheses above are not syntactically required; they're just my personal preference.

@Simwar I've added extensive instructional comments to my improved procedure.

Please post your complete code, showing the error message. You can upload a worksheet by using the green up-arrow on the toolbar of the MaplePrimes editor.

What do you intend to happen when you use 3 colors instead of 1?

And what is f0?

@acer I had forgotten that unevaluation quotes could be significant even in the proc line, but only on the right side of :=.

Your procedure can be further improved like this:

sim:= proc(                                                             (*Notes*)
   x::posint,                                                           (*1*)
   n::And(posint, satisfies(n-> n >= x)),                               (*2*) 
   o::identical(exactly, minimum, maximum):= 'exactly'
)
uses RT= RandomTools;                                                   (*3*)
local
   counter, roll,
   relation:= Record('exactly'= `=`, 'minimum'= `>=`, 'maximum'= `<=`)  (*4*)
;
   for counter do                                                       (*5*)
      roll:= RT:-Generate('list'('integer'('range'= 1..6), x))          (*6*)
   until relation[o](add(roll), n);                                     (*7*)
   roll, counter                                                        (*8*)
end proc:

By far the most important of these improvements is (*8*) that I removed print. A procedure should never use print to return its value. You may use print to return supplementary information. If a procedure tries to return its value with print, then you won't be able to assign that return value to a variable, and you won't be able to use the procedure effectively inside other code.

Other notes:

(*1*) It's usually a good idea to put a type restriction on all parameters (posint means positive integer).

(*2*) That type restriction can include a dependency on other parameters. Here, n is restricted to be a positive integer greater than or equal to x. This can usually be done without using the depends modifier, whose documentation is quite weak (so I recommend that you completely avoid that while you learn the rest). The type satisfies is used to turn any boolean condition into a type.

(*3*) It's my personal preference that package names not be declared 

uses package name;

but rather

uses abbreviation= package name;

This makes it absolutely clear which package, if any, the members come from.

(*4*) Locals can be assigned values directly in their declaration.

Record is one of Maple's many indexable container data structures. It can be used when the indices are all symbols, as are exactlyminimum, and maximum. The target values can be anything.

When operators (such as <><>) are referenced without operands (or when used in prefix form), they need to be put in back quotes: `<>``<``<`. Don't confuse these with the forward quotes used to prevent evaluation, as in 'exactly'.

(*5*) When a counter needs to be incremented for every pass through a loop, you should use for to do it. You can include a while clause on the for line, but in this particular case, I thought that an until clause was better.

(*6*) Note that RandomTools:-Generate can generate an entire list in a single call by using this syntax. The second argument to list(...is the length of the list, x in this case. This is more efficient than using repeated calls to Generate.

(*7*) The until is a clause of the do statement (as in for ... do). It's not a statement that can stand alone. It replaces the end do or od. It's like the opposite of while, but unlike while, it forces the loop to be executed at least once.

The relational operator is being used here in prefix form.

When add (or seq or mul) are used on a list or Vector, there's no need to use an index.

@digerdiga Your and return lists of different lengths when given the same input?? I don't understand the point then. You'd have the same problem if they were specifed as linear.

@vv The OP's point is that the L.D.L^T decomposition can be computed without first computing the L.L^T decomposition, and that this can be done without using square roots. This is described in the Wikipedia page.

@Klausklabauter I'll see if I can implement the square-root-free L.D.L^T algorithm in Maple for you, guided by the Wikipedia article. Are you only doing the hardware-float case? Note that avoiding square roots is not necessarily such a great thing because it tends to be implemented in hardware these days, and thus is fast. Here's an example comparing sqrt on a million elements versus squaring those same elements, both in hardware floats:

M:= LinearAlgebra:-RandomMatrix(1000$2, generator= rand(0. .. 1.)):
M2:= copy(M):

CodeTools:-Usage(map[evalhf,inplace](sqrt, M2)):
memory used=7.63MiB, alloc change=7.63MiB, cpu time=125.00ms, real time=112.00ms, gc time=0ns
CodeTools:-Usage(map[evalhf,inplace](`^`, M, 2)):
memory used=7.63MiB, alloc change=7.63MiB, cpu time=141.00ms, real time=148.00ms, gc time=0ns

The point of my earlier messages was not that the LDL^T decomposition was somehow inferior to LL^T; my point was simply that it is not standard to call it "Cholesky".

@Mariusz Iwaniuk Vote up. Conversion to Heaviside is another way to simplify piecewise's conditions. If you convert the Heaviside expression back to piecewise, it'll be in the simplified form:

convert(h1, piecewise, t) assuming n::posint;

@Rouben Rostamian  Vote up. It is curious that the following does not work: 

inttrans:-fourier(piecewise(abs(t) < 2*Pi*n, cos(t), 0), t, w) assuming t::real, n::posint;

I think that piecewise often works better when the conditions are simplified, as you did, even if that means there are more conditons.

@Klausklabauter When your instructor told you not to use the "old method", I think that they are referring to the long-since deprecated Maple command linalg[cholesky]. I don't think that they are referring to any distinction between L.LT and L.D.LT.

@mmcdara That's what I thought. The pop-up is not saying that the input is incorrect. It's saying that there are two possible interpretations, and it's giving you the opportunity to select one of them. So, I stand by my statement that the OP's input is correct when entered as 2D Input, even in Maple 2015.2.

I also abhor the 2D Input, and this dialog box is one of the many reasons. I think that they managed to get rid of it for Maple 2018. There's some connection between that and the option function_assign that you see when the procedure is copied to a 1D Input field.

@Britzel Yes, that's what it's supposed to mean. If there's a case where that's not true, it's a bug. (Of course, returning undefined isn't considered as returning "a value" for the purposes of this question.)

@Kitonum You'd might as well use

signum(a - b)  assuming a < b;

because by your method, the expression is only being analyzed at this superficial level. How is the user expected to know which parts need to be encapsulated, and, if they did know that, why would they use Maple for this?

Is the third problem in your PDF simply to be ignored? It is completely different from the first two. Indeed, it's not even a numeric problem as no initial condition is given.

First 312 313 314 315 316 317 318 Last Page 314 of 709