- // See if operation can be applied to children of this in the same dimension
- {
- // (a / b) / c = a / (b*c)
- // (a * b) / c = a * (b/c)
- // (a / b) * c = a / (b/c)
- // (a * b) * c = a * (b*c)
- // (a + b) + c = a + (b+c)
- // (a - b) + c = a - (b-c)
- // (a + b) - c = a + (b-c)
- // (a - b) - c = a - (b+c)
- Optype fwd(op);
- Optype rev(invop);
- if (op == DIVIDE || op == SUBTRACT)
- {
- fwd = invop;
- rev = op;
- }
- // opposite direction first (because ideally things will cancel each other out...)
- if (m_next[invop] != NULL && m_next[invop]->Operation(b, rev, &append_at) != NULL)
- return b;
- // forward direction
- if (m_next[op] != NULL && m_next[op]->Operation(b, fwd, &append_at) != NULL)
- return b;