How to add custom bitwise XOR operator? #795
-
I want to create a bitwise operators like in the ^ operator in python. I've tried many things, and asking AI nothing works. I keep getting MethodError. Copilot gave me the following that doesn't work...
|
Beta Was this translation helpful? Give feedback.
Answered by
MilesCranmer
Jan 3, 2025
Replies: 1 comment 1 reply
-
Maybe try this? "my_xor(x, y) = convert(typeof(x), xor(x > 0, y > 0))" i.e., model = PySRRegressor(
niterations=1000,
binary_operators=["+", "-", "*", "/", "my_xor(x, y) = convert(typeof(x), xor(x > 0, y > 0))"],
unary_operators=[],
extra_sympy_mappings={"my_xor": lambda x, y: x ^ y}, # Define how the operator should be represented in SymPy
)
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
binseq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe try this?
"my_xor(x, y) = convert(typeof(x), xor(x > 0, y > 0))"
i.e.,
logical_or
andlogical_and
are built-in: https://ai.damtp.cam.ac.uk/pysr/operators