An extractor for Source
An extractor for Source
Collects a set of objects from all sub-expressions
Collects a set of objects from all sub-expressions
Returns true if the expression contains a function call
Counts how many times the predicate holds in sub-expressions
Counts how many times the predicate holds in sub-expressions
Computes the depth of the tree
Computes the depth of the tree
Checks if the predicate holds in some sub-expression
Checks if the predicate holds in some sub-expression
Returns a set of all sub-expressions matching the predicate
Returns a set of all sub-expressions matching the predicate
Does a right tree fold
Does a right tree fold
A right tree fold applies the input function to the subnodes first (from left to right), and combine the results along with the current node value.
a function that takes the current node and the seq of results form the Sources.
The value on which to apply the fold.
The expression after applying f
on all Sources.
the computation is lazy, hence you should not rely on side-effects of f
Computes the size of a tree
Computes the size of a tree
Freshens all local variables
Returns all Function calls found in the expression
Applies functions and combines results in a generic way
Applies functions and combines results in a generic way
Start with an initial value, and apply functions to nodes before and after the recursion in the children. Combine the results of all children and apply a final function on the resulting node.
a function applied on a node before doing a recursion in the children
a function applied to the node built from the recursive application to all children
a function to combine the resulting values from all children with the current node
the initial value
the expression on which to apply the transform
Returns true if the formula is Ground, which means that it does not contain any variables (variablesOf e is empty)
Returns true if the formula is simple, which means that it requires no special encoding for an unrolling solver.
Returns true if the formula is simple, which means that it requires no special encoding for an unrolling solver. See implementation for what this means exactly.
Given a tree toSearch
present in treeToLookInto
, if treeToLookInto
has the same shape as treeToExtract
,
returns the matching expression in treeToExtract
.
Given a tree toSearch
present in treeToLookInto
, if treeToLookInto
has the same shape as treeToExtract
,
returns the matching expression in treeToExtract
.
Computes the negation of a boolean formula, with some simplifications.
Some helper methods for FractionLiterals
Post-transformation of the tree.
Post-transformation of the tree.
Takes a partial function of replacements. Substitutes after recurring down the trees.
Supports two modes :
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> z, Minus(e,c) -> d, b -> e
will yield:
Add(a, Minus(e, c))
Add(a, Minus(b, c)) with replacements: Minus(e,c) -> d, b -> e, d -> f
will yield:
Add(a, f)
The mode with applyRec true can diverge if f is not well formed (i.e. not convergent)
Post-traversal of the tree.
Post-traversal of the tree.
Invokes the input function on every node after visiting children.
e.g.
Add(a, Minus(b, c))
will yield, in order:
f(a), f(b), f(c), f(Minus(b, c)), f(Add(a, Minus(b, c)))
a function to apply on each node of the expression
the expression to traverse
Pre-transformation of the tree.
Pre-transformation of the tree.
Takes a partial function of replacements and substitute before recursing down the trees.
Supports two modes :
e.g.
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> d, b -> e, d -> f
will yield:
Add(a, d) // And not Add(a, f) because it only substitute once for each level.
e.g.
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> d, b -> e, d -> f
will yield:
Add(a, f)
The mode with applyRec true can diverge if f is not well formed
Pre-transformation of the tree, with a context value from "top-down".
Pre-transformation of the tree, with a context value from "top-down".
Takes a partial function of replacements. Substitutes before recursing down the trees. The function returns an option of the new value, as well as the new context to be used for the recursion in its children. The context is "lost" when going back up, so changes made by one node will not be see by its siblings.
Pre-traversal of the tree.
Pre-traversal of the tree.
Invokes the input function on every node before visiting children. Traverse children from left to right Sources.
e.g.
Add(a, Minus(b, c))
will yield, in order:
f(Add(a, Minus(b, c))); f(a); f(Minus(b, c)); f(b); f(c)
a function to apply on each node of the expression
the expression to traverse
Replaces bottom-up sub-expressions by looking up for them in a map
Replaces bottom-up sub-expressions by looking up for them in a map
Replaces bottom-up variables by looking them up in a map from ValDef to expressions
Replaces bottom-up variables by looking up for them in a map
A simpleTransform without a pre-transformation
A simpleTransform without a pre-transformation
A simpleTransform without a post-transformation
A simpleTransform without a post-transformation
A genericTransform with the trivial combiner that returns ()
A genericTransform with the trivial combiner that returns ()
Simple, local simplification on arithmetic
Simple, local simplification on arithmetic
You should not assume anything smarter than some constant folding and simple cancellation. To avoid infinite cycle we only apply simplification that reduce the size of the tree. The only guarantee from this function is to not augment the size of the expression and to be sound.
Simple, local optimization on string
Returns the set of free variables in an expression
Provides functions to manipulate Expressions.Expr.
This object provides a few generic operations on Inox expressions, as well as some common operations.
The generic operations lets you apply operations on a whole tree expression. You can look at:
These operations usually take a higher order function that gets applied to the expression tree in some strategy. They provide an expressive way to build complex operations on Inox expressions.