├── .github ├── ISSUE_TEMPLATE │ ├── ask_question.md │ ├── bug_report.md │ └── suggest_idea.md ├── additional │ └── readme │ │ ├── icon_white.png │ │ ├── interactive.PNG │ │ ├── interactive2.PNG │ │ ├── interactive3.PNG │ │ ├── pic1.PNG │ │ ├── side.PNG │ │ └── vscnotebook.gif ├── codecov.yml └── workflows │ ├── Benchmark.yml │ ├── CPPBuild.yml │ ├── CPPTest.yml │ ├── CSharpBuild.yml │ ├── CSharpTest.yml │ ├── EverythingBuild.yml │ ├── FSharpBuild.yml │ ├── FSharpTest.yml │ ├── IntegrationTest.yml │ ├── InteractiveBuild.yml │ ├── InteractiveTest.yml │ ├── Nuget.yml │ └── TerminalNightly.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md └── Sources ├── .editorconfig ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── Analyzers ├── Analyzers.CodeFixes │ ├── Analyzers.CodeFixes.csproj │ └── FieldThreadSafetyCodeFixProvider.cs ├── Analyzers.Debug │ ├── Analyzers.Debug.csproj │ └── source.extension.vsixmanifest └── Analyzers │ ├── Analyzers.csproj │ ├── EitherAbstractOrSealed.cs │ ├── GlobalSuppressions.cs │ └── StaticFieldThreadSafety.cs ├── AngouriMath.sln ├── AngouriMath ├── AngouriMath │ ├── AngouriMath.csproj │ ├── Convenience │ │ ├── AdditionalExtensions.cs │ │ ├── AngouriMathExtensions.cs │ │ ├── CompilationExtensions.cs │ │ ├── CompilationExtensions.tt │ │ ├── Diagnostic │ │ │ └── MathS.Diagnostic.cs │ │ ├── Experimental │ │ │ └── MathS.Experimental.cs │ │ ├── MathS.cs │ │ ├── SettingClass.cs │ │ ├── StringToEachClass.Classes.cs │ │ └── UnsafeAndInternal │ │ │ └── MathS.UnsafeAndInternal.cs │ ├── Core │ │ ├── Antlr │ │ │ ├── AngouriMath.g │ │ │ ├── AngouriMath.interp │ │ │ ├── AngouriMath.tokens │ │ │ ├── AngouriMathBaseListener.cs │ │ │ ├── AngouriMathLexer.cs │ │ │ ├── AngouriMathLexer.interp │ │ │ ├── AngouriMathLexer.tokens │ │ │ ├── AngouriMathListener.cs │ │ │ ├── AngouriMathParser.cs │ │ │ ├── ParsingHelpers.cs │ │ │ └── antlr-4.8-complete.jar │ │ ├── CoreAttributes.cs │ │ ├── Domains.Classes.cs │ │ ├── Domains.Definition.cs │ │ ├── Domains.cs │ │ ├── Entity │ │ │ ├── Continuous │ │ │ │ ├── Entity.Continuous.AbsSignum.Classes.cs │ │ │ │ ├── Entity.Continuous.ArcTrigonometry.Classes.cs │ │ │ │ ├── Entity.Continuous.Calculus.Classes.cs │ │ │ │ ├── Entity.Continuous.Complex.Definition.cs │ │ │ │ ├── Entity.Continuous.Definition.cs │ │ │ │ ├── Entity.Continuous.Exponential.Classes.cs │ │ │ │ ├── Entity.Continuous.Factorial.Classes.cs │ │ │ │ ├── Entity.Continuous.Integer.Definition.cs │ │ │ │ ├── Entity.Continuous.Number.Definition.cs │ │ │ │ ├── Entity.Continuous.Operators.Classes.cs │ │ │ │ ├── Entity.Continuous.Rational.Definition.cs │ │ │ │ ├── Entity.Continuous.Real.Definition.cs │ │ │ │ ├── Entity.Continuous.Trigonometry.Classes.cs │ │ │ │ └── Number │ │ │ │ │ ├── Casts.cs │ │ │ │ │ └── Operators.cs │ │ │ ├── Discrete │ │ │ │ ├── Entity.Discrete.Classes.cs │ │ │ │ └── Entity.Discrete.Definition.cs │ │ │ ├── Entity.Definition.cs │ │ │ ├── Entity.ImplicitOperators.cs │ │ │ ├── GenericMath │ │ │ │ ├── Entity.GenericMath.Classes.cs │ │ │ │ ├── Entity.GenericMath.Definition.cs │ │ │ │ ├── IClosedArithmetics.cs │ │ │ │ ├── IHasAbsoluteValue.cs │ │ │ │ ├── IHasNeutralValues.cs │ │ │ │ └── IScalarClosedArithmetics.cs │ │ │ ├── HashCodeFunctional.cs │ │ │ ├── INode.cs │ │ │ └── Omni │ │ │ │ ├── Entity.Matrix.cs │ │ │ │ ├── Entity.Omni.Classes.cs │ │ │ │ ├── Entity.Omni.Definition.cs │ │ │ │ ├── Entity.Piecewise.cs │ │ │ │ ├── Entity.Set.cs │ │ │ │ ├── Entity.Variable.cs │ │ │ │ └── Sets │ │ │ │ ├── SetOperators.Definition.cs │ │ │ │ ├── SetOperators.Intersection.cs │ │ │ │ ├── SetOperators.SetSubtraction.cs │ │ │ │ └── SetOperators.Union.cs │ │ ├── EquationSystem.cs │ │ ├── Exceptions │ │ │ ├── AngouriMathBaseException.cs │ │ │ ├── ParseException.cs │ │ │ ├── SysExceptions.cs │ │ │ └── UserInputInvalidException.cs │ │ ├── FiniteSetBuilder.cs │ │ ├── MatrixBuilder.cs │ │ ├── Multithreading │ │ │ └── MultithreadingFunctional.cs │ │ └── Parser.cs │ ├── Docs │ │ ├── Contributing │ │ │ ├── AddingNode.cs │ │ │ ├── General.md │ │ │ ├── ImproveParser.md │ │ │ ├── README.md │ │ │ ├── RS1617Errors.md │ │ │ └── coding_rules.md │ │ ├── Usage │ │ │ └── Exceptions.md │ │ └── WhatsNew │ │ │ ├── README.md │ │ │ └── version_performance_control.md │ ├── Functions │ │ ├── BaseConversion.cs │ │ ├── Boolean │ │ │ ├── AnalyticalSolving │ │ │ │ └── AnalyticalSolver.cs │ │ │ ├── Simplifier.cs │ │ │ └── TableSolver.cs │ │ ├── Compilation │ │ │ ├── Compile.FE.Definition.cs │ │ │ ├── Compile.Linq.Definition.cs │ │ │ ├── Compile.Linq.Definition.tt │ │ │ ├── IntoFE │ │ │ │ ├── Compiler.cs │ │ │ │ └── FastExpression.cs │ │ │ └── IntoLinq │ │ │ │ ├── CompilationProtocol.cs │ │ │ │ ├── DefaultConverters.cs │ │ │ │ ├── IntoLinqCompiler.cs │ │ │ │ ├── MathAllMethods.cs │ │ │ │ └── MathAllMethods.tt │ │ ├── Continuous │ │ │ ├── Differentiation.cs │ │ │ ├── Integration │ │ │ │ ├── IndefiniteIntegralSolver.cs │ │ │ │ ├── IntegralPatterns.cs │ │ │ │ └── Integration.Definition.cs │ │ │ ├── Limits │ │ │ │ ├── Limit.Definition.cs │ │ │ │ ├── Solvers │ │ │ │ │ ├── Limit.Classes.cs │ │ │ │ │ ├── Limit.Solvers.cs │ │ │ │ │ └── Solvers.Definition.cs │ │ │ │ └── Transformations.cs │ │ │ └── Solvers │ │ │ │ ├── EquationSolver.cs │ │ │ │ ├── EquationSolver │ │ │ │ ├── AnalyticalEquationSolver.cs │ │ │ │ ├── CommonDenominatorSolver.cs │ │ │ │ ├── ExponentialSolver.cs │ │ │ │ ├── FractionedPolynoms.cs │ │ │ │ ├── InvertNode.Classes.cs │ │ │ │ ├── PolynomialSolver.cs │ │ │ │ ├── SolveStatement.cs │ │ │ │ └── TrigonometricSolver.cs │ │ │ │ ├── InequalitySolver │ │ │ │ └── AnalyticalInequalitySolver.cs │ │ │ │ ├── InvertNode.Definition.cs │ │ │ │ ├── NumericalSolving │ │ │ │ └── NewtonSolver.cs │ │ │ │ ├── SetSolver │ │ │ │ └── AnalyticalSetSolver.cs │ │ │ │ └── Solvers.Definition.cs │ │ ├── EqualsImprecisely.cs │ │ ├── Evaluation │ │ │ ├── Evaluation.Classes.cs │ │ │ ├── Evaluation.Continuous │ │ │ │ ├── Evaluation.Continuous.Arithmetics.Classes.cs │ │ │ │ ├── Evaluation.Continuous.Calculus.Classes.cs │ │ │ │ ├── Evaluation.Continuous.Definition.cs │ │ │ │ └── Evaluation.Continuous.Trigonometry.Classes.cs │ │ │ ├── Evaluation.Definition.cs │ │ │ ├── Evaluation.Discrete │ │ │ │ ├── Evaluation.Discrete.Classes.cs │ │ │ │ └── Evaluation.Discrete.Definition.cs │ │ │ └── Evaluation.Omni │ │ │ │ ├── Evaluation.Omni.Classes.cs │ │ │ │ └── Evaluation.Omni.Definition.cs │ │ ├── ExpressionNumerical.Equality.cs │ │ ├── InternalAMExtensions.cs │ │ ├── MatrixOperations.cs │ │ ├── NumberTheory │ │ │ ├── Diophantine.cs │ │ │ ├── Fraction.cs │ │ │ └── Primes.cs │ │ ├── Output │ │ │ ├── Latex.Definition.cs │ │ │ ├── Latex │ │ │ │ ├── Latex.Arithmetics.Classes.cs │ │ │ │ ├── Latex.Calculus.Classes.cs │ │ │ │ ├── Latex.Classes.cs │ │ │ │ ├── Latex.Discrete.Classes.cs │ │ │ │ ├── Latex.Number.Classes.cs │ │ │ │ ├── Latex.Omni.Classes.cs │ │ │ │ └── Latex.Trigonometry.Classes.cs │ │ │ ├── ToString.Definition.cs │ │ │ ├── ToString │ │ │ │ ├── ToString.Arithmetics.Classes.cs │ │ │ │ ├── ToString.Calculus.Classes.cs │ │ │ │ ├── ToString.Classes.cs │ │ │ │ ├── ToString.Discrete.Classes.cs │ │ │ │ ├── ToString.Number.Classes.cs │ │ │ │ ├── ToString.Omni.Classes.cs │ │ │ │ └── ToString.Trigonometry.Classes.cs │ │ │ ├── ToSympy.Definition.cs │ │ │ └── ToSympy │ │ │ │ ├── ToSympy.Arithmetics.Classes.cs │ │ │ │ ├── ToSympy.Calculus.Classes.cs │ │ │ │ ├── ToSympy.Classes.cs │ │ │ │ ├── ToSympy.Discrete.Classes.cs │ │ │ │ ├── ToSympy.Number.Classes.cs │ │ │ │ ├── ToSympy.Omni.Classes.cs │ │ │ │ └── ToSympy.Trigonometry.Classes.cs │ │ ├── Series.cs │ │ ├── Simplification │ │ │ ├── Patterns │ │ │ │ ├── Patterns.Boolean.cs │ │ │ │ ├── Patterns.Common.cs │ │ │ │ ├── Patterns.EqualityInequality.cs │ │ │ │ ├── Patterns.ExpandFactorize.cs │ │ │ │ ├── Patterns.Factorial.cs │ │ │ │ ├── Patterns.NumberTheory.cs │ │ │ │ ├── Patterns.Power.cs │ │ │ │ ├── Patterns.Rational.cs │ │ │ │ ├── Patterns.Sets.cs │ │ │ │ ├── Patterns.Trigonometry.cs │ │ │ │ └── Patterns.cs │ │ │ ├── Simplificator.cs │ │ │ ├── TrigonometricAngleExpansion.cs │ │ │ └── TrigonometricTableValues.cs │ │ ├── Substitute.cs │ │ └── TreeAnalyzer │ │ │ ├── Expansion.cs │ │ │ ├── InnerSimplifyUnpacking.cs │ │ │ ├── LongDivision.cs │ │ │ ├── PolyParser.cs │ │ │ ├── Sort.Classes.cs │ │ │ └── Sort.Definition.cs │ ├── GlobalUsings.cs │ ├── PackageReadme.md │ └── icon.png ├── Directory.Build.props ├── Directory.Build.targets ├── extension.dib └── key.snk ├── Directory.Build.props ├── NuGet.Config ├── Pack.AngouriMath.FSharp.bat ├── Pack.AngouriMath.Interactive.bat ├── Pack.AngouriMath.bat ├── Package.Build.props ├── Samples ├── AngouriMathPlot │ ├── AMPlotter.cs │ └── AngouriMathPlot.csproj ├── CPlusPlusPlayground │ ├── AngouriMath.CPP.natvis │ ├── CMakeLists.txt │ ├── CMakeSettings.json │ ├── CPlusPlusPlayground.cpp │ └── CPlusPlusPlayground.h ├── CSharp.Interactive.Sample.ipynb ├── FSharpPlayground │ ├── FSharpPlayground.fsproj │ └── Program.fs ├── FSharpSample │ ├── FSharpSample.fsproj │ └── Program.fs ├── GraphicExample │ ├── GraphicExample.csproj │ ├── MainForm.Designer.cs │ ├── MainForm.cs │ ├── MainForm.resx │ └── Program.cs ├── Interactive.Sample.ipynb ├── InteractivePlayground │ ├── InteractivePlayground.fsproj │ └── Program.fs ├── SampleNet5 │ ├── Program.cs │ └── SampleNet5.csproj └── Samples │ ├── Playground.csproj │ └── Program.cs ├── Terminal ├── AngouriMath.Terminal.Lib │ ├── AngouriMath.Terminal.Lib.fsproj │ ├── AssemblyLoadBuilder.fs │ ├── Consts.fs │ ├── FSharpInteractive.fs │ └── PreRunCode.fs ├── AngouriMath.Terminal │ ├── AngouriMath.Terminal.fsproj │ ├── PackageReadme.md │ ├── Program.fs │ ├── UserInterface.fs │ ├── icon.ico │ ├── icon.png │ ├── pack-deb-linux.sh │ └── publish.sh ├── VERSION │ └── VERSION ├── readme.md ├── screenshot.png └── terminal.gif ├── Tests ├── CPPWrapperUnitTests │ ├── Test.bat │ └── tests │ │ ├── CMakeLists.txt │ │ └── RunTests.cpp ├── DotnetBenchmark │ ├── BenchLinqCompilation.cs │ ├── CacheCompiledFunc.cs │ ├── CommonFunctionsInterVersion.cs │ ├── DotnetBenchmark.csproj │ ├── Program.cs │ └── RAMUsageTest.cs ├── FSharpWrapperUnitTests │ ├── Common.fs │ ├── CompilationTest.fs │ ├── CoreTest.fs │ ├── FSharpWrapperUnitTests.fsproj │ ├── Functions.Continuous.fs │ ├── Functions.Discrete.fs │ ├── Functions.Matrices.fs │ ├── Functions.Order.fs │ ├── Functions.Sets.fs │ ├── MatricesTest.fs │ ├── Program.fs │ ├── ShortcutsTest.fs │ └── Utils.fs ├── InteractiveWrapperUnitTests │ ├── AggressiveOperators.fs │ ├── HtmlOutput.fs │ ├── InteractiveWrapperUnitTests.fsproj │ └── Program.fs ├── TerminalUnitTests │ ├── Program.fs │ ├── TerminalUnitTests.fsproj │ └── Tests.fs └── UnitTests │ ├── Algebra │ ├── FunctionTest.cs │ ├── MatrixTest.cs │ ├── NumberTheoryTest.cs │ └── SolveTest │ │ ├── SolveEquationWithConstraints.cs │ │ ├── SolveEquationWithPiecewise.cs │ │ ├── SolveInequality.cs │ │ ├── SolveOneEquation.cs │ │ ├── SolveStatement.cs │ │ ├── SolveSystem.cs │ │ └── SolverNumericalTests.cs │ ├── Calculus │ ├── DerivativeTest.cs │ ├── IntegrationTest.cs │ ├── LimitTest.cs │ └── SeriesTest.cs │ ├── Common │ ├── BuiltinFunctionsAppliedTest.cs │ ├── CircleTest.cs │ ├── CompilationFETest.cs │ ├── CompilationIntoLinqTest.cs │ ├── ExpandCollapseTest.cs │ ├── FreeVariablesTest.cs │ ├── HierarchyTest.cs │ ├── ImplicitOperators.cs │ ├── InnerSimplifyTest.cs │ ├── LambdaCalculusTest.cs │ ├── NonStrictTest.cs │ ├── OperatorTest.cs │ └── SubstituteTest.cs │ ├── Convenience │ ├── Casts.cs │ ├── ExtensionTest.cs │ ├── FromStringTest.cs │ ├── LatexTest.cs │ ├── PriorityTest.cs │ ├── SynonymFunctionTest.cs │ ├── ToSymPyTEst.cs │ └── TupleToIntervalTest.cs │ ├── Core │ ├── Domains.cs │ ├── Multithreading │ │ ├── CancelTest.cs │ │ ├── MultithreadedTest.cs │ │ ├── MultithreadingCancel.cs │ │ └── SettingsAndThreads.cs │ ├── Numeric.cs │ ├── NumericDigits.cs │ ├── NumericDowncasting.cs │ ├── PolyParser.cs │ ├── Sets │ │ ├── Arithmetics.cs │ │ ├── CSetAndCSet.cs │ │ ├── Contains.cs │ │ ├── FiniteAndFinite.cs │ │ ├── General.cs │ │ ├── IntervalAndInterval.cs │ │ └── SetsTest.cs │ ├── Settings.cs │ ├── TreeEqualityPrecision.cs │ └── UserInvalidExceptions.cs │ ├── Discrete │ ├── BooleanEval.cs │ ├── BooleanSolver.cs │ ├── EqualityInequalityEval.cs │ └── InSet.cs │ ├── GenericMath.cs │ ├── GlobalSuppressions.cs │ ├── PatternsTest │ ├── BooleanSimplify.cs │ ├── FractionSimplify.cs │ ├── PatternTest.cs │ ├── PhiSimplify.cs │ ├── SetSimplify.cs │ ├── SimplifyTest.cs │ ├── SmartExpander.cs │ ├── SortSimplifyTest.cs │ └── TrigTest.cs │ ├── TestUtils.cs │ ├── UnitTests.csproj │ └── xunit.runner.json ├── Utils ├── Utils │ ├── AdditionalExtensionsTestGenerator.cs │ ├── AntlrPostProcessor.cs │ ├── CommonTemplate.txt │ ├── CopyCovReport.cs │ ├── EquationSystemFunctionPattern.txt │ ├── ExportsGenerator │ │ ├── ExportedFunctions.txt │ │ ├── ExportsGenerator.cs │ │ ├── ImportFile.txt │ │ ├── ImportedFunctions.txt │ │ ├── UsingFile.txt │ │ └── UsingFunctions.txt │ ├── ExtensionGenerator.cs │ ├── Program.cs │ ├── SourceGenerator.cs │ ├── TupleToIntervalTemplate.txt │ ├── TupleToIntervalTest.txt │ └── Utils.csproj ├── antlr_rerun.bat ├── generate_additional_extensions.bat ├── generate_additional_extensions_tests.bat └── generate_exports.bat ├── Wrappers ├── AngouriMath.CPP.Exporting │ ├── A.Exports.Hyperbolic.Functions.cs │ ├── A.Exports.MathS.Functions.cs │ ├── AngouriMath.CPP.Exporting.csproj │ ├── Build │ │ ├── 1.generate-exports.bat │ │ ├── 2.build-win-x64.bat │ │ └── 3.pack-win-x64.bat │ ├── CSharpWorkarounds.cs │ ├── Exceptions.cs │ ├── Exports.Entity.Methods.cs │ ├── Exports.Entity.Operators.cs │ ├── Exports.Entity.Properties.cs │ ├── Exports.Free.cs │ ├── Exports.MathS.Functions.cs │ ├── Exports.cs │ ├── IFreeable.cs │ ├── NativeStructs │ │ ├── ErrorCode.cs │ │ ├── NativeArray.cs │ │ ├── NativeBool.cs │ │ └── ObjRef.cs │ ├── ObjectStorage.cs │ └── README.md ├── AngouriMath.CPP.Importing │ ├── A.Imports.Hyperbolic.Functions.h │ ├── A.Imports.MathS.Functions.h │ ├── A.Usages.Hyperbolic.Functions.h │ ├── A.Usages.MathS.Functions.h │ ├── AmgouriMathException.h │ ├── AngouriMath.CPP.natvis │ ├── AngouriMath.cpp │ ├── AngouriMath.h │ ├── CMakeLists.txt │ ├── CMakeSettings.json │ ├── ErrorCode.cpp │ ├── ErrorCode.h │ ├── FieldCache.h │ ├── Imports.h │ └── TypeAliases.h ├── AngouriMath.FSharp │ ├── AngouriMath.FSharp.fsproj │ ├── Compilation.fs │ ├── Constants.fs │ ├── Core.fs │ ├── Functions.fs │ ├── Matrices.fs │ ├── Operators.fs │ ├── PackageReadme.md │ ├── Shortcuts.fs │ ├── fsharp.key │ └── icon.png └── AngouriMath.Interactive │ ├── AggressiveOperators.fs │ ├── AngouriMath.Interactive.fsproj │ ├── KernelExtension.fs │ ├── PackageReadme.md │ ├── Plot.fs │ ├── Repack.ps1 │ └── icon.png └── icon.png /.github/ISSUE_TEMPLATE/ask_question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a question 3 | about: The Issues tab is not only for bug reports. Feel free to ask questions about the project! 4 | title: '' 5 | labels: Question 6 | assignees: '' 7 | 8 | --- 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Report a bug 3 | about: If you encounter unexpected behaviour or a bug, feel free to create an issue for it. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **The version I use**: 15 | 16 | **Unexpected behaviour or bug**: 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggest_idea.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Suggest an idea 3 | about: Your ideas might help the project! 4 | title: '' 5 | labels: Proposal 6 | assignees: '' 7 | 8 | --- 9 | 10 | **The package I want to suggest the idea to**: 14 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /.github/additional/readme/icon_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/icon_white.png -------------------------------------------------------------------------------- /.github/additional/readme/interactive.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/interactive.PNG -------------------------------------------------------------------------------- /.github/additional/readme/interactive2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/interactive2.PNG -------------------------------------------------------------------------------- /.github/additional/readme/interactive3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/interactive3.PNG -------------------------------------------------------------------------------- /.github/additional/readme/pic1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/pic1.PNG -------------------------------------------------------------------------------- /.github/additional/readme/side.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/side.PNG -------------------------------------------------------------------------------- /.github/additional/readme/vscnotebook.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/.github/additional/readme/vscnotebook.gif -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: no 3 | 4 | coverage: 5 | precision: 2 6 | round: down 7 | range: "50...100" 8 | patch: no 9 | changes: no 10 | 11 | parsers: 12 | gcov: 13 | branch_detection: 14 | conditional: yes 15 | loop: yes 16 | method: no 17 | macro: no 18 | 19 | comment: 20 | layout: "reach,diff,flags,tree" 21 | behavior: default 22 | require_changes: no 23 | -------------------------------------------------------------------------------- /.github/workflows/Benchmark.yml: -------------------------------------------------------------------------------- 1 | name: 'Kernel Benchmark' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Benchmark: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Setup .NET 7 18 | uses: actions/setup-dotnet@v1 19 | with: 20 | dotnet-version: '7.0.x' 21 | include-prerelease: true 22 | 23 | - name: 'Inter version CPU benchmark' 24 | run: | 25 | cd Sources/Tests/DotnetBenchmark 26 | dotnet run -c Release CommonFunctionsInterVersion 27 | 28 | - name: 'Inter version RAM benchmark' 29 | run: | 30 | cd Sources/Tests/DotnetBenchmark 31 | dotnet run -c Release RAMUsageTest 32 | 33 | -------------------------------------------------------------------------------- /.github/workflows/CSharpBuild.yml: -------------------------------------------------------------------------------- 1 | name: 'C#/Kernel Build' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | AngouriMath: 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | matrix: 16 | os: [windows-latest, ubuntu-latest, macos-latest] 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | submodules: 'recursive' 21 | - name: Setup .NET 7 22 | uses: actions/setup-dotnet@v1 23 | with: 24 | dotnet-version: '7.0.100' 25 | include-prerelease: true 26 | 27 | - name: Build AngouriMath 28 | run: | 29 | cd Sources/AngouriMath/AngouriMath 30 | dotnet build 31 | -------------------------------------------------------------------------------- /.github/workflows/EverythingBuild.yml: -------------------------------------------------------------------------------- 1 | name: 'Solution Build' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Everything: 13 | runs-on: windows-latest # Window application cannot be run on other OS 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | with: 18 | submodules: 'recursive' 19 | 20 | - name: Setup .NET 7 21 | uses: actions/setup-dotnet@v1 22 | with: 23 | dotnet-version: '7.0.x' 24 | include-prerelease: true 25 | 26 | - name: Build AM 27 | run: dotnet build Sources/AngouriMath/AngouriMath/AngouriMath.csproj 28 | 29 | - name: Build FSharp 30 | run: dotnet build Sources/Wrappers/AngouriMath.FSharp/AngouriMath.FSharp.fsproj 31 | 32 | - name: Build Interactive 33 | run: dotnet build Sources/Wrappers/AngouriMath.Interactive/AngouriMath.Interactive.fsproj 34 | 35 | - name: Build Analyzers 36 | run: dotnet build Sources/Analyzers/Analyzers/Analyzers.csproj 37 | 38 | - name: Build Utils 39 | run: dotnet build Sources/Utils/Utils/Utils.csproj 40 | -------------------------------------------------------------------------------- /.github/workflows/FSharpBuild.yml: -------------------------------------------------------------------------------- 1 | name: 'F# Build' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Test: 13 | strategy: 14 | matrix: 15 | os: [windows-latest, ubuntu-latest, macos-latest] 16 | 17 | runs-on: ${{ matrix.os }} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | submodules: 'recursive' 23 | 24 | - name: Setup .NET Core 3.1 25 | uses: actions/setup-dotnet@v1 26 | with: 27 | dotnet-version: 3.1.302 28 | 29 | - name: Setup .NET 7 # The dotnet CLI above is replaced by this but the runtime is kept 30 | uses: actions/setup-dotnet@v1 31 | with: 32 | dotnet-version: '7.0.x' 33 | include-prerelease: true 34 | 35 | - name: Build 36 | run: | 37 | cd Sources/Wrappers 38 | dotnet build AngouriMath.FSharp 39 | -------------------------------------------------------------------------------- /.github/workflows/FSharpTest.yml: -------------------------------------------------------------------------------- 1 | name: 'F# Test' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Test: 13 | strategy: 14 | matrix: 15 | os: [windows-latest, ubuntu-latest, macos-latest] 16 | 17 | runs-on: ${{ matrix.os }} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | submodules: 'recursive' 23 | 24 | - name: Setup .NET 25 | uses: actions/setup-dotnet@v1 26 | with: 27 | dotnet-version: 5.0.202 28 | 29 | - name: Setup .NET 7 30 | uses: actions/setup-dotnet@v1 31 | with: 32 | dotnet-version: '7.0.x' 33 | include-prerelease: true 34 | 35 | - name: Build Tests # We need it to be able to retry 36 | run: | 37 | dotnet add "Sources/Tests/FSharpWrapperUnitTests" package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything 38 | dotnet add "Sources/Tests/FSharpWrapperUnitTests" package GitHubActionsTestLogger 39 | dotnet build Sources/Tests/FSharpWrapperUnitTests 40 | 41 | - name: Test 42 | run: | 43 | dotnet test "Sources/Tests/FSharpWrapperUnitTests" -c Release -l GitHubActions 44 | -------------------------------------------------------------------------------- /.github/workflows/InteractiveBuild.yml: -------------------------------------------------------------------------------- 1 | name: 'Interactive Build' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Test: 13 | strategy: 14 | matrix: 15 | os: [windows-latest, ubuntu-latest, macos-latest] 16 | 17 | runs-on: ${{ matrix.os }} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | submodules: 'recursive' 23 | 24 | - name: Setup .NET Core 3.1 25 | uses: actions/setup-dotnet@v1 26 | with: 27 | dotnet-version: 3.1.302 28 | 29 | - name: Setup .NET 7 # The dotnet CLI above is replaced by this but the runtime is kept 30 | uses: actions/setup-dotnet@v1 31 | with: 32 | dotnet-version: '7.0.x' 33 | include-prerelease: true 34 | 35 | - name: Build 36 | run: | 37 | cd Sources/Wrappers 38 | dotnet build AngouriMath.Interactive 39 | -------------------------------------------------------------------------------- /.github/workflows/InteractiveTest.yml: -------------------------------------------------------------------------------- 1 | name: 'Interactive Test' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Test: 13 | strategy: 14 | matrix: 15 | os: [windows-latest, ubuntu-latest, macos-latest] 16 | 17 | runs-on: ${{ matrix.os }} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | submodules: 'recursive' 23 | 24 | - name: Setup .NET Core 5 25 | uses: actions/setup-dotnet@v1 26 | with: 27 | dotnet-version: 5.0.202 28 | 29 | - name: Setup .NET 7 30 | uses: actions/setup-dotnet@v1 31 | with: 32 | dotnet-version: '7.0.100' 33 | 34 | - name: Build Tests # We need it to be able to retry 35 | run: | 36 | dotnet build Sources/Tests/InteractiveWrapperUnitTests -c Release 37 | dotnet build Sources/Tests/TerminalUnitTests -c Release 38 | 39 | - name: Test Interactive Wrapper 40 | run: | 41 | dotnet test "Sources/Tests/InteractiveWrapperUnitTests" -c Release 42 | 43 | - name: Test Terminal Lib 44 | run: | 45 | dotnet test "Sources/Tests/TerminalUnitTests" -c Release 46 | -------------------------------------------------------------------------------- /.github/workflows/Nuget.yml: -------------------------------------------------------------------------------- 1 | name: 'Upload last-master versions to MyGet' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | main: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Setup .NET 7 13 | uses: actions/setup-dotnet@v1 14 | with: 15 | dotnet-version: '7.0.100' 16 | include-prerelease: true 17 | 18 | - uses: actions/checkout@v2 19 | 20 | - name: 'Pack AngouriMath' 21 | run: | 22 | cd Sources 23 | 24 | # versioning 25 | commithash=$(git rev-parse --short HEAD) 26 | currtime=$(date +%s) 27 | echo "commit hash is $commithash" 28 | echo "time is $currtime" 29 | name=10.0.0-master-$currtime-$commithash 30 | echo "name is $name" 31 | 32 | # AngouriMath 33 | cd AngouriMath/AngouriMath 34 | dotnet restore AngouriMath.csproj 35 | dotnet build AngouriMath.csproj -c release 36 | dotnet pack AngouriMath.csproj -c release -p:PackageVersion=$name 37 | cd bin/release 38 | dotnet nuget push AngouriMath.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget" 39 | cd ../../../.. 40 | 41 | # AngouriMath.FSharp 42 | cd Wrappers/AngouriMath.FSharp 43 | dotnet restore 44 | dotnet build -c Release 45 | dotnet pack -c Release -p:PackageVersion=$name 46 | cd bin/Release 47 | dotnet nuget push AngouriMath.FSharp.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget" 48 | cd ../../../.. 49 | 50 | # AngouriMath.Interactive 51 | cd Wrappers/AngouriMath.Interactive 52 | dotnet restore 53 | dotnet build -c Release 54 | dotnet pack -c Release -p:PackageVersion=$name 55 | cd bin/Release 56 | dotnet nuget push AngouriMath.Interactive.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget" 57 | cd ../../../.. 58 | -------------------------------------------------------------------------------- /.github/workflows/TerminalNightly.yml: -------------------------------------------------------------------------------- 1 | name: 'Terminal nightly builds' 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - 'Sources/Terminal/VERSION/**' 9 | 10 | jobs: 11 | TerminalBuild: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | with: 17 | submodules: 'recursive' 18 | 19 | - name: Setup .NET 7 20 | uses: actions/setup-dotnet@v1 21 | with: 22 | dotnet-version: '7.0.x' 23 | include-prerelease: true 24 | 25 | - name: 'Build terminal' 26 | run: | 27 | cd Sources/Terminal/AngouriMath.Terminal 28 | ./publish.sh 29 | ./pack-deb-linux.sh 30 | 31 | - name: 'Pack' 32 | run: | 33 | for arch in linux-x64 linux-arm linux-arm64 win-x64 win-x86 osx-x64 osx.12-arm64 34 | do 35 | zip -r "angourimath-terminal-${arch}.zip" ./Sources/Terminal/AngouriMath.Terminal/publish-output/$arch 36 | done 37 | 38 | - name: 'Release' 39 | run: | 40 | name=$(cat ./Sources/Terminal/VERSION/VERSION) 41 | echo "Version: $name" 42 | 43 | cp ./Sources/Terminal/AngouriMath.Terminal/publish-output/angourimath-terminal-*.deb . 44 | 45 | echo ${{ secrets.LAB_ACCESS_TOKEN }} > token.txt 46 | gh auth login --with-token < token.txt 47 | gh release create v$name \ 48 | 'angourimath-terminal-linux-x64.zip' \ 49 | 'angourimath-terminal-linux-arm.zip' \ 50 | 'angourimath-terminal-linux-arm64.zip' \ 51 | 'angourimath-terminal-win-x64.zip' \ 52 | 'angourimath-terminal-win-x86.zip' \ 53 | 'angourimath-terminal-osx-x64.zip' \ 54 | 'angourimath-terminal-osx.12-arm64.zip' \ 55 | 'angourimath-terminal-amd64.deb' \ 56 | 'angourimath-terminal-arm.deb' \ 57 | 'angourimath-terminal-arm64.deb' \ 58 | -R asc-community/AngouriMathLab \ 59 | -t 'AngouriMath.Terminal' \ 60 | -n "Expand 'assets' and choose the one for your OS" 61 | 62 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Follow changes here 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct for members and contributors of AngouriMath 2 | 3 | Maintainers, contributors, and anyone participating in the project are supposed to abide by the [**Code of Conduct**](https://github.com/asc-community/.github/blob/main/CODE_OF_CONDUCT.md). Instances of unacceptable behaviour can be reported to wbg@angouri.org. 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019-2022 Angouri 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /Sources/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # CS0660: 'IntervalPiece' defines operator == or operator != but does not override Object.Equals(object o) 4 | dotnet_diagnostic.CS0660.severity = suggestion 5 | 6 | # RS0016: some public method is not mentioned as public API 7 | dotnet_diagnostic.RS0016.severity = error 8 | 9 | # RS0017: some method mentioned as public API is not public 10 | dotnet_diagnostic.RS0017.severity = error 11 | 12 | # Missing header warning 13 | dotnet_diagnostic.IDE0073.severity = warning 14 | 15 | # new can't be simplified ffs 16 | dotnet_diagnostic.IDE0090.severity = none 17 | 18 | # Requires preview features bla-bla 19 | # dotnet_diagnostic.CA2252.severity = none 20 | 21 | file_header_template=\nCopyright (c) 2019-2022 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n 22 | -------------------------------------------------------------------------------- /Sources/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Playground", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "Build Debug Playground", 9 | "program": "${workspaceFolder}/Samples/Samples/bin/Debug/net5.0/Playground.dll", 10 | "args": [], 11 | "cwd": "${workspaceFolder}/Samples/Samples", 12 | "console": "internalConsole", 13 | "stopAtEntry": false 14 | }, 15 | { 16 | "name": "Interactive playground", 17 | "type": "coreclr", 18 | "request": "launch", 19 | "preLaunchTask": "Build Debug InteractivePlayground", 20 | "program": "${workspaceFolder}/Samples/InteractivePlayground/bin/Debug/net5.0/InteractivePlayground.dll", 21 | "args": [], 22 | "cwd": "${workspaceFolder}/Samples/InteractivePlayground", 23 | "console": "internalConsole", 24 | "stopAtEntry": false 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /Sources/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dotnet-test-explorer.testProjectPath": "Tests/*/*Test*.**proj", 3 | "cmake.configureOnOpen": false 4 | } -------------------------------------------------------------------------------- /Sources/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Build Debug Playground", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Samples/Samples/Playground.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile", 15 | "group": { 16 | "kind": "build", 17 | "isDefault": true 18 | } 19 | }, 20 | { 21 | "label": "Build Debug InteractivePlayground", 22 | "command": "dotnet", 23 | "type": "process", 24 | "args": [ 25 | "build", 26 | "${workspaceFolder}/Samples/InteractivePlayground/InteractivePlayground.fsproj", 27 | "-bl" 28 | ], 29 | "problemMatcher": "$msCompile", 30 | "group": { 31 | "kind": "build", 32 | "isDefault": true 33 | } 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | false 6 | Analyzers 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers.CodeFixes/FieldThreadSafetyCodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CodeFixes; 10 | using System.Collections.Immutable; 11 | using System.Composition; 12 | using System.Threading.Tasks; 13 | 14 | namespace Analyzers 15 | { 16 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(FieldThreadSafetyCodeFixProvider)), Shared] 17 | public class FieldThreadSafetyCodeFixProvider : CodeFixProvider 18 | { 19 | public sealed override ImmutableArray FixableDiagnosticIds 20 | { 21 | get { return ImmutableArray.Create(EitherAbstractOrSealed.DiagnosticId); } 22 | } 23 | 24 | public sealed override FixAllProvider GetFixAllProvider() 25 | { 26 | // See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers 27 | return WellKnownFixAllProviders.BatchFixer; 28 | } 29 | 30 | #pragma warning disable CS1998 // To be implemented yet 31 | public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) 32 | #pragma warning restore CS1998 33 | { 34 | 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers.Debug/Analyzers.Debug.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net472 7 | Analyzers.Debug 8 | Analyzers.Debug 9 | win 10 | 11 | 12 | 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | Roslyn 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Program 28 | $(DevEnvDir)devenv.exe 29 | /rootsuffix $(VSSDKTargetPlatformRegRootSuffix) 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers.Debug/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Analyzers 6 | This extension allows to easily debug analyzers for AngouriMath 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers/Analyzers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | false 6 | 7 | 8 | *$(MSBuildProjectFullPath)* 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers/EitherAbstractOrSealed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | using System.Collections.Immutable; 11 | using System.Linq; 12 | 13 | 14 | namespace Analyzers 15 | { 16 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 17 | public class EitherAbstractOrSealed : DiagnosticAnalyzer 18 | { 19 | public const string DiagnosticId = "SealedOrAbstract"; 20 | private static readonly string Title = "AMAnalyzer"; 21 | private static readonly string MessageFormat = $"If a type is not sealed, it should be either static or abstract"; 22 | private static readonly string Description = "Unsafe type extension prevention."; 23 | private const string Category = "Security"; 24 | 25 | private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description); 26 | 27 | public override ImmutableArray SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } } 28 | 29 | public override void Initialize(AnalysisContext context) 30 | { 31 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 32 | context.EnableConcurrentExecution(); 33 | 34 | context.RegisterSymbolAction(symbolContext => 35 | { 36 | var typeDecl = (INamedTypeSymbol)symbolContext.Symbol; 37 | var containingType = typeDecl.ContainingType; 38 | if (!typeDecl.IsAbstract && !typeDecl.IsSealed && !typeDecl.IsStatic) 39 | { 40 | var diag = Diagnostic.Create(Rule, typeDecl.Locations.First()); 41 | symbolContext.ReportDiagnostic(diag); 42 | } 43 | }, SymbolKind.NamedType); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/Analyzers/Analyzers/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Diagnostics.CodeAnalysis; 9 | 10 | // Most warnings about shipping are because we are not planning to ship 11 | // this analyzer, it is exclusively for contributors of the project. 12 | 13 | [assembly: SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking", Justification = "", Scope = "member", Target = "~F:Analyzers.StaticFieldThreadSafety.RuleShouldBeNull")] 14 | [assembly: SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking", Justification = "", Scope = "member", Target = "~F:Analyzers.StaticFieldThreadSafety.RuleAddAttribute")] 15 | [assembly: SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking", Justification = "", Scope = "member", Target = "~F:Analyzers.EitherAbstractOrSealed.Rule")] 16 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/AngouriMath.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net7.0; 6 | net472; 7 | netstandard2.0; 8 | netstandard2.1; 9 | 10 | 11 | AngouriMath 12 | AngouriMath 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Antlr/ParsingHelpers.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | using static AngouriMath.Entity; 10 | 11 | namespace AngouriMath.Core.Antlr 12 | { 13 | internal static class ParsingHelpers 14 | { 15 | internal static Matrix TryBuildingMatrix(List elements) 16 | { 17 | if (!elements.Any()) 18 | return MathS.Vector(elements.ToArray()); 19 | var first = elements.First(); 20 | if (first is not Matrix { IsVector: true } firstVec) 21 | return MathS.Vector(elements.ToArray()); 22 | var tb = new MatrixBuilder(firstVec.RowCount); 23 | foreach (var row in elements) 24 | { 25 | if (row is not Matrix { IsVector: true } rowVec) 26 | return MathS.Vector(elements.ToArray()); 27 | if (rowVec.RowCount != firstVec.RowCount) 28 | return MathS.Vector(elements.ToArray()); 29 | tb.Add(rowVec); 30 | } 31 | return tb.ToMatrix() ?? throw new AngouriBugException("Should've been checked already"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Antlr/antlr-4.8-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/AngouriMath/AngouriMath/Core/Antlr/antlr-4.8-complete.jar -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/CoreAttributes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | 10 | namespace AngouriMath.Core 11 | { 12 | /// 13 | /// Use this attribute on those static fields that do not require thread static attribute 14 | /// because they are constant 15 | /// 16 | [AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] 17 | internal sealed class ConstantFieldAttribute : Attribute { } 18 | 19 | /// 20 | /// Use this attribute on those static fields that are already synchronized 21 | /// internally or explicitly 22 | /// 23 | [AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] 24 | internal sealed class ConcurrentFieldAttribute : Attribute { } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Domains.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Entity.Set; 9 | 10 | namespace AngouriMath.Core 11 | { 12 | /// 13 | /// Specify the domain used within a record 14 | /// 15 | public enum Domain 16 | { 17 | /// 18 | /// The domain of all boolean values (true, false) 19 | /// 20 | Boolean, 21 | 22 | /// 23 | /// The domain of all integer values 24 | /// 25 | Integer, 26 | 27 | /// 28 | /// The domain of all rational values 29 | /// 30 | Rational, 31 | 32 | /// 33 | /// The domain of all real values 34 | /// 35 | Real, 36 | 37 | /// 38 | /// The domain of all complex values 39 | /// 40 | Complex, 41 | 42 | /// 43 | /// The domain of all values (might be removed in the future) 44 | /// 45 | Any 46 | } 47 | 48 | internal static class DomainsFunctional 49 | { 50 | public static bool FitsDomainOrNonNumeric(Entity entity, Domain domain) 51 | => domain == Domain.Any || SpecialSet.Create(domain).MayContain(entity); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/Continuous/Entity.Continuous.AbsSignum.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | #pragma warning disable CS1591 // only while records' parameters cannot be documented 15 | /// 16 | /// A node of signum 17 | /// 18 | public sealed partial record Signumf(Entity Argument) : Function, IUnaryNode 19 | { 20 | public Entity NodeChild => Argument; 21 | 22 | private Signumf New(Entity arg) => 23 | ReferenceEquals(Argument, arg) ? this : new(arg); 24 | /// 25 | public override Entity Replace(Func func) => func(New(Argument.Replace(func))); 26 | /// 27 | protected override Entity[] InitDirectChildren() => new[] { Argument }; 28 | } 29 | 30 | /// 31 | /// A node of abs 32 | /// 33 | public sealed partial record Absf(Entity Argument) : Function, IUnaryNode 34 | { 35 | public Entity NodeChild => Argument; 36 | 37 | private Absf New(Entity arg) => 38 | ReferenceEquals(Argument, arg) ? this : new(arg); 39 | /// 40 | public override Entity Replace(Func func) => func(New(Argument.Replace(func))); 41 | /// 42 | protected override Entity[] InitDirectChildren() => new[] { Argument }; 43 | } 44 | #pragma warning restore CS1591 // only while records' parameters cannot be documented 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/Continuous/Entity.Continuous.Factorial.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | #pragma warning disable CS1591 // only while records' parameters cannot be documented 15 | /// 16 | /// A node of factorial 17 | /// 18 | public sealed partial record Factorialf(Entity Argument) : Function, IUnaryNode 19 | { 20 | /// Reuse the cache by returning the same object if possible 21 | private Factorialf New(Entity argument) => ReferenceEquals(Argument, argument) ? this : new(argument); 22 | // This is still a function for pattern replacement 23 | internal override Priority Priority => Priority.Factorial; 24 | 25 | public Entity NodeChild => Argument; 26 | 27 | /// 28 | public override Entity Replace(Func func) => func(New(Argument.Replace(func))); 29 | /// 30 | protected override Entity[] InitDirectChildren() => new[] { Argument }; 31 | } 32 | #pragma warning restore CS1591 // only while records' parameters cannot be documented 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/GenericMath/Entity.GenericMath.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Diagnostics.CodeAnalysis; 10 | using System.Numerics; 11 | 12 | namespace AngouriMath; 13 | 14 | partial record Entity : 15 | IParsable, 16 | 17 | IEqualityOperators, 18 | 19 | IHasNeutralValues, 20 | 21 | IClosedArithmetics, 22 | IDivisionOperators 23 | { 24 | /// 25 | /// Parses the string into expression. 26 | /// Ignores the provided format provider. 27 | /// 28 | public static Entity Parse(string s, IFormatProvider? _) 29 | => s; 30 | 31 | /// 32 | /// Tries to parse the string into expression. 33 | /// Ignores the provided format provider. 34 | /// 35 | public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? _, out Entity result) 36 | => MathS.Parse(s ?? throw new ArgumentNullException()).Is(out result); 37 | 38 | /// 39 | public static Entity AdditiveIdentity => 0; 40 | 41 | /// 42 | public static Entity MultiplicativeIdentity => 1; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/GenericMath/IClosedArithmetics.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Numerics; 9 | 10 | namespace AngouriMath.Core; 11 | 12 | /// 13 | /// Represents operators closed in respect to the 14 | /// set of integer, rational, real, complex numbers 15 | /// and matrices. 16 | /// 17 | public interface IClosedArithmetics : 18 | IUnaryNegationOperators, 19 | IUnaryPlusOperators, 20 | 21 | IAdditionOperators, 22 | ISubtractionOperators, 23 | IMultiplyOperators 24 | 25 | where T : IClosedArithmetics 26 | { 27 | 28 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/GenericMath/IHasAbsoluteValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.Core; 9 | 10 | 11 | /// 12 | /// Values which have absolute value 13 | /// 14 | public interface IHasAbsoluteValue 15 | where TSelf : IHasAbsoluteValue 16 | { 17 | /// 18 | /// The absolute value of the entity 19 | /// 20 | abstract static TOut Abs(TSelf self); 21 | } 22 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/GenericMath/IHasNeutralValues.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Numerics; 9 | 10 | namespace AngouriMath.Core; 11 | 12 | /// 13 | /// Entities which have 14 | /// both multiplicative and additive 15 | /// identities. 16 | /// 17 | /// 18 | public interface IHasNeutralValues : 19 | IMultiplicativeIdentity, 20 | IAdditiveIdentity 21 | where T : IHasNeutralValues 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/GenericMath/IScalarClosedArithmetics.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Numerics; 9 | 10 | namespace AngouriMath.Core; 11 | 12 | /// 13 | /// Represents comparable items 14 | /// of 15 | /// 16 | public interface IScalarClosedArithmetics : 17 | IClosedArithmetics, 18 | IComparisonOperators 19 | 20 | where T : IScalarClosedArithmetics 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/HashCodeFunctional.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | 10 | namespace AngouriMath.Core.HashCode 11 | { 12 | internal static class HashCodeFunctional 13 | { 14 | public enum HashCodeShifts 15 | { 16 | FiniteSet = 0x10000000, 17 | Piecewise = 0x20000000 18 | } 19 | 20 | public static int Multielement(HashCodeShifts type, IEnumerable objects) 21 | => (int)type | 22 | objects.Count() switch 23 | { 24 | 0 => 0, 25 | 1 => objects.First()?.GetHashCode() ?? throw new AngouriBugException("If count is 1, it can't be null"), 26 | _ => objects.Select(c => c?.GetHashCode() ?? throw new AngouriBugException("Can't be null here")).Aggregate((acc, next) => (acc, next).GetHashCode()) 27 | }; 28 | 29 | public static int HashCodeOfSequence(this IEnumerable @this, HashCodeShifts type) 30 | => Multielement(type, @this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/INode.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.Core 9 | { 10 | /// 11 | /// From this interface all single-argument nodes are inherited 12 | /// 13 | public interface IUnaryNode 14 | { 15 | /// 16 | /// The only child of the node 17 | /// 18 | public Entity NodeChild { get; } 19 | } 20 | 21 | /// 22 | /// From this interface all double-argument nodes are inherited 23 | /// 24 | public interface IBinaryNode 25 | { 26 | /// 27 | /// The left child of the node 28 | /// 29 | public Entity NodeFirstChild { get; } 30 | 31 | /// 32 | /// The right child of the node 33 | /// 34 | public Entity NodeSecondChild { get; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/Omni/Entity.Omni.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Entity.Set; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | /// 15 | /// Creates a node of whether the given element is an element of the given set 16 | /// 17 | /// 18 | /// The assumed super-set of the given expression. 19 | /// 20 | /// A node 21 | public Entity In(Entity supSet) 22 | => new Inf(this, supSet); 23 | 24 | /// 25 | /// Creates a node of a expression assuming some condition 26 | /// 27 | /// 28 | /// A condition under which a given expression (this) is valid. 29 | /// 30 | /// A node 31 | public Entity Provided(Entity that) 32 | => new Providedf(this, that); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Entity/Omni/Sets/SetOperators.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Entity.Set; 9 | 10 | namespace AngouriMath.Core.Sets 11 | { 12 | internal static partial class SetOperators 13 | { 14 | internal static (ConditionalSet one, ConditionalSet another) MergeToOneVariable 15 | (ConditionalSet one, ConditionalSet another) 16 | { 17 | var stat1 = another.Predicate.Substitute(another.Var, one.Var); 18 | return (one, (ConditionalSet)another.New(one.Var, stat1)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Exceptions/AngouriMathBaseException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | 10 | namespace AngouriMath.Core.Exceptions 11 | { 12 | /// 13 | /// This is the base exception of all exceptions thrown by AngouriMath. 14 | /// If one needs to catch all exceptions from AngouriMath, it is enough 15 | /// to catch this one 16 | /// 17 | public abstract class AngouriMathBaseException : Exception 18 | { 19 | internal AngouriMathBaseException() { } 20 | internal AngouriMathBaseException(string msg) : base(msg) { } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Core/Multithreading/MultithreadingFunctional.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Threading; 9 | 10 | namespace AngouriMath.Core.Multithreading 11 | { 12 | internal static class MultithreadingFunctional 13 | { 14 | #pragma warning disable ThreadSafety // Because it is AsyncLocal 15 | private static readonly AsyncLocal globalCancellationToken = new(); 16 | #pragma warning restore ThreadSafety // AMAnalyzer 17 | 18 | internal static void SetLocalCancellationToken(CancellationToken? token) 19 | => globalCancellationToken.Value = token; 20 | 21 | // Inject this code in places where the function might potentially get stuck 22 | internal static void ExitIfCancelled() 23 | { 24 | var token = globalCancellationToken.Value; 25 | if (token is { } tok) 26 | tok.ThrowIfCancellationRequested(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Contributing/General.md: -------------------------------------------------------------------------------- 1 | ## General information for contributors 2 | 3 | AM's class structure is a hierarchy with `Entity` as the ultimate class. All class-nodes are defined 4 | inside of `Entity`. Those that can be simplifed to a number are inherited from `NumericNode`, but are not 5 | located in this class. Those that can be simplified to a boolean are inherited from `BooleanNode`, but are not 6 | located in this class. -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Contributing/ImproveParser.md: -------------------------------------------------------------------------------- 1 | If you want to contribute to the parser, follow these steps: 2 | 1. Make sure you have the JRE (Java Runtime Environment) installed on your machine 3 | 2. Change the file ./AngouriMath/Core/Antlr/AngouriMath.g (other source files in the Antlr folder are generated from this file) 4 | 3. Run `start ./Utils/antlr_rerun.bat` or `./Utils/antlr_rerun.bat` to regenerate the parser via ANTLR 5 | 4. Observe that other source files in the Antlr folder have been updated -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Contributing/README.md: -------------------------------------------------------------------------------- 1 | ## Documentation for contributors and developers 2 | 3 | This folder contains documentation required for proper contributing to the project. Some files are in `.cs` so that 4 | it is easier to go through links. 5 | 6 | If you aren't sure about what to add, you may want to check the current projects 7 | [here](https://github.com/asc-community/AngouriMath/projects). 8 | 9 | #### Table of content 10 | 1. General information 11 | 2. Adding a new node (function, operator) 12 | 3. Improve parser 13 | 4. Adding a public member -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Contributing/RS1617Errors.md: -------------------------------------------------------------------------------- 1 | ## Public methods and classes 2 | 3 | When adding a class for purposes inside the library, you must not mark them as `public`. 4 | When adding a method, make sure that it's either not `public` or the class you are adding the method to 5 | is not `public`. 6 | 7 | However, if you intentionally want to add a publicly-exposed functional, you will get the 8 | RS0016 error. 9 | 10 | That means you're required to report about this public method or class. You can simply add it to the 11 | PublicApi.*.txt file or hit `ctrl + .` to do it. -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Contributing/coding_rules.md: -------------------------------------------------------------------------------- 1 | ## Coding rules 2 | 3 | It is highly recommended to follow them to avoid rewriting your code after submitting a PR. 4 | 5 | ### OOP 6 | 7 | Each inheritable type is either abstract or sealed. 8 | 9 | ### Immutability 10 | 11 | It should be guaranteed that the user cannot change fields of a record which is inherited from `Entity`. -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/Usage/Exceptions.md: -------------------------------------------------------------------------------- 1 | ### AngouriMathBaseException 2 | 3 | ... is the ultimate exception, the root of all exceptions thrown by AngouriMath. If needed to catch all exceptions thrown by 4 | AngouriMath exclusively, catch this one. -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Docs/WhatsNew/README.md: -------------------------------------------------------------------------------- 1 | ### What's new 2 | 3 | See [here](https://am.angouri.org/#whatsnew). -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Boolean/AnalyticalSolving/AnalyticalSolver.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | using AngouriMath.Functions.Boolean.AnalyticalSolving; 10 | 11 | namespace AngouriMath 12 | { 13 | partial record Entity 14 | { 15 | /// 16 | /// Solves the given equation over 17 | /// symbolically 18 | /// 19 | public Set SolveBoolean(Variable x) 20 | => BooleanAnalyticalSolver.SolveBoolean(this, x); 21 | } 22 | } 23 | 24 | namespace AngouriMath.Functions.Boolean.AnalyticalSolving 25 | { 26 | using static Entity; 27 | internal static class BooleanAnalyticalSolver 28 | { 29 | internal static Set SolveBoolean(Entity expr, Variable x) 30 | => throw FutureReleaseException.Raised("Piecewise", "1.2.1"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Compilation/Compile.FE.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Core.FastExpression; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | /// 15 | /// Compile function so you can evaluate numerical value 15x faster, 16 | /// than subsitution 17 | /// 18 | /// 19 | /// List string names of variables in the same order as you will list them when evaluating. 20 | /// Constants, i.e. and will be ignored. 21 | /// 22 | /// 23 | public FastExpression Compile(params Variable[] variables) => Compiler.Compile(this, variables); 24 | 25 | /// 26 | /// Compile function so you can evaluate numerical value 15x faster, 27 | /// than subsitution 28 | /// 29 | /// 30 | /// List string names of variables in the same order as you will list them when evaluating. 31 | /// Constants, i.e. and will be ignored. 32 | /// 33 | /// 34 | public FastExpression Compile(params string[] variables) => 35 | Compiler.Compile(this, variables.Select(x => (Variable)x)); 36 | } 37 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Compilation/IntoLinq/DefaultConverters.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Linq.Expressions; 10 | using static AngouriMath.Entity; 11 | 12 | namespace AngouriMath.Core.Compilation.IntoLinq 13 | { 14 | /// 15 | /// It is a storage of default constant converters that you can use 16 | /// 17 | [Obsolete("Default converters have been moved to CompilationProtocol.")] 18 | public static class CompilationProtocolBuiltinConstantConverters 19 | { 20 | [ConstantField] private static CompilationProtocol defaultProtocol = new(); 21 | 22 | /// 23 | public static Expression ConverterConstant(Entity e) => defaultProtocol.ConvertConstant(e); 24 | 25 | /// 26 | public static Expression ConverterNaN(Type type) => defaultProtocol.ConvertNaN(type); 27 | 28 | /// 29 | public static Expression ConverterType(Expression expr, Type type) => defaultProtocol.ConvertType(expr, type); 30 | 31 | /// 32 | public static Expression OneArgumentEntity(Expression e, Entity typeHolder) => defaultProtocol.ConvertUnaryNode(e, typeHolder); 33 | 34 | /// 35 | public static Expression TwoArgumentEntity(Expression left, Expression right, Entity typeHolder) => defaultProtocol.ConvertBinaryNode(left, right, typeHolder); 36 | 37 | /// 38 | public static Expression AnyArgumentEntity(IEnumerable en, Entity typeHolder) => defaultProtocol.ConvertOtherNode(en, typeHolder); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.Functions.Algebra 9 | { 10 | internal static class IntegralPatterns 11 | { 12 | internal static Entity? TryStandardIntegrals(Entity expr, Entity.Variable x) => expr switch 13 | { 14 | Entity.Sinf(var arg) when 15 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 16 | -MathS.Cos(arg) / a, 17 | 18 | Entity.Cosf(var arg) when 19 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 20 | MathS.Sin(arg) / a, 21 | 22 | Entity.Secantf(var arg) when 23 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 24 | MathS.Hyperbolic.Artanh(MathS.Sin(arg)) / a, 25 | 26 | Entity.Cosecantf(var arg) when 27 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 28 | MathS.Ln(MathS.Tan(0.5 * arg)) / a, 29 | 30 | Entity.Tanf(var arg) when 31 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 32 | -MathS.Ln(MathS.Cos(arg)) / a, 33 | 34 | Entity.Cotanf(var arg) when 35 | TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => 36 | MathS.Ln(MathS.Sin(arg)) / a, 37 | 38 | Entity.Logf(var @base, var arg) when 39 | !@base.ContainsNode(x) && TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out var b) => 40 | ((b / a + x) * MathS.Ln(arg) - x) / MathS.Ln(@base), 41 | 42 | Entity.Powf(var @base, var power) when 43 | !@base.ContainsNode(x) && TreeAnalyzer.TryGetPolyLinear(power, x, out var a, out _) => 44 | MathS.Pow(@base, power) / (a * MathS.Ln(@base)), 45 | 46 | _ => null 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/EquationSolver/TrigonometricSolver.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Multithreading; 9 | using AngouriMath.Extensions; 10 | 11 | namespace AngouriMath.Functions.Algebra.AnalyticalSolving 12 | { 13 | using static AngouriMath.Entity.Set; 14 | using static Entity; 15 | internal static class TrigonometricSolver 16 | { 17 | // solves equation f(sin(x), cos(x), tan(x), cot(x)) for x 18 | internal static bool TrySolveLinear(Entity expr, Variable variable, out Set res) 19 | { 20 | res = Empty; 21 | var replacement = Variable.CreateTemp(expr.Vars); 22 | expr = expr.Replace(Patterns.NormalTrigonometricForm); 23 | expr = expr.Replace(Patterns.TrigonometricToExponentialRules(variable, replacement)); 24 | MultithreadingFunctional.ExitIfCancelled(); 25 | // if there is still original variable after replacements, 26 | // equation is not in a form f(sin(x), cos(x), tan(x), cot(x)) 27 | if (expr.ContainsNode(variable)) 28 | return false; 29 | 30 | if (AnalyticalEquationSolver.Solve(expr, replacement) is FiniteSet els) 31 | { 32 | MultithreadingFunctional.ExitIfCancelled(); 33 | res = (Set)els.Select(sol => MathS.Pow(MathS.e, MathS.i * variable).Invert(sol, variable).ToSet()).Unite().InnerSimplified; 34 | return true; 35 | } 36 | else 37 | return false; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/SetSolver/AnalyticalSetSolver.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Extensions; 9 | using static AngouriMath.Entity; 10 | using static AngouriMath.Entity.Set; 11 | 12 | namespace AngouriMath.Functions.Continuous.Solvers.SetSolver 13 | { 14 | internal static class AnalyticalSetSolver 15 | { 16 | internal static Set Solve(Entity left, Entity right, Variable x) 17 | { 18 | left = left.Replace(Patterns.SetOperatorRules); 19 | right = right.Replace(Patterns.SetOperatorRules); 20 | if (left.DirectChildren.Count(c => c == x) 21 | + 22 | right.DirectChildren.Count(c => c == x) != 1) 23 | return Empty; 24 | if (left.ContainsNode(x)) 25 | return left.Invert(right, x).ToSet(); 26 | else 27 | return right.Invert(left, x).ToSet(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | /// 15 | /// Use this to verify whether it is safe to call 16 | /// 17 | public bool EvaluableNumerical => Evaled is Complex; 18 | 19 | /// 20 | /// Evaluates a given expression to one number or throws exception 21 | /// 22 | /// 23 | /// since new version 24 | /// 25 | /// 26 | /// Thrown when this entity cannot be represented as a simple number. 27 | /// should be used to check beforehand. 28 | /// 29 | public Complex EvalNumerical() => 30 | Evaled is Complex value ? value : 31 | throw new CannotEvalException 32 | ($"Result cannot be represented as a simple number! Use {nameof(EvaluableNumerical)} to check beforehand."); 33 | } 34 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Evaluation/Evaluation.Discrete/Evaluation.Discrete.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | /// 15 | /// Use this to verify whether it is safe to call 16 | /// 17 | public bool EvaluableBoolean => Evaled is Boolean; 18 | 19 | /// 20 | /// Evaluates a given expression to one boolean or throws exception 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// Thrown when this entity cannot be represented as a simple boolean. 27 | /// should be used to check beforehand. 28 | /// 29 | public Boolean EvalBoolean() => 30 | Evaled is Boolean value ? value : 31 | throw new CannotEvalException 32 | ($"Result cannot be represented as a simple boolean! Use {nameof(EvaluableBoolean)} to check beforehand."); 33 | } 34 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Sets; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | /// 15 | public Entity Apply(params Entity[] args) => new Application(this, LList.Of(args)); 16 | /// 17 | public Entity Apply(LList args) => new Application(this, args); 18 | /// 19 | public Entity LambdaOver(Variable param) 20 | => new Lambda(param, this); 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/Latex.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | using Core; 11 | partial record Entity : ILatexiseable 12 | { 13 | /// 14 | /// Returns the expression in LaTeX 15 | /// 16 | /// 17 | /// 18 | /// Entity expr = "a / b + sqrt(c)"; 19 | /// Console.WriteLine(expr.Latexise()); 20 | /// 21 | /// Output: 22 | /// 23 | /// \frac{a}{b}+\sqrt{c} 24 | /// 25 | /// 26 | /// 27 | /// 28 | /// using System; 29 | /// using AngouriMath; 30 | /// using static AngouriMath.MathS; 31 | /// 32 | /// Entity expr = "sqrt(a) + integral(sin(x), x)"; 33 | /// Console.WriteLine(expr); 34 | /// Console.WriteLine(expr.Latexise()); 35 | /// Entity expr2 = "a / b ^ limit(sin(x) - cosh(y), x, +oo)"; 36 | /// Console.WriteLine(expr2); 37 | /// Console.WriteLine(expr2.Latexise()); 38 | /// 39 | /// Prints 40 | /// 41 | /// sqrt(a) + integral(sin(x), x) 42 | /// \sqrt{a}+\int \left[\sin\left(x\right)\right] dx 43 | /// a / b ^ limit(sin(x) - (e ^ y + e ^ (-y)) / 2, x, +oo) 44 | /// \frac{a}{{b}^{\lim_{x\to \infty } \left[\sin\left(x\right)-\frac{{e}^{y}+{e}^{-y}}{2}\right]}} 45 | /// 46 | /// 47 | public abstract string Latexise(); 48 | 49 | /// Returns the expression in LaTeX (for example, a / b -> \frac{a}{b}) 50 | /// Whether to wrap it with parentheses 51 | protected internal string Latexise(bool parenthesesRequired) => 52 | parenthesesRequired ? @$"\left({Latexise()}\right)" : Latexise(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/Latex/Latex.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | public partial record Variable 13 | { 14 | /// 15 | /// List of constants LaTeX will correctly display 16 | /// Yet to be extended 17 | /// Case does matter, not all letters have both displays in LaTeX 18 | /// 19 | [ConstantField] 20 | private static readonly HashSet LatexisableConstants = new HashSet 21 | { 22 | "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta", "eta", "theta", "vartheta", 23 | "iota", "kappa", "varkappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "varpi", "rho", 24 | "varrho", "sigma", "varsigma", "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", 25 | 26 | "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon", "Phi", "Psi", "Omega", 27 | }; 28 | 29 | private static string LatexiseIfCan(string symbol) 30 | => LatexisableConstants.Contains(symbol) ? $@"\{symbol}" : symbol; 31 | 32 | /// 33 | /// Returns latexised const if it is possible to latexise it, 34 | /// or its original name otherwise 35 | /// 36 | public override string Latexise() => 37 | SplitIndex() is var (prefix, index) 38 | ? 39 | $"{LatexiseIfCan(prefix)}_{{{LatexiseIfCan(index)}}}" 40 | : 41 | LatexiseIfCan(Name); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToString.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | /// 13 | /// Converts an expression into a string. Works synonymically into . 14 | /// 15 | public abstract string Stringize(); 16 | 17 | /// 18 | /// Converts an expression into a string 19 | /// 20 | /// Whether to wrap with '(' and ')' 21 | protected internal string Stringize(bool parenthesesRequired) => 22 | parenthesesRequired || MathS.Diagnostic.OutputExplicit ? $"({Stringize()})" : Stringize(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToString/ToString.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | public partial record Variable 13 | { 14 | /// 15 | public override string Stringize() => Name; 16 | /// 17 | public override string ToString() => Stringize(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToSympy.Definition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | /// Generates Python code that you can use with sympy 13 | internal abstract string ToSymPy(); 14 | 15 | /// 16 | /// Generates python code without any additional symbols that can be run in SymPy 17 | /// 18 | /// 19 | /// Whether to wrap it with parentheses 20 | /// Usually depends on its parental nodes 21 | /// 22 | /// 23 | /// 24 | /// using System; 25 | /// using static AngouriMath.MathS; 26 | /// 27 | /// var (x, y, a) = Var("x", "y", "a"); 28 | /// var expr = Limit(Integral(Sin(x) / (Cos(x) + Tan(y)), x) / a, y, +oo); 29 | /// Console.WriteLine(expr); 30 | /// Console.WriteLine("----------------------------"); 31 | /// Console.WriteLine(ToSympyCode(expr)); 32 | /// 33 | /// Prints 34 | /// 35 | /// limit(integral(sin(x) / (cos(x) + tan(y)), x) / a, y, +oo) 36 | /// ---------------------------- 37 | /// import sympy 38 | /// 39 | /// x = sympy.Symbol('x') 40 | /// y = sympy.Symbol('y') 41 | /// a = sympy.Symbol('a') 42 | /// 43 | /// expr = sympy.limit(sympy.integrate(sympy.sin(x) / (sympy.cos(x) + sympy.tan(y)), x, 1) / a, y, +oo) 44 | /// 45 | /// 46 | protected string ToSymPy(bool parenthesesRequired) => 47 | parenthesesRequired ? @$"({ToSymPy()})" : ToSymPy(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToSympy/ToSympy.Calculus.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Core.Exceptions; 9 | 10 | namespace AngouriMath 11 | { 12 | partial record Entity 13 | { 14 | public partial record Derivativef 15 | { 16 | internal override string ToSymPy() => $"sympy.diff({Expression.ToSymPy()}, {Var.ToSymPy()}, {Iterations})"; 17 | } 18 | 19 | public partial record Integralf 20 | { 21 | // TODO: The 3rd parameter of sympy.integrate is not interpreted as iterations, unlike sympy.diff 22 | // which allows both sympy.diff(expr, var, iterations) and sympy.diff(expr, var1, var2, var3...) 23 | internal override string ToSymPy() => $"sympy.integrate({Expression.ToSymPy()}, {Var.ToSymPy()}, {Iterations})"; 24 | } 25 | 26 | public partial record Limitf 27 | { 28 | internal override string ToSymPy() => 29 | @$"sympy.limit({Expression.ToSymPy()}, {Var.ToSymPy()}, {Destination.ToSymPy()}{ApproachFrom switch 30 | { 31 | ApproachFrom.Left => ", '-'", 32 | ApproachFrom.BothSides => "", 33 | ApproachFrom.Right => ", '+'", 34 | _ => throw new AngouriBugException 35 | ($"Unresolved enum {ApproachFrom}") 36 | }})"; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToSympy/ToSympy.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | public partial record Variable 13 | { 14 | internal override string ToSymPy() 15 | => Name switch 16 | { 17 | "e" => "sympy.E", 18 | "pi" => "sympy.pi", 19 | _ => Name 20 | }; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Output/ToSympy/ToSympy.Number.Classes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath 9 | { 10 | partial record Entity 11 | { 12 | partial record Number 13 | { 14 | partial record Complex 15 | { 16 | internal override string ToSymPy() 17 | { 18 | if (ImaginaryPart == 0) 19 | return RealPart.ToSymPy(); 20 | if (RealPart == 0) 21 | return $"{ImaginaryPart.ToSymPy()} * sympy.I"; 22 | return $"{RealPart.ToSymPy()} + {ImaginaryPart.ToSymPy()} * sympy.I"; 23 | } 24 | } 25 | 26 | partial record Real 27 | { 28 | internal override string ToSymPy() 29 | => Stringize(); 30 | } 31 | 32 | partial record Rational 33 | { 34 | internal override string ToSymPy() 35 | => $"sympy.Rational({Numerator.ToSymPy()}, {Denominator.ToSymPy()}"; 36 | } 37 | 38 | partial record Integer 39 | { 40 | internal override string ToSymPy() 41 | => Stringize(); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Simplification/Patterns/Patterns.NumberTheory.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Entity; 9 | 10 | namespace AngouriMath.Functions 11 | { 12 | internal static partial class Patterns 13 | { 14 | internal static Entity PhiFunctionRules(Entity x) => x switch 15 | { 16 | Phif(Powf(Integer prime, var variable)) when prime.IsPrime => new Powf(prime, variable - 1) * (prime - 1), 17 | _ => x 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/Functions/Simplification/Patterns/Patterns.Sets.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using static AngouriMath.Entity; 9 | using static AngouriMath.Entity.Boolean; 10 | using static AngouriMath.Entity.Set; 11 | 12 | namespace AngouriMath.Functions 13 | { 14 | internal static partial class Patterns 15 | { 16 | [ConstantField] private static readonly FiniteSet FullBooleanSet = new FiniteSet(True, False); 17 | 18 | internal static Entity SetOperatorRules(Entity x) => x switch 19 | { 20 | Intersectionf(var any1, var any1a) when any1 == any1a => any1, 21 | Unionf(var any1, var any1a) when any1 == any1a => any1, 22 | SetMinusf(var any1, var any1a) when any1 == any1a => Empty, 23 | ConditionalSet(var var1, Inf(var var1a, var set)) when var1 == var1a => set, 24 | 25 | Inf(var var1, FiniteSet finite) when finite.Count == 1 => var1.Equalizes(finite.First()), 26 | Inf(not Set and not Matrix and var var, Interval(var left, var leftClosed, var right, var rightClosed)) => 27 | Simplificator.ParaphraseInterval(var, left, leftClosed, right, rightClosed), 28 | 29 | FiniteSet potentialBB when potentialBB == FullBooleanSet => SpecialSet.Create(Domain.Boolean), 30 | Interval(var left, _, var right, _) interval when left == Real.NegativeInfinity && right == Real.PositiveInfinity => SpecialSet.Create(interval.Codomain), 31 | 32 | _ => x 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | global using System.Collections.Generic; 9 | global using System.Linq; 10 | global using HonkSharp.Fluency; 11 | global using HonkSharp.Functional; 12 | global using AngouriMath.Core; 13 | global using AngouriMath.Functions; 14 | 15 | 16 | global using ReasonWhyParsingFailed = 17 | HonkSharp.Functional.Either< 18 | AngouriMath.Core.ReasonOfFailureWhileParsing.Unknown, 19 | AngouriMath.Core.ReasonOfFailureWhileParsing.MissingOperator, 20 | AngouriMath.Core.ReasonOfFailureWhileParsing.InternalError 21 | >; 22 | 23 | global using ParsingResult = 24 | HonkSharp.Functional.Either< 25 | AngouriMath.Entity, 26 | HonkSharp.Functional.Failure< 27 | HonkSharp.Functional.Either< 28 | AngouriMath.Core.ReasonOfFailureWhileParsing.Unknown, 29 | AngouriMath.Core.ReasonOfFailureWhileParsing.MissingOperator, 30 | AngouriMath.Core.ReasonOfFailureWhileParsing.InternalError 31 | > 32 | > 33 | >; 34 | 35 | global using static AngouriMath.Entity.Number; 36 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/PackageReadme.md: -------------------------------------------------------------------------------- 1 | That's the core package of AngouriMath set of packages. Made for C# projects. 2 | 3 | References: 4 | [Website](https://am.angouri.org) · [Github](https://github.com/asc-community/AngouriMath) · [What's new](https://am.angouri.org/whatsnew/) · [Wiki](https://am.angouri.org/wiki/) · [Contacts](https://am.angouri.org/#contacts) 5 | -------------------------------------------------------------------------------- /Sources/AngouriMath/AngouriMath/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/AngouriMath/AngouriMath/icon.png -------------------------------------------------------------------------------- /Sources/AngouriMath/Directory.Build.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sources/AngouriMath/extension.dib: -------------------------------------------------------------------------------- 1 | #!csharp 2 | 3 | using AngouriMath; 4 | using AngouriMath.Extensions; 5 | using Microsoft.DotNet.Interactive; 6 | using Microsoft.DotNet.Interactive.Formatting; 7 | 8 | static void RegisterLatex(Func latexer) 9 | { 10 | Formatter.Register( 11 | t => $"$${latexer(t)}$$", 12 | "text/latex"); 13 | 14 | Formatter.Register( 15 | t => $@" 16 | 17 | 18 | \[{latexer(t)}\]", 19 | "text/html" 20 | ); 21 | 22 | Formatter.SetPreferredMimeTypesFor(typeof(T), "text/latex"); 23 | } 24 | 25 | Formatter.SetPreferredMimeTypesFor(typeof(PeterO.Numbers.EDecimal), "text/plain"); 26 | Formatter.Register(o => o.ToString(), "text/plain"); 27 | 28 | Formatter.SetPreferredMimeTypesFor(typeof(PeterO.Numbers.EInteger), "text/plain"); 29 | Formatter.Register(o => o.ToString(), "text/plain"); 30 | 31 | RegisterLatex(o => o.Latexise()); 32 | 33 | RegisterLatex(o => $@"\frac{{{o.Numerator}}}{{{o.Denominator}}}"); 34 | 35 | "Extensions for LaTeX loaded!" 36 | 37 | -------------------------------------------------------------------------------- /Sources/AngouriMath/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/AngouriMath/key.snk -------------------------------------------------------------------------------- /Sources/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | preview 5 | enable 6 | 7 | -------------------------------------------------------------------------------- /Sources/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Sources/Pack.AngouriMath.FSharp.bat: -------------------------------------------------------------------------------- 1 | cd Wrappers/AngouriMath.FSharp 2 | dotnet pack -c release 3 | cd ../.. -------------------------------------------------------------------------------- /Sources/Pack.AngouriMath.Interactive.bat: -------------------------------------------------------------------------------- 1 | cd Wrappers/AngouriMath.Interactive 2 | dotnet pack -c release 3 | cd ../.. -------------------------------------------------------------------------------- /Sources/Pack.AngouriMath.bat: -------------------------------------------------------------------------------- 1 | cd AngouriMath 2 | dotnet pack -c release 3 | cd .. -------------------------------------------------------------------------------- /Sources/Package.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 1.4.0-preview.3 16 | 17 | WhiteBlackGoose and contributors 18 | Angouri 19 | © Angouri 2019-2022 20 | 21 | false 22 | MIT 23 | 24 | git 25 | See it on the website https://am.angouri.org/whatsnew 26 | https://am.angouri.org 27 | https://github.com/asc-community/AngouriMath 28 | math, symbolics, latex, evaluate, evaluation, dotnet, parse, simplify, derivation, equation, calculus, symbolic algebra 29 | 30 | false 31 | icon.png 32 | 33 | PackageReadme.md 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Sources/Samples/AngouriMathPlot/AngouriMathPlot.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0-windows 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Sources/Samples/CPlusPlusPlayground/AngouriMath.CPP.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | {innerEntityInstance._Ptr->string.cached} 18 | 19 | 20 | -------------------------------------------------------------------------------- /Sources/Samples/CPlusPlusPlayground/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeList.txt : CMake project for CPlusPlusPlayground, include source and define 2 | # project specific logic here. 3 | # 4 | cmake_minimum_required (VERSION 3.8) 5 | 6 | project ("CPlusPlusPlayground") 7 | 8 | set(CMAKE_CXX_STANDARD 17) 9 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 10 | 11 | set(ANGOURIMATH_CPP_IMPORTING_PATH "../../Wrappers/AngouriMath.CPP.Importing") 12 | 13 | add_subdirectory(${ANGOURIMATH_CPP_IMPORTING_PATH} ${CMAKE_CURRENT_BINARY_DIR}/AngouriMath.CPP.Importing) 14 | 15 | set(SOURCES "CPlusPlusPlayground.cpp") 16 | 17 | add_executable(${PROJECT_NAME} ${SOURCES}) 18 | 19 | target_link_libraries(${PROJECT_NAME} PUBLIC AngouriMath.CPP.Importing) 20 | target_include_directories(${PROJECT_NAME} PUBLIC ${ANGOURIMATH_CPP_IMPORTING_PATH}) 21 | 22 | # TODO: Add tests and install targets if needed. 23 | -------------------------------------------------------------------------------- /Sources/Samples/CPlusPlusPlayground/CPlusPlusPlayground.cpp: -------------------------------------------------------------------------------- 1 | // CPlusPlusPlayground.cpp : Defines the entry point for the application. 2 | // 3 | 4 | #include "CPlusPlusPlayground.h" 5 | #include "AngouriMath.h" 6 | #include "A.Usages.MathS.Functions.h" 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | /* 13 | AngouriMath::Entity expr("x + 2 sin(x) + 2y"); 14 | auto newExpr = expr.Differentiate("x"); 15 | for (auto ent : newExpr.Nodes()) 16 | std::cout << ent << "\n"; 17 | std::cout << "\n\n"; 18 | auto ex = AngouriMath::Entity("x + y"); 19 | for (auto ent : ex.Vars()) 20 | std::cout << ent << "\n"; 21 | */ 22 | auto expr = AngouriMath::Entity("5 / 30"); 23 | auto sim = expr.Simplify(); 24 | auto rat = sim.AsRational(); 25 | auto real = sim.AsReal(); 26 | 27 | AngouriMath::Entity e("x2 + 3x + 1"); 28 | 29 | auto solutions = e.SolveEquation("x"); 30 | 31 | for (const auto& child : solutions.DirectChildren()) 32 | { 33 | std::cout << child << '\n'; 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Samples/CPlusPlusPlayground/CPlusPlusPlayground.h: -------------------------------------------------------------------------------- 1 | // CPlusPlusPlayground.h : Include file for standard system include files, 2 | // or project specific include files. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // TODO: Reference additional headers your program requires here. 9 | -------------------------------------------------------------------------------- /Sources/Samples/FSharpPlayground/FSharpPlayground.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Sources/Samples/FSharpPlayground/Program.fs: -------------------------------------------------------------------------------- 1 | open AngouriMath.FSharp.Functions 2 | open AngouriMath.FSharp.Shortcuts 3 | 4 | 5 | printfn "%O" (solutions "x" "x + 2 = 0") 6 | 7 | printfn "%O" (simplified (solutions "x" "x2 + 2 a x + a2 = 0")) 8 | 9 | printfn "%O" (``d/dx`` "x2 + a x") 10 | 11 | printfn "%O" (integral "x" "x2 + e") 12 | 13 | printfn "%O" (``lim x->0`` "sin(a x) / x") 14 | 15 | printfn "%O" (latex "x / e + alpha + sqrt(x) + integral(y + 3, y, 1)") 16 | -------------------------------------------------------------------------------- /Sources/Samples/FSharpSample/FSharpSample.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Sources/Samples/FSharpSample/Program.fs: -------------------------------------------------------------------------------- 1 | open AngouriMath.FSharp.Core 2 | open AngouriMath.FSharp.Functions 3 | open AngouriMath.FSharp.Shortcuts 4 | 5 | // build an expression manually 6 | let x = symbol "x" 7 | let y = symbol "y" 8 | let expr = x / y + x * y 9 | printfn "%O" expr 10 | 11 | // just print a parsed expression 12 | printfn "%O" (parsed "x + 2") 13 | 14 | // substitute a value 15 | printfn "%O" (("x", 3) -|> "x + 2") 16 | 17 | // evaluation to another entity 18 | printfn "%O" (evaled "2 + 3 > 0 or false") 19 | 20 | // evaluation to AM's number 21 | printfn "%O" (asNumber "2 + 3") 22 | 23 | // evaluation to AM's boolean 24 | printfn "%O" (asBool "true or false implies true") 25 | 26 | // solving 27 | printfn "%O" (solutions "x" "x + 2 = 0") 28 | printfn "%O" (simplified (solutions "x" "x2 + 2 a x + a2 = 0")) 29 | printfn "%O" (solutions "x" "(x - 3)(x + a) = 0 and (x - 3)(x + 3) = 0 or x > a") 30 | 31 | // differentiation 32 | printfn "%O" (``d/dx`` "x2 + a x") 33 | printfn "%O" (``d/dx`` "e^x + ln(x) + log(2, x)") 34 | printfn "%O" (derivative "y" "sin(sin(y))") 35 | 36 | // integration 37 | printfn "%O" (integral "x" "x2 + e") 38 | printfn "%O" (integral "x" "a x") 39 | printfn "%O" (integral "x" "a x + b e ^ x + ln(x)") 40 | 41 | // limit 42 | printfn "%O" (``lim x->0`` "sin(a x) / x") 43 | printfn "%O" (limit "x" 0 "sin(a x) / x") 44 | 45 | // LaTeX 46 | printfn "%O" (latex "x / e + alpha + sqrt(x) + integral(y + 3, y, 1)") 47 | -------------------------------------------------------------------------------- /Sources/Samples/GraphicExample/GraphicExample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net7.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Sources/Samples/GraphicExample/Program.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Windows.Forms; 10 | 11 | namespace GraphicExample 12 | { 13 | static class Program 14 | { 15 | /// 16 | /// The main entry point for the application. 17 | /// 18 | [STAThread] 19 | static void Main() 20 | { 21 | Application.SetHighDpiMode(HighDpiMode.SystemAware); 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | Application.Run(new MainForm()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/Samples/InteractivePlayground/InteractivePlayground.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Sources/Samples/SampleNet5/SampleNet5.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Sources/Samples/Samples/Playground.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | preview 7 | enable 8 | 9 | 10 | 11 | full 12 | true 13 | false 14 | 15 | 16 | 17 | false 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Sources/Samples/Samples/Program.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using AngouriMath.Core; 10 | using static AngouriMath.MathS; 11 | 12 | var expr = Sqrt(-1); 13 | Console.WriteLine(expr); 14 | Console.WriteLine(expr.Codomain); 15 | Console.WriteLine(expr.Evaled); 16 | Console.WriteLine("------------------------------------"); 17 | var newExpr = expr.WithCodomain(Domain.Real); 18 | Console.WriteLine(newExpr); 19 | Console.WriteLine(newExpr.Codomain); 20 | Console.WriteLine(newExpr.Evaled); -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal.Lib/AngouriMath.Terminal.Lib.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal.Lib/AssemblyLoadBuilder.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.Terminal.Lib.AssemblyLoadBuilder 2 | 3 | open System 4 | open Microsoft.DotNet.Interactive.FSharp 5 | open AngouriMath.Terminal.Lib.Consts 6 | 7 | type AssemblyLoadResult = 8 | | AssemblyLoadSuccess 9 | | AssemblyLoadFailure of string 10 | 11 | type AssemblyLoadBuilder (execute : FSharpKernel -> string -> ExecutionResult, kernel) = 12 | member this.Yield x = this.load x 13 | member _.Run _ = Result.Ok kernel 14 | 15 | member this.Combine (a : AssemblyLoadResult, b) = 16 | match (a, b) with 17 | | AssemblyLoadSuccess, Result.Ok kernel -> Result.Ok kernel 18 | | AssemblyLoadFailure reason, Result.Ok _ -> Result.Error [ reason ] 19 | | AssemblyLoadSuccess, Result.Error reasons -> Result.Error reasons 20 | | AssemblyLoadFailure reason, Result.Error reasons -> Result.Error (reason::reasons) 21 | 22 | member this.Delay(f) = f() 23 | 24 | member this.Zero () = Result.Ok () 25 | 26 | member private this.loadAssembly kernel (path : string) = 27 | path.Replace("\\", "\\\\") 28 | |> (fun loc -> execute kernel $"#r \"{loc}\"") 29 | 30 | member private this.load (typeInfo : Type) = 31 | let assemblyLocation = typeInfo.Assembly.Location 32 | if System.IO.File.Exists assemblyLocation then 33 | match this.loadAssembly kernel assemblyLocation with 34 | | Error error -> AssemblyLoadFailure error 35 | | _ -> AssemblyLoadSuccess 36 | else 37 | AssemblyLoadFailure $"Assembly {assemblyLocation} does not exist" -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal.Lib/Consts.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.Terminal.Lib.Consts 2 | 3 | let EncodingPlainPrefix = "encp" 4 | 5 | let EncodingLatexPrefix = "encl" 6 | 7 | type ExecutionResult = 8 | | SuccessPackageAdded 9 | | Error of string 10 | | VoidSuccess 11 | | PlainTextSuccess of string 12 | | LatexSuccess of Latex : string * Source : string 13 | | EndOfFile -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal.Lib/PreRunCode.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.Terminal.Lib.PreRunCode 2 | 3 | open AngouriMath.Terminal.Lib.FSharpInteractive 4 | 5 | let OpensAndOperators = @" 6 | open AngouriMath 7 | open AngouriMath.FSharp.Core 8 | open AngouriMath.FSharp.Functions 9 | open AngouriMath.FSharp.Matrices 10 | open AngouriMath.FSharp.Shortcuts 11 | open AngouriMath.FSharp.Constants 12 | open AngouriMath.Interactive 13 | 14 | let eval (x : obj) = 15 | match (parsed x).InnerSimplified with 16 | | :? Entity.Number.Integer as i -> i.ToString() 17 | | :? Entity.Number.Rational as i -> i.RealPart.EDecimal.ToString() 18 | | :? Entity.Number.Real as re -> re.RealPart.EDecimal.ToString() 19 | | :? Entity.Number.Complex as cx -> cx.RealPart.EDecimal.ToString() + "" + "" + cx.ImaginaryPart.EDecimal.ToString() + ""i"" 20 | | other -> (evaled other).ToString() 21 | 22 | open AngouriMath.Interactive.AggressiveOperators 23 | 24 | let x = symbol ""x"" 25 | let y = symbol ""y"" 26 | let z = symbol ""z"" 27 | let w = symbol ""w"" 28 | let a = symbol ""a"" 29 | let b = symbol ""b"" 30 | let c = symbol ""c"" 31 | let d = symbol ""d"" 32 | let n = symbol ""n"" 33 | let m = symbol ""m"" 34 | 35 | let help () = 36 | let url = ""https://github.com/asc-community/AngouriMath/wiki/Terminal"" 37 | let psi = System.Diagnostics.ProcessStartInfo () 38 | psi.FileName <- url 39 | psi.UseShellExecute <- true 40 | System.Diagnostics.Process.Start psi 41 | $""Sending you to {url}"" 42 | " 43 | 44 | let enableAngouriMath kernel = 45 | let innerCode = OpensAndOperators.Replace("\"", "\\\"") 46 | let preRunCode = OpensAndOperators + $"let preRunCode = \"{innerCode}\"" 47 | execute kernel preRunCode 48 | -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/AngouriMath.Terminal.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Exe 7 | net7.0 8 | icon.ico 9 | 10 | true 11 | amcli 12 | 13 | icon.png 14 | F#-based command line interface for symbolic algebra library AngouriMath 15 | 16 | 1.4.0-preview.3-2 17 | 18 | $(PackageTags), cli, terminal 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/PackageReadme.md: -------------------------------------------------------------------------------- 1 | This is a dotnet tool package to use AngouriMath from F# from console. 2 | 3 | References: 4 | [Website](https://am.angouri.org) · [Github](https://github.com/asc-community/AngouriMath) · [What's new](https://am.angouri.org/whatsnew/) · [Wiki](https://am.angouri.org/wiki/) · [Contacts](https://am.angouri.org/#contacts) 5 | -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/Program.fs: -------------------------------------------------------------------------------- 1 | open System 2 | open AngouriMath.Terminal.Lib.FSharpInteractive 3 | open AngouriMath.Terminal.Lib.PreRunCode 4 | open AngouriMath.Terminal.Lib.Consts 5 | open UserInterface 6 | open Spectre.Console 7 | open AngouriMath.Terminal.Lib.AssemblyLoadBuilder 8 | 9 | 10 | // All other platforms do not support setting custom window width 11 | if System.OperatingSystem.IsWindows() then 12 | Console.WindowHeight <- Math.Min(50, Console.LargestWindowHeight) 13 | Console.WindowWidth <- Math.Min(150, Console.LargestWindowWidth) 14 | 15 | 16 | let lineEditor = getLineEditor AnsiConsole.Console 17 | 18 | let rec readAndRespond kernel = 19 | printf "\n" 20 | match readLine lineEditor |> execute kernel with 21 | | PlainTextSuccess text -> 22 | writeLine AnsiConsole.Console text 23 | | LatexSuccess (_, text) -> 24 | writeLine AnsiConsole.Console text 25 | | Error message -> 26 | writeLineError AnsiConsole.Console message 27 | | _ -> () 28 | 29 | readAndRespond kernel 30 | 31 | let handleErrors errors = 32 | let concat = String.concat "\n" 33 | printfn $"Errors: {concat errors}" 34 | printfn $"Report about it to the official repo. The terminal will be closed." 35 | Console.ReadLine() |> ignore 36 | 37 | "\n\n" |> Console.Write 38 | 39 | FigletText "AngouriMath" 40 | |> AlignableExtensions.Centered 41 | |> (fun p -> FigletTextExtensions.Color(p, Color.Pink1)) 42 | |> AnsiConsole.Console.Write 43 | 44 | $@" 45 | Hi! Type `help ()` to get more info. 46 | " |> Markup 47 | |> AlignableExtensions.Centered 48 | |> AnsiConsole.Console.Write 49 | 50 | 51 | 52 | 53 | printf "Starting the kernel..." 54 | 55 | 56 | match createKernel () with 57 | | Result.Error reasons -> handleErrors reasons 58 | | Result.Ok kernel -> 59 | execute kernel "1 + 1" |> ignore // warm up 60 | match enableAngouriMath kernel with 61 | | Error msg -> handleErrors [ msg ] 62 | | _ -> 63 | printfn " loaded." 64 | readAndRespond kernel -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Terminal/AngouriMath.Terminal/icon.ico -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Terminal/AngouriMath.Terminal/icon.png -------------------------------------------------------------------------------- /Sources/Terminal/AngouriMath.Terminal/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | for arch in linux-x64 linux-arm linux-arm64 win-x64 win-x86 osx-x64 osx.12-arm64 5 | do 6 | dotnet publish \ 7 | -r $arch \ 8 | -c release \ 9 | -o ./publish-output/$arch \ 10 | --self-contained 11 | done 12 | 13 | -------------------------------------------------------------------------------- /Sources/Terminal/VERSION/VERSION: -------------------------------------------------------------------------------- 1 | 1.0.0.6 2 | -------------------------------------------------------------------------------- /Sources/Terminal/readme.md: -------------------------------------------------------------------------------- 1 | ## AngouriMath Terminal 2 | 3 | ![](https://img.shields.io/nuget/vpre/AngouriMath?color=blue&label=NuGet&logo=nuget&style=flat-square) 4 | 5 | This is desktop-targeted convenient CLI for AngouriMath. The idea is to provide convenient 6 | easy-to-use and lightweight terminal to run some basic calculations in it. 7 | 8 | The interface language is F#. If you're not familiar with it, check out a [Jupyter notebook](https://mybinder.org/v2/gh/asc-community/AngouriMathLab/try?filepath=HelloBook.AngouriMath.Interactive.ipynb), 9 | an interactive graphical notebook to working with AngouriMath. 10 | 11 | ![gif](https://raw.githubusercontent.com/asc-community/AngouriMath/terminal-as-global-tool/Sources/Terminal/terminal.gif) 12 | 13 | ## Installation 14 | 15 | ### For your desktop 16 | 17 | Refer for instructions [**here**](https://am.angouri.org/quickstart/#terminal) 18 | 19 | ### As a .NET tool 20 | 21 | It is available on [NuGet](https://www.nuget.org/packages/AngouriMath.Terminal), install it via 22 | ``` 23 | dotnet tool install --global AngouriMath.Terminal --version versionyoulike 24 | ``` 25 | To uninstall it, run 26 | ``` 27 | dotnet tool uninstall --global AngouriMath.Terminal 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /Sources/Terminal/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Terminal/screenshot.png -------------------------------------------------------------------------------- /Sources/Terminal/terminal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Terminal/terminal.gif -------------------------------------------------------------------------------- /Sources/Tests/CPPWrapperUnitTests/Test.bat: -------------------------------------------------------------------------------- 1 | cd tests 2 | cmake -S . -B build 3 | mkdir "build\Debug" 4 | copy "..\..\..\Wrappers\AngouriMath.CPP.Importing\win-x64\AngouriMath.CPP.Exporting.dll" "build\Debug\AngouriMath.CPP.Exporting.dll" 5 | cmake --build build 6 | cd build 7 | ctest 8 | cd ../.. 9 | pause -------------------------------------------------------------------------------- /Sources/Tests/CPPWrapperUnitTests/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project ("CPlusPlusWrapperUnitTests") 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | set(AM_TESTS_ENTRY_POINT "RunTests.cpp") 9 | 10 | 11 | 12 | ### Google Test 1/2 13 | 14 | include(FetchContent) 15 | FetchContent_Declare( 16 | googletest 17 | URL https://github.com/google/googletest/archive/df7fee587d442b372ef43bd66c6a2f5c9af8c5eb.zip 18 | ) 19 | # For Windows: Prevent overriding the parent project's compiler/linker settings 20 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 21 | FetchContent_MakeAvailable(googletest) 22 | 23 | enable_testing() 24 | 25 | ### AngouriMath 1/2 26 | 27 | set(ANGOURIMATH_CPP_IMPORTING_PATH "../../../Wrappers/AngouriMath.CPP.Importing") 28 | add_subdirectory(${ANGOURIMATH_CPP_IMPORTING_PATH} ${CMAKE_CURRENT_BINARY_DIR}/AngouriMath.CPP.Importing) 29 | link_directories(./build/Debug/) 30 | 31 | ### Shared 32 | 33 | add_executable( 34 | ${PROJECT_NAME} 35 | ${AM_TESTS_ENTRY_POINT} 36 | ) 37 | 38 | target_link_libraries( 39 | ${PROJECT_NAME} 40 | gtest_main 41 | ) 42 | 43 | target_link_libraries( 44 | ${PROJECT_NAME} 45 | AngouriMath.CPP.Importing 46 | ) 47 | 48 | ### GoogleTest 2/2 49 | 50 | include(GoogleTest) 51 | gtest_discover_tests(${PROJECT_NAME}) 52 | 53 | 54 | 55 | ### AngouriMath 2/2 56 | 57 | target_include_directories(${PROJECT_NAME} PUBLIC ${ANGOURIMATH_CPP_IMPORTING_PATH}) 58 | -------------------------------------------------------------------------------- /Sources/Tests/DotnetBenchmark/CacheCompiledFunc.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using AngouriMath.Core; 10 | using System; 11 | using System.Numerics; 12 | using BenchmarkDotNet.Attributes; 13 | using System.Linq.Expressions; 14 | 15 | namespace DotnetBenchmark 16 | { 17 | public class CacheCompiledFunc 18 | { 19 | private readonly FastExpression complexFunc; 20 | private readonly Func myCompiledIntoLinq; 21 | private readonly Func linqComp; 22 | private readonly Entity notCompiled; 23 | private readonly Entity.Variable x = MathS.Var("x"); 24 | private readonly Entity.Number.Complex ComNumToSub = 3; 25 | private readonly Complex ComToSub = 3; 26 | public CacheCompiledFunc() 27 | { 28 | 29 | notCompiled = MathS.Sin(MathS.Sqr(x)) + MathS.Cos(MathS.Sqr(x)) + MathS.Sqr(x) + MathS.Sin(MathS.Sqr(x)); 30 | complexFunc = notCompiled.Compile(x); 31 | 32 | Expression> linqExpr = x => Complex.Sin(Complex.Pow(x, 2)) + Complex.Cos(Complex.Pow(x, 2)) + Complex.Pow(x, 2) + Complex.Sin(Complex.Pow(x, 2)); 33 | linqComp = linqExpr.Compile(); 34 | 35 | myCompiledIntoLinq = notCompiled.Compile(x); 36 | } 37 | [Benchmark] public Complex MyCompiled() => complexFunc.Call(ComToSub); 38 | [Benchmark] public Complex MyLinqCompiled() => myCompiledIntoLinq(ComToSub); 39 | [Benchmark] public Complex SysIncode() => Complex.Sin(Complex.Pow(3, 2)) + Complex.Cos(Complex.Pow(3, 2)) + Complex.Pow(3, 2) + Complex.Sin(Complex.Pow(3, 2)); 40 | [Benchmark] public Complex LinqCompiled() => linqComp.Invoke(3); 41 | [Benchmark] public Entity.Number.Complex NotCompiled() => notCompiled.Substitute(x, 3).EvalNumerical(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/Tests/DotnetBenchmark/DotnetBenchmark.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Common.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Common 2 | 3 | open AngouriMath.FSharp.Core 4 | open Xunit 5 | 6 | 7 | 8 | let x = symbol "x" 9 | let x_ = symbol "x" 10 | 11 | [] 12 | let ``Test symbol x`` () = Assert.Equal(x, x_) 13 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/CompilationTest.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Compilation 2 | 3 | open AngouriMath.FSharp.Compilation 4 | open Xunit 5 | 6 | [] 7 | let ``Compile from 1`` () = 8 | Assert.Equal(32, (compiled1In "x" "x * 5 + 7") 5) 9 | [] 10 | let ``Compile from 2`` () = 11 | Assert.Equal(32, (compiled2In "x" "y" "x * 5 + y") 5 7) 12 | [] 13 | let ``Compile from 3`` () = 14 | Assert.Equal(1188, (compiled3In "x" "y" "z" "(x + 1)(y + 2)(z + 3)") 5 7 19) 15 | [] 16 | let ``Compile from 4`` () = 17 | Assert.Equal(1191, (compiled4In "x" "y" "z" "duck" "(x + 1)(y + 2)(z + 3) + duck") 5 7 19 3) 18 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/CoreTest.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Core 2 | 3 | open Xunit 4 | open AngouriMath.FSharp.Core 5 | open AngouriMath 6 | 7 | [] 8 | let ``withSetting test`` () = 9 | let expr = parsed "a + b + c" 10 | let res = withSetting MathS.Diagnostic.OutputExplicit true (fun () -> expr.ToString()) 11 | Assert.Equal("((a) + (b)) + (c)", res) 12 | 13 | [] 14 | let ``withSetting test with exception`` () = 15 | let expr = parsed "a + b + c" 16 | let expectedValue = MathS.Settings.MaxExpansionTermCount.Value 17 | try 18 | try 19 | let res = withSetting MathS.Settings.MaxExpansionTermCount 100L (fun() -> 20 | let a = "x + 2" 21 | parsed "x + " 22 | ) 23 | () 24 | with 25 | | _ -> () 26 | finally 27 | let actualValue = MathS.Settings.MaxExpansionTermCount.Value 28 | Assert.Equal(expectedValue, actualValue) -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/FSharpWrapperUnitTests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | runtime; build; native; contentfiles; analyzers; buildtransitive 31 | all 32 | 33 | 34 | all 35 | runtime; build; native; contentfiles; analyzers; buildtransitive 36 | 37 | 38 | all 39 | runtime; build; native; contentfiles; analyzers; buildtransitive 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Functions.Discrete.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Discrete 2 | 3 | open AngouriMath.FSharp.Core 4 | open AngouriMath.FSharp.Functions 5 | open Xunit 6 | 7 | let a = symbol "a" 8 | let b = symbol "b" 9 | 10 | [] 11 | let ``Conj test`` () = Assert.Equal(parsed "a and b", conjunction a b) 12 | [] 13 | let ``Disj test`` () = Assert.Equal(parsed "a or b", disjunction a b) 14 | [] 15 | let ``Impl test`` () = Assert.Equal(parsed "a implies b", implication a b) 16 | [] 17 | let ``Neg test`` () = Assert.Equal(parsed "not a", negation a) 18 | [] 19 | let ``Xor test`` () = Assert.Equal(parsed "a xor b", exDisjunction a b) 20 | [] 21 | let ``Equality test`` () = Assert.Equal(parsed "a = b", equality a b) 22 | [] 23 | let ``Greater test`` () = Assert.Equal(parsed "a > b", greater a b) 24 | [] 25 | let ``Less test`` () = Assert.Equal(parsed "a < b", less a b) 26 | [] 27 | let ``Greater or equal test`` () = Assert.Equal(parsed "a >= b", greaterOrEqual a b) 28 | [] 29 | let ``Less or equal test`` () = Assert.Equal(parsed "a <= b", lessOrEqual a b) -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Functions.Order.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Order 2 | 3 | open AngouriMath.FSharp.Core 4 | open AngouriMath.FSharp.Functions 5 | open Xunit 6 | 7 | let x = symbol "x" 8 | let y = symbol "y" 9 | let z = symbol "z" 10 | 11 | [] 12 | let ``Derivative test`` () = Assert.Equal(parsed "derivative(x, y)", derivativeNode y x) 13 | [] 14 | let ``Integral test`` () = Assert.Equal(parsed "integral(x, y)", integralNode y x) 15 | [] 16 | let ``Limit test`` () = Assert.Equal(parsed "limit(x, y, z)", limitNode y z x) 17 | [] 18 | let ``Differentiate test`` () = Assert.Equal(parsed "2x + 2", derivative x "x2 + 2x") 19 | [] 20 | let ``Integrate test`` () = Assert.Equal(parsed "sin(x) + x", integral x "1 + cos(x)") 21 | [] 22 | let ``Limited test`` () = Assert.Equal(parsed "a", limit x 0 "a x / sin(x)") 23 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Functions.Sets.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.FunctionsTest 2 | 3 | open Xunit 4 | open AngouriMath.FSharp.Functions 5 | open AngouriMath.FSharp.Core 6 | 7 | [] 8 | let ``Closed interval test`` () = 9 | Assert.Equal(parsed "[2; 3]", closedInterval 2 3) 10 | [] 11 | let ``Open interval test`` () = 12 | Assert.Equal(parsed "(2; 3)", openInterval 2 3) 13 | [] 14 | let ``LeftInclusiveRightExclusive interval test`` () = 15 | Assert.Equal(parsed "[2; 3)", leftInclusiveRightExclusive 2 3) 16 | [] 17 | let ``LeftExclusiveRightInclusive interval test`` () = 18 | Assert.Equal(parsed "(2; 3]", leftExclusiveRightInclusive 2 3) 19 | [] 20 | let ``LeftInclusive interval test`` () = 21 | Assert.Equal(parsed "[2; +oo)", leftInclusive 2) 22 | [] 23 | let ``LeftExclusive interval test`` () = 24 | Assert.Equal(parsed "(2; +oo)", leftExclusive 2) 25 | [] 26 | let ``RightInclusive interval test`` () = 27 | Assert.Equal(parsed "(-oo; 2]", rightInclusive 2) 28 | [] 29 | let ``RightExclusive interval test`` () = 30 | Assert.Equal(parsed "(-oo; 2)", rightExclusive 2) -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/ShortcutsTest.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Shortcuts 2 | 3 | open Xunit 4 | open AngouriMath.FSharp.Shortcuts 5 | open AngouriMath.FSharp.Core 6 | 7 | [] 8 | let ``Test d/dx`` () = 9 | Assert.Equal(parsed "a + cos(x)", ``d/dx`` "a x + sin(x)") 10 | [] 11 | let ``Test int [dx]`` () = 12 | Assert.Equal(parsed "sin(x) + a x", ``int [dx]`` "a + cos(x)") 13 | [] 14 | let ``Test lim x->+oo`` () = 15 | Assert.Equal(parsed "6", ``lim x->+oo`` "(6x6 + 3x3 + a x) / (x6 - 4x)") 16 | [] 17 | let ``Test lim x->-oo`` () = 18 | Assert.Equal(parsed "-oo", ``lim x->-oo`` "2x") 19 | [] 20 | let ``Test lim x->0`` () = 21 | Assert.Equal((parsed "-1/6").InnerSimplified, ``lim x->0`` "(sin(x) - x) / x3") 22 | [] 23 | let ``Test -|>``() = 24 | Assert.Equal(parsed "25", ("x", 5) -|> (parsed "5x")) 25 | [] 26 | let ``Test <|-``() = 27 | Assert.Equal(parsed "25", (parsed "5x") <|- ("x", 5)) 28 | [] 29 | let ``Test -|><|-``() = 30 | Assert.Equal(parsed "125", ("y", 100) -|> (parsed "5x + y") <|- ("x", 5)) -------------------------------------------------------------------------------- /Sources/Tests/FSharpWrapperUnitTests/Utils.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Tests.Utils 2 | 3 | open AngouriMath 4 | open Xunit 5 | 6 | let testEqual (a : Entity, b : Entity) = 7 | match a, b with 8 | | :? Entity.Matrix as m1, (:? Entity.Matrix as m2) -> 9 | if m1 <> m2 then 10 | Assert.False(true, $"First:\n{m1.ToString(true)}\n\nSecond:\n{m2.ToString(true)}") 11 | | otherA, otherB -> Assert.Equal(otherA, otherB) -------------------------------------------------------------------------------- /Sources/Tests/InteractiveWrapperUnitTests/AggressiveOperators.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.Interactive.Tests.AggressiveOperators 2 | 3 | open Xunit 4 | open AngouriMath.FSharp.Functions 5 | open AngouriMath.FSharp.Core 6 | open AngouriMath.Interactive.AggressiveOperators 7 | 8 | [] 9 | let ``Int / int is rational`` () = 10 | let threeOverTwo = 3 / 2 11 | Assert.IsAssignableFrom(threeOverTwo) |> ignore 12 | Assert.Equal(simplified (parsed "3 / 2"), threeOverTwo) 13 | 14 | [] 15 | let ``Int + real is real`` () = 16 | let num = 3 + 4.5 17 | Assert.IsAssignableFrom(num) |> ignore 18 | Assert.Equal(simplified (parsed "3 + 4.5"), num) 19 | 20 | [] 21 | let ``Int - real is real`` () = 22 | let num = 3 - 4.5 23 | Assert.IsAssignableFrom(num) |> ignore 24 | Assert.Equal(simplified (parsed "3 - 4.5"), num) 25 | 26 | [] 27 | let ``Int * real is real`` () = 28 | let num = 3 * 4.5 29 | Assert.IsAssignableFrom(num) |> ignore 30 | Assert.Equal(simplified (parsed "3 * 4.5"), num) 31 | 32 | [] 33 | let ``Int ** big number is real`` () = 34 | let num = 3 ** "1000" 35 | Assert.IsAssignableFrom(num) |> ignore 36 | Assert.Equal(simplified (parsed "3 ^ 1000"), num) 37 | 38 | [] 39 | let ``equals test`` () = Assert.Equal(simplified (parsed "1 = 2"), (1 = 2)) 40 | 41 | [] 42 | let ``greaterThan test`` () = Assert.Equal(simplified (parsed "1 > 2"), (1 > 2)) 43 | 44 | [] 45 | let ``lessThan test`` () = Assert.Equal(simplified (parsed "1 < 2"), (1 < 2)) 46 | 47 | [] 48 | let ``greaterOrEqual test`` () = Assert.Equal(simplified (parsed "1 >= 2"), (1 >= 2)) 49 | 50 | [] 51 | let ``lessOrEqual test`` () = Assert.Equal(simplified (parsed "1 <= 2"), (1 <= 2)) -------------------------------------------------------------------------------- /Sources/Tests/InteractiveWrapperUnitTests/InteractiveWrapperUnitTests.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | all 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Sources/Tests/InteractiveWrapperUnitTests/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /Sources/Tests/TerminalUnitTests/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /Sources/Tests/TerminalUnitTests/TerminalUnitTests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | all 21 | 22 | 23 | runtime; build; native; contentfiles; analyzers; buildtransitive 24 | all 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Algebra/SolveTest/SolveEquationWithPiecewise.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Extensions; 9 | using Xunit; 10 | using static AngouriMath.Entity.Set; 11 | 12 | namespace AngouriMath.Tests.Algebra 13 | { 14 | public sealed class SolveEquationWithPiecewise 15 | { 16 | [Theory] 17 | [InlineData("piecewise((x + 2)2 provided y > 0, (x + 1)2 provided y = 0, x2 provided y < 0) = 9", 18 | "1 provided y > 0", "-5 provided y > 0", 19 | "2 provided y = 0 and not y > 0", "-4 provided y = 0 and not y > 0", 20 | "3 provided y < 0 and (not y > 0 and not y = 0)", "-3 provided y < 0 and (not y > 0 and not y = 0)")] 21 | public void CheckIfRootWasObtained(string eq, 22 | string? r1 = null, string? r2 = null, 23 | string? r3 = null, string? r4 = null, 24 | string? r5 = null, string? r6 = null) 25 | { 26 | var sols = eq.Solve("x"); 27 | foreach (var expectedRoot in new[] { r1, r2, r3, r4, r5, r6 }) 28 | if (expectedRoot is not null) 29 | Assert.True(((FiniteSet)sols).Contains(expectedRoot), $"Root {expectedRoot} expected to be in {sols}"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Algebra/SolveTest/SolveStatement.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using Xunit; 10 | 11 | namespace AngouriMath.Tests.Algebra.SolveTest 12 | { 13 | public sealed class SolveStatement 14 | { 15 | [Theory] 16 | [InlineData("x2 = 3 and x > 0", "{ sqrt(3) }")] 17 | [InlineData("x4 = 3 and x in RR", "{ -3^(1/4), 3^(1/4) }")] 18 | public void TestStatementSolver(string statement, string expectedRaw) 19 | { 20 | var expr = MathS.FromString(statement); 21 | var expected = MathS.FromString(expectedRaw); 22 | var actual = expr.Solve("x"); 23 | Assert.Equal(expected, actual); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/CompilationFETest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using System.Numerics; 10 | using Xunit; 11 | using AngouriMath.Extensions; 12 | 13 | namespace AngouriMath.Tests.Common 14 | { 15 | public sealed class CompilationFETest 16 | { 17 | private static readonly Entity.Variable x = MathS.Var(nameof(x)); 18 | private static readonly Entity.Variable y = MathS.Var(nameof(y)); 19 | 20 | [Theory] 21 | [InlineData("x")] 22 | [InlineData("x + 2")] 23 | [InlineData("sin(x) + cos(x)")] 24 | [InlineData("arcsin(x) + arccos(x)")] 25 | [InlineData("arcsin(x) + arccos(x) / 2")] 26 | [InlineData("sqrt(x) + e ^ x")] 27 | [InlineData("sin(x) + 2")] 28 | [InlineData("cos(x) + 2")] 29 | [InlineData("tan(x) + 2")] 30 | [InlineData("cot(x) + 2")] 31 | [InlineData("sec(x) + 2")] 32 | [InlineData("csc(x) + 2")] 33 | [InlineData("arcsin(x) + 2")] 34 | [InlineData("arccos(x) + 2")] 35 | [InlineData("arctan(x) + 2")] 36 | [InlineData("arccot(x) + 2")] 37 | [InlineData("arcsec(x) + 2")] 38 | [InlineData("arccsc(x) + 2")] 39 | [InlineData("log(3, x) + 2")] 40 | [InlineData("log(x, 3) + 2")] 41 | [InlineData("3 ^ x + 2")] 42 | [InlineData("1 / x")] 43 | [InlineData("1 - x")] 44 | [InlineData("(x + 2)!")] 45 | [InlineData("sign(x + 2)")] 46 | [InlineData("(|x + 2|)")] 47 | public void Test(string expr, float? toSub = null) 48 | { 49 | toSub ??= 3; 50 | var exprCompiled = expr.Compile(x); 51 | var expected = (Complex)expr.Substitute("x", toSub).EvalNumerical(); 52 | var actual = exprCompiled.Call((Complex)toSub); 53 | var error = Complex.Abs(expected - actual); 54 | Assert.True(error < 0.001, $"Error: {error}\nActual: {actual}\nExpected: {expected}"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/ExpandCollapseTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using Xunit; 10 | 11 | namespace AngouriMath.Tests.Common 12 | { 13 | public sealed class ExpandFactorizeTest 14 | { 15 | public static readonly Entity.Variable x = MathS.Var(nameof(x)); 16 | public static readonly Entity.Variable y = MathS.Var(nameof(y)); 17 | [Fact] public void ExpandAlgebra1() => 18 | Assert.Equal(16, ((x + y) * (x - y)).Expand().Substitute(x, 5).Substitute(y, 3).EvalNumerical()); 19 | [Fact] public void ExpandAlgebra2() => 20 | Assert.Equal(64, ((x + y + x + y) * (x - y + x - y)).Expand().Substitute(x, 5).Substitute(y, 3).EvalNumerical()); 21 | [Fact] public void Factorize1() => 22 | Assert.Equal(x * (1 + y), (x * y + x).Factorize()); 23 | [Fact] 24 | public void Factorial() 25 | { 26 | var expr = MathS.Factorial(x + 3) / MathS.Factorial(x + 1); 27 | Assert.Equal(MathS.Pow(x, 2) + x * 3 + (2 * x + 6), expr.Expand()); 28 | expr = MathS.Factorial(x + -3) / MathS.Factorial(x + -1); 29 | Assert.Equal(1 / (x + -2) / (x + -1), expr.Expand()); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/HierarchyTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Xunit; 9 | using AngouriMath; 10 | using AngouriMath.Extensions; 11 | 12 | namespace AngouriMath.Tests.Common 13 | { 14 | public static class HierarchyTestExtensions 15 | { 16 | public static bool IsOfType(this string @this) 17 | { 18 | Assert.IsAssignableFrom(@this.ToEntity()); 19 | return true; 20 | } 21 | } 22 | 23 | public sealed class HierarchyTest 24 | { 25 | [Theory, CombinatorialData] 26 | public void TestContinuousNode( 27 | [CombinatorialValues( 28 | "a + b", "a - b", "a * b", "a / b", "a ^ b", 29 | "(|a|)", "sgn(a)" 30 | )] 31 | string expr) 32 | => expr.IsOfType(); 33 | 34 | [Theory, CombinatorialData] 35 | public bool TestTrigonometricNode( 36 | [CombinatorialValues("arcsin", "arccos", "sin", "cos", 37 | "tan", "cotan", "arctan", "arccotan", "sec", "cosec", 38 | "arcsec", "arccosec")] string node) 39 | => $"{node}(x)".IsOfType() && $"{node}(x)".IsOfType(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/ImplicitOperators.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using PeterO.Numbers; 10 | using System; 11 | using Xunit; 12 | 13 | namespace AngouriMath.Tests.Common 14 | { 15 | public sealed class ImplicitOperators 16 | { 17 | internal void Test(Entity expr, Entity expected) => Assert.Equal(expected, expr); 18 | 19 | [Fact] public void FromByte() => Test((byte)3, "3"); 20 | [Fact] public void FromSByte() => Test((sbyte)3, "3"); 21 | [Fact] public void FromInt16() => Test((Int16)3, "3"); 22 | [Fact] public void FromUInt16() => Test((UInt16)3, "3"); 23 | [Fact] public void FromInt32() => Test((Int32)3, "3"); 24 | [Fact] public void FromUInt32() => Test((UInt32)3, "3"); 25 | [Fact] public void FromInt64() => Test((Int64)3, "3"); 26 | [Fact] public void FromUInt64() => Test((UInt64)3, "3"); 27 | [Fact] public void FromSingle() => Test((Single)3.5f, "3.5"); 28 | [Fact] public void FromDouble() => Test((Double)3.5, "3.5"); 29 | [Fact] public void FromDecimal() => Test((Decimal)3.5m, "3.5"); 30 | [Fact] public void FromComplex() => Test(new System.Numerics.Complex(3, 5), Entity.Number.Complex.Create(3, 5)); 31 | [Fact] public void FromBigInteger() => Test(System.Numerics.BigInteger.Parse("28374832742384"), "28374832742384"); 32 | [Fact] public void FromEInteger() => Test(EInteger.FromString("32324"), "32324"); 33 | [Fact] public void FromERational() => Test(ERational.Create(EInteger.FromString("32324"), EInteger.FromString("243244")), ((Entity)"32324/243244").InnerSimplified); 34 | [Fact] public void FromEDecimal() => Test(EDecimal.FromString("3.4"), "3.4"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/OperatorTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using static AngouriMath.Entity.Number; 10 | using Xunit; 11 | 12 | namespace AngouriMath.Tests.Common 13 | { 14 | public sealed class OperatorTest 15 | { 16 | [Fact] public void TestEq() => Assert.Equal(MathS.Var("x"), MathS.Var("x")); 17 | [Fact] public void TestIneq() => Assert.NotEqual(MathS.Var("x"), MathS.Var("y")); 18 | [Fact] 19 | public void TestR() => 20 | Assert.Equal(Complex.Create(0, 1), 21 | Complex.Create(0, PeterO.Numbers.EDecimal.FromInt32(1).NextPlus(MathS.Settings.DecimalPrecisionContext))); 22 | [Fact] public void TestDP() => Assert.Equal(-23, MathS.FromString("-23").EvalNumerical()); 23 | [Fact] public void TestDM() => Assert.Equal(0, MathS.FromString("1 + -1").EvalNumerical()); 24 | [Fact] public void TestB() => Assert.Equal(0, MathS.FromString("1 + (-1)").EvalNumerical()); 25 | [Fact] public void TestMi() => Assert.Equal(1, MathS.FromString("-i^2").EvalNumerical()); 26 | [Fact] public void TestMm() => Assert.Equal(-1, MathS.FromString("-1 * -1 * -1").EvalNumerical()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Common/SubstituteTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Extensions; 9 | using Xunit; 10 | 11 | namespace AngouriMath.Tests.Common 12 | { 13 | public sealed class SubstituteTest 14 | { 15 | [Theory] 16 | [InlineData("x + 2", "1 + 2")] 17 | [InlineData("x2", "1 ^ 2")] 18 | [InlineData("sqrt(x)", "sqrt(1)")] 19 | [InlineData("x", "1")] 20 | [InlineData("sin(x)", "sin(1)")] 21 | [InlineData("{ x : x > 3 }", "{ x : x > 3 }")] 22 | [InlineData("x + { x : x > 3 }", "1 + { x : x > 3 }")] 23 | [InlineData("x * derivative(x + 2, x, 1)", "1 * derivative(x + 2, x, 1)")] 24 | [InlineData("x * integral(x + 2, x, 1)", "1 * integral(x + 2, x, 1)")] 25 | [InlineData("x * limit(x + 2, x, 1)", "1 * limit(x + 2, x, 1)")] 26 | [InlineData("sin(cos(sec(csc(x))))", "sin(cos(sec(csc(1))))")] 27 | [InlineData("arcsin(arccos(arcsec(arccsc(x))))", "arcsin(arccos(arcsec(arccsc(1))))")] 28 | [InlineData("[ i , 3 , x ]", "[ i , 3 , 1 ]")] 29 | [InlineData("[ [ 1, 2, x ] , [ 4, x^2, 3 ] , [ x, x, x ] ]", "[ [ 1, 2, 1 ] , [ 4, 1^2, 3 ] , [ 1, 1, 1 ] ]")] 30 | public void Test(string unsubstituted, string expectedRaw) 31 | { 32 | var actual = unsubstituted.Substitute("x", 1); 33 | var expected = expectedRaw.ToEntity(); 34 | Assert.Equal(expected, actual); 35 | } 36 | 37 | [Fact] public void TupleSub1() => Assert.Equal("3 + 2 * 6", "x + 2y".Substitute(("x", "y"), (3, 6))); 38 | [Fact] public void TupleSub2() => Assert.Equal("3 + 2 * 6 + 8", "x + 2y + z".Substitute(("x", "y", "z"), (3, 6, 8))); 39 | [Fact] public void TupleSub3() => Assert.Equal("3 + 2 * 6 + 8 / 11", "x + 2y + z / d".Substitute(("x", "y", "z", "d"), (3, 6, 8, 11))); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Convenience/Casts.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Xunit; 9 | using AngouriMath.Extensions; 10 | using System.Numerics; 11 | using AngouriMath.Core.Exceptions; 12 | 13 | namespace AngouriMath.Tests.Convenience 14 | { 15 | public sealed class Casts 16 | { 17 | [Fact] public void ToDoubleSuccess1() => Assert.Equal(3d, (double)"3".EvalNumerical()); 18 | [Fact] public void ToDoubleSuccess2() => Assert.Equal(3.4d, (double)"3 + 2 / 5".EvalNumerical()); 19 | [Fact] public void ToFloatSuccess1() => Assert.Equal(3f, (float)"3".EvalNumerical()); 20 | [Fact] public void ToFloatSuccess2() => Assert.Equal(3.4f, (float)"3 + 2 / 5".EvalNumerical()); 21 | [Fact] public void ToIntSuccess1() => Assert.Equal(3, (int)"3".EvalNumerical()); 22 | [Fact] public void ToIntSuccess2() => Assert.Equal(-10, (int)"3 - 4 - 9".EvalNumerical()); 23 | [Fact] public void ToInt64Success3() => Assert.Equal(3, (long)"16 / 5".EvalNumerical()); 24 | [Fact] public void ToInt64Success1() => Assert.Equal(3, (long)"3".EvalNumerical()); 25 | [Fact] public void ToInt64Success2() => Assert.Equal(-10, (long)"3 - 4 - 9".EvalNumerical()); 26 | [Fact] public void ToBigIntegerSuccess1() => Assert.Equal(BigInteger.Parse("32758732583275823578"), (BigInteger)"32758732583275823578".EvalNumerical()); 27 | [Fact] public void ToComplexSuccess1() => Assert.Equal(new Complex(1, 2), (Complex)"1 + 2i".EvalNumerical()); 28 | [Fact] public void ToComplexSuccess2() => Assert.Equal(new Complex(1, 0.5), (Complex)"1 + 1/2 * i".EvalNumerical()); 29 | 30 | [Fact] public void ToDoubleUnsuc1() => Assert.Throws(() => (double)"1 + i".EvalNumerical()); 31 | [Fact] public void ToDoubleUnsuc2() => Assert.Throws(() => (double)"1 + i / 2".EvalNumerical()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Core/Domains.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using AngouriMath.Extensions; 10 | using Xunit; 11 | 12 | namespace AngouriMath.Tests.Core 13 | { 14 | public sealed class Domains 15 | { 16 | [Theory] 17 | [InlineData("domain(sqrt(-3), RR)")] 18 | [InlineData("domain(sqrt(3), ZZ)")] 19 | [InlineData("domain(sqrt(3), QQ)")] 20 | [InlineData("1 / 0")] 21 | [InlineData("domain(true and false, CC)")] 22 | [InlineData("domain(domain(sqrt(-3), RR) + 3, CC)")] 23 | [InlineData("domain(sqrt(4 / 9), ZZ)")] 24 | [InlineData("domain(1 / 2, ZZ)")] 25 | public void CheckNaN(string expr) 26 | => Assert.Equal(MathS.NaN, expr.EvalNumerical()); 27 | 28 | [Theory] 29 | [InlineData("domain(sqrt(4), RR)")] 30 | [InlineData("domain(sqrt(4), QQ)")] 31 | [InlineData("domain(sqrt(4), ZZ)")] 32 | [InlineData("domain(sqrt(4 / 9), QQ)")] 33 | [InlineData("domain(sqrt(-3), CC)")] 34 | [InlineData("domain(3 / 5, CC)")] 35 | [InlineData("domain(3 / 5, RR)")] 36 | [InlineData("domain(3 / 5, QQ)")] 37 | public void CheckNotNaN(string expr) 38 | => Assert.NotEqual(MathS.NaN, expr.EvalNumerical()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Core/Sets/Arithmetics.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Xunit; 9 | using AngouriMath.Extensions; 10 | 11 | namespace AngouriMath.Tests.Core.Sets 12 | { 13 | public sealed class Arithmetics 14 | { 15 | [Theory] 16 | [InlineData("[2; 3] + 3", "[5; 6]")] 17 | [InlineData("3 + [2; 3]", "[5; 6]")] 18 | [InlineData("3 * [2; 3]", "3 * [2; 3]")] 19 | [InlineData("[2; 3] * 3", "[2; 3] * 3")] 20 | [InlineData("[2; 3] / 2", "[2; 3] / 2")] 21 | [InlineData("{ 1, 2, 3 } + 10", "{ 11, 12, 13 }")] 22 | [InlineData("10 + { 1, 2, 3 }", "{ 11, 12, 13 }")] 23 | [InlineData("{ 1, 2, 3 } * 10", "{ 10, 20, 30 }")] 24 | [InlineData("10 * { 1, 2, 3 }", "{ 10, 20, 30 }")] 25 | [InlineData("10 / { 1, 2, 5 }", "{ 10, 5, 2 }")] 26 | [InlineData("{ 1, 2, 5 } / 10", "{ 0.1, 0.2, 0.5 }")] 27 | [InlineData("{ 1, 2, 5 } ^ 2", "{ 1, 4, 25 }")] 28 | [InlineData("{ 1, 2, 5 }!", "{ 1, 2, 120 }")] 29 | public void TestSimplify(string unsimplified, string expected) 30 | { 31 | var exp = expected.ToEntity(); 32 | var actUnsim = unsimplified.ToEntity(); 33 | var act = actUnsim.InnerSimplified; 34 | Assert.Equal(exp, act); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Core/Sets/CSetAndCSet.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using Xunit; 10 | using static AngouriMath.Entity; 11 | using static AngouriMath.Entity.Set; 12 | namespace AngouriMath.Tests.Core.Sets 13 | { 14 | public sealed class CSetAndCSet 15 | { 16 | private readonly Set A = new ConditionalSet("x", "x > 0"); 17 | private readonly Set A1 = new ConditionalSet("y", "y > 0"); 18 | private readonly Set B = new ConditionalSet("x", "x xor true"); 19 | private readonly Set C = new ConditionalSet("x", "x5 - x - 1 = 0"); 20 | private readonly Set D = new ConditionalSet("x", "x < 0"); 21 | 22 | private void Test(Set actual, ConditionalSet expected) 23 | { 24 | var csetAct = Assert.IsType(actual.Simplify()); 25 | Assert.Equal(expected, csetAct); 26 | } 27 | 28 | private void TestArb(Entity actual, Entity expected) 29 | { 30 | Assert.Equal(expected, actual); 31 | } 32 | 33 | [Fact] public void VarDoesntMatter1() => Test(A, new("y", "y > 0")); // { x | f(x) } == { y | f(y) } 34 | [Fact] public void VarDoesntMatter2() => Test(B, new("y", "not y")); 35 | 36 | [Fact] public void Union1() => Test(A.Unite(A1), new("x", "x > 0")); 37 | [Fact] public void Union2() => Test(A1.Unite(A), new("x", "x > 0")); 38 | [Fact] public void Union3() => Test(A.Unite(B), new("x", "x implies x > 0")); 39 | [Fact] public void Union4() => Test(B.Unite(A), new("x", "x implies x > 0")); 40 | 41 | [Fact] public void Intersection1() => Test(A1.Intersect(A), new("x", "x > 0")); 42 | [Fact] public void Intersection2() => Test(A.Intersect(A1), new("x", "x > 0")); 43 | [Fact] public void Intersection3() => TestArb(A.Intersect(D).Simplify(), Set.Empty); 44 | [Fact] public void Intersection4() => TestArb(D.Intersect(A).Simplify(), Set.Empty); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/Discrete/InSet.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Xunit; 9 | using AngouriMath.Extensions; 10 | using AngouriMath; 11 | 12 | namespace AngouriMath.Tests.Discrete 13 | { 14 | public sealed class InSet 15 | { 16 | [Theory] 17 | [InlineData(@"x in {}", false)] 18 | [InlineData(@"x in { x }", true)] 19 | [InlineData(@"1 in { 2, 3 }", false)] 20 | [InlineData(@"1 in { 2, 3 } \/ { 3, 5 }", false)] 21 | [InlineData(@"5 in { 2, 3 } \/ { 3, 5 }", true)] 22 | [InlineData(@"a in { 2, 3 } \/ { 3, 5 } \/ [1; a]", true)] 23 | [InlineData(@"3 in [2; 3]", true)] 24 | [InlineData(@"2 in [2; 3]", true)] 25 | [InlineData(@"2.5 in [2; 3]", true)] 26 | [InlineData(@"1.9 in [2; 3]", false)] 27 | [InlineData(@"3.1 in [2; 3]", false)] 28 | public void TestInnerSimplify(string input, bool expected) 29 | { 30 | var ent = input.ToEntity().InnerSimplified; 31 | Assert.Equal((Entity)expected, ent); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Diagnostics.CodeAnalysis; 9 | 10 | [assembly: SuppressMessage("Usage", "xUnit1004:Test methods should not be skipped", Justification = "Yes they should be")] -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/PatternsTest/FractionSimplify.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath; 9 | using Xunit; 10 | 11 | namespace AngouriMath.Tests.PatternsTest 12 | { 13 | public sealed class FractionSimplify 14 | { 15 | [Theory] 16 | [InlineData("(a - 1) / (1 - b) - (1 - a) / (b - 1)", "0")] // #254 17 | [InlineData("(4a - 2) / (2x) + (1 - 2a) / x", "0")] 18 | [InlineData("sin(a) * a * b / a", "sin(a) * b")] // #311 19 | [InlineData("sin(a) * cos(b) * tan(c) / (tan(c)3 * sin(a)2 * cos(b)^(-2))", "csc(a) * cos(b) ^ 3 * cotan(c) ^ 2")] 20 | public void TestSimplify(string testeeRaw, string expectedRaw) 21 | { 22 | Entity expected = expectedRaw; 23 | Entity testee = testeeRaw; 24 | var actual = testee.Simplify(); 25 | Assert.Equal(expected, actual); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/PatternsTest/PatternTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using Xunit; 9 | using AngouriMath.Extensions; 10 | 11 | namespace AngouriMath.Tests.PatternsTest 12 | { 13 | public sealed class PatternTest 14 | { 15 | private const int GithubIssue170Timeout = 1600; // we don't know the target machines 16 | 17 | // GitHub issue #170 18 | [Fact] 19 | public void TestSimplifyHangs1() => 20 | Assert.True(new TimeOutChecker(). 21 | BeingCompletedForLessThan( 22 | () => "1 + 1 / x".Simplify(), GithubIssue170Timeout)); 23 | 24 | [Fact] 25 | public void TestSimplifyHangs2() => 26 | Assert.True(new TimeOutChecker(). 27 | BeingCompletedForLessThan( 28 | () => "1 + 1 / (a + b)".Simplify(), GithubIssue170Timeout)); 29 | 30 | [Fact] 31 | public void TestSimplifyHangs3() => 32 | Assert.True(new TimeOutChecker(). 33 | BeingCompletedForLessThan( 34 | () => "1 / x + 1".Simplify(), GithubIssue170Timeout)); 35 | 36 | [Fact] 37 | public void TestSimplifyHangs4() => 38 | Assert.True(new TimeOutChecker(). 39 | BeingCompletedForLessThan( 40 | () => "(1 + 1 / x)^2 / (1 + 1 / x)".Simplify(), GithubIssue170Timeout)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/PatternsTest/PhiSimplify.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | /* Copyright (c) 2019-2020 Angourisoft 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 12 | * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 13 | * is furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | using AngouriMath.Extensions; 23 | using Xunit; 24 | 25 | namespace AngouriMath.Tests.PatternsTest 26 | { 27 | public sealed class PhiSimplify 28 | { 29 | [Theory] 30 | [InlineData("phi(2 ^ x) / 2 ^ x", "1/2")] 31 | [InlineData("phi(5 ^ x) / 5 ^ x", "4/5")] 32 | public void TestSimplify(string unsimplified, string simplified) 33 | { 34 | Assert.Equal(simplified.Simplify(), unsimplified.Simplify()); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/PatternsTest/SortSimplifyTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using AngouriMath.Extensions; 9 | using Xunit; 10 | 11 | namespace AngouriMath.Tests.PatternsTest 12 | { 13 | public sealed class SortSimplifyTest 14 | { 15 | [Theory] 16 | [InlineData("a + x + e + d + sin(x) + c + 1 + 2 + 2a", "3 * a")] 17 | [InlineData("x + a + b + c + arcsin(x2) + d + e + 1/2 - 23 * sqrt(3) + arccos(x * x)", "pi / 2")] 18 | [InlineData("x + a + b + c + arctan(x2) + d + e + 1/2 - 23 * sqrt(3) + arccot(x * x)", "pi / 2")] 19 | [InlineData("a / b + c + d + e + f + sin(x) + arcsin(x) + 1 + 0 - a * (b ^ -1)", "a / b", false)] 20 | // Skipped 21 | // [InlineData("sin(arcsin(c x) + arccos(x c) + c)2 + a + b + sin(x) + 0 + cos(c - -arcsin(c x) - -arccos(-c x * (-1)))2", "1")] 22 | // [InlineData("sin(arcsin(c x) + arccos(x c) + c)2 + a + b + sin(x) + 0 + cos(c - -arcsin(c x) - -arccos(-c x * (-1)))2", ") ^ 2", false)] 23 | [InlineData("sec(x) + a + sin(x) + c + 1 + 0 + 3 + sec(x)", "2 * sec(x)")] 24 | [InlineData("tan(x) * a * b / c / sin(h + 0.1) * cotan(x)", "tan", false)] 25 | [InlineData("sin(x) * a * b / c / sin(h + 0.1) * cosec(x)", "cosec", false)] 26 | [InlineData("cos(x) * a * b / c / sin(h + 0.1) * sec(x)", "cos", false)] 27 | [InlineData("sec(x) * a * b / c / sin(h + 0.1) * cos(x)", "sec", false)] 28 | [InlineData("cosec(x) * a * b / c / sin(h + 0.1) * sin(x)", "cosec", false)] 29 | public void TestStringIn(string exprRaw, string toBeIn, bool ifToBeIn = true) 30 | { 31 | var entity = exprRaw.ToEntity(); 32 | var actual = entity.Simplify(5); 33 | if (ifToBeIn) 34 | Assert.Contains(toBeIn, actual.Stringize()); 35 | else 36 | Assert.DoesNotContain(toBeIn, actual.Stringize()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | 6 | false 7 | AnyCPU;x64 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | all 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | 27 | 28 | all 29 | runtime; build; native; contentfiles; analyzers; buildtransitive 30 | 31 | 32 | all 33 | runtime; build; native; contentfiles; analyzers; buildtransitive 34 | 35 | 36 | 37 | 38 | 39 | 40 | TargetFramework=net7.0 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Sources/Tests/UnitTests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", 3 | "parallelizeAssembly": false 4 | } -------------------------------------------------------------------------------- /Sources/Utils/Utils/AdditionalExtensionsTestGenerator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.IO; 9 | using System.Text; 10 | 11 | namespace Utils 12 | { 13 | public static class AdditionalExtensionsTestGenerator 14 | { 15 | private static string Pattern(string name) 16 | => File.ReadAllText($"./Utils/{name}.txt"); 17 | 18 | public static string GenerateTupleToInterval() 19 | { 20 | var types = new[] { "3", "4.5", "\"6\"" }; 21 | var contentTemplate = Pattern("TupleToIntervalTest"); 22 | var gen = new SourceGenerator(contentTemplate, "%testid%", "%arg1%", "%arg2%"); 23 | var sb = new StringBuilder(); 24 | var id = 0; 25 | foreach (var type1 in types) 26 | foreach (var type2 in types) 27 | { 28 | sb.Append(gen.Generate(id.ToString(), type1, type2)); 29 | id++; 30 | } 31 | return sb.ToString(); 32 | } 33 | 34 | public static void Do() 35 | { 36 | var commonTemplate = Pattern("CommonTemplate"); 37 | 38 | var com = new SourceGenerator(commonTemplate, "%bat%", "%usings%", "%namespace%", "%classheader%", "%content%"); 39 | 40 | var fullText = com.Generate("generate_additional_extensions_tests.bat", "using Xunit;\nusing AngouriMath;\nusing AngouriMath.Extensions;", "UnitTest.Extensions", "public class IntervalExtensionTest", GenerateTupleToInterval()); 41 | 42 | File.WriteAllText("../Tests/UnitTests/Convenience/TupleToIntervalTest.cs", fullText); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/AntlrPostProcessor.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.IO; 9 | using System.Text; 10 | 11 | namespace Utils 12 | { 13 | public static class AntlrPostProcessorReplacePublicWithInternal 14 | { 15 | public const string ANTLR_PATH = "../AngouriMath/Core/Antlr/"; 16 | 17 | private static void ProcessFile(string path) 18 | { 19 | var finalPath = Path.Combine(ANTLR_PATH, path); 20 | 21 | var textSb = new StringBuilder(File.ReadAllText(finalPath)); 22 | textSb.Replace("public sealed class", "internal class"); 23 | textSb.Replace("public partial class", "internal partial class"); 24 | textSb.Replace("public interface", "internal interface"); 25 | File.WriteAllText(finalPath, textSb.ToString()); 26 | } 27 | 28 | public static void Do() 29 | { 30 | ProcessFile("AngouriMathBaseListener.cs"); 31 | ProcessFile("AngouriMathLexer.cs"); 32 | ProcessFile("AngouriMathListener.cs"); 33 | ProcessFile("AngouriMathParser.cs"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/CommonTemplate.txt: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | // This file is auto-generated. Use %bat% to re-generate it, do not edit the file itself. 9 | 10 | %usings% 11 | 12 | namespace %namespace% 13 | { 14 | %classheader% 15 | { 16 | %content% 17 | } 18 | } -------------------------------------------------------------------------------- /Sources/Utils/Utils/EquationSystemFunctionPattern.txt: -------------------------------------------------------------------------------- 1 |  ///Solves a given set of arbitrary equations 2 | ///A tensor whose width is %i% columns long or null if no solutions were found 3 | public static Tensor? SolveSystem(this (%tupleargs%) eqs, %vars%) 4 | => MathS.Equations(%argspassed%).Solve(%varspassed%); 5 | 6 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/ExportsGenerator/ExportedFunctions.txt: -------------------------------------------------------------------------------- 1 |  [UnmanagedCallersOnly(EntryPoint = "%exportedname%")] 2 | public static NErrorCode %name%(%params%, ObjRef* res) 3 | => ExceptionEncode(res, (%paramswithouttype%), e => %localname%(%paramswithe%)); 4 | 5 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/ExportsGenerator/ImportFile.txt: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | // This file is auto-generated. 9 | 10 | #pragma once 11 | 12 | #include "TypeAliases.h" 13 | 14 | using namespace AngouriMath::Internal; 15 | 16 | extern "C" 17 | { 18 | %content% 19 | } -------------------------------------------------------------------------------- /Sources/Utils/Utils/ExportsGenerator/ImportedFunctions.txt: -------------------------------------------------------------------------------- 1 |  __declspec(dllimport) NativeErrorCode %exportname%(%params%EntityOut); 2 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/ExportsGenerator/UsingFile.txt: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | // This file is auto-generated. 9 | 10 | #pragma once 11 | 12 | #include "AngouriMath.h" 13 | #include "%importfile%" 14 | 15 | namespace AngouriMath 16 | { 17 | %content% 18 | } -------------------------------------------------------------------------------- /Sources/Utils/Utils/ExportsGenerator/UsingFunctions.txt: -------------------------------------------------------------------------------- 1 |  Entity %name%(%params%) 2 | { 3 | EntityRef res; 4 | HandleErrorCode(%exportname%(%paramswithouttype%, &res)); 5 | return CreateByHandle(res); 6 | } 7 | 8 | Entity %name%(%params%, ErrorCode& e) 9 | { 10 | EntityRef res; 11 | HandleErrorCode(%exportname%(%paramswithouttype%, &res), e); 12 | return CreateByHandle(res); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/Program.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.IO; 10 | using System.Reflection; 11 | using System.Runtime; 12 | 13 | namespace Utils 14 | { 15 | class Program 16 | { 17 | public static string GetPathIntoSources() 18 | { 19 | var path = Directory.GetCurrentDirectory(); 20 | while (Path.GetFileName(path) != "Sources" && path is not "") 21 | path = Path.GetDirectoryName(path); 22 | return path ?? ""; 23 | } 24 | 25 | static void Main(string[] args) 26 | { 27 | if (args.Length != 1) 28 | throw new InvalidOperationException("Specify class' name whose method to call"); 29 | 30 | var className = args[0]; 31 | 32 | var typeToCall = Type.GetType("Utils." + className); 33 | 34 | if (typeToCall is null) 35 | throw new EntryPointNotFoundException($"Class {className} not found"); 36 | 37 | MethodInfo? methodDo; 38 | 39 | try 40 | { 41 | methodDo = typeToCall.GetMethod("Do"); 42 | } 43 | catch (AmbiguousMatchException amb) 44 | { 45 | throw new AmbiguousImplementationException("There should be one Do", amb); 46 | } 47 | 48 | if (methodDo is null) 49 | throw new AmbiguousImplementationException("There should be one Do"); 50 | 51 | methodDo.Invoke(null, new object[] { }); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/SourceGenerator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Text; 10 | 11 | namespace Utils 12 | { 13 | // Yes, I must be inventing wheel... but why adding yet another dependency 14 | // for such a simple action? 15 | public sealed class SourceGenerator 16 | { 17 | private readonly string[] toReplace; 18 | private readonly string template; 19 | public SourceGenerator(string template, params string[] toReplace) 20 | { 21 | this.toReplace = toReplace; 22 | this.template = template; 23 | } 24 | 25 | public string Generate(params string[] replacements) 26 | { 27 | if (replacements.Length != toReplace.Length) 28 | throw new ArgumentException(); 29 | var sb = new StringBuilder(template); 30 | for (int i = 0; i < toReplace.Length; i++) 31 | sb.Replace(toReplace[i], replacements[i]); 32 | return sb.ToString(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/TupleToIntervalTemplate.txt: -------------------------------------------------------------------------------- 1 |  /// 2 | /// Takes a and and returns 3 | /// a closed interval (so that left and right ends are included) 4 | /// 5 | /// Interval 6 | public static Interval ToInterval(this (%type1% left, %type2% right) arg) 7 | => MathS.Sets.Interval(arg.left, arg.right); 8 | 9 | /// 10 | /// Takes a and and returns 11 | /// a closed interval (so that left and right ends are included) 12 | /// 13 | /// Interval 14 | public static Interval ToInterval(this (%type1% left, bool leftClosed, %type2% right, bool rightClosed) arg) 15 | => new Interval(arg.left, arg.leftClosed, arg.right, arg.rightClosed); 16 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/TupleToIntervalTest.txt: -------------------------------------------------------------------------------- 1 | [Fact] public void Test%testid%() 2 | => Assert.Equal( 3 | MathS.Matrices.Interval(%arg1%, %arg2%), 4 | (%arg1%, %arg2%).ToInterval() 5 | ); 6 | 7 | [Fact] public void Test%testid%_custom() 8 | => Assert.Equal( 9 | MathS.Matrices.Interval(%arg1%, true, %arg2%, false), 10 | (%arg1%, true, %arg2%, false).ToInterval() 11 | ); 12 | 13 | -------------------------------------------------------------------------------- /Sources/Utils/Utils/Utils.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Sources/Utils/antlr_rerun.bat: -------------------------------------------------------------------------------- 1 | cd ../AngouriMath/Core/Antlr 2 | 3 | :;# AngouriMath.Core.Antlr is the namespace of the generated lexer and parser source files 4 | java -jar ./antlr-4.8-complete.jar -package AngouriMath.Core.Antlr ./AngouriMath.g 5 | 6 | cd ../../../Utils 7 | 8 | :;# Antlr's generated classes should be internal, not public 9 | dotnet run --project Utils -c release AntlrPostProcessorReplacePublicWithInternal 10 | 11 | :; echo Press Enter to continue...; read dummy; exit $? # Line for Unix Bash 12 | pause REM Line for Windows Command Prompt -------------------------------------------------------------------------------- /Sources/Utils/generate_additional_extensions.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project Utils ExtensionGenerator -c release 2 | pause -------------------------------------------------------------------------------- /Sources/Utils/generate_additional_extensions_tests.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project Utils AdditionalExtensionsTestGenerator -c release 2 | pause -------------------------------------------------------------------------------- /Sources/Utils/generate_exports.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project Utils ExportsGenerator -c release 2 | pause -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/AngouriMath.CPP.Exporting.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Build/1.generate-exports.bat: -------------------------------------------------------------------------------- 1 | cd ../../../Utils 2 | dotnet run -p Utils ExportsGenerator 3 | cd ../Wrappers/AngouriMath.CPP.Exporting/Build 4 | pause 5 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Build/2.build-win-x64.bat: -------------------------------------------------------------------------------- 1 | echo "building for 64-bit windows..." 2 | cd ../ 3 | dotnet publish -p:NativeLib=Shared -p:SelfContained=true -r win-x64 -c release 4 | cd Build -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Build/3.pack-win-x64.bat: -------------------------------------------------------------------------------- 1 | cd ../../ 2 | tar --exclude=./AngouriMath.CPP.Importing/out --exclude=./AngouriMath.CPP.Importing/.vs -c -f AngouriMath-Win-x64.zip ./AngouriMath.CPP.Importing 3 | tar --exclude=./AngouriMath.CPP.Importing/out --exclude=./AngouriMath.CPP.Importing/.vs --exclude=./AngouriMath.CPP.Importing/win-x64/AngouriMath.CPP.Exporting.pdb -c -f AngouriMath-Win-x64-No-Pdb.zip ./AngouriMath.CPP.Importing -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/CSharpWorkarounds.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace System.Runtime.InteropServices 9 | { 10 | /// 11 | /// Any method marked with can be directly called from 12 | /// native code. The function token can be loaded to a local variable using the address-of operator 13 | /// in C# and passed as a callback to a native method. 14 | /// 15 | /// 16 | /// Methods marked with this attribute have the following restrictions: 17 | /// * Method must be marked "static". 18 | /// * Must not be called from managed code. 19 | /// * Must only have blittable arguments. 20 | /// 21 | [AttributeUsage(AttributeTargets.Method, Inherited = false)] 22 | public sealed class UnmanagedCallersOnlyAttribute : Attribute 23 | { 24 | public UnmanagedCallersOnlyAttribute() 25 | { 26 | } 27 | 28 | /// 29 | /// Optional. If omitted, the runtime will use the default platform calling convention. 30 | /// 31 | /// 32 | /// Supplied types must be from the official "System.Runtime.CompilerServices" namespace and 33 | /// be of the form "CallConvXXX". 34 | /// 35 | public Type[]? CallConvs; 36 | 37 | /// 38 | /// Optional. If omitted, no named export is emitted during compilation. 39 | /// 40 | public string? EntryPoint; 41 | } 42 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Exceptions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | 10 | namespace AngouriMath.CPP.Exporting 11 | { 12 | public abstract class ObjectStorageException : Exception { } 13 | 14 | public sealed class DeallocationException : ObjectStorageException 15 | { 16 | 17 | } 18 | public sealed class AllocationException : ObjectStorageException 19 | { 20 | } 21 | 22 | public sealed class NonExistentObjectAddressingException : ObjectStorageException 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Exports.Free.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Runtime.InteropServices; 10 | 11 | namespace AngouriMath.CPP.Exporting 12 | { 13 | partial class Exports 14 | { 15 | private static void Free(IntPtr ptr) 16 | { 17 | if (ptr.ToInt64() == 0) 18 | return; 19 | Marshal.FreeHGlobal(ptr); 20 | } 21 | 22 | [UnmanagedCallersOnly(EntryPoint = "free_entity")] 23 | public static NErrorCode FreeEntity(ObjRef handle) 24 | => ExceptionEncode(handle, static h => ObjStorage.Dealloc(h)); 25 | 26 | [UnmanagedCallersOnly(EntryPoint = "free_error_code")] 27 | public static NErrorCode FreeErrorCode(NErrorCode code) 28 | => ExceptionEncode(code, static code => code.Free() ); 29 | 30 | [UnmanagedCallersOnly(EntryPoint = "free_native_array")] 31 | public static NErrorCode FreeNativeArray(NativeArray arr) 32 | => ExceptionEncode(arr, static arr => arr.Free() ); 33 | 34 | [UnmanagedCallersOnly(EntryPoint = "free_string")] 35 | public static NErrorCode FreeNativeArray(IntPtr s) 36 | => ExceptionEncode(s, static s => Free(s) ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Exports.MathS.Functions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Runtime.InteropServices; 10 | 11 | namespace AngouriMath.CPP.Exporting 12 | { 13 | unsafe partial class Exports 14 | { 15 | [UnmanagedCallersOnly(EntryPoint = "maths_from_string")] 16 | public static NErrorCode Parse(IntPtr strPtr, ObjRef* res) 17 | => ExceptionEncode(res, strPtr, static strPtr => 18 | { 19 | var str = Marshal.PtrToStringAnsi(strPtr); 20 | return ObjStorage.Alloc(str); 21 | }); 22 | 23 | [UnmanagedCallersOnly(EntryPoint = "matrix_from_vector_of_vectors")] 24 | public static NErrorCode MatrixFromVectorOfVectors(NativeArray arr, ObjRef* res) 25 | => ExceptionEncode(res, arr, static arr => 26 | { 27 | // TODO: 28 | throw new InvalidOperationException("This method should be implemented after native-aot-attempt-2 is merged into master"); 29 | }); 30 | 31 | [UnmanagedCallersOnly(EntryPoint = "matrix_transpose")] 32 | public static NErrorCode MatrixTranspose(ObjRef m, ObjRef* res) 33 | => ExceptionEncode(res, m, static m => 34 | { 35 | // TODO: 36 | throw new InvalidOperationException("This method should be implemented after native-aot-attempt-2 is merged into master"); 37 | }); 38 | 39 | [UnmanagedCallersOnly(EntryPoint = "finite_set_to_vector")] 40 | public static NErrorCode FiniteSetToVector(ObjRef m, NativeArray* res) 41 | => ExceptionEncode(res, m, static m 42 | => NativeArray.Alloc((Entity.Set.FiniteSet)m.AsEntity) 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/Exports.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | /* 9 | * 10 | * Great thanks to Andrey Kurdyumov for help! 11 | * 12 | */ 13 | 14 | using System; 15 | 16 | namespace AngouriMath.CPP.Exporting 17 | { 18 | internal static unsafe partial class Exports 19 | { 20 | internal static NErrorCode ExceptionEncode(TOut* destination, TIn input, Func func) 21 | where TIn : unmanaged 22 | where TOut : unmanaged 23 | { 24 | try 25 | { 26 | *destination = func(input); 27 | return NErrorCode.Ok; 28 | } 29 | catch (Exception e) 30 | { 31 | return NErrorCode.Thrown(e); 32 | } 33 | } 34 | 35 | internal static NErrorCode ExceptionEncode(TIn input, Action func) 36 | { 37 | try 38 | { 39 | func(input); 40 | return NErrorCode.Ok; 41 | } 42 | catch (Exception e) 43 | { 44 | return NErrorCode.Thrown(e); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/IFreeable.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.CPP.Exporting 9 | { 10 | /// 11 | /// Responsible for native deallocation 12 | /// 13 | public interface IFreeable 14 | { 15 | public void Free(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/NativeStructs/ErrorCode.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Runtime.InteropServices; 10 | 11 | namespace AngouriMath.CPP.Exporting 12 | { 13 | partial class Exports 14 | { 15 | /// 16 | /// Native structure to transfer exceptions 17 | /// 18 | public struct NErrorCode : IFreeable 19 | { 20 | private readonly IntPtr name; 21 | private readonly IntPtr message; 22 | private readonly IntPtr stackTrace; 23 | private NErrorCode(Exception exception) 24 | { 25 | name = Marshal.StringToHGlobalAnsi(exception.GetType().FullName); 26 | message = Marshal.StringToHGlobalAnsi(exception.Message); 27 | stackTrace = Marshal.StringToHGlobalAnsi(exception.StackTrace); 28 | } 29 | public static NErrorCode Thrown(Exception exception) 30 | => new(exception); 31 | public static NErrorCode Ok 32 | => new(); 33 | public void Free() 34 | { 35 | Exports.Free(name); 36 | Exports.Free(message); 37 | Exports.Free(stackTrace); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/NativeStructs/NativeArray.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Runtime.InteropServices; 12 | 13 | namespace AngouriMath.CPP.Exporting 14 | { 15 | partial class Exports 16 | { 17 | public struct NativeArray : IFreeable 18 | { 19 | public int Length { get; init; } 20 | public IntPtr Ptr { get; init; } 21 | internal static NativeArray Alloc(IEnumerable elements) 22 | { 23 | var arr = elements.Select(c => ObjStorage.Alloc(c)).ToArray(); 24 | var allocated = GCHandle.Alloc(arr, GCHandleType.Pinned); 25 | var ptr = allocated.AddrOfPinnedObject(); 26 | ObjStorage.Alloc(new((ulong)ptr), allocated); 27 | return new() { Length = arr.Length, Ptr = ptr }; 28 | } 29 | public void Free() 30 | { 31 | var handle = ObjStorage.Get(new((ulong)Ptr)); 32 | handle.Free(); 33 | ObjStorage.Dealloc(new((ulong)Ptr)); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/NativeStructs/NativeBool.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.CPP.Exporting 9 | { 10 | partial class Exports 11 | { 12 | public struct NativeBool 13 | { 14 | private int value; 15 | public NativeBool(bool value) 16 | => this.value = value ? 1 : 0; 17 | public static NativeBool True => new(true); 18 | public static NativeBool False => new(false); 19 | public static implicit operator NativeBool(bool value) 20 | => new(value); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/NativeStructs/ObjRef.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | namespace AngouriMath.CPP.Exporting 9 | { 10 | partial class Exports 11 | { 12 | internal struct ObjRef 13 | { 14 | private readonly ulong handle; 15 | public ObjRef(ulong handle) 16 | => this.handle = handle; 17 | public ObjRef Next() 18 | => new ObjRef(handle + 1); 19 | public Entity AsEntity => ObjStorage.Get(this); 20 | public static implicit operator ObjRef(Entity entity) 21 | => ObjStorage.Alloc(entity); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/ObjectStorage.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | using System.Collections.Generic; 9 | 10 | namespace AngouriMath.CPP.Exporting 11 | { 12 | partial class Exports 13 | { 14 | internal static class ObjStorage 15 | { 16 | private static ObjRef lastId = new(0); 17 | private readonly static Dictionary allocations = new(); 18 | internal static ObjRef Alloc(T obj) 19 | { 20 | lastId = lastId.Next(); 21 | allocations[lastId] = obj; 22 | return lastId; 23 | } 24 | internal static ObjRef Alloc(ObjRef ptr, T obj) 25 | { 26 | allocations[ptr] = obj; 27 | return ptr; 28 | } 29 | internal static void Dealloc(ObjRef ptr) 30 | { 31 | if (!allocations.ContainsKey(ptr)) 32 | throw new DeallocationException(); 33 | allocations.Remove(ptr); 34 | } 35 | internal static T Get(ObjRef ptr) 36 | { 37 | if (!allocations.ContainsKey(ptr)) 38 | throw new NonExistentObjectAddressingException(); 39 | return allocations[ptr]; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Exporting/README.md: -------------------------------------------------------------------------------- 1 | ## Building exports manually 2 | 3 | There will be archives or setup for normal use. However, if needs to be built, there are two steps: 4 | 5 | #### 1. Generating code 6 | 7 | First, run `generate_exports.bat` or `generate_exports.bat`. This will generate C# and C++ code which exports and 8 | imports functions. If you are satisfied with what is currently generated, there is no need to run this file. 9 | 10 | #### 2. Building the library 11 | 12 | Depending on your operating system, run `build-win-x64.bat`, `build-linux-x64.sh` or `build-mac-x64.sh`. This will generate 13 | `dll`/`so` file as well as `pdb` and linking files into `../AngouriMath.CPP.Importing/[your-os]-x64/`. -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/A.Imports.Hyperbolic.Functions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019-2022 Angouri. 3 | // AngouriMath is licensed under MIT. 4 | // Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. 5 | // Website: https://am.angouri.org. 6 | // 7 | 8 | // This file is auto-generated. 9 | 10 | #pragma once 11 | 12 | #include "TypeAliases.h" 13 | 14 | using namespace AngouriMath::Internal; 15 | 16 | extern "C" 17 | { 18 | __declspec(dllimport) NativeErrorCode hyperbolic_sinh(EntityRef, EntityOut); 19 | __declspec(dllimport) NativeErrorCode hyperbolic_cosh(EntityRef, EntityOut); 20 | __declspec(dllimport) NativeErrorCode hyperbolic_tanh(EntityRef, EntityOut); 21 | __declspec(dllimport) NativeErrorCode hyperbolic_cotanh(EntityRef, EntityOut); 22 | __declspec(dllimport) NativeErrorCode hyperbolic_sech(EntityRef, EntityOut); 23 | __declspec(dllimport) NativeErrorCode hyperbolic_cosech(EntityRef, EntityOut); 24 | __declspec(dllimport) NativeErrorCode hyperbolic_arsinh(EntityRef, EntityOut); 25 | __declspec(dllimport) NativeErrorCode hyperbolic_arcosh(EntityRef, EntityOut); 26 | __declspec(dllimport) NativeErrorCode hyperbolic_artanh(EntityRef, EntityOut); 27 | __declspec(dllimport) NativeErrorCode hyperbolic_arcotanh(EntityRef, EntityOut); 28 | __declspec(dllimport) NativeErrorCode hyperbolic_arsech(EntityRef, EntityOut); 29 | __declspec(dllimport) NativeErrorCode hyperbolic_arcosech(EntityRef, EntityOut); 30 | 31 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/AmgouriMathException.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "ErrorCode.h" 5 | 6 | namespace AngouriMath 7 | { 8 | class AngouriMathException : public std::exception 9 | { 10 | public: 11 | AngouriMathException(ErrorCode e) 12 | : error(e) { } 13 | 14 | virtual const char* what() const noexcept override 15 | { 16 | return this->Name().c_str(); 17 | } 18 | 19 | const std::string& Name() const 20 | { 21 | return this->error.Name(); 22 | } 23 | 24 | const std::string& Message() const 25 | { 26 | return this->error.Message(); 27 | } 28 | 29 | const std::string& StackTrace() const 30 | { 31 | return this->error.StackTrace(); 32 | } 33 | 34 | private: 35 | ErrorCode error; 36 | }; 37 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/AngouriMath.CPP.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | {innerEntityInstance._Ptr->string.cached} 18 | 19 | 20 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeList.txt : CMake project for AngouriMath.CPP, include source and define 2 | # project specific logic here. 3 | # 4 | cmake_minimum_required (VERSION 3.8) 5 | 6 | project ("AngouriMath.CPP.Importing") 7 | # Add source to this project's executable. 8 | 9 | set(CMAKE_CXX_STANDARD 17) 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 11 | 12 | # TODO: Add tests and install targets if needed. 13 | 14 | set(SOURCES 15 | "AngouriMath.cpp" 16 | "ErrorCode.cpp") 17 | 18 | add_library(${PROJECT_NAME} ${SOURCES}) 19 | 20 | # link_directories(./out-x64/) 21 | target_link_directories(${PROJECT_NAME} PUBLIC out-x64) 22 | if (WIN32) 23 | target_link_libraries(${PROJECT_NAME} PUBLIC AngouriMath.CPP.Exporting) 24 | else () 25 | target_link_libraries(${PROJECT_NAME} PUBLIC -lAngouriMath.CPP.Exporting) 26 | endif() 27 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "x64-Debug", 5 | "generator": "Ninja", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ "msvc_x64_x64" ], 8 | "buildRoot": "${projectDir}\\out\\build\\${name}", 9 | "installRoot": "${projectDir}\\out\\install\\${name}", 10 | "cmakeCommandArgs": "", 11 | "buildCommandArgs": "", 12 | "ctestCommandArgs": "" 13 | }, 14 | { 15 | "name": "x64-Clang-Debug", 16 | "generator": "Ninja", 17 | "configurationType": "Debug", 18 | "buildRoot": "${projectDir}\\out\\build\\${name}", 19 | "installRoot": "${projectDir}\\out\\install\\${name}", 20 | "cmakeCommandArgs": "", 21 | "buildCommandArgs": "", 22 | "ctestCommandArgs": "", 23 | "inheritEnvironments": [ "clang_cl_x64_x64" ], 24 | "variables": [] 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/ErrorCode.cpp: -------------------------------------------------------------------------------- 1 | #include "AmgouriMathException.h" 2 | #include 3 | #include "Imports.h" 4 | 5 | namespace AngouriMath::Internal 6 | { 7 | void DeleteNativeErrorCode(NativeErrorCode nec) 8 | { 9 | (void)free_error_code(nec); 10 | } 11 | 12 | void HandleErrorCode(NativeErrorCode nec) 13 | { 14 | if (nec.name != nullptr) 15 | { 16 | auto ec = ErrorCode( 17 | nec.name != nullptr ? nec.name : "", 18 | nec.message != nullptr ? nec.message : "", 19 | nec.stackTrace != nullptr ? nec.stackTrace : "" 20 | ); 21 | DeleteNativeErrorCode(nec); 22 | throw AngouriMathException(ec); 23 | } 24 | } 25 | 26 | void HandleErrorCode(NativeErrorCode nec, ErrorCode& ec) 27 | { 28 | ec = ErrorCode( 29 | nec.name != nullptr ? nec.name : "", 30 | nec.message != nullptr ? nec.message : "", 31 | nec.stackTrace != nullptr ? nec.stackTrace : "" 32 | ); 33 | DeleteNativeErrorCode(nec); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/ErrorCode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "TypeAliases.h" 5 | 6 | namespace AngouriMath 7 | { 8 | struct ErrorCode 9 | { 10 | public: 11 | ErrorCode() { } 12 | 13 | ErrorCode(std::string name, std::string message, std::string stackTrace) 14 | : name(std::move(name)), message(std::move(message)), stackTrace(std::move(stackTrace)) { } 15 | 16 | bool IsOk() const { return this->name.empty(); } 17 | const std::string& Name() const { return this->name; } 18 | const std::string& Message() const { return this->message; } 19 | const std::string& StackTrace() const { return this->stackTrace; } 20 | private: 21 | std::string name; 22 | std::string message; 23 | std::string stackTrace; 24 | }; 25 | 26 | namespace Internal 27 | { 28 | void HandleErrorCode(ErrorCode ec); 29 | void HandleErrorCode(NativeErrorCode nec); 30 | void HandleErrorCode(NativeErrorCode nec, ErrorCode& ec); 31 | } 32 | } 33 | 34 | namespace std 35 | { 36 | inline std::string to_string(AngouriMath::ErrorCode e) 37 | { 38 | return e.Name(); 39 | } 40 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/FieldCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TypeAliases.h" 4 | #include 5 | 6 | namespace AngouriMath::Internal 7 | { 8 | template 9 | class FieldCache 10 | { 11 | private: 12 | std::optional cached; 13 | public: 14 | // TODO: make thread-safe 15 | template 16 | const T& GetValue(Factory&& factory, EntityRef ref) 17 | { 18 | if (!cached.has_value()) 19 | cached = factory(ref); 20 | return this->cached.value(); 21 | } 22 | }; 23 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.CPP.Importing/TypeAliases.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace AngouriMath::Internal 6 | { 7 | typedef uint64_t EntityRef; 8 | typedef EntityRef* EntityOut; 9 | typedef char** StringOut; 10 | 11 | typedef const char* String; 12 | typedef int32_t ApproachFrom; // in the outer API, it should be a enum 13 | 14 | typedef struct { int64_t first; int64_t second; } LongTuple; 15 | typedef struct { double first; double second; } DoubleTuple; 16 | 17 | struct NativeErrorCode 18 | { 19 | const char* name; 20 | const char* message; 21 | const char* stackTrace; 22 | }; 23 | 24 | struct NativeArray 25 | { 26 | int32_t length; 27 | const EntityRef* refs; 28 | }; 29 | } -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/AngouriMath.FSharp.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | netstandard2.0 7 | true 8 | fsharp.key 9 | F# wrapper for some functions from AngouriMath. https://am.angouri.org/quickstart/index.html 10 | $(PackageTags), fsharp 11 | true 12 | true 13 | 14 | true 15 | 16 | 17 | 18 | bin\Release\netstandard2.0\AngouriMath.FSharp.XML 19 | 20 | 21 | 22 | bin\Debug\netstandard2.0\AngouriMath.FSharp.XML 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/Compilation.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Compilation 2 | 3 | open Core 4 | 5 | /// Compiles the given expression into a function 6 | /// Use it for performance. Pass some built-in type, 7 | /// be that a BigInteger, int, long, bool, float, double. 8 | /// If a necessary type is missing, use the original function 9 | /// Entity.Compile<> with a passed Compilation protocol 10 | let compiled1In<'TIn1, 'TOut> x1 expr = 11 | let compiled = (parsed expr).Compile<'TIn1, 'TOut>(symbol x1) 12 | fun x1 -> compiled.Invoke(x1) 13 | 14 | /// Compiles the given expression into a function 15 | /// Use it for performance. Pass some built-in type, 16 | /// be that a BigInteger, int, long, bool, float, double. 17 | /// If a necessary type is missing, use the original function 18 | /// Entity.Compile<> with a passed Compilation protocol 19 | let compiled2In<'TIn1, 'TIn2, 'TOut> x1 x2 expr = 20 | let compiled = (parsed expr).Compile<'TIn1, 'TIn2, 'TOut>(symbol x1, symbol x2) 21 | fun x1 x2 -> compiled.Invoke(x1, x2) 22 | 23 | /// Compiles the given expression into a function 24 | /// Use it for performance. Pass some built-in type, 25 | /// be that a BigInteger, int, long, bool, float, double. 26 | /// If a necessary type is missing, use the original function 27 | /// Entity.Compile<> with a passed Compilation protocol 28 | let compiled3In<'TIn1, 'TIn2, 'TIn3, 'TOut> x1 x2 x3 expr = 29 | let compiled = (parsed expr).Compile<'TIn1, 'TIn2, 'TIn3, 'TOut>(symbol x1, symbol x2, symbol x3) 30 | fun x1 x2 x3 -> compiled.Invoke(x1, x2, x3) 31 | 32 | /// Compiles the given expression into a function 33 | /// Use it for performance. Pass some built-in type, 34 | /// be that a BigInteger, int, long, bool, float, double. 35 | /// If a necessary type is missing, use the original function 36 | /// Entity.Compile<> with a passed Compilation protocol 37 | let compiled4In<'TIn1, 'TIn2, 'TIn3, 'TIn4, 'TOut> x1 x2 x3 x4 expr = 38 | let compiled = (parsed expr).Compile<'TIn1, 'TIn2, 'TIn3, 'TIn4, 'TOut>(symbol x1, symbol x2, symbol x3, symbol x4) 39 | fun x1 x2 x3 x4 -> compiled.Invoke(x1, x2, x3, x4) -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/Constants.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Constants 2 | 3 | open AngouriMath 4 | 5 | let zero = Entity.op_Implicit(0) 6 | let one = Entity.op_Implicit(1) 7 | let minusOne = Entity.op_Implicit(-1) 8 | let pi = MathS.pi 9 | let e = MathS.e 10 | let i = MathS.i 11 | let I_1 = MathS.I_1 12 | let I_2 = MathS.I_2 13 | let I_3 = MathS.I_3 14 | let I_4 = MathS.I_4 15 | let O_1 = MathS.O_1 16 | let O_2 = MathS.O_2 17 | let O_3 = MathS.O_3 18 | let O_4 = MathS.O_4 -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/Operators.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module Operators 3 | 4 | open Core 5 | open AngouriMath 6 | 7 | type Tending = { var: Entity; destination: Entity; } 8 | 9 | let (@?) (expr : Entity) x = expr.Solve x 10 | 11 | let (&&&&) (expr : Entity) (right : obj) = 12 | match right with 13 | | :? Tending as tending -> expr.Limit(parse_symbol tending.var, parse tending.destination) 14 | | _ -> MathS.Conjunction(expr, parse right) 15 | 16 | let (|||) left right = MathS.Disjunction(left, right) 17 | 18 | let (=>) (assumption : Entity) conclusion = assumption.Implies(conclusion) 19 | 20 | let (-->) x destination = { var = x; destination = destination; } 21 | 22 | let (^) (base_ : Entity) (power : Entity) = base_.Pow power -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/PackageReadme.md: -------------------------------------------------------------------------------- 1 | This package includes AngouriMath and wrappers convenient for use in F#. 2 | 3 | References: 4 | [Website](https://am.angouri.org) · [Github](https://github.com/asc-community/AngouriMath) · [What's new](https://am.angouri.org/whatsnew/) · [Wiki](https://am.angouri.org/wiki/) · [Contacts](https://am.angouri.org/#contacts) 5 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/Shortcuts.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.FSharp.Shortcuts 2 | 3 | // Here we will store "overloads" and short forms of functions with some parameters 4 | // being set to default (for example, it might be variable `x` in many cases) 5 | 6 | open Functions 7 | open Core 8 | 9 | /// Finds the derivative of the given expression 10 | /// over x 11 | let ``d/dx`` expr = derivative "x" expr 12 | 13 | /// Finds the integral of the given expression 14 | let ``int [dx]`` expr = integral "x" expr 15 | 16 | /// Finds the both-sided limit of the given expression 17 | /// for x approaching 0 18 | let ``lim x->0`` expr = limit "x" 0 expr 19 | 20 | /// Finds the both-sided limit of the given expression 21 | /// for x approaching positive infinity 22 | let ``lim x->+oo`` expr = limit "x" "+oo" expr 23 | 24 | /// Finds the both-sided limit of the given expression 25 | /// for x approaching negative infinity 26 | let ``lim x->-oo`` expr = limit "x" "-oo" expr 27 | 28 | /// Substitutes the first argument from the tuple with the second 29 | /// argument in the tuple in the given expression 30 | let (-|>) (x, v) expr = (substituted (symbol x) (parsed v) expr).InnerSimplified 31 | 32 | /// In the given expresion, substitutes the first argument from the tuple 33 | /// with the second argument from the tuple 34 | let (<|-) expr (x, v) = (substituted (symbol x) (parsed v) expr).InnerSimplified 35 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/fsharp.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Wrappers/AngouriMath.FSharp/fsharp.key -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.FSharp/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Wrappers/AngouriMath.FSharp/icon.png -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.Interactive/AggressiveOperators.fs: -------------------------------------------------------------------------------- 1 | module AngouriMath.Interactive.AggressiveOperators 2 | 3 | open AngouriMath.FSharp.Core 4 | open AngouriMath.FSharp.Functions 5 | 6 | let ( + ) a b = 7 | ((parsed a) + (parsed b)).InnerSimplified 8 | let ( - ) a b = 9 | ((parsed a) - (parsed b)).InnerSimplified 10 | let ( * ) a b = 11 | ((parsed a) * (parsed b)).InnerSimplified 12 | let ( / ) a b = 13 | ((parsed a) / (parsed b)).InnerSimplified 14 | let ( ** ) a b = 15 | ((parsed a).Pow(parsed b)).InnerSimplified 16 | let ( ~~~ ) a = 17 | (negation (parsed a)).InnerSimplified 18 | let ( ||| ) a b = 19 | (union (parsed a) (parsed b)).InnerSimplified 20 | let ( &&& ) a b = 21 | (intersect (parsed a) (parsed b)).InnerSimplified 22 | let ( = ) a b = 23 | (equality (parsed a) (parsed b)).InnerSimplified 24 | let ( <> ) a b = 25 | (negation (equality (parsed a) (parsed b))).InnerSimplified 26 | let ( > ) a b = 27 | (greater (parsed a) (parsed b)).InnerSimplified 28 | let ( < ) a b = 29 | (less (parsed a) (parsed b)).InnerSimplified 30 | let ( >= ) a b = 31 | (greaterOrEqual (parsed a) (parsed b)).InnerSimplified 32 | let ( <= ) a b = 33 | (lessOrEqual (parsed a) (parsed b)).InnerSimplified 34 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.Interactive/PackageReadme.md: -------------------------------------------------------------------------------- 1 | This package adds support for interactive use, like terminal or notebooks in VSC or Jupyter. 2 | 3 | References: 4 | [Website](https://am.angouri.org) · [Github](https://github.com/asc-community/AngouriMath) · [What's new](https://am.angouri.org/whatsnew/) · [Wiki](https://am.angouri.org/wiki/) · [Contacts](https://am.angouri.org/#contacts) 5 | -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.Interactive/Repack.ps1: -------------------------------------------------------------------------------- 1 | # clean up the previously-cached NuGet packages 2 | Remove-Item -Recurse ~\.nuget\packages\AngouriMath.Interactive* -Force 3 | Remove-Item -Recurse ~\.nuget\packages\AngouriMath.FSharp* -Force 4 | 5 | # build AngouriMath.Interactive 6 | dotnet restore 7 | dotnet clean 8 | dotnet build -c Release 9 | dotnet pack -c Release -------------------------------------------------------------------------------- /Sources/Wrappers/AngouriMath.Interactive/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/Wrappers/AngouriMath.Interactive/icon.png -------------------------------------------------------------------------------- /Sources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asc-community/AngouriMath/726a3d8975c491edb3a1bfaaf3097f2d17456976/Sources/icon.png --------------------------------------------------------------------------------