Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AngouriMath/Core/FromString/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ void InsertIntoPair(TokenType t1, TokenType t2, Token token)

// )sqrt -> ) * sqrt
InsertIntoPair(TokenType.PARENTHESIS_CLOSE, TokenType.FUNCTION, multiplyer);

// )( -> ) * (
// )sqrt -> ) * sqrt
InsertIntoPair(TokenType.PARENTHESIS_CLOSE, TokenType.PARENTHESIS_OPEN, multiplyer);
}
}
}
40 changes: 30 additions & 10 deletions AngouriMath/Core/Sys/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@

namespace AngouriMath
{
public static class Const
internal static class Const
{
public static readonly int PRIOR_SUM = 2;
public static readonly int PRIOR_MINUS = 2;
public static readonly int PRIOR_MUL = 4;
public static readonly int PRIOR_DIV = 4;
public static readonly int PRIOR_POW = 6;
public static readonly int PRIOR_FUNC = 8;
public static readonly int PRIOR_VAR = 10;
public static readonly int PRIOR_NUM = 2;
public static readonly string ARGUMENT_DELIMITER = ",";
internal static readonly int PRIOR_SUM = 2;
internal static readonly int PRIOR_MINUS = 2;
internal static readonly int PRIOR_MUL = 4;
internal static readonly int PRIOR_DIV = 4;
internal static readonly int PRIOR_POW = 6;
internal static readonly int PRIOR_FUNC = 8;
internal static readonly int PRIOR_VAR = 10;
internal static readonly int PRIOR_NUM = 2;
internal static readonly string ARGUMENT_DELIMITER = ",";
internal static OperatorEntity FuncIfSum(Entity child)
{
return new OperatorEntity("mulf", Const.PRIOR_MUL)
{
Children = new List<Entity> {
-1,
child
}
};
}
internal static OperatorEntity FuncIfMul(Entity child)
{
return new OperatorEntity("powf", Const.PRIOR_POW)
{
Children = new List<Entity> {
child,
-1
}
};
}
}
}
4 changes: 4 additions & 0 deletions AngouriMath/Core/Sys/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public bool IsComplex()
{
return !Number.IsDoubleZero(Im);
}
public bool IsInteger()
{
return !IsComplex() && (Number.IsDoubleZero(Re - Math.Round(Re)));
}
public static Number Pow(Number a, Number b) => new Number(b.value == 0.5 ? Complex.Sqrt(a.value) : Complex.Pow(a.value, b.value));
public static Number Log(Number a, Number b) => new Number(Complex.Log(a.value, b.Re));
public static Number Sin(Number a) => a.__isReal ? new Number(Math.Sin(a.value.Real)) : new Number(Complex.Sin(a.value));
Expand Down
2 changes: 1 addition & 1 deletion AngouriMath/Core/TreeAnalysis/LinearChildren.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AngouriMath.Core.TreeAnalysis
{
internal static partial class TreeAnalyzer
public static partial class TreeAnalyzer
{
internal static List<Entity> LinearChildren(Entity tree,
string funcName /*e. g. "sumf" */,
Expand Down
27 changes: 27 additions & 0 deletions AngouriMath/Core/TreeAnalysis/Search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AngouriMath
{
public abstract partial class Entity
{
/// <summary>
/// Finds a subtree in the tree
/// </summary>
/// <returns></returns>
public Entity FindSubtree(Entity subtree)
{
if (this == subtree)
return this;
else
foreach (var child in Children)
{
Entity found = child.FindSubtree(subtree);
if (found != null)
return found;
}
return null;
}
}
}
26 changes: 3 additions & 23 deletions AngouriMath/Core/TreeAnalysis/Sort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,8 @@ internal string Hash(SortLevel level)

internal Entity Sort(SortLevel level)
{
OperatorEntity FuncIfSum(Entity child)
{
return new OperatorEntity("mulf", Const.PRIOR_MUL)
{
Children = new List<Entity> {
-1,
child
}
};
}
OperatorEntity FuncIfMul(Entity child)
{
return new OperatorEntity("powf", Const.PRIOR_POW)
{
Children = new List<Entity> {
child,
-1
}
};
}
Func<Entity, OperatorEntity> funcIfSum = FuncIfSum;
Func<Entity, OperatorEntity> funcIfMul = FuncIfMul;
Func<Entity, OperatorEntity> funcIfSum = Const.FuncIfSum;
Func<Entity, OperatorEntity> funcIfMul = Const.FuncIfMul;
for (int i = 0; i < Children.Count; i++)
Children[i] = Children[i].Sort(level);
if (Name != "sumf" && Name != "mulf" && Name != "minusf" && Name != "divf")
Expand All @@ -67,7 +47,7 @@ OperatorEntity FuncIfMul(Entity child)

namespace AngouriMath.Core.TreeAnalysis
{
internal static partial class TreeAnalyzer
public static partial class TreeAnalyzer
{
internal enum SortLevel
{
Expand Down
Loading