{"id":18303086,"url":"https://github.com/b1z0n/derivas","last_synced_at":"2025-04-09T10:14:15.620Z","repository":{"id":56561912,"uuid":"279801823","full_name":"B1Z0N/derivas","owner":"B1Z0N","description":"Library for analytical calculation of mathematical expressions ","archived":false,"fork":false,"pushed_at":"2023-09-09T01:56:22.000Z","size":142,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T04:26:00.247Z","etag":null,"topics":["csharp","derivative","expressions","inheritance","oop","pet-project"],"latest_commit_sha":null,"homepage":"https://b1z0n.github.io/derivas/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/B1Z0N.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-15T07:46:30.000Z","updated_at":"2022-02-15T13:54:06.000Z","dependencies_parsed_at":"2024-12-23T02:42:33.610Z","dependency_job_id":"4c36e998-5707-4b2c-a985-5f8ce393936a","html_url":"https://github.com/B1Z0N/derivas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B1Z0N%2Fderivas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B1Z0N%2Fderivas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B1Z0N%2Fderivas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B1Z0N%2Fderivas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/B1Z0N","download_url":"https://codeload.github.com/B1Z0N/derivas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018070,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","derivative","expressions","inheritance","oop","pet-project"],"created_at":"2024-11-05T15:24:05.676Z","updated_at":"2025-04-09T10:14:15.602Z","avatar_url":"https://github.com/B1Z0N.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nLibrary for analytical calculation of mathematical expressions. \nСurrently derivative and simplifiers are supported.\n\nP.S. this is just my project to learn some C# basics, so take it easy\n\n# Notes\n\n1. **For all of this to work you need to prepend each piece with**\n    ```csharp\n    using static Derivas.Expression.DvOps;\n    ```\n    But you may use it as you want in your real code.\n    \n2. Most of the methods accept `object` as it's argument, but\n    this means that you can pass in numeric type(shortcut for a `Const`) or\n    string(for a `Sym`) and `IDvExpr`. This was done to prevent writing this:\n    ```csharp\n    Add(Const(3), Sym(\"x\"), Pow(Const(5), Const(3))\n    ```\n    And transform it to \n    \n    ```csharp\n    Add(3, \"x\", Pow(5, 3))\n    ```\n    \n# Table of contents\n\n- [About](#about)\n- [Notes](#notes)\n- [Table of contents](#table-of-contents)\n- [How to run](#how-to-run)\n- [Example](#example)\n- [Entities](#entities)\n    + [`IDvExpr`](#idvexpr)\n    + [`IDvSimplifier`](#idvsimplifier)\n      - [ByConst](#byconst)\n      - [ByPolynom](#bypolynom)\n      - [ByPartial](#bypartial)\n      - [ByCustom](#bycustom)\n- [Expressions reference](#expressions-reference)\n    + [CommutativeAssocitaiveOperator](#commutativeassocitaiveoperator)\n    + [BinaryOperator](#binaryoperator)\n    + [UnaryOperator](#unaryoperator)\n    + [Others](#others)\n- [Exceptions](#exceptions)\n- [Utility](#utility)\n    + [Dict](#dict)\n    + [Constants](#constants)\n\n# How to run\n\nOpen sln in visual studio/rider/... or from the command line:\n\n```\ndotnet build Derivas # to build from cli\ndotnet test Derivas.Tests # to test\n```\n\n# Example\n\n```csharp\nusing static Derivas.Expression.DvOps;\n\nnamespace Usage\n{\n    internal class Program\n    {\n        private static void Main(string[] args)\n        {\n            var finExpr = Add(Pow(Sin(\"x\"), 2), Pow(Cos(\"x\"), 2));\n            var finDict = new Dictionary\u003cstring, double\u003e() \n            { \n                { \"x\", Math.PI }, { \"y\", 1 }\n            };\n            Print(finExpr, finDict);\n            // sin(x) ^ 2 + cos(x) ^ 2\n            // 1\n            var derived = Der(finExpr, \"x\");\n            Print(derived, finDict);\n            // 2 * sin(x) * cos(x) - 2 * cos(x) * sin(x)\n            // 0\n            \n            var simplified = Simpl(finExpr)\n                .ByCustom(Pow(Sin(\"x\"), 2), 3)\n                .Simplify();\n            Print(simplified, finDict);\n            // 3 + cos(x) ^ 2\n            // 4\n            \n            var parsedExpr = Parse(\"sin(x) ^ 2 + cos(x)^2\");\n            Print(parsedExpr, finDict);\n            // the same as the original\n        }\n\n        private static void Print(IDvExpr expr, Dictionary\u003cstring, double\u003e dict)\n        {\n            Console.WriteLine(expr.Represent());\n            Console.WriteLine(expr.Calculate(dict));\n        }\n    }\n}\n```\n\n# Entities\n\nThere are two main entities in Derivas: `Expression` and `Simplifier`, which implemented as interfaces: `IDvExpr` and `IDvSimplifier` accordingly.\n\n### `IDvExpr`\n\nUltimate base interface. Symbol, Constant, Operators implement it.\n\n```csharp\ninterface IDvExpr : IEquatable\u003cIDvExpr\u003e\n{\n    double Calculate(IDictionary\u003cstring, double\u003e concrete);\n    string Represent();\n}\n```\n\nGo to the full expressions reference [here](#expressions-reference).\n\n### `IDvSimplifier`\n\nSimplifier performs some kind of transformation, it has only one method:\n```csharp\nIDvExpr Simplify(IDvExpr expr)\n```\n\nIn external API you should use it like this: \n```csharp\nIDvExpr res = Simpl(/* IDvExpr */ expr)\n    .By...()\n    .By...()\n    .Simplify();\n```\nThere are 4 kinds of simplifiers:\n\n#### ByConst\n\nPartially reduce constants in operators:\n```csharp\nAdd(3, 5, 10) -\u003e Const(18)\nMul(3, 5, \"x\") -\u003e Add(8, \"x\")\n```\n\n#### ByPolynom\n\nCollect similar expressions in one scope:\n```csharp\nAdd(\"x\", \"x\", \"x\") -\u003e Mul(3, \"x\")\nAdd(\"x\", \"y\", \"x\") -\u003e Add(Mul(2, \"x\"), \"y\")\n```\n\n#### ByPartial\n\nPartially replace some symbols from the dictionary or by hand:\nThe `Dict` is explained [here](#utility)\n```csharp\nIDictionary\u003cstring, double\u003e d = Dict.Add(\"x\", 5).Add(\"y\", 3).Get();\nvar expr = Add(\"x\", Pow(2, \"y\"), \"z\");\nvar simplified = Simpl(expr).ByPartial(d).Simplify();\n// 5 + 2 ^ 3 + z\nvar orTheSame = Simpl(expr).ByPartial(\"x\", 5).ByPartial(\"y\", 3).Simplify();\n// 5 + 2 ^ 3 + z\n```\n\n#### ByCustom\n\nReplace one IDvExpr with another or use your own simplifiers:\n```csharp\nvar expr = Log(Mul(2, \"x\"), 3);\n\nvar replaced = Simpl(expr).ByCustom(3, DvConsts.E).Simplify();\nvar orTheSame = Simpl(expr)\n    .ByCustom(expr =\u003e Const(3).Equals(expr) ? DvConsts.E : expr)\n    .Simplify();\n```\n\n# Expressions reference\n\n### CommutativeAssocitaiveOperator\n\n* API: `Add`, `Mul`\n* Description: takes more than one argument, order doesn't matter\n* Example: `Add(3, 5, \"x\", Add(6, 3))`\n* Throws: `DvNotEnoughArguments`\n\n### BinaryOperator\n\n* API: `Sub`, `Div`, `Pow`\n* Description: takes only two arguments, order does matter\n* Example: `Div(Pow(1, 2), 0)`\n* Throws: **no Dv exceptions**\n\n### UnaryOperator\n\n* API:\n    1. `Cos`, `Sin`, `Tan`, `Cotan`\n    2. `Acos`, `Asin`, `Atan`, `Acotan`\n    3. `Cosh`, `Sinh`, `Tanh`, `Cotanh`\n* Description: takes one argument\n* Example: `Cos(Sin(DvConsts.PI)) // equals 1` \n* Throws: **no Dv exceptions**\n\n### Others\n\n* `Log` - acts just like `Math.Log`, takes two parameters and one is optional\n* `Der` - takes expression and symbol to take derivative on. \n\n# Exceptions\n\nAll exceptions are located in `Derivas.Exception` namespace.\n\n* `DvBaseException` - base exception class for the project\n\n* `DvSymbolMismatchException` - symbol value not supplied during calculation\n\n* `DvDerivativeMimatchException` - no derivative rule for this expression\n\n* `DvNotEnoughArguments` - the wrong number of arguments passed to the operator\n\n# Utility\n\nSome useful features to help you use the library.\n\n### Parse\n\nTakes string and returns it's `IDvExpr` equivalent. Temporarily not accepting numbers with exponent in them(like `1e-10`). \n\n### Dict\n\nYou will frequently need an `IDictionary\u003cstring, double\u003e` to pass into `Calculate` or other such methods. but it's very verbose to create new dictionary each time, so here you go, a shortcut:\n```csharp\ndouble res = expr.Calculate(Dict.Add(\"x\", 1).Add(\"y\", 3).Get());\n```\n\n### Constants\n\nCommon mathematical constants in `IDvExpr`(surrounded with `DvOps.Const`):\n* `DvOps.DvConsts.E`\n* `Dvops.DvConsts.PI`\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1z0n%2Fderivas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb1z0n%2Fderivas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1z0n%2Fderivas/lists"}