-
Notifications
You must be signed in to change notification settings - Fork 12
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
Partial evaluation assuming a complex expression is true #19
Comments
Hi @farnoy, This is a really interesting question! I've thought about it for a bit and I can't come up with any simple and fully general solutions, but maybe there's a trick I'm not seeing right now. For a case where the "assumptions" are a single boolean product (AND of terminals and not-terminals), I think this reduces to just partial evaluation with the given term values; e.g. in your example, we could do a recursive transform on But if we have an I suppose one could maybe build a BDD that contains both expressions and then merge the node for I'll think more about this though! |
Thanks, My usecase consists of doing analysis at compile time to do validation and generate optimized code. For now, I'm forced to do very basic analysis, like expressions simplifying to a const value. I'd love to be able to do more robust checks, but it'll work for now. The code generation part is working out great though. I'm using the following to generate a Rust expression that evaluates the boolean function: fn evaluate_to_tokens(e: Expr<String>) -> TokenStream {
match e {
Expr::Terminal(ref name) => {
let ident = syn::parse_str::<Ident>(name).unwrap();
quote!(#ident)
}
Expr::Const(bool) => quote!(#bool),
Expr::Not(inner) => {
let inner = evaluate_to_tokens(*inner);
quote!(!#inner)
}
Expr::And(a, b) => {
let a = evaluate_to_tokens(*a);
let b = evaluate_to_tokens(*b);
quote!((#a && #b))
}
Expr::Or(a, b) => {
let a = evaluate_to_tokens(*a);
let b = evaluate_to_tokens(*b);
quote!((#a || #b))
}
}
} Every Terminal is supposed to be a boolean variable with the same name. |
Hi and thanks for this helpful library.
I figured out how to do partial evaluation by substituting Terminals, but I don't know how to simplify an expression assuming some other expression is true.
Assuming it's always in SOP form, I could compare recursively until I find my "assumption" and substitute it with a constant, but it would be so fragile that even a different order of either expression would fail to match.
Ideally, what I'd like to do:
Is this possible, or would I need to reach for some kind of SMT solver to be able to express this?
The text was updated successfully, but these errors were encountered: