{"id":22517590,"url":"https://github.com/sys27/xfunc","last_synced_at":"2025-04-04T12:09:45.543Z","repository":{"id":6102341,"uuid":"7329748","full_name":"sys27/xFunc","owner":"sys27","description":"xFunc provides a powerful parser and analyzer for mathematical expressions. It excels at calculating derivatives, simplifying expressions, and achieving high performance.","archived":false,"fork":false,"pushed_at":"2024-10-29T09:16:59.000Z","size":7121,"stargazers_count":57,"open_issues_count":19,"forks_count":6,"subscribers_count":8,"default_branch":"dev","last_synced_at":"2024-10-29T11:07:04.719Z","etag":null,"topics":["analyzer","c-sharp","complex-numbers","derivative","differentiation","dotnet","evaluate-expressions","expression","lexer","logic","math","math-parser","mathematics","parse","parser","simplification","units","units-of-measure"],"latest_commit_sha":null,"homepage":"https://sys27.github.io/xFunc/","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/sys27.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"DmytroKyshchenko"}},"created_at":"2012-12-26T17:18:14.000Z","updated_at":"2024-10-29T09:17:02.000Z","dependencies_parsed_at":"2023-09-29T14:09:14.955Z","dependency_job_id":"2c995f5b-dc55-4849-9f8b-836f7dd959eb","html_url":"https://github.com/sys27/xFunc","commit_stats":{"total_commits":1528,"total_committers":3,"mean_commits":509.3333333333333,"dds":0.05890052356020947,"last_synced_commit":"2d924a939445ae4c6c4193a475fcee6d826def50"},"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys27%2FxFunc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys27%2FxFunc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys27%2FxFunc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys27%2FxFunc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sys27","download_url":"https://codeload.github.com/sys27/xFunc/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174454,"owners_count":20896078,"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":["analyzer","c-sharp","complex-numbers","derivative","differentiation","dotnet","evaluate-expressions","expression","lexer","logic","math","math-parser","mathematics","parse","parser","simplification","units","units-of-measure"],"created_at":"2024-12-07T04:09:59.659Z","updated_at":"2025-04-04T12:09:45.517Z","avatar_url":"https://github.com/sys27.png","language":"C#","funding_links":["https://patreon.com/DmytroKyshchenko"],"categories":[],"sub_categories":[],"readme":"Master: [![Build Status](https://dev.azure.com/exit/xFunc/_apis/build/status/sys27.xFunc?branchName=master)](https://exit.visualstudio.com/xFunc/_build/latest?definitionId=4\u0026branchName=master) [![codecov](https://codecov.io/gh/sys27/xFunc/branch/master/graph/badge.svg)](https://codecov.io/gh/sys27/xFunc)  \nDev: [![Build Status](https://dev.azure.com/exit/xFunc/_apis/build/status/sys27.xFunc?branchName=dev)](https://exit.visualstudio.com/xFunc/_build/latest?definitionId=4\u0026branchName=dev) [![codecov](https://codecov.io/gh/sys27/xFunc/branch/dev/graph/badge.svg)](https://codecov.io/gh/sys27/xFunc)  \nxFunc.Maths: [![NuGet](https://img.shields.io/nuget/v/xFunc.Maths.svg)](https://www.nuget.org/packages/xFunc.Maths) [![Downloads](https://img.shields.io/nuget/dt/xFunc.Maths.svg)](https://www.nuget.org/packages/xFunc.Maths)  \nxFunc.Cli: [![NuGet](https://img.shields.io/nuget/v/xFunc.Cli.svg)](https://www.nuget.org/packages/xFunc.Cli)\n\nxFunc\n=====\n\nxFunc is a user-friendly C# library for constructing and manipulating mathematical and logical expressions. This lightweight library empowers developers to effortlessly parse strings into expression trees, analyze expressions (including derivatives and simplifications), and perform various mathematical operations.\n\nxFunc is a versatile tool suitable for both educators and students, allowing the creation of complex mathematical expressions.\n\nNote: The WPF application (xFunc UI) was migrated to a separate repository [xFunc.UI](https://github.com/sys27/xFunc.UI).\n\n## Features:\n\n* Evaluate expressions (see all [supported functions and operators](https://sys27.github.io/xFunc/articles/supported-functions-and-operations.html)):\n  * basic arithmetic operators: `+`, `-`, `*`, `/`, `^`, etc.\n  * trigonometric functions: `sin(x)`, `cos(x)`, `tan(x)`, etc.\n  * inverse trigonometric functions: `arcsin(x)`, `arccos(x)`, `arctan(x)`, etc.\n  * hyperbolic functions:`sinh(x)`, `cosh(x)`, `tanh(x)`, etc.\n  * inverse hyperbolic functions: `arsinh(x)`, `arcosh(x)`, `artanh(x)`, etc.\n  * complex numbers: `1 + 2i`, `im(x)`, `re(x)`, etc.\n  * vector/matrix: `{1, 2, 3}`, `{{1, 2}, {3, 4}}`, etc.\n  * statistical: `sum(a, b, c)`, `avg(a, b, c)`, etc.\n  * bitwise operators: `x or y`, `x and y`, etc.\n  * units: `90 'deg'` - angles, `10 'm'` - length, `10 'min'` - time, etc.\n  * lambdas: `f := (x) =\u003e x ^ 2`, `((x) =\u003e x ^ 2)(3)`, `curry(f)`, etc.\n* Derivative calculation; \n* Simplify expressions ([simplification rules](https://sys27.github.io/xFunc/articles/simplification-rules.html));\n* Supported Framework: .NET 6+;\n\n## Usage\n\nThe main class of xFunc library is `Processor`. Detailed documentation is located on [GitHub Pages](https://sys27.github.io/xFunc/articles/get-started.html).\n\n### Processor\n\nIt allows you to:\n\n**Parse:**\n\n```csharp\nvar processor = new Processor();\nvar exp = processor.Parse(\"2 + x\"); \n\n// 'exp' will contain the expression tree for later use\n// you can calculate it or process it by analyzers (Differentiator, Simplifier, etc.)\n\n// 'exp' has a parameter\n// we should provide a value for variable 'x'\nvar parameters = new ExpressionParameters\n{\n    { \"x\", 10 }\n};\nvar result = exp.Execute(parameters);\n\n// result will be equal to 12\n```\n\n_Note: The `Parse` method won't simplify the expression automatically, it will return the complete representation of provided string expression._\n\n**Solve:**\n\nThis method parses string expression (like the `Parse` method) and then calculates it (returns object which implements the `Result` abstract class).\n\n```csharp\nvar processor = new Processor();\nvar result = processor.Solve(\"2 + 2\");\n\nConsole.WriteLine(result); // 4.0\n```\n\nThe `result` variable will contain `4` (as `NumberResult` which is the implementation of the `Result` class). It is a hand-made implementation of the discriminated union. The `Result` class provides the abstraction (root class) for DU, whereas implementation for each possible return type is dedicated to the appropriate nested result class. Check documentation for more examples: [Result](https://sys27.github.io/xFunc/api/xFunc.Maths.Results.Result.html), [Processor](https://sys27.github.io/xFunc/api/xFunc.Maths.Processor.html).\n\nIf your expression has any parameter, you need to assign a value to it (otherwise xFunc will throw an exception), because `Processor` has a build-in collection of parameters and user functions, you don't need to use `ExpressionParameters` directly:\n\n```csharp\nprocessor.Solve(\"x := 10\");\n\n// or explicitly through Parameters property\n\nprocessor.Parameters.Variables.Add(\"x\", 10);\n```\n\n**Simplify:**\n\n```csharp\nvar processor = new Processor();\n\nprocessor.Solve(\"simplify((x) =\u003e arcsin(sin(x)))\");\n// or\nprocessor.Simplify(\"arcsin(sin(x))\");\n// will return simplified expression = \"x\"\n```\n\n**Differentiate:**\n\n```csharp\nvar processor = new Processor();\n\nprocessor.Solve(\"deriv((x) =\u003e 2x)\");\n// or\nprocessor.Differentiate(\"2x\");\n// will return \"2\"\n```\n\nYou can specify variable (default is \"x\") of differentiation:\n\n```csharp\nvar processor = new Processor();\nprocessor.Differentiate(\"2y\", Variable.Y); // will return \"2\"\nprocessor.Differentiate(\"2x + sin(y)\", new Variable(\"x\")); // will return \"2\"\n```\n\n## Performance\n\n### Processor\n\n| Version | Method |          Mean | Allocated |\n|--------:|--------|--------------:|----------:|\n|   3.7.3 | Parse  |   39,567.9 ns |   63736 B |\n|   4.3.0 | Parse  |  10,434.04 ns |    4848 B |\n|   3.7.3 | Solve  |   55,260.0 ns |   96920 B |\n|   4.3.0 | Solve  |  15,683.42 ns |    9552 B |\n\n[More details](https://sys27.github.io/xFunc/articles/performance-comparison.html)\n\n## License\n\nxFunc is released under MIT License.\n\n## Thanks\n\n[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)  \n[Coverlet](https://github.com/coverlet-coverage/coverlet)  \n[ReportGenerator](https://github.com/danielpalme/ReportGenerator)  \n[NUnit](https://github.com/nunit/nunit)  \n[NSubstitute](https://github.com/nsubstitute/NSubstitute)  \n[docfx](https://github.com/dotnet/docfx)  \n[BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsys27%2Fxfunc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsys27%2Fxfunc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsys27%2Fxfunc/lists"}