Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Markiyan Hirnyk Yes, the 'accept' option was one of the features I added and have not yet submitted. It permits assigning a predicate (that is, a procedure that returns true or false) to qualify the output.  At the moment you can do the following

with(Iterator):

VecToStr := proc(V)
local i;
    cat("",seq('(i,"+*/-"[V[i]+1])',i=1..8),"9=100")
end proc:

iter := MixedRadixTuples([4$8]
                          , 'transformer' = VecToStr  # Assign VecToStr as before
                        ):

for s in iter do
    if evalb(parse(s)) then
        printf("%s\n", s);
    end if;
end do:

@Carl Love Because Div is sorted, a binary search can be used in place of a sequential search to determine k, however, whether it pays off depends on how efficient you can make it.  A simpler change is to count downwards from Nsq rather than upwards from 1; that reduces the search on the average (at least for the integers I was playing with). 

Followup

I implemented a binary search, but the typical search isn't long enough to get a payback for the overhead, so there was no time saving.

Thanks for the interesting post. The task of generating all factorizations, given the prime factorization, is equivalent to computing all partitions of a multiset. I've just locally added an iterator, MultiPartition, for doing so to the Iterator package and will update the package in the Application Center shortly.

Your procedure can be improved, for large integers, by avoiding the O(n^2) list-building employed in two places.  Here is a modification that uses a table to build the lists.

Factoring := proc(n::posint, m::posint)
local p, L, M, Div, k, i, j, K, cnt, Omega;
uses NT=numtheory;
    if n=1 then error "should be n>1"; fi;
    Omega := NT:-bigomega(n);
    if nargs=2 and m>Omega then
        error "should be m<=%1",Omega;
    fi;
    if _params['m']=NULL then
        p:=Omega;
    else
        p:=m;
    fi;
    L[1]:=[[n]];
    Div:=sort(convert(NT:-divisors(n) minus {1, n}, list), `>`):
    M := table();
    cnt := 0;
    for k in Div while n/k<=k do
        cnt := cnt+1;
        M[cnt] := [n/k, k];
    od;
    M := [seq(M[cnt], cnt=1..cnt)];
    L[2]:=M;
    K := table();
    for i from 3 to p do
        cnt := 0;
        for j from 1 to nops(L[i-1]) do
            Div := NT:-divisors(L[i-1][j,i-1]) minus {1, L[i-1][j,i-1]}:
            for k in Div do
                if k<=(L[i-1][j][i-1])/k and L[i-1][j][i-2]<=k then
                    cnt := cnt+1;
                    K[cnt] := [op(L[i-1][j][1..i-2]), k, (L[i-1][j][i-1])/k];
                fi;
            od;
        od;
        L[i]:=[seq(K[cnt],cnt=1..cnt)];
    od;
    if _params['m']=NULL then
        [seq(op(L[i]), i=1..p)]
    else
        L[m];
    fi;
end proc:

@Carl Love It (reset) is a method of the iterator.  The iterators constructed by the Iterator package are Maple objects (also new for Maple 16). Methods of Maple objects are called differently than exports of modules.  That is, rather than doing, say, Y:-reset(), one does reset(Y).  For those versed in the standard Maple syntax (myself included), the notation is, at first, surprising.  Maple's kernel handles this by detecting that Y is an object and then checks whether it has a method named reset.  At least that's how I understand it.  

Here is a partial listing of the code that assigns the base object used by the iterators in the Iterator package.

module iterator()
option object;       # this designates an object

export ModuleCopy
    ,  ModuleIterator
    ,  length
    ,  output
    ,  reset
    ;
       reset :: static := proc(self :: iterator, $)
       local i;
           for i to numelems(self:-A0) do
               self:-A[i] := self:-A0[i];  # restore the state-vector to the initial value
           end do;
           self;
       end proc;

(* the rest is elided, it consists of local declarations and the remaining procedure assignments *)
end module:

The only documentation for reset is in the main help page of the Iterator package.  I should probably expand it a bit. Not all the iterators in the package need to be reset to be reused, but some do (it depends whether the state-machine returns to the initial state at the completion).

Bug

I just noticed that the documentation for the TopologicalSorts iterator suggests there is a bug in it (look at the first example in its help page). The problem is that it returns the inverse permutation rather than the normal permutation.  The inverse is suitable for solving a Young tableau.  I've since added an inverse option to the procedure so you can choose one or the other.  I'll update the package shortly.

I've updated the source and help page and uploaded it to the Application Center.

Could upload a worksheet that demonstrates the problem?

Wouldn't the issue be mostly avoided if we, the users, used the "Reply to This" link when responding to a previous response?

 

@acer Consider using ?FileTools[TemporaryDirectory] for the temporary directory.

@ollyjg Multiply is spelled wrong, and Maple is case-sensitive, so you have to use B rather than b. However, that doesn't explain why Determinant and Adjoint did not evaluate.  I'll guess that you didn't execute the with(LinearAlgebra); statement.  If you did, and terminated it with a semicolon (use a colon to suppress the output), the worksheet would have displayed all the exports of LinearAlgebra.

@ollyjg Multiply is spelled wrong, and Maple is case-sensitive, so you have to use B rather than b. However, that doesn't explain why Determinant and Adjoint did not evaluate.  I'll guess that you didn't execute the with(LinearAlgebra); statement.  If you did, and terminated it with a semicolon (use a colon to suppress the output), the worksheet would have displayed all the exports of LinearAlgebra.

The original poster should be aware that Determinant and Adjoint are members of the LinearAlgebra module.  To access them in the short-form, use with(LinearAlgebra):

The original poster should be aware that Determinant and Adjoint are members of the LinearAlgebra module.  To access them in the short-form, use with(LinearAlgebra):

You'll want to first expand 3*a. I'd choose to enclose the 1/3 in the blank function:

``(1/3)*expand(3*a);
                                   2
                           (1/3) (x  + 1/2 x - 1/4)

You'll want to first expand 3*a. I'd choose to enclose the 1/3 in the blank function:

``(1/3)*expand(3*a);
                                   2
                           (1/3) (x  + 1/2 x - 1/4)

It would be helpful if you uploaded the worksheet. Use the green arrow on the toolbar (here).

Yes, that is the straightforward approach.  I was thinking more along the lines of having already created the expression.

Welcome aboard, Carl.

First 55 56 57 58 59 60 61 Last Page 57 of 195