Closed dylannrees closed 6 years ago
Thinking more about the second point, I think ldepth
should be 1
and that make_digits = True
should be removed or left as it is.
I'll think about the vectorization behavior. I'd rather remove ldepth = 1
than make_digits = True
, but that's not really backwards-compatible.
I like the Œ¡
idea, but sympy.utilities.iterables.multiset_permutations
seems way too slow.
Also, it always sorts the permutations. I see three choices:
Do what SymPy does. Might be useful in general, but there's really no way of "going back" from sorting the permutations.
Permutations of [1, 0, 0, 1]
are
[[0, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0]]
.
Sort and rotate the argument to the first position.
Permutations of [1, 0, 0, 1]
are
[[1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0]]
.
Order by first occurrence rather than value. That still performs some kind of sorting.
Permutations of [1, 0, 0, 1]
are
[[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 0, 1], [0, 0, 1, 1]]
.
Order by first occurrence and rotate the argument to the first position.
Permutations of [1, 0, 0, 1]
are
[[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 0, 1], [0, 0, 1, 1], [[1, 1, 0, 0], [1, 0, 1, 0]]
.
up2
might be the most natural one. If there was a next permutation atom Ŋ
, we could use ŊƬ
to implement up2
.
Is 3 the reverse of 1?
A fifth option would be to order by the initial index.
[1, 0, 0, 1]
would give
[[1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1]]
.
Same as getting the sorted permutations of [1, 2, 3, 4]
then indexing each back into the initial list [1, 0, 0, 1]
. TIO.
That being said I agree that the second option would be most useful in general. We could amend the code page again to make room for Ŋ
or perhaps .Ñ
Slightly altering up2
, this could be the next_perm
function based on lexicographic sorting:
After removing iseq = seq[:]
, that's exactly what I had in mind. It minor tweaking to handle the empty array and to avid clobbering the argument.
An alternative to a next permutation atom would be an all permutations quick.
I thought about it and neither Œɠ
nor Œœ
should vectorize.
Could the Œ¡
be removed for now? That way, I can merge the atoms that are already done.
Œ¡
unique permutations. Uses sympy's multiset permutations built-in.Œœ
Odd-even. Same ass2Z
.Œɠ
Group lengths.Same asUnlikeŒgL€
.Œg
, this does not vectorize. If the argument is an integer, the lengths of groups of it's consecutive digits will be found.Two details I wasn't sure about:
Œœ
vectorize? If so, at what depth?Œg
makes a call toiterable(array, make_digits = True)
, but becauseldepth = 1
, applying it to an integer never causes it to be converted to decimal. I included the same call toiterable
inŒɠ
and specifiedldepth = 1
to be consistent, but I think it would be more useful ifldepth
was0
or if the atom didn't vectorize.