-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combinatorial procedures #550
Comments
I like the names. For
or similar. By default, Is
Yes, so the result of
Yes, see above what I thought about
I think it could be useful, let's get some feedback on it. If yes, I think it should be a separate PR so that we keep PRs as small as possible. Does this belong in |
Thanks for your input! I have thought about a Apparently "row-major order" is a confusing term. In all cases the number of items should be the first dimension and the number of compositions the second. The question is about the order of those compositions. What comes after "aa", is it "ba" or "ab"? Is it [1,2] or [2,1] after [1,1]? If the first entry increases, it mimics the array-logic of Fortran, but last-entry increases would lead to lexically ordered strings (and/or arrays). Should it be different for strings than for other items? Feedback sounds great. Another idea: How about functions that calculate just the size/shape of the results. Those are usually simple expressions like factorial or powers but would be quite convenient to first check if the result is small enough. I am not sure where this belongs. |
Motivation
Functions or subroutines that take an array (or a string) and return an array (of higher rank, or of strings) with combinatorial compositions of the input values. Common facilities (e.g. Python's itertools) with example results given here in a non-Fortran nested format:
products([1, 2, 3], r=2)
returns[[1, 1], [2, 1], [3, 1], [1, 2], [2, 2], [3, 2], [1, 3], [2, 3], [3, 3]]
permutations([1, 2, 3], r=2)
returns[[2, 1], [3, 1], [1, 2], [3, 2], [1, 3], [2, 3]]
combinations([1, 2, 3], r=2)
returns[[2, 1], [3, 1], [3, 2]]
combinations_with_replacement([1, 2, 3], r=2)
returns[[1, 1], [2, 1], [3, 1], [2, 2], [3, 2], [3, 3]]
These examples are in column-major order, which makes sense for indices but less so for other elements. If this behavior is consistent, for strings the result would not be lexically ordered:
products('ABC', r=2)
returns['AA', 'BA', 'CA', 'AB', 'BB', 'CB', 'AC', 'BC', 'CC']
permutations('ABC', r=2)
returns['BA', 'CA', 'AB', 'CB', 'AC', 'BC']
combinations('ABC', r=2)
returns['BA', 'CA', 'CB']
combinations_with_replacement('ABC', r=2)
returns['AA', 'BA', 'CA', 'BB', 'CB', 'CC']
The procedures can be extended to lists.
Questions
combinations_with_replacement
is quite long)?Prior Art
Additional Information
sample
procedureThe text was updated successfully, but these errors were encountered: