Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@rsweet Yeah, I think that it's too many terms.

As an interesting aside, irrespective of the bug in limit---and at the risk of stating the obvious: If we define the limit function

B:= x-> Sum(s(2^n*x))/2^n, n= 0..infinity),

then this is a Weierstrass type fractal: a continuous nowhere differentiable function. The 2^n in the denominator makes it easy to prove it continuous, and the fact that s'(x) is always 1 or -1 (where defined) makes it easy to prove nowhere differentiable.

@jefryyhalim Note that to get Tom's symbolic solution, it's still essential that the "fudge factor" 1e-10 (which I called epsilon) be removed from your original code and /tan changed to *cot. I don't want you to go away thinking that that effort was for nought. When a problem like that "sticks out like a sore thumb" in the code, my first focus is removing that problem.

@acer Thank you so much for your very helpful comments, Acer!

1. Yeah, I thought that that random matrix took too long to generate. I didn't worry about it fixing it because it was just an example.

2. So, you're saying that my type declaration checks whether the Matrix is actually symmetric if it's not declared symmetric?

3. I realized that I was accessing in C_order, and I tried to adjust the algorithm for that, but it didn't work. I saw a time improvement, but the results were wrong. So, I'm eager to take a look at what you did.

[Later]

Now I've looked at what you did. Seems simple enough. Is there a good reason to convert the output to Fortran_order?

@acer I've traced is as far back as this erroneous result:

limit((frac(x) - 1/2)/(x - 1/2), x= 1/2),

which returns 0 even though it's clearly equal to 1.

@Desruim Yes, you're right that the period is 1/2. Apparently, I didn't follow my own proposition!, which is still correct. I will correct the text and look into that 0.

@Rouben Rostamian  Oh no, I totally missed seeing that 0!! I thought that the OP was asking why the derivative is 3. So, I spent all that effort to write a precise freshman-level explanation of why the derivative is 3... and now the OP is not likely a freshman.

I'll think about that 0.

My code above implements precisely the formulas on Slide #9 from the course notes that you linked: 

https://www.igpm.rwth-aachen.de/Numa/NumaMB/SS17/handouts/Handout20170516.pdf

Apparently, your professor calls this algorithm Cholesky-Verfahren.

Unfortunately, compiled Maple only allows some fairly "primitive" coding style. So, for example, you can't use add to do summation. There are two spots in the code where that would've been nice to have.

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

First 311 312 313 314 315 316 317 Last Page 313 of 708