-
Hi! I'm having difficulty expressing a property of the EClass that I want to obtain through extraction. I have a simple calculator with variables, u32's, Add and Mul, similar to the tests/math.rs example but simplified. I'd like to prefer output in the form of a sum of products, like a polynomial "x^2 + 3x + 4" or "(+ (* x x) (+ (* 3 x) 4))". The idea I have is to replace the CostFunction's
Unfortunately this doesn't do the trick:
I have a theory that this might be because of instability in the ordering of the costs, a cost might appear to be more expensive until it's merged into the enode parent. I wasn't able to find documentation on what the requirements on |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
I think the issue is that this is ultimately a non-local cost function. In this case, you might true collapsing the pattern you're looking for into a single e-node. Perhaps with a add-multiply (
|
Beta Was this translation helpful? Give feedback.
-
Alternatively, you might want to keep track of multiple best candidates per e-class to choose the right one depending on context? #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Context {
IsAdd,
IsMul,
IsOther
}
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Hash)]
pub struct PolyCost {
costs: HashMap<Context, u32>,
}
// [...] You can't use the vanilla extractor with this, because you need to associate an |
Beta Was this translation helpful? Give feedback.
I basically think that the current extractor does not support what you're looking for. You are right, we could do better to document the "monotonicity" requirements of the current extractor.