Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is this the best way to reverse(r::Rule)? #126

Open
anandijain opened this issue May 31, 2022 · 1 comment
Open

is this the best way to reverse(r::Rule)? #126

anandijain opened this issue May 31, 2022 · 1 comment

Comments

@anandijain
Copy link

I haven't really read through this repo, but I didn't see an easy way to take @rule ~x => exp(~x) to @rule exp(~x) => ~x.
This was the hack I came up with

myreverse(r::Metatheory.Rules.AbstractRule) = myreverse(r.expr)

function myreverse(rex)
    args = rex.args
    newex = Expr(:call, args[[1, 3, 2]]...)
    eval(:(@rule $newex))
end

it seems to work fine but it might be a bad way of doing it

@0x0f0f0f
Copy link
Member

0x0f0f0f commented Jul 2, 2022

Hi anand. This is possible and fairly easy. I can add a function overloading Base.inv, but you have to know that inverting a rule that has more variables on the lhs. than the rhs will result in an error. (e.g., @rule f(~x, ~y, ~z) => g(~x) is not invertible)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants