Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Carl Love Can't say I've ever seen the show.  I realized that removing the uppercase matching would change the algorithm; that was done merely to  avoid the nuisance of eliminating too many matches.  Figured a more interested party would restore it. 

You shouldn't have to use Typseset notation; it works fine for me in Maple 16 with the output display as 2D Math Notation (my normal setting).

Alas, Maple's use of MathML isn't documented. It uses a functional notation, rather than the tags of MathML, but the function names are the same as the MathML tags, which you can find on the web. Not all elements of MathML are handled. To figure out how a particular 2D display is represented, enter it into a 2D input region, select it, right-click, and convert it to an atomic identifier ( 2D-Math -> Convert To -> Atomic Identifier).  Then either copy and paste that to an input region, or evaluate and ?lprint the result. 

I've uploaded a Maple 16 worksheet that assigns BreakBad, shows an example of its usage, and shows an example of converting a 2D input to an atomic identifier and displaying the MathML

BreakBad.mw

While it may not be a concern, you should be able to use the symbolic Pi (but not pi, Maple is case sensitive).

While it may not be a concern, you should be able to use the symbolic Pi (but not pi, Maple is case sensitive).

@brian bovril The 2D parser is the issue; I'll track that down and file a bug when I get a chance. To work-around it, copy and paste the original code (above) into a Maple input region (1D).  The code is fine.

@brian bovril The 2D parser is the issue; I'll track that down and file a bug when I get a chance. To work-around it, copy and paste the original code (above) into a Maple input region (1D).  The code is fine.

Nice start.  Rather than using textplot I think using Maple's mathml formatting might be a better approach. Here I've added some functionality to your module to do that. The output will only display properly in Standard Maple.  I used a crude method to avoid collisions in the matches, it can be improved.

BreakBad := module()

uses ST = StringTools
    , ST_PD= StringTools:-PatternDictionary
    , SC= ScientificConstants
    , LT = ListTools
    ;

export ModuleApply;


    # PatternDictionary is case sensitive. Thus, all text is uppercased for searching.

local Dict, Format, RetStr;
    # Periodic (remember) Table of Elements:
    # Map from uppercase elem symbs to standard capitalized symbs.
#    PTE := proc(EL::string) option remember; ST:-Capitalize(EL) end proc

    # Dictionary of uppercased elem symbs.
#    , Dict:= ST_PD:-Create(ST:-UpperCase ~ ([SC:-GetElements()]))
    Dict := ST_PD:-Create(map2(cat,"",[SC:-GetElements()]));

    # ST_PD:-Search returns seq of 2-member lists, with 2nd member
    # being the dict. id# of found pattern. RetStr is operator that turns that id#
    # into standard elem symbol.
    RetStr := curry(applyop, curry(ST_PD:-Get, Dict), 2);
    Format := proc(txt,wt)
    local s;
        if txt = "" then
            "";
        elif searchtext(" ",txt)<>0 then
            # Spaces at the ends of symbols are elided.
            # This avoids that by converting all spaces
            # to an invisible times operator.
            ST:-Join([seq(`if`(s=""
                               , "mo(&InvisibleTimes;)"
                               , thisproc(s,wt)
                              ), s = ST:-Split(txt))]
                     , ",");
        else
            sprintf("mi(\"%s\",fontweight=\"%s\")", txt, wt);
        end if;
    end proc;

    ModuleApply := proc(S::string)
    local bold,e,elems,mathml,plain,rngs,i,r;
        elems := RetStr ~ ([ST_PD:-Search](Dict, S));
        elems := sort(elems, (a,b) -> evalb(a[1]<=b[1]));
        elems := LT:-MakeUnique(elems, 1, (x,y)->x[1]=y[1]);
        elems := [[1,""], elems[],[0,""]];
        rngs := [seq(op([i,1],elems)+length(op([i,2],elems))..op([i+1,1],elems)-1
                     , i = 1..nops(elems)-1)];
        bold := [seq(Format(e[2],"bold"), e=elems)];
        plain := [seq(Format(S[r],"normal"), r=rngs)];
        mathml := remove(`=`, LT:-Interleave(bold,plain), "");
        nprintf("#mrow(%s)", ST:-Join(mathml, ","));
    end proc;

end module:

Nice start.  Rather than using textplot I think using Maple's mathml formatting might be a better approach. Here I've added some functionality to your module to do that. The output will only display properly in Standard Maple.  I used a crude method to avoid collisions in the matches, it can be improved.

BreakBad := module()

uses ST = StringTools
    , ST_PD= StringTools:-PatternDictionary
    , SC= ScientificConstants
    , LT = ListTools
    ;

export ModuleApply;


    # PatternDictionary is case sensitive. Thus, all text is uppercased for searching.

local Dict, Format, RetStr;
    # Periodic (remember) Table of Elements:
    # Map from uppercase elem symbs to standard capitalized symbs.
#    PTE := proc(EL::string) option remember; ST:-Capitalize(EL) end proc

    # Dictionary of uppercased elem symbs.
#    , Dict:= ST_PD:-Create(ST:-UpperCase ~ ([SC:-GetElements()]))
    Dict := ST_PD:-Create(map2(cat,"",[SC:-GetElements()]));

    # ST_PD:-Search returns seq of 2-member lists, with 2nd member
    # being the dict. id# of found pattern. RetStr is operator that turns that id#
    # into standard elem symbol.
    RetStr := curry(applyop, curry(ST_PD:-Get, Dict), 2);
    Format := proc(txt,wt)
    local s;
        if txt = "" then
            "";
        elif searchtext(" ",txt)<>0 then
            # Spaces at the ends of symbols are elided.
            # This avoids that by converting all spaces
            # to an invisible times operator.
            ST:-Join([seq(`if`(s=""
                               , "mo(&InvisibleTimes;)"
                               , thisproc(s,wt)
                              ), s = ST:-Split(txt))]
                     , ",");
        else
            sprintf("mi(\"%s\",fontweight=\"%s\")", txt, wt);
        end if;
    end proc;

    ModuleApply := proc(S::string)
    local bold,e,elems,mathml,plain,rngs,i,r;
        elems := RetStr ~ ([ST_PD:-Search](Dict, S));
        elems := sort(elems, (a,b) -> evalb(a[1]<=b[1]));
        elems := LT:-MakeUnique(elems, 1, (x,y)->x[1]=y[1]);
        elems := [[1,""], elems[],[0,""]];
        rngs := [seq(op([i,1],elems)+length(op([i,2],elems))..op([i+1,1],elems)-1
                     , i = 1..nops(elems)-1)];
        bold := [seq(Format(e[2],"bold"), e=elems)];
        plain := [seq(Format(S[r],"normal"), r=rngs)];
        mathml := remove(`=`, LT:-Interleave(bold,plain), "");
        nprintf("#mrow(%s)", ST:-Join(mathml, ","));
    end proc;

end module:

@Carl Love Mostly it's a habit: the stuff I typically work on invariably have lots of procedures, both local and exported, and likely submodules. In posting this I'm trying to give a flavor for what can be done, but on a small scale, though it may be unnecessary for the problem at hand. If I were really constructing a large Array of records I'd probably do 

Array(map(L -> Record['packed']('upperbound'=L[1], 'grade'=L[2]), [ [10, "flunked"], ... ]);

@Carl Love Mostly it's a habit: the stuff I typically work on invariably have lots of procedures, both local and exported, and likely submodules. In posting this I'm trying to give a flavor for what can be done, but on a small scale, though it may be unnecessary for the problem at hand. If I were really constructing a large Array of records I'd probably do 

Array(map(L -> Record['packed']('upperbound'=L[1], 'grade'=L[2]), [ [10, "flunked"], ... ]);

To clarify Axel's comment. The code shown uses print, which means the value is printed but nothing (NULL, actually) is returned.  Beginning Maple programmers frequently use print, rather than return. Printing has its uses, but for most things, returning the computed values is better in that it allows you do something with them, rather than just inspecting them.

To clarify Axel's comment. The code shown uses print, which means the value is printed but nothing (NULL, actually) is returned.  Beginning Maple programmers frequently use print, rather than return. Printing has its uses, but for most things, returning the computed values is better in that it allows you do something with them, rather than just inspecting them.

Please post the relevant code.  Or upload the worksheet (green arrow).

What are you looking for?  An equation?  A 3D plot?  Are you supposed to model a roller coaster (i.e. generate a dynamic simulation) or create a picture  of one? Or make a working prototype (that would be quite an engineering class, let alone a math class)?

Note that the same procedure works with nine balls. More generally, with w weighings, one can find a single heavy ball in a group of 3^w balls, ignoring practical considerations like  the precision of the scale. One might ask why wasn't the puzzle posed with 9 balls.  Probably because 9's factorization makes it easier to guess the solution.

It's a fork in the road, so there are three directions.  Suppose he points in the direction from which you came?  

First 52 53 54 55 56 57 58 Last Page 54 of 195