Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

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

@dharr My comments regarding the is and coulditbe statements were strictly regarding those statements in the OP's followup entitled "p. s.". It looks to me as if he took term1 from the Question and substituted x= t/2^n, but also took term2 and substituted x= t/2^(n-1). Thus the is(term1 = term2) correctly returns false in "p. s.". The false return from is in the Question is a problem. If it can't prove the identity, but also finds no counterexample, it should return FAIL.

@vv Thank you; I stand corrected. I was previously aware of this distinction, but I forgot to apply it here. Nonetheless, the graphical evidence of the (nearly) space-filling curves suggests to me that in this case those are indeed the liminf and limsup.

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