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
7 changes: 0 additions & 7 deletions AngouriMath.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetBenchmark", "Tests\Do
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngouriMathPlot", "AngouriMathPlot\AngouriMathPlot.csproj", "{B7D28355-A342-4E6E-AD45-3D47F4A054A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphicExample", "Samples\GraphicExample\GraphicExample\GraphicExample.csproj", "{EE064BFF-CDE6-43E3-8924-D8562BDDDF02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -51,10 +49,6 @@ Global
{B7D28355-A342-4E6E-AD45-3D47F4A054A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7D28355-A342-4E6E-AD45-3D47F4A054A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7D28355-A342-4E6E-AD45-3D47F4A054A5}.Release|Any CPU.Build.0 = Release|Any CPU
{EE064BFF-CDE6-43E3-8924-D8562BDDDF02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE064BFF-CDE6-43E3-8924-D8562BDDDF02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE064BFF-CDE6-43E3-8924-D8562BDDDF02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE064BFF-CDE6-43E3-8924-D8562BDDDF02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -64,7 +58,6 @@ Global
{23AA3D9F-77DA-4439-8F18-31B37F427492} = {D15528F2-AB50-46E2-9DB1-821B278C4931}
{587644B2-EBB3-432E-82B6-860F5586BB04} = {50DD3C1E-42AD-498E-9BE7-1604058CF1D8}
{3F82FF3F-13E3-4106-9FE6-E986549528F2} = {50DD3C1E-42AD-498E-9BE7-1604058CF1D8}
{EE064BFF-CDE6-43E3-8924-D8562BDDDF02} = {D15528F2-AB50-46E2-9DB1-821B278C4931}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E1CD9B3-4EAB-4B8C-BDC1-03280EB31298}
Expand Down
10 changes: 5 additions & 5 deletions AngouriMath/AngouriMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>Angourisoft</Authors>
<Company>Angourisoft</Company>
<Copyright>Angourisoft</Copyright>
<PackageProjectUrl>asc-community.org</PackageProjectUrl>
<RepositoryUrl>https://github.com/Angourisoft/MathS</RepositoryUrl>
<AssemblyVersion>0.0.17.2</AssemblyVersion>
<FileVersion>0.0.17.2</FileVersion>
<AssemblyVersion>0.0.18.0</AssemblyVersion>
<FileVersion>0.0.18.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageTags>Math, csharp, derivation, latex, calculator, parse, simplification, compute, symbol, compilation, algebra</PackageTags>
<Version>1.0.17.2-Beta</Version>
<Version>1.0.18.0-Alpha</Version>
<PackageIconUrl>https://raw.githubusercontent.com/Angourisoft/MathS/master/icon.png</PackageIconUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>Enables to work with formulas built in the code or from a string. Computing, derivating, latex rendering, fast functions, and many more.</Description>
<PackageReleaseNotes>Infinite loop simplification fixed</PackageReleaseNotes>
<PackageReleaseNotes>Solving equations &amp; simplification has improved &amp; tons of bugs fixed &amp; some more features</PackageReleaseNotes>
<PackageId>AngouriMath</PackageId>
<Product>AngouriMath</Product>
<ApplicationIcon />
Expand Down
61 changes: 61 additions & 0 deletions AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,18 @@ public static partial class MathS
/// <returns></returns>
public static Number Num(double a) => new Number(a);

/// <summary>
/// List of public constants
/// </summary>
public static readonly VariableEntity e = "e";
public static readonly Number i = new Number(0, 1);
public static readonly VariableEntity pi = "pi";

/// <summary>
/// Sets threshold for comparison
/// For example, if you don't need precision higher than 6 digits after .,
/// you can set it to 1.0e-6 so 1.0000000 == 0.9999999
/// </summary>
public static double EQUALITY_THRESHOLD { get; set; } = 1.0e-11;

/// <summary>
Expand Down Expand Up @@ -263,5 +272,57 @@ public static EntitySet GetUniqueVariables(Entity expr)
/// <param name="N"></param>
/// <returns></returns>
public static double FromBaseN(string num, int N) => NumberSystem.FromBaseN(num, N);

/// <summary>
/// Creates an instance of Tensor: Matrix
/// Usage example:
/// var t = MathS.Matrix(5, 3,
/// 10, 11, 12,
/// 20, 21, 22,
/// 30, 31, 32,
/// 40, 41, 42,
/// 50, 51, 52
/// );
/// creates matrix 5x3 with the appropriate elements
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static Tensor Matrix(int rows, int columns, params Entity[] values)
{
if (values.Length != rows * columns)
throw new MathSException("Axes don't match data");
var r = new Tensor(rows, columns);
r.Assign(values);
return r;
}

/// <summary>
/// Creates an instance of vector
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static Tensor Vector(params Entity[] p)
{
var r = new Tensor(p.Length);
r.Assign(p);
return r;
}

/// <summary>
/// Returns dot product of two matrices
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <returns></returns>
public static Tensor DotProduct(Tensor A, Tensor B) => AngouriMath.Core.Sys.Items.Tensors.TensorFunctional.DotProduct(A, B);

/// <summary>
/// Returns scalar product of two matrices
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <returns></returns>
public static Entity ScalarProduct(Tensor A, Tensor B) => AngouriMath.Core.Sys.Items.Tensors.TensorFunctional.ScalarProduct(A, B);
}
}
11 changes: 11 additions & 0 deletions AngouriMath/Convenience/SynonymFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace AngouriMath
using SynTable = Dictionary<string, string>;
internal static class SynonymFunctions
{
/// <summary>
/// While parsing, we want to understand functions like "sqrt". After parsing, we replace
/// nodes with this name by the appropriate expression
/// </summary>
internal static readonly FuncTable SynFunctions = new FuncTable
{
{ "sqrtf", args => MathS.Pow(args[0], 0.5) },
Expand All @@ -16,6 +20,13 @@ internal static class SynonymFunctions
{ "secf", args => MathS.Sec(args[0]) },
{ "cosecf", args => MathS.Cosec(args[0]) },
};

/// <summary>
/// Expects a tree with "sqrt" and some other unresolved functions. Returns
/// that with all "sqrt" and other replaced
/// </summary>
/// <param name="tree"></param>
/// <returns></returns>
internal static Entity Synonymize(Entity tree)
{
for (int i = 0; i < tree.Children.Count; i++)
Expand Down
14 changes: 11 additions & 3 deletions AngouriMath/Core/FromLinq/LinqParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@

namespace AngouriMath.Core.FromLinq
{
/// <summary>
/// To parse linq lambda expressions into Entity
/// </summary>
internal class LinqParser
{
private readonly Expression src;
internal LinqParser(Expression linq)
{
src = linq;
}

/// <summary>
/// Parses the function interpreting "Math.Sqr" as sqr
/// TODO
/// </summary>
/// <param name="linq"></param>
/// <returns></returns>
private static Entity InnerParse(Expression linq)
{
var unary = linq as UnaryExpression;
Expand Down Expand Up @@ -68,8 +78,6 @@ private static Entity InnerParse(Expression linq)
}
}
internal Entity Parse()
{
return InnerParse(src);
}
=> InnerParse(src);
}
}
51 changes: 50 additions & 1 deletion AngouriMath/Core/FromString/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace AngouriMath.Core.FromString
using TokenType = Token.TokenType;
internal class TokenList : List<Token>
{
/// <summary>
/// Safely appends a token to a list
/// </summary>
/// <param name="a"></param>
public new void Add(Token a)
{
if (!string.IsNullOrEmpty(a.Value))
Expand All @@ -19,6 +23,10 @@ internal class TokenList : List<Token>
}
internal partial class Token
{
/// <summary>
/// Safe copy of a token
/// </summary>
/// <returns></returns>
internal Token Copy()
{
var res = new Token();
Expand Down Expand Up @@ -57,7 +65,6 @@ internal enum BraceType
}
internal TokenType Type { get; private set; }
internal string Value { get; set; }
internal Entity Attribute { get; private set; }
internal static BraceType GetBraceType(char s)
{
switch(s)
Expand Down Expand Up @@ -97,6 +104,12 @@ public override string ToString()
{
return "{" + Value + " | " + this.Type.ToString() + "}";
}

/// <summary>
/// Normal way to get the type of a token is to seal it and resolve the type
/// But sometimes we need to get it without sealing the token
/// </summary>
/// <returns></returns>
internal TokenType GetCurrentType()
{
TokenType type;
Expand Down Expand Up @@ -144,19 +157,38 @@ internal class Lexer
{
private readonly TokenList tokens;
private int index;

/// <summary>
/// Seals all the tokens
/// </summary>
internal void Seal()
{
foreach (var token in tokens)
token.Seal();
}

/// <summary>
/// If EOF, there's no tokens remaining
/// </summary>
/// <returns></returns>
internal bool EOF()
{
return index >= tokens.Count;
}

/// <summary>
/// Goes to the next
/// Current changes
/// </summary>
internal void Next()
{
index++;
}

/// <summary>
/// Goes to the next without changing Current
/// </summary>
/// <returns></returns>
internal Token GlanceNext()
{
if (index >= tokens.Count)
Expand All @@ -168,19 +200,36 @@ internal Token GlanceNext()
return tokens[index + 1];
}
}

/// <summary>
/// If needed, we have a way back
/// </summary>
internal void Prev()
{
index = Math.Max(index - 1, 0);
}

/// <summary>
/// Property. Returns the current token
/// </summary>
internal Token Current
{
get => tokens[index];
}

/// <summary>
/// Resets the lexer
/// </summary>
internal void ToBegin()
{
index = 0;
}


/// <summary>
/// DOCTODO
/// </summary>
/// <param name="src"></param>
internal Lexer(string src)
{
tokens = new TokenList();
Expand Down
Loading