Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Carl Love It should be noted that my technique above is not limited to selecting the first entries. Any one entry from each class can be selected. The following selects a random equation from each class:

R:= 1+~(rand@nops)~((AA2:= ([entries]@op~@ListTools:-Classify)(lhs, AA))):
AnyCombo:= ()-> op~(R(), AA2):
AnyCombo();

AnyCombo();

For 2D-Input the first line of code may need to be changed to

AA2:= ([entries]@op~@ListTools:-Classify)(lhs, AA):
R:= 1+~(rand@nops)~(AA2):

 

@vv Thank you. In the meantime, both the worksheet's original creator and I have noticed several other anomalies with the output display from this worksheet.

@Teep Indeed, there is something very odd that is specific to the output display in your worksheet. I don't know what it is; perhaps you made some setting, or perhaps it's some type of corruption. I had already posted a separate Question about it: "Bad output display from LPSolve".

@tomleslie I disagree with what you said in two ways.

First, I think that there are often good reasons for extracting the numeric data from a plot rather than generating it by other means. I do it very often. My most-common reason is to get the min and max of the plotted points in all dimensions in order to programmatically set a view that is slightly larger than those ranges. My second most-common reason is to track down the specific parameter values that have led to some plot anomaly.

Second, I think that the OP has provided enough detail in this case that the Question can be adequately Answered.

@TechnicalSupport For a table of unknown expressions, it's much more likely that Grid will work and Threads won't. Of course, if both could work,Threads is likely to be more efficient; but that's a very unlikely "if". Grid is also much easier for a newbie to understand, whereas Threads nearly requires a CompSci degree or equivalent. (This is not meant as a criticism of Threads, which is necessarily difficult to understand; rather than being difficult due to a poor implementation or documentation.)

You have a bug in your second constraint set. You refer to a vector Supply which hasn't been defined. I assume that you mean the vector RegionA. This is what I used in my Answer below.

So x is a 3D array. You've probably figured out by now that x can be declared in Maple via

x:= Array(1..n, 1..k, 1..r);

I understand squaring of individual elements of x. Indeed, the 1st part of your TSS formula is the sum of the squares of all elements of x, which can be done in Maple simply as add(x^~2) (note the tilde ~). But I don't know what you mean by the "squares" of "slices" of x, such as in your SS_P formula x[i, .., ..]^2/(k*r). I think that what you likely mean is the squares of the means (averages) of various rows, columns, planes of x. In that case, we'd need to first add the subsection of x, divide by the number of elements, then square the result.

@Tamour_Zubair I think that something can be done, but I think that you might have made a mistake in entering the system. One of Z_0(t)Z_1(t)Z_2(t) seems to be "extra". Did you really intend for the system to contain all three?

@acer Since acer couldn't upload his worksheet (due to limitations of MaplePrimes), here is a transcription:

restart;
with(Student:-Calculus1): with(DocumentTools): with(DocumentTools:-Layout):

P:=VolumeOfRevolution(2*x^2+1,x=0..1,volumeoptions=[color= ["Niagara 1"],
                      transparency=0.5],orientation=[0,90,0],labels=[z,x,y],
                      view=[-1..1,-2..2,0..3],output=plot,axis=vertical,
                      scaling=constrained):
P;

InsertContent(Worksheet(Group(Output(Textfield(InlinePlot(
   subsindets(plots:-display(P,size=[600,500]),'specfunc'(_TYPESET),
              u->_TYPESET(Typesetting:-Typeset~([op(u)])[])),
   ':-scale'=1.9,ytrans=2)))))):

 

@achreftabet The integral in your photo is a definite integral with respect to theta. Thus, its value cannot depend on theta.

@Christian Wolinski Christian, I'd appreciate any comments that you have on my Answer. It seems to me that it fulfills your two long-standing requests: 1) detecting overloads, and 2) undoing them.

@vs140580 Why haven't you first tried the simplest thing, which happens to also be the correct thing in this case?:

AnyOp:= proc(`&op`, F1, F2) 

I don't know where you got the idea below. It's not valid Maple syntax. Perhaps you are confusing Maple with some other language:

AnyOp:= proc(`&op`, Function::F1, Function::F2)

 

@tomleslie I can confirm that 11 Maple 10 worksheets are on the textbook's website that you linked. They're in a Google Drive folder that apparently one must request access to. The worksheets seem to have been posted in 2015.

@tomleslie The Question above does contain an uploaded worksheet/document; it's not a "picture". But for some reason the download link is missing. I guess the OP deleted the link by mistake.

Here's some major improvements to the above:

  • made predicate into a formal type
  • packaged as a module
  • eliminated false positives caused by deeply embedded overloads
  • allow extraction of just the member procedures
  • member procedures have their option overload made inert
     

    Some Simple Tools for Manipulating Overloaded Procedure

    Author: Carl Love <carl.j.love@gmail.com> 2022-Jun-19

     

    Goals:

    1. The ability to detect whether a procedure is constructed as an overload. (Note that the result of the overload command is nominally type procedure.)

     

    2. The ability to deconstruct an overload into an inert form that can be reconstructed with value. 

     

    3. The ability to extract the component procedures with their option overload declarations suppressed.

     

    :
    restart
    :

    kernelopts(version);

    `Maple 2022.1, X86 64 WINDOWS, May 26 2022, Build ID 1619613`

    OverloadTools:= module()
    option
        package,
        `Author: Carl Love <carl.j.love#gmail.com> 2022-Jun-19`
    ;
    local
        #Some abbreviations:
        `&<`:= curry,  `&>`:= rcurry,
        `&I`:= cat &< _Inert_,  `&SF`:= specfunc @ `&I`,

        ModuleLoad:= proc($)
        uses TT= TypeTools;
            if TT:-Exists(overload) then TT:-RemoveType(overload) fi;
            TT:-AddType(
                overload,
                P-> P::procedure and
                    membertype((&I STATSEQ)(&SF OVERLOADLIST), ToInert(eval(P)))
            );
            return
        end proc
    ;
    export
        UnOverload:= (P::overload)->
        local OPTS:= 3; #op-index of proc options
            indets(
                subsindets(
                    subsindets(
                        ToInert(eval(P)),
                        &SF OPTIONSEQ,
                        subs &< ("overload"= "%overload")
                    ),
                    &SF OVERLOADLIST,
                    %overload
                        @ %applyop~ &<
                            ((op@subs) &< (%overload= overload) @ `[]`, OPTS)
                        @ [FromInert]
                        @ op
                ),
                specfunc(%overload)
            )[-1],

        ExtractProcs:= (DC::%overload(list(specfunc(%applyop))))->
            ((op &< (-1))~ @ op)(DC)
    ;
        ModuleLoad()
    end module
    :

    #Example:

    Collatz:= overload([
        proc(n::And(posint, even), $) option overload; n/2 end proc,
        proc(n::And(posint, odd), $) option overload; 3*n+1 end proc,
        proc(n::algebraic, $) 'Collatz'(args) end proc
    ]):
    lprint[2](eval(Collatz));

    overload([proc( n::And(posint,even), $ )
        option overload;
        1/2*n;
    end proc, proc( n::And(posint,odd), $ )
        option overload;
        3*n+1;
    end proc, proc( n::algebraic, $ )
        ('Collatz')(_passed);
    end proc])

    with(OverloadTools);

    [ExtractProcs, UnOverload]

    type~([Collatz, x-> x], overload);

    [true, false]

    #Simple test cases:
    N:= [22, 11, n]
    :
    Collatz~(N);

    [11, 34, Collatz(n)]

    #Deconstruct:
    Decon:= UnOverload(Collatz);
    lprint[2](Decon):

    %overload([%applyop(`@`(proc () options operator, arrow; (`@`(op, subs))(%overload = overload, args) end proc, `[]`), 3, proc (n::(And(posint, even)), ` $`) option %overload; (1/2)*n end proc), %applyop(`@`(proc () options operator, arrow; (`@`(op, subs))(%overload = overload, args) end proc, `[]`), 3, proc (n::(And(posint, odd)), ` $`) option %overload; 3*n+1 end proc), %applyop(`@`(proc () options operator, arrow; (`@`(op, subs))(%overload = overload, args) end proc, `[]`), 3, proc (n::algebraic, ` $`) ('Collatz')(args) end proc)])

    %overload([%applyop((() -> (op@subs)(%overload = overload,_passed))@`[]`,3,proc
      ( n::And(posint,even), $ )
        option %overload;
        1/2*n;
    end proc), %applyop((() -> (op@subs)(%overload = overload,_passed))@`[]`,3,proc
      ( n::And(posint,odd), $ )
        option %overload;
        3*n+1;
    end proc), %applyop((() -> (op@subs)(%overload = overload,_passed))@`[]`,3,proc
      ( n::algebraic, $ )
        ('Collatz')(_passed);
    end proc)])

    #If you want just the procedures...
    CzProcs:= ExtractProcs(Decon);
    lprint[2]~(CzProcs):

    [proc (n::(And(posint, even)), ` $`) option %overload; (1/2)*n end proc, proc (n::(And(posint, odd)), ` $`) option %overload; 3*n+1 end proc, proc (n::algebraic, ` $`) ('Collatz')(args) end proc]

    proc( n::And(posint,even), $ )
        option %overload;
        1/2*n;
    end proc
    proc( n::And(posint,odd), $ )
        option %overload;
        3*n+1;
    end proc
    proc( n::algebraic, $ )
        ('Collatz')(_passed);
    end proc

    #Verify extracted procs work like originals:
    apply~(CzProcs, N);

    [11, 34, Collatz(n)]

    #Reconstruct the overload from its deconstruction:
    Collatz2:= value(Decon);
    lprint[2](eval(Collatz2));

    proc () [proc (n::(And(posint, even)), ` $`) option overload; (1/2)*n end proc, proc (n::(And(posint, odd)), ` $`) option overload; 3*n+1 end proc, proc (n::algebraic, ` $`) ('Collatz')(args) end proc] end proc

    overload([proc( n::And(posint,even), $ )
        option overload;
        1/2*n;
    end proc, proc( n::And(posint,odd), $ )
        option overload;
        3*n+1;
    end proc, proc( n::algebraic, $ )
        ('Collatz')(_passed);
    end proc])

    #Verify it works like the original:
    Collatz2~(N);

    [11, 34, Collatz(n)]

     

  •  

    Download OverloadTools.mw

First 87 88 89 90 91 92 93 Last Page 89 of 708