Skip to content

Commit

Permalink
#224 - Introduce simplification rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Oct 13, 2022
1 parent 8824554 commit 0bd59b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xFunc.Maths/Analyzers2/Rules/ExpLnUnaryRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace xFunc.Maths.Analyzers2.Rules;

public class ExpLnUnaryRule : Rule<Exp>
{
protected override Result ExecuteInternal(Exp expression, RuleContext context)
=> expression.Argument switch
{
Ln ln => Handled(ln.Argument),
_ => NotHandled(),
};

public override string Name => "Exponential Ln Rule";

public override string Description => "";
}
11 changes: 11 additions & 0 deletions xFunc.Maths/Analyzers2/Rules/ExpUnaryRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace xFunc.Maths.Analyzers2.Rules;

public class ExpUnaryRule : UnaryRule<Exp>
{
protected override Exp Create(IExpression argument)
=> new Exp(argument);

public override string Name => "Exponential Unary Rule";

public override string Description => "";
}
3 changes: 3 additions & 0 deletions xFunc.Maths/Analyzers2/Simplifier2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public Simplifier2()
.WithNext(new DivConstUnit())
.WithNext(new DivBySameExpression())
.WithNext(new DivGroupRule()))
.WithChain<Exp>(builder => builder
.WithRule(new ExpUnaryRule())
.WithNext(new ExpLnUnaryRule()))
.WithChain<Sub>(builder => builder
.WithRule(new SubBinaryRule())
.WithNext(new SubZeroRule())
Expand Down

0 comments on commit 0bd59b7

Please sign in to comment.