# 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!!!

edit retag close merge delete

Sort by » oldest newest most voted

The 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.

more