Joe Riel

9660 Reputation

23 Badges

20 years, 12 days

MaplePrimes Activity


These are replies submitted by Joe Riel

No, you want the combinations, not the permutations.  Doug's algorithm will work, but instead of interpreting its output as the locations for the zeros, interpret it as the locations of the nonzeros (and adjust k accordingly). So for your example do

Q := (n,k) -> remove( L -> has( L[2..-1]-L[1..-2], 1 )
                      , combinat:-choose(n+k,k)
                     ):
Q(2,2);
               [[1, 3], [1, 4], [2, 4]]

Each list represents where the integers 1 and 2 go, the rest are zero.

Rather than calling ?combinat[permute] and selecting the sorted, use ?combinat[choose], which generates the combinations of a list, already sorted.

Rather than calling ?combinat[permute] and selecting the sorted, use ?combinat[choose], which generates the combinations of a list, already sorted.

Note that rather than create a list and then 'unlist' it, you can delay the evaluation of an expression sequence:

m := iquo(n,2,'r');
[ seq( '(S[i], S[-i])', i = 1..m), `if`(r=1, S[m+1], NULL) ];

Note that rather than create a list and then 'unlist' it, you can delay the evaluation of an expression sequence:

m := iquo(n,2,'r');
[ seq( '(S[i], S[-i])', i = 1..m), `if`(r=1, S[m+1], NULL) ];

Consider my original suggestion.  Zip the file, upload here, and let us have a look at it. 

Consider my original suggestion.  Zip the file, upload here, and let us have a look at it. 

Thanks. 

At some point I elided a comment about my cas routine; it is not supposed to represent an atomic cas, but rather tests the basic operation of incr.

You mean, why do

for L from 1 to 2 by 0.1 do
    subs(lambda = L, ...)
end do

rather than

for lambda from 1 to 2 by 0.1 do
    ...
end do

You probably could do the latter, however, as a rule I generally do not like to assign to variables in expressions (in the second example, lambda is given a numeric value by the loop).  Doing so can make it difficult to deal with the expression later in symbolic form, because its variables now evaluate to numbers.

You mean, why do

for L from 1 to 2 by 0.1 do
    subs(lambda = L, ...)
end do

rather than

for lambda from 1 to 2 by 0.1 do
    ...
end do

You probably could do the latter, however, as a rule I generally do not like to assign to variables in expressions (in the second example, lambda is given a numeric value by the loop).  Doing so can make it difficult to deal with the expression later in symbolic form, because its variables now evaluate to numbers.

Replacing the lambda was not needed.  Instead you could replace eigen with a fully evaluated version (or assign it to a new variable):

eigen2 := map(eval, eigen);

and then use eigen2 in the loop.

Replacing the lambda was not needed.  Instead you could replace eigen with a fully evaluated version (or assign it to a new variable):

eigen2 := map(eval, eigen);

and then use eigen2 in the loop.

The problem is the way you are assigning values.  That is, you do (essentially)

A := Matrix(1, [a]):
a := lambda:
A;
                                                           [lambda]
subs(lambda=1, A);
                                                           [lambda]
 

That does not work because A actually contains a, not lambda .  You can make it work by fully evaluating A before substituting:

subs(lambda=1, map(eval, A));
                                                             [1]

In your worksheet, use map(eval, eigen) in the subs call.

Followup:

There is a subtlety that needs some explanation.  At the top-level, that is, outside of procedures, Maple usually fully evaluates expressions.  So you could do

restart:
B := [b]:
b := lambda:
subs(lambda=1, b);
                                              [1]

That appears the same as above, but here it works.  The difference is that here B is a list rather than a Matrix (more generally, an rtable).  Maple does not fully evaluate rtables at top level because doing so would be too expensive.

Tip: You can take advantage of this difference in evaluation to get a speed boost by enclosing a sequence of top-level commands inside a procedure, however, that assumes you have written them in such a way that they work properly without full evaluation.

The problem is the way you are assigning values.  That is, you do (essentially)

A := Matrix(1, [a]):
a := lambda:
A;
                                                           [lambda]
subs(lambda=1, A);
                                                           [lambda]
 

That does not work because A actually contains a, not lambda .  You can make it work by fully evaluating A before substituting:

subs(lambda=1, map(eval, A));
                                                             [1]

In your worksheet, use map(eval, eigen) in the subs call.

Followup:

There is a subtlety that needs some explanation.  At the top-level, that is, outside of procedures, Maple usually fully evaluates expressions.  So you could do

restart:
B := [b]:
b := lambda:
subs(lambda=1, b);
                                              [1]

That appears the same as above, but here it works.  The difference is that here B is a list rather than a Matrix (more generally, an rtable).  Maple does not fully evaluate rtables at top level because doing so would be too expensive.

Tip: You can take advantage of this difference in evaluation to get a speed boost by enclosing a sequence of top-level commands inside a procedure, however, that assumes you have written them in such a way that they work properly without full evaluation.

That would be case if threshold were set to 0.5 (and low and high their default values).  If threshold is not assigned, then Otsu's method is to use to determine an appropriate threshold.

First 96 97 98 99 100 101 102 Last Page 98 of 195