Modifying expressions
Nancy.Expressions allows to apply equivalences to (sub-parts of) expressions that may reduce their computational complexity. Equivalences can be either user-defined ones or well-known ones (already reported in literature and implemented in the library). Furthermore, the user can also replace parts of expressions by specifying which sub-expression needs to be substituted (replacing all occurences) or using its position (replace only one occurence).
Applying a simplification​
The following code cell constructs the DNC expression .
var f = Expressions.FromCurve(
curve: new Curve(<args>),
name: "f");
var g = Expressions.FromCurve(
curve: new Curve(<args>),
name: "g");
var f_sac = f.SubAdditiveClosure();
var conv = Expressions.Convolution(f_sac, g);
var deconv = Expressions.Deconvolution(conv, f_sac);
The expression is equivalent to which allows to avoid completely the deconvolution operation.
Therefore, it is possible to manually simplify the expression by using the method ApplyEquivalence
and the class DeconvAndSubAdditiveClosure
which represents the simplification:
var deconv_sac_equivalence = new DeconvAndSubAdditiveClosure();
var deconv_eq = deconv.ApplyEquivalence(deconv_sac_equivalence);
Replacing all occurences​
Substitute all occurences of with , and re-apply the previous equivalence:
Replacement at position​
Substitute the deconvolution with a convolution, and re-apply the previous equivalence (which does not hold in this case). Another equivalence can be applied in this case: , when is subadditive, as shown in the following screen:
Other example: replace the right operand of the deconvolution with from the initial expression. The right operand is specified as first argument of the method ReplaceByPosition
writing deconv.RootPosition().RightOperand()
(whose correctness is checked only at runtime, therefore the user should take care of its consistency during development).