ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Oct 2020 23:55:47 +0200search in a narrow range of values using IntegerListsLexhttps://ask.sagemath.org/question/53995/search-in-a-narrow-range-of-values-using-integerlistslex/ Hello everyone,
I am having trouble finding solutions to a system of equations because the search involves so many variables that the computation time is large. I am using
for A in IntegerListsLex(length=30, min_part=0, max_part=100, min_slope=0):
if...(properties of A):
print(A)
The problem is it is searching through a bunch of values that I know don't need to be there. How can I get rid of particular search values, like say I want to avoid ever using the numbers 7,11,13 can I somehow remove them from the search parameters?
Thank you all so much!!!
Wed, 21 Oct 2020 13:46:56 +0200https://ask.sagemath.org/question/53995/search-in-a-narrow-range-of-values-using-integerlistslex/Answer by slelievre for <p>Hello everyone,</p>
<p>I am having trouble finding solutions to a system of equations because the search involves so many variables that the computation time is large. I am using </p>
<pre><code>for A in IntegerListsLex(length=30, min_part=0, max_part=100, min_slope=0):
if...(properties of A):
print(A)
</code></pre>
<p>The problem is it is searching through a bunch of values that I know don't need to be there. How can I get rid of particular search values, like say I want to avoid ever using the numbers 7,11,13 can I somehow remove them from the search parameters?</p>
<p>Thank you all so much!!!</p>
https://ask.sagemath.org/question/53995/search-in-a-narrow-range-of-values-using-integerlistslex/?answer=54001#post-id-54001The documentation for `IntegerListsLex` (accessed for example
using `IntegerListsLex?`) does not mention a way to exclude
specific isolated values for the parts.
One way to organise your code would be to give a name to the
properties of `A` you want to test for, and write a function
to test them.
For example say we call the function `is_palatable`.
Silly example (replace with testing the properties you want):
def is_palatable(A):
return True
Since it is cheap to test whether 7, 11 or 13 are parts of
a given integer list, we can write a test for it:
def checks(A):
return 7 not in A and 11 not in A and 13 not in A
and then iterate as follows, starting with the cheap tests
before testing the more serious properties if those are likely
to take time (this way we only test them if silly checks pass):
I = IntegerListsLex(length=30, min_part=0, max_part=100, min_slope=0)
for A in I:
if checks(A) and is_palatable(A):
print(A)
Another way to write such code is to write an iterator.
it = (A for A in I if checks(A) and is_palatable(A))
Then we can explore these objects one by one:
a = next(it)
print(a)
and explore this object as we need, before getting the next one.
Wed, 21 Oct 2020 23:55:47 +0200https://ask.sagemath.org/question/53995/search-in-a-narrow-range-of-values-using-integerlistslex/?answer=54001#post-id-54001