AngouriMath

Navigation

← Back to list of members

Replace​(System.​Func{AngouriMath.​Entity,​AngouriMath.​Entity})

 Method (no overloads)

Summary

Applies the given function to every node starting from the leaves

Parameter "func"

The delegate that takes the current node as an argument and replaces the current node
with the result of the delegate

Returns

Processed expression

Example

using System;
using AngouriMath;
using static AngouriMath.MathS;
using static AngouriMath.Entity;
using static AngouriMath.Entity.Number;

static Entity MySimplify(Entity expr) => expr switch
{
    Sumf(Powf(Sinf(var e1), Integer(2)), Powf(Cosf(var e2), Integer(2))) when e1 == e2 => 1,
    Sinf(Integer(0)) => 0,
    var other => other
};

var x = Var("x");
Entity expr = (Sqr(Sin(x / 3)) + Sqr(Cos(x / 3))) + Sin(0);
Console.WriteLine(expr);
Console.WriteLine(expr.Replace(MySimplify));

Prints
sin(x / 3) ^ 2 + cos(x / 3) ^ 2 + 0
1 + 0

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1534 pages online