Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

Transposition is an involution (f(f(x))=x); it's not idempotent (f(f(x)) = f(x)). A linear idempotent function is called a projection.

@janhardo Yes.

Let me know if you need any mathematical hints to compute the x-interval needed to obtain a particular length of tangent line.

Why do you want the extrema of the spline rather than the extrema of the original data?

@janhardo I suggest making the x-ranges of the tangent lines (tangency point) +- (b-a)/2/n where n is the number of tangency points. Currently, you have n hard-coded as 6. If you want to improve this procedure, my next suggested step is to make this 6 a variable.

@janhardo Since a and are now parameters of the procedure, they can't be locals. You simply need to remove them from the local list. While you're at it, you might as well add xaxis to the locals.

Then if you run the procedure, it'll work, but you'll see that the tangent lines are too long. Can you correct that?

@ Please read the help pages ?assume, ?assuming, and ?assuming,details, paying particular attention to the additionally command and the additionally subclause of assuming. Then, let me know if you have further questions.

@janhardo There are two ways to make comments in Maple code. The first style is #, which causes all input to the end of the line to be a comment. I use this style for explanatory comments. The other style is (* ... *), which causes all input, including line breaks, between (* and *) to be ignored. I use this style for commenting out code.

@ Like I said in my Answer below, which you apparently acknowledged, the algorithm is called branch-and-bound. How did you miss that?

@Scot Gould Please give a practical example such as might be used in an introductory course using Maple where this evaluation-level stuff makes any difference. The examples in this thread are highly contrived, not practical.

I think that you've misconstrued the comment about other programming languages. In a language without symbolic variables, it's impossible for there to be any distinction between full and one-level evaluation. Symbolic variables means variables that have no value other than their own name.

@Mariusz Iwaniuk Your scaling along the time axis is unrealistic. You have t=20 matched to 2010 and 2015.

@janhardo You wrote:

  • This is not looking here above anymore on a procedure definition with proc().. end proc;? 
    But it seems to be a procedure. 
    Its function made by the operator -> then.

Yes, there's no significant performance difference between the proc() end proc and ()-> forms. One insignificant difference, unrelated to performance, that you've noticed is how these forms are displayed in prettyprinted or 2-D output. If you want to suppress that output, you could end the procedure definition with a colon (:) instead of a semicolon (;). This is what I assumed you meant by "outcomment".

  • Another point about a while clause of the do statement in relation to summing up a list of numbers. I can take a partial sum of the list,therefore should be needed a while clause.

Your English is a bit difficult for me to understand. Are you saying that you want a procedure for the partial sums of a list? Here is such a procedure:

PartialSums:= (L::list(algebraic))-> local S:= 0, x; [seq((S+= x), x= L)];  

The command ListTools:-PartialSums also handles this. This procedure does not need a while clause.

  • PR:=proc(A,N)   # PR is product
       p:=1;
       for i from 1 to N do p:=p*A[i] end do:
    end proc;

Your solution is pretty good. I'd like to point out some issues. Here's my version:

PR:= (A::indexable)->
    if numelems(A)=0 then 1 else local p:=  1, x; for x in eval(A) do p*= x od fi
:  

Issues:

  1. It is not necessary or desirable to pass the size N. The size can be determined inside the procedure using numelems. If A is restricted to lists and sets, then nops can be used. I'm sure that you'll see nops somewhere in Betounes's book.
  2. In your procedure, and i should be declared local.
  3. Your procedure will return NULL (which displays as nothing at all) if A is empty. The usual mathematical convention is that when an associative operator with identity is applied to an empty set of operands, its identity is returned. That means that 1 should be returned.
  4. It is not necessary or desirable to index A to extract its elements. Use the in form of for-do loop instead.
  5. The eval is only needed for certain types of that I probably shouldn't detail right now. If is restricted to lists and sets, eval is not needed.
  • To make a factorial 4! from the list A you must fill it with natural numbers : that is not handy

Yes, of course. It was not the point of my exercise that you would directly use this procedure to compute factorials. But the next exercise is to write a procedure that computes the factorial of a nonnegative integer n.

@janhardo Note that there's no practical difference between a procedure written as proc(...) ... end proc and one written as (...)-> .... For example,

f1:= proc(x) x^sin(x) end proc versus f2:= x-> x^sin(x).

@Scot Gould I have not memorized Maple help pages in the sense of "photographic memory". The way my memory works is akin to a Maple table whose indices are "question that has an answer" and whose entries are "help page that has the answer". I've read some pages (?type,structure, ?operators,precedence) hundreds of times.

I think that any efficiency gain due to shallow evaluation is worth exploiting. The only drawback to it that I'm aware of is the occasional "inconsistency" in the top-level results that you noted. That inconsistency is always resolved by doing one more top-level evaluation.

Like you, I overwhelmingly tend to use "bottom-up" evaluation rather than "top-down". 

@dharr I appreciate your concern for better error messages. Like I said, sometimes the message needs to come from the argument checking. In those cases the end user will never see the error message, and the arguments are passed to another procedure.

The name speclist is by analogy with the standard type names specfuncspecindex, and specop; though your listcontaining is good also.

@Scot Gould Yes, there is a good reason for that. The level of evaluation of variables within procedures is minimal (one level I think), for efficiency, but there's more evaluation at the top level (full evaluation up to removing one level of unevaluation quotes), because that's what's usually wanted for a top-level result. The level of evaluation also depends on whether it's a local or global that's being evaluated. See ?eval.

First 193 194 195 196 197 198 199 Last Page 195 of 709