AngouriMath

Navigation

← Back to list of members

ComplexityCriteria

 Property

Summary

Criteria for simplifier so you could control which expressions are considered easier by you.
The higher the value - the more complicated an expression is.

Example

Consider a situation, when we simplify this simple expression:
using System;
using AngouriMath.Extensions;

Console.WriteLine("a / b + b / c".ToEntity().Simplify());

The output is
a / b + b / c

Assume we now hate division operators. For simplicity, our new complexity criteria
equals to how many division operators are there. Basically, the more of them there are in
expression, the more complicated it is. Now we add it:
using System;
using System.Linq;
using AngouriMath;
using AngouriMath.Extensions;
using static AngouriMath.MathS;

Console.WriteLine("a / b + b / c".ToEntity().Simplify());

    using var _ = Settings.ComplexityCriteria.Set(
    expr => expr.Nodes.Count(node => node is Entity.Divf)
);

Console.WriteLine("a / b + b / c".ToEntity().Simplify());

The output:
a / b + b / c
(a * c + b ^ 2) / (b * c)

Note that in the second case, this expression is simpler, because our complexity
criteria gets lower when there's fewer division operators. Let's check the
property SimplifiedRate:
using System;
using System.Linq;
using AngouriMath;
using AngouriMath.Extensions;
using static AngouriMath.MathS;

Console.WriteLine("a / b + b / c".ToEntity().SimplifiedRate);
Console.WriteLine("a / b + b / c".ToEntity().Simplify().SimplifiedRate);


using var _ = Settings.ComplexityCriteria.Set(
    expr => expr.Nodes.Count(node => node is Entity.Divf)
);

Console.WriteLine(FromString("a / b + b / c", useCache: false).SimplifiedRate);
Console.WriteLine(FromString("a / b + b / c", useCache: false).Simplify().SimplifiedRate);

Prints
24
24
2
1

By default criteria it cannot simplify it further, however, the custom one
it simplified from 2 to 1.

























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