[Open source, .NET, C#, Математика, F#] AngouriMath 1.3 update

Автор Сообщение
news_bot ®

Стаж: 6 лет 3 месяца
Сообщений: 27286

Создавать темы news_bot ® написал(а)
04-Июл-2021 16:31

What is it about?AngouriMath is a free open-source symbolic algebra library, written in and for .NET, that I've been working since the end of 2019. The previous major release happened on the second of March, I made an article about it too.Now, let me tell what we, together with contributors, did within these four months!
AngouriMath is made for C#, F#, Interactive, and to an extent, C++, so let me draw a distinction, what package affects what environment:C#F#InteractiveC++AngouriMath✓ ✓✓AngouriMath.FSharp✓✓AngouriMath.Interactive✓AngouriMath.CPP✓MatricesThis is the main change in terms of breaking API and behaviour. Now, instead of tensor, there's matrix, which is Entity.Matrix. There is also vector, but it doesn't have its own type. Instead, it's a single-column matrix. So for matrices there's only one type.The syntax for parsing is
Entity a = "[1, 2, 3]";
it becomes a vector of three elements.
Entity a = "[1, 2, 3]T"
becomes a transposed vector, that is, instead of column vector, it's a row vector. Here's how we create a 2x2 matrix:
Entity a = "[[1, 2], [3, 4]]"
[1, 2] is a row.The properties and functions of matrix:
Entity.Matrix m = ...
m.Adjugate   // null if it doesn't exist
m.AsScalar() // casts a 1x1 to scalar
m.Inverse    // null if it doesn't exist
m.Pow(int)   // finds a matrix power or throws
m.ReducedRowEchelonForm
See more at the docs.There are also improvements in AngouriMath.FSharp's matrices. All matrix-related functions moved to AngouriMath.FSharp.Matrices. Now there is a number of operators for matrices specifically all of which end with dot. For example,
a +. b
a -. b
a *. b
a /. b
a **. b // matrix power
a ***. b // tensor product
a ****. b // tensor power
Parser and LaTeXThe parser now supports Cyrillic and Greek letters, as well as it skips \n and \r letters, which might be helpful for building matrices.There's also now a setting MathS.Settings.ExplicitParsingOnly, which, when set to true, does not insert omitted operators, so while
Entity a = "2x + 3(x + 1)";
is fine when the setting is disabled, it won't be considered valid with the setting enabled.There is also MathS.Parse which returns an Either of Entity and reason why parsing failed. Either is an anonymous type union from Honk#, which I'll mention later. Example of code using it:
using AngouriMath;
using System;
var res = MathS.Parse("2x + 3")
    .Switch(
        valid => valid,
        failure => failure.Reason.Switch<Entity>(
                unknown => $"Unknown reason: {unknown.Reason}",
                missingOperator => $"Operator missed: {missingOperator.Details}",
                internalError => $"Internal error: {internalError.Details}"
        )
    );
Console.WriteLine(res);
Latexise now doesn't produce unneeded \times, and instead, \dot-s are only produced when needed (e. g. between variables). A few bugs in it fixed.New FunctionsMathS.Series.Maclaurin, MathS.Series.Taylor , MathS.Series.TaylorTerms are functions to generate Taylor expansion expressions. A lot of experimental API added for number theory. The final function is the symbolic form of sine and cosine based on existing analytical angles, for example, here's the precise value of sin(17/42 pi):
1/2 * ((sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) ^ 2 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) * sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) - 2 * sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) * sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) * sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2))) - -(2 * sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) * sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) * sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) + (sqrt(1 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) ^ 2 - sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2)) ^ 2) * sqrt(1/2 - 1/2 * sqrt(1 - sqrt(1 - (1/6 * (-1 + ((7 + 21 * sqrt(-3)) / 2) ^ (1/3) + ((7 - 21 * sqrt(-3)) / 2) ^ (1/3))) ^ 2) ^ 2))) * sqrt(3) / 2
All added functions: SymbolicFormOfSineSymbolicFormOfCosineExpandSineOfSumExpandConsineOfSumExpandSineArgumentMultipliedExpandCosineArgumentMultipliedGetSineOfHalvedAngleGetCosineOfHalvedAngleDecomposeRationalGetSineOfHalvedAngle A few synonyms added for hyperbolic functions. All functions from AngouriMath.FSharp now get InnerSimplified applied (for instance, sqrt 4 will return 2 while MathS.Sqrt(4) will still return a power node).AngouriMath.Interactive now has a AggressiveOperators module, which overrides the default operators, such as +, -, *, /, **, <, >, >=, <=, =. It is not recommended to use it as a library, but might be useful for some small calculations, like I did it in the terminal.AngouriMath.CPP: wrapper for C++Now there's a native version of the library that can be consumed from unmanaged code. It is possible thanks to NativeAOT, new feature which allows to compile managed .NET assemblies into native code.It is currently in the experimental phase. You can try it by installing it following a short instruction. Very few functions are still exposed, so it can be barely used for now, but hope it will be developed further in the future.My Reddit postabout it.Using AngouriMath in your projectsNow, aside from netstandard2.0, it multitargets .NET Framework 4.7.2+ and netstandard2.1. The former allows to use the library in legacy projects more conveniently.Honk# now helps to maintain the project easier, but since it's shipped with AngouriMath now, it might be a good idea to try its syntax in some cases.ConclusionThere are a lot of minor features and fixes that are not very interesting to read about. Most of them and other updates are listed in the what's new page on the website.Thank you for your attention! Feel free to ask questions.References ThanksAside from myself, I want to thank these people for helping with the project:Contributors: Happypig375, ryynmapes, MomoDeve, TheSeems, KuhakuPixel, jaimeadf, yoshiask.Consultants: Happypig375, mednik.Sponsors: zyzhu.
===========
Источник:
habr.com
===========

Похожие новости: Теги для поиска: #_open_source, #_.net, #_c#, #_matematika (Математика), #_f#, #_angourimath, #_csharp, #_fsharp, #_math, #_update, #_open_source, #_.net, #_c#, #_matematika (
Математика
)
, #_f#
Профиль  ЛС 
Показать сообщения:     

Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете голосовать в опросах
Вы не можете прикреплять файлы к сообщениям
Вы не можете скачивать файлы

Текущее время: 10-Май 10:13
Часовой пояс: UTC + 5