Ask Your Question
1

search in a narrow range of values using IntegerListsLex

asked 2020-10-21 06:46:56 -0600

brennan gravatar image

updated 2020-10-22 11:40:25 -0600

FrédéricC gravatar image

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-10-21 16:55:47 -0600

slelievre gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-10-21 06:46:56 -0600

Seen: 78 times

Last updated: Oct 22