Skip to content

How to add custom bitwise XOR operator? #795

Answered by MilesCranmer
binseq asked this question in Q&A
Discussion options

You must be logged in to vote

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
)

logical_or and logical_and are built-in: https://ai.damtp.cam.ac.uk/pysr/operators

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@binseq
Comment options

Answer selected by binseq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants