Carl Love

Carl Love

28050 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@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

@vs140580 The limitation of your Excel is that the number of columns must be less than 256. So how is writing row-by-row going to help with that? Did you intend for there to be 256 columns or 16 columns? If 16, then it's trivial to correct it in Maple. For example, instead of sending to Excel, you could send A[.., ..16] (if the 1st 16 columns have the numbers that you want).

@vs140580 For the situation you now describe, the variables ABC, etc., are not needed, and I recommend that you not use them. All that you need is

for i to n do OutMat[i]:= F(M[i]) od;

where and OutMat are matrices with n rows (they don't need the same number of columns) and takes vector input and produces vector output.

By the way, the word doubt in your most-recent Reply's title should be question. I mention this because if you use doubt that way, it could be misunderstood as slightly offensive, and I doubt that that was your intention.

@Christopher2222 The context menu works for that. For example, enter 

20.*Unit(MPa);

select (i.e., mouse-highlight) the output, right click, choose Convert Output Units, enter psi in the Enter Unit field (the other fields can be ignored), and click Okay.

What you're experiencing is an issue with the display (the display only, not the computation) of all vectors and matrices above a certain size; it's not specific to unit conversion. In other words, all the computations (unit conversions in this case) have been done and are stored in the vector, but that vector is not being shown (or shown completely) on your screen. The default number of rows (r) or columns (c) shown is 10. You can change that setting with the command

interface(rtablesize= [r, c]):

where r and c are nonnegative integers or infinity. This only needs to be done once per session (i.e., per restart).

@Earl Yes, MaplePrimes might have a problem with the worksheet name; try removing the underscores.

@Christian Wolinski You can give a name to that "unnamed module" if you want:

main:= ():
main:-`+`(1, 1.1);

 

Try uploading the worksheet with the "Insert contents" button instead of the "Insert link" button. In my experience, this always inserts the link even if it fails to insert the contents.

@Christian Wolinski Sorry, I misread your Question. I read "undo" as "do".

Have you read the help page ?overload and not understood it? Or were you not aware of the help page?

I wrote:

  • It's asking min for the position in the list of the minimal entry rather than the entry itself.

And the reason that I did that is that the Question asks not for the minimal value of but rather for the value of z that produces the minimal value of F.

First 88 89 90 91 92 93 94 Last Page 90 of 709