Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@taro Thank you. Yes, the code was intended as an educational illustration rather than for any practical computation, and I see that it has served that educational purpose. The output of the code is in fact the MESH form that could be used inside PLOT3D to produce the same plot. In other words, the following two PLOT3Ds produce the same plot:

PLOT3D(GRID(1..2, 1..3, k)), 
PLOT3D(MESH(ExpandGrid(GRID(1..2, 1..3, k)));

@rcorless Inert percent-sign operators are neither obscure nor old. Some form of inertness is needed to achieve the OP's goal. It could also be done with add and ``, but I think Kitonum's solution is the best possible. 

Why not just do the following, which is over 60 times faster than working through the EmpiricalDistribution?

my_data:= [1, 2, 4, 5.5, 5.5, 6]:
Statistics:-Bootstrap(
    Statistics:-Mean, my_data, samplesize= 4, replications= 10000
);

 

@dharr I think that the OP only needs to do this:

interface(typesetting= extended, prettyprint= 3):
Typesetting:-EnableTypesetRule(Typesetting:-SpecialFunctionRules);

I need to do this 2nd line in Maple 2021.2 to enable the MeijerG rule, and others.

@janhardo It's easy to add dots and to change square brackets to parentheses, but I don't know how to remove or change the legend border.

InterPlot:= proc(f1,f2)
local 
    F:= [f1,f2], x:= indets(F, And(name, Not(constant)))[], 
    y, v:= [x,y], Int:= solve(y=~ F, v)
;
    plots:-display(
        plot(
            F, (v=~ (min-1..max+1)~(map(eval~, v, Int)))[],
            legend= (y=~F), color= [blue, red]
        ),
        plot(
            map2(eval, v, Int), style= point, symbol= solidcircle,
            symbolsize= 16
        ),
        plots:-textplot(
            map2(eval, [v[],``(v[])], Int), 
            align= [above, left], color= magenta
        )
    )
end proc
:
pl:= (InterPlot@op)~(
    [x^~[1,3], x^~[2,4], x^~[-1,-2], x^~[2,1/2], [x^3, abs(x^(1/3))]]
):
DocumentTools:-Tabulate(
    widthmode= percentage, width= 75, [pl[1..2], pl[3..4], pl[5..5]]
):

 

Making some small changes to my above code to accommodate the style of your worksheet, I got this:

InterPlot:= proc(f1,f2)
local 
    F:= [f1,f2], x:= indets(F, And(name, Not(constant)))[], 
    y, v:= [x,y], Int:= solve(y=~ F, v)
;
    plots:-display(
        plot(
            F, (v=~ (min-1..max+1)~(map(eval~, v, Int)))[],
            legend= (y=~F), color= [blue, red]
        ),
        plots:-textplot(
            map2(eval, [v[],v], Int), 
            align= [above, left], color= magenta
        )
    )
end proc
:
pl:= (InterPlot@op)~(
    [x^~[1,3], x^~[2,4], x^~[-1,-2], x^~[2,1/2], [x^3, abs(x^(1/3))]]
):
DocumentTools:-Tabulate(
    widthmode= percentage, width= 75, [pl[1..2], pl[3..4], pl[5..5]]
):

Please give a more-elaborate definition of a Bohemian matrix and some small examples. I'm particularly confused by the use of "height" in your definition.

@tomleslie Geez, Tom, give the guy a break. It's obviously his first time on MaplePrimes.

If you want to get all complex solutions, add option complex to fsolve, as in

x =~ {fsolve}(g(x) - y, complex)

The { } makes the result of fsolve into a set. The makes it a set of equations rather than a single equation whose right side is a set.

[I have no expertise in this field. I'm only reporting what I just learned from Wikipedia.]

From my reading of the Wikipedia article "Vapour pressure of water" and the closely linked articles on the various formulas, I get the impressions that

  1. there are numerous approximation formulas used for this,
  2. the formulas have been revised many times in the past century or so,
  3. there is no general agreement as to a single best formula,
  4. the "below 0" range that you're looking at is especially problematic.

Here's a substantial update to the code above to handle all inert forms of exponentiation also. I also added extensive comments.

#This code must be parsed as 1D input.
FlattenPowers:= module()
description 
    "An appliable module to insert an explicit ^ operator into the "
    "prettyprinted forms of expressions with exponents"
;
option `Author: Carl Love <carl.j.love@gmail.com>, 2022-Jan-11`;
uses T= Typesetting;
local
    ModuleLoad:= proc() #Add types
    uses TT= TypeTools, ST= StringTools;
    local
        Types:= [
            [
                #inert functions with any number of %s   
                Inert,
                (f, s::{symbol, string}, n::nonnegint)->
                    f::function and op(0,f)::symbol and
                    ST:-RegMatch("^%+\\" || s || "$", op(0,f)) and 
                    (nargs=3 implies f::(n &under nops))
            ],
            [
                #patfunc to match the beginning arguments and ignore
                #the rest
                Patfunc, 
                (f, T::seq(anything))-> evalb(f::patfunc(T, anything))
            ],
            [
                #combine specfunc and Patfunc
                Specfunc, 
                (f, s, T::seq(anything))-> 
                    f::specfunc(s) and f::Patfunc(T)
            ]
        ]
    ;
        for local T in Types do
            if TT:-Exists(T[1]) then TT:-RemoveType(T[1]) fi;
            TT:-AddType(T[])
        od;
        return
    end proc,
    
    #Procedure Hold maintains a table, _Hold, that matches the typeset
    #forms of implicitly inert expressions with their typeset form
    #correctly annotated as inert.

    _Hold:= table(),
    Hold:= proc(pi, p)
    option remember;
    local ts:= T:-Typeset(T:-EV(pi));
        _Hold[ts]:= T:-mcomplete(ts, T:-_Hold([p]));
        pi
    end proc,
    
    ModuleApply:= proc(ex)
    local 
        `&_p`, `&_pi`, R, p:= "&amp;&lowbar;p", pi:= cat(p, "i"),
        e:= "&ExponentialE;", inert_color:= 'mathcolor'= "#909090"
    ;
        #Step 1: 
        #   a. Replace the main operator in expressions with
        #      superscripted exponents with a neutral `&` binary infix
        #      operator.
        #   b. Retain info to annotate typeset forms of inert
        #      expressions.

        R:= evalindets(
            ex, 
            {
                anything^Not(-1), specfunc(Not(1), exp), 
                Inert~(["^", exp], [2,1])[]
            }, 
            p-> 
                if p::`^` then
                    if op(2,p)::And(rational, negative) then
                        1/(op(1,p) &_p (-op(2,p)))
                    else
                        `&_p`(op(p))
                    fi
                elif p::specfunc(exp) then exp(1) &_p op(p)
                else #inert
                    Hold(
                        if p::Inert(exp) then %exp(1) &_pi op(p)
                        else `&_pi`(op(p))
                        fi,
                        p
                    )
                fi
        );

        #Step 2:
        #   a: Typeset the expression.
        #   b: Add the annotation for inert forms that is stored in
        #      _Hold.
        #   c: Remove extra parentheses (T:-mfenced) around e.

        R:= subsindets(
            subs({indices}(_Hold, 'pairs'), T:-Typeset(T:-EV(R))),
            Specfunc(
                T:-mfenced,
                {
                    Specfunc(T:-mcomplete, Specfunc(T:-mo, e)),
                    Specfunc(T:-mo, e)
                }
            ),
            op
        );

        #Step 3:
        #   a. Replace special neutral `&` operators with "^".
        #   b. Remove extra spaces.
        #   c. Color the "^" appropriately if it's inert.
                
        subsindets(
            R,
            Patfunc(
                anything,
                specfunc(T:-mspace),
                Specfunc(T:-mo, {p, pi}),      
                specfunc(T:-mspace)
            ),
            f-> subsop(
                2= (), 
                3= T:-mo(
                    "^", #could also use "&circ;"
                    `if`(op([3,1], f)[-1]="i", inert_color, '()'),
                    op([3,2..], f)
                ), 
                4= (), 
                f
            )
        )        
    end proc
;
    ModuleLoad()
end module
:
#Example usage:
ex:= [
    1/sqrt(a), a^4/(a+b%^2)^3, %exp(x), a%^x, 1/a, 1/a^2,
    exp(-(x-mu)^2/2/sigma^2), exp(1)
];
FlattenPowers(ex);

 

@mmcdara I mean like this:

A:= Array(1..2, 1..3, 1..4, (i,j,k)-> i+2*j+3*k):
perm:= [2,1,3]:
TA:= Array(rtable_dims(A)[perm], ()-> A[args[perm]]):

@mmcdara Thanks. The methods in all of our Answers build a new copy of the Array rather than simply use a new indexing method on the existing Array. In some situations, a new indexing method might be more efficient. It would need to be coded from scratch though (not difficult, there is a help page on it).

Regarding your Answer: There's no need to suppose that the dimensions being transposed have the same bounds.

@janhardo I think that saying that it's "only a notation" understates the massive importance of this formula to Number Theory. For one thing, it shows the connection between primes and the Zeta function. Note that the sum side of the formula is by definition Zeta(s), and that s is not necessarily real.

@janhardo Okay, I now understand where you got this idea:

  • There are two approaches to defining a complex function in Maple. Method 1. Make f(x, y) a function of two real variables x, y. Method 2. Make f(z) a function of the complex variable z.

The idea shown in that worksheet is correct; however, the example function used, z-> z^4, is way too trivial to illustrate the pros and cons of either method. (Perhaps the worksheet continues on to some deeper examples that you haven't shown.) But note that the two methods are being used to define the same function

Those two methods have nothing to do with the definitions of one-argument arctan and two-argument arctan as shown by FunctionAdvisor. As I said, those are two different functions that just happen to both be named arctan. It's this coincidence of the name that leads to your confusion.They might as well be named arctan(z) and foobar(y,x). Some simple plots should convince you that they're different. Now, of course, they are related to each other, hence the same-name thing, but that is not the same thing as being the same function defined differently.

Maple has many examples of "families" of functions with the same name that are distinguished only by their number of arguments. I'm not a fan of this practice (partly because it makes the first several lines of those procedures and many of their associated subprocedures difficult to read), but that's the way it is. Some important examples are

  1. the Riemann Zeta function Zeta(...), which is of fundamental importance to the intersection of complex analysis with the study of prime numbers, and is the subject of one of the most-important (perhaps the most-important) unsolved problems in mathematics: the Riemann Hypothesis;
  2. GAMMA, which generalizes factorials to complex numbers; GAMMA restricted to real numbers is of fundamental importance in statistics;
  3. LambertW, the inverse function of x-> x*exp(x); like most functions defined as inverse functions, it has many branches.

Regarding the use of back quotes in that worksheet: They are simply being used to make what are essentially string literals (though the constructed objects are actually type symbol rather than string).  Any characters can be placed between them, including control characters and non-ASCII characters. Usually, but not always, their​​​​​​ prettyprinted display is italicized and without quotes. This is what's being done by the `f(x,y)`, The ` ` doesn't seem to be doing anything other than displaying ` `, for whatever that's worth.

There are many uses of back quotes in Maple, and not only for display purposes. They can seem quite different, but all can be understood in this framework:

  1. The constructed object is always type symbol.
  2. There is some desire or need that the characters in the symbol not be interpreted, at least initially, by the kernel. Often this is because they wouldn't make sense syntactically.
  3. There is some desire that the characters be interpreted in some alternate way, perhaps at some future time. This alternate interpretation can be by the kernel, the display, the plot renderer, some other program, or perhaps simply a human reader.
First 103 104 105 106 107 108 109 Last Page 105 of 709