pyDatalog
pyDatalog copied to clipboard
Implement modulo operator % for Term objects
Right now I use divmod
for defining an is_prime rule but actually X % Y == 0
would be more concise.
pyDatalog.create_terms('divmod')
@pyDatalog.program()
def _():
divisible(X, Y) <= (divmod(X, Y)[1] == 0)
divisible(X, Y) <= (X > Y+1) & divisible(X, Y+1)
+is_prim(2)
is_prim(X) <= (X > 2) & ~divisible(X, 2)
print(X.in_(range(10)) & is_prim(X))
There is a function version of % operator in the python library you can use.