Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

I'm not aware that lfsrlength is a Maple command.  Was it a procedure that you assigned? If so, how did you assign it?

There isn't a good way to do that.  Using quotes is robust and only two more characters.  Here is a bad way to do what you want; it only works if the subdirectories are valid Maple names, are not assigned, don't appear more than once, and manage to stay in the desired order, which isn't guaranteed. Basically, you're asking for trouble using this.

frac2path := proc(p :: `*`)
local N,D;
    (N,D) := (numer,denom)(p);
    if member(N, '{c,d}') then
        N := cat(N,":");
    end if;
    StringTools:-Join([op(N),op(D)], "/");
end proc:

frac2path(c/b/x);
                                   "c:/x/b"

Note that the directories have swapped places. Like I said, bad idea.

There isn't a good way to do that.  Using quotes is robust and only two more characters.  Here is a bad way to do what you want; it only works if the subdirectories are valid Maple names, are not assigned, don't appear more than once, and manage to stay in the desired order, which isn't guaranteed. Basically, you're asking for trouble using this.

frac2path := proc(p :: `*`)
local N,D;
    (N,D) := (numer,denom)(p);
    if member(N, '{c,d}') then
        N := cat(N,":");
    end if;
    StringTools:-Join([op(N),op(D)], "/");
end proc:

frac2path(c/b/x);
                                   "c:/x/b"

Note that the directories have swapped places. Like I said, bad idea.

That was what I guessed you were doing, which is why I asked "why". Using a counter is the proper way to do so.  It is more efficient, you don't have to create the unneeded list. If you are using the table to, say, prevent O(n^2) list building, then by using a counter you can also reuse the table structure the next time you need it.  That is, all you have to do is reset the counter to zero.  There may be extra entries in the table when you reuse it, but if you only access those from 1 to the count then you will be fine.  This saves memory and time compard with starting with a new (empty) table each time because allocating the link chains that make up the table's internal structure has a cost.  Reusing the existing structure and just replacing the entries as needed is cheaper.

That was what I guessed you were doing, which is why I asked "why". Using a counter is the proper way to do so.  It is more efficient, you don't have to create the unneeded list. If you are using the table to, say, prevent O(n^2) list building, then by using a counter you can also reuse the table structure the next time you need it.  That is, all you have to do is reset the counter to zero.  There may be extra entries in the table when you reuse it, but if you only access those from 1 to the count then you will be fine.  This saves memory and time compard with starting with a new (empty) table each time because allocating the link chains that make up the table's internal structure has a cost.  Reusing the existing structure and just replacing the entries as needed is cheaper.

@Alejandro Jakubi One reason they don't change is that doing so would break a lot of Maple code, both internally and in user-land. Both ?has and ?member are builtin procedures and have been so for as long as I recall. 

Possibly my conjecture of how the argument order for has and member might have been chosen will permit one to recall that order.  That is, translate the natural English order of the predicate from infix to functional notation.

@Alejandro Jakubi One reason they don't change is that doing so would break a lot of Maple code, both internally and in user-land. Both ?has and ?member are builtin procedures and have been so for as long as I recall. 

Possibly my conjecture of how the argument order for has and member might have been chosen will permit one to recall that order.  That is, translate the natural English order of the predicate from infix to functional notation.

Consider their inline English equivalents: "circus has [a] bear" and "bear member [of a] circus."  The direct translation to the function form is "has(circus,bear)" and "member(bear, circus)."  I believe this is the reason for their order. 

Consider their inline English equivalents: "circus has [a] bear" and "bear member [of a] circus."  The direct translation to the function form is "has(circus,bear)" and "member(bear, circus)."  I believe this is the reason for their order. 

So what's the problem?  yc is assigned 1 after executing that.

So what's the problem?  yc is assigned 1 after executing that.

I'm a bit confused, though.  What happens at the end?  You appear to come out of the Kein bottle (i.e. the journey appears to be through a curving tube).  But that isn't right.  You have to reverse direction to get out.

Posting the question as a Word document is less than ideal.

So I take it you want a procedure that works with symbolic groups, that is, groups whose elements are symbols rather than positive integers?  To avoid defining the elements of the group, you could do

ApplyGroup := proc(grp::list(list), elem)
local djc, p;
    for djc in grp do
        if member(elem,djc,'p') then
            break;
        end if;
    end do;
    if p = 'p' then return elem; end if;
    djc[modp(p,nops(djc))+1];
end proc:

grp := [[a,b],[c,d,e]]:
map2(ApplyGroup, grp, [a,b,c,d,e,z]);
              [b, a, d, e, c, z]                                                       

This assumes that the group (grp) is in disjoint cyclic notation.

So I take it you want a procedure that works with symbolic groups, that is, groups whose elements are symbols rather than positive integers?  To avoid defining the elements of the group, you could do

ApplyGroup := proc(grp::list(list), elem)
local djc, p;
    for djc in grp do
        if member(elem,djc,'p') then
            break;
        end if;
    end do;
    if p = 'p' then return elem; end if;
    djc[modp(p,nops(djc))+1];
end proc:

grp := [[a,b],[c,d,e]]:
map2(ApplyGroup, grp, [a,b,c,d,e,z]);
              [b, a, d, e, c, z]                                                       

This assumes that the group (grp) is in disjoint cyclic notation.

First 84 85 86 87 88 89 90 Last Page 86 of 195