Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@sand15 You asked:

  • By the way: in your Maple 2025 codes you write alpha::evaln in the parameter sequence. I had always thought in this sequence N::T refered to to expected type T of name N... but evaln is not a type, so "How can  alpha::evaln be authorized?"

Usually is required to be a type, but there are 6 exceptions. These are dcoumented on the help page ?parameter,modifiers. This is not anything new to Maple 2025. Most, if not all, of these exist in Maple 2015, Surely uneval and seq are even much older than that. Here are the 6 modifiers, where the ...'s indicate that additional arguments are required:

  • uneval
  • evaln or evaln(...)
  • seq(...)
  • expects(...)
  • depends(...)
  • coerce(...or ~...

In the cases where these keywords or symbols match other Maple commands---namely evalnseqdepends, and ---, the usage within a parameter declaration is not related to the other usage. 

 

@Kitonum What not use align= [above, left] instead of align= left and thus avoid the need for the artificial constant 0.06?

The header for this Question shows that you checked the Maple Flow box. How could you check it if it weren't there? It's the 2nd-to-last Product shown.

@michele If a matrix A has n columns, then they can be reversed by

A[.., -[$n]]

If it has n rows, then they can be reversed by

A[-[$n]]

@michele Pkease use the Reply button, not the Answer button, to Reply to a Comment.

How can a circle lying in the plane z=0 contain the point [5,1,4]?

@Andiguys There's no solution: If all the variables are positive, then how could the quadratic expression in X3 be nonpositive?

This is the same as my last column graph but with a logarithmic color scale for the probabilities. With this, you can see the many orders of magnitude of variation among the vast "field" of values  (in front of the "mountain") that originally just appeared to be close to 0.

p1:= 1/5:  p2:= 1/2:  p3:= 1-p1-p2:  n:= 20:
Multinom:= table([seq](seq(
    (i,j)= n!/i!/j!/(n-i-j)!*p1^i*p2^j*p3^(n-i-j), i= 0..n-j), j= 0..n)
):
E:= [evalf({entries}(Multinom, nolist))[]]:
(m,M):= [min,max](ln~(E))[]:
plots:-display(
    seq(seq(
        plottools:-cuboid(
            [i-2/5, j-2/5, 0], [i+2/5, j+2/5, (p:= Multinom[i,j])], 
            style= surface, 
            color= COLOR(HSV, 0.85*((ln(p)-m)/(M-m)), 1, 1)
        ),
        i= 0..n-j), j= 0..n
    ),
    plot3d(
        0, (i,j)=~ -1/2..n+1/2, grid= [(n+2)$2],
        style= wireframe, color= black, thickness= 0.6
    ),
    labels= ["Cat. 1", "Cat. 2", "Prob."], labelfont= [times, bold, 12],
    axis[1,2]= [tickmarks= [seq](x= `if`(x::odd,``,x), x= 0..n)],
    axes= frame, glossiness= 1, 
    projection= 0.8, orientation= [-125, 65], lightmodel= light1,
    view= [(-1/2..n+1/2)$2, default]
);

#Color legend:
plots:-display(
    seq(
        plot([[p,0],[p,1]], color= COLOR(HSV, 0.85*((ln(p)-m)/(M-m)), 1, 1)),
        p= E
    ),
    axis[1]= [mode= log], axis[2]= [tickmarks= []], size= 100*[7,2], 
    thickness= 3, title= "Logarithmic Color Scale:\n", 
    titlefont= [times, bold, 12],
    labels= [`probabilities by color\n`, ``], labelfont= [times,10]
);

@sand15 You are not using the view option that I included:

view= [min(X)-W..max(X)+W, 0.1..max(Y)]

The purpose of its component is to avoid losing a bar on the left or right. I believe that that will work in all cases. The purpose of its component is to avoid seeing any "0 height" bars between the true bars.

And how does this have any significant effect on the length of the plot structure?

Here is another way to make a column graph similar to the matrixplot from raw components. I like this better than the matrixplot because like the trianglar-base plots shown, it avoids the area i+j > n (i.e., the part outside the support of the distributuion).

p1:= 1/5:  p2:= 1/2:  p3:= 1-p1-p2:  n:= 20:
Multinom:= (i,j)-> n!/i!/j!/(n-i-j)!*p1^i*p2^j*p3^(n-i-j):
plots:-display(
    seq(seq(
        plottools:-cuboid(
            [i-2/5, j-2/5, 0], [i+2/5, j+2/5, Multinom(i,j)], 
            style= surface, transparency= 0.15
        ),
        i= 0..n-j), j= 0..n
    ),
    plot3d(
        0, (i,j)=~ -1/2..n+1/2, grid= [(n+2)$2],
        style= wireframe, color= black, thickness= 0.6
    ),
    labels= ["Cat. 1", "Cat. 2", "Prob."], labelfont= [times, bold, 12],
    axis[1,2]= [tickmarks= [seq](x= `if`(x::odd,``,x), x= 0..n)],
    axes= frame, glossiness= 1, 
    projection= .8, orientation= [-125, 65], lightmodel= light1,
    view= [(-1/2..n+1/2)$2, default]
);


 

@sand15 I totally agree that no fixed setting of binwidth will work adequately over a variety of cases. But likewise no fixed setting of thickness will work either. A further complication of thickness is that it's not measured in any units that are meaningful within the plot's coordinate system. For example (I found these by trial-and-error), in your first plot, thickness= 70 is equivalent to binwidth= 1; whereas in your 2nd plot (after commenting out randomize()), thickness= 39 is equivalent to binwidth= 1.

Here is, I think, a reasonable way to choose the binwidth, as you asked at the end of your worksheet. I assume that the data are given as equal-length lists X and with all X-values distinct.

# What binwidth to choose in Carl Love's code?
Xs:= sort(X); W:= min(Xs[2..] -~ Xs[..-2]);
Statistics:-Histogram(
    `$`~(X, Y), frequencyscale= absolute, binwidth= W, 
    axis[1]= [tickmarks= (Xs=~ typeset~(Xs))],
    view= [min(X)-W..max(X)+W, 0.1..max(Y)],
    axesfont= [times, bold, 9], axes= frame
);


You need to add frequencyscale= absolute to your earlier histograms to achieve what the OP wants.

While randomize() is essential for "production" code, it's not great when generating examples because they're not reproducible unless you display the "key" that is the value returned by the command randomize().

Regarding tickmarks: This option works the same way for all plotting commands. If a tickmark is specified as an "equation", the left side must be a number in the background coordinate system for its axis. The coordinate system for an n x n matrix in a matrixplot is (1..n) x (1..n). The right side of the "equation" can be anything, not necessarily a number, and is what should be printed at the position indicated by the left side. (I put "equation" in quotes to indicate that I simply mean a Maple expression with an =, not a mathematical equation.) So, for example, 1.5= 0 means to display a tickmark labeled 0 at the position that was originally 1.5.

Regarding small histograms: To make a small histogram such as you asked for: 

Statistics:-Histogram(
    (`$`@op)~([[1,4],[2,3],[4,5]]), frequencyscale= absolute, binwidth= 1
);

Actually, even the combine is not necessary. It might help a human see what's going on, but is can do the verification without it:

term1:= n-> (2*cos(2^n*x)+1)/(2*cos(x)+1):

term2_inner:= k-> 2*cos(2^k*x)-1:

term2:= n-> product(term2_inner(k), k= 0..n-1)
:

#Verify base case:
term1(1) = term2(1); is(%);

(2*cos(2*x)+1)/(2*cos(x)+1) = 2*cos(x)-1

true

#Induction hypothesis:
IH:= (term2 = term1)(n);

product(2*cos(2^k*x)-1, k = 0 .. n-1) = (2*cos(2^n*x)+1)/(2*cos(x)+1)

term2(n+1) = term2(n)*term2_inner(n);

product(2*cos(2^k*x)-1, k = 0 .. n) = (product(2*cos(2^k*x)-1, k = 0 .. n-1))*(2*cos(2^n*x)-1)

subs(IH, rhs(%)) = term1(n+1); is(%);

(2*cos(2^n*x)+1)*(2*cos(2^n*x)-1)/(2*cos(x)+1) = (2*cos(2^(n+1)*x)+1)/(2*cos(x)+1)

true

 

Download CosProductInduct.mw

@dharr I tried the is with assuming n::posint, x > 0, x < Pi/2, but I still got false. It's not at all surprising to me that is cannot prove the identity, and I wouldn't even expect it to be able to. But IMO it should never return false without a witness. (A witness is an assignment to the variables under universal quantification that fulfills their assumptions and for which the identity is definitively false.)

The fully symbolic induction can be done with a single combine command, like this:

term1:= n-> (2*cos(2^n*x)+1)/(2*cos(x)+1):

term2_inner:= k-> 2*cos(2^k*x)-1:

term2:= n-> product(term2_inner(k), k= 0..n-1):

#Base case:
term1(1) = term2(1); is(%);

(2*cos(2*x)+1)/(2*cos(x)+1) = 2*cos(x)-1

true

#Induction hypothesis:
IH:= term2(n) = term1(n);

product(2*cos(2^k*x)-1, k = 0 .. n-1) = (2*cos(2^n*x)+1)/(2*cos(x)+1)

#Obviously,...
#term2(n+1) =
term2(n)*term2_inner(n);

(product(2*cos(2^k*x)-1, k = 0 .. n-1))*(2*cos(2^n*x)-1)

is(combine(subs(IH,%)) = term1(n+1));

true

 

Download CosProductInduct.mw

1 2 3 4 5 6 7 Last Page 1 of 709