Boolean expression subs and xreplace poor preformance

21 views
Skip to first unread message

imshteam

unread,
Feb 3, 2017, 5:12:49 AM2/3/17
to sympy
Hi,

I have the following function:
def is_caught(doc, rule):
    return rule.xreplace({key: key in doc for key in rule.atoms()}) == True # I have tested it also with subs instead of xreplace

This function's input is a doc which is a set of Sympy symbols, i.e. set([x,y]) and a boolean rule, i.e. And(x,z).
The function returns True if the rule is satisfied by the doc, in the above example it returns False.

I have profiled my code and 99% of the time is taken by this function. The rules and docs aren't complicated but I have a lot of them, i.e. 10 symbols over 5000 rules.

Is there any way to speed this up?
Reply all
Reply to author
Forward
0 new messages