Skip to content

Commit

Permalink
Merge branch 'dev' into feature/simplification-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 authored Jun 24, 2023
2 parents c15b667 + c32663a commit 763296b
Show file tree
Hide file tree
Showing 211 changed files with 3,520 additions and 2,460 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dotnet_diagnostic.CA1200.severity = warning
dotnet_diagnostic.CA1303.severity = warning
dotnet_diagnostic.CA1304.severity = warning
dotnet_diagnostic.CA1305.severity = warning
dotnet_diagnostic.CA1308.severity = warning
dotnet_diagnostic.CA1308.severity = none
dotnet_diagnostic.CA1310.severity = warning
dotnet_diagnostic.CA1507.severity = warning
dotnet_diagnostic.CA1508.severity = warning
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "CodeQL"

on:
push:
branches: [ "dev", master ]
pull_request:
branches: [ "dev", master ]
schedule:
- cron: '44 18 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: "7.0.x"

- run: |
dotnet restore xFunc.sln
dotnet build -c Release xFunc.sln
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"coverage.cobertura.xml": true,
"xFunc": true,
"desktop.ini": true
}
}
},
"dotnet.defaultSolution": "xFunc.sln"
}
6 changes: 3 additions & 3 deletions CI/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:

steps:
- task: UseDotNet@2
displayName: 'Install .NET 6'
displayName: 'Install .NET 7'
inputs:
packageType: 'sdk'
version: '6.0.x'
version: '7.0.x'

- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:

- task: PublishPipelineArtifact@1
inputs:
path: xFunc.Maths/bin/Release/netstandard2.1
path: xFunc.Maths/bin/Release/net6.0
artifact: xFunc.Maths

- task: PublishPipelineArtifact@1
Expand Down
18 changes: 18 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.5.119" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.2" />

<PackageVersion Include="coverlet.msbuild" Version="3.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageVersion Include="Moq" Version="4.18.3" />
<PackageVersion Include="ReportGenerator" Version="5.1.12" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.analyzers" Version="1.1.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>
</Project>
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Note: The WPF application (xFunc UI) was migrated to a separate repository [xFun
* Derivative and simplifying expressions;
* Plotting graphs;
* Truth tables;
* Supported Framework: .NET Standard 2.1+;
* Supported Framework: .NET 6+;

## Usage

Expand All @@ -39,7 +39,7 @@ var exp = processor.Parse("2 + x");
// you can calculate it or process it by analyzers (Differentiator, Simplifier, etc.)
// 'exp' has a parameter
// we should provide a value for varible 'x'
// we should provide a value for variable 'x'
var parameters = new ParameterCollection
{
{ "x", 10 }
Expand All @@ -49,13 +49,13 @@ var result = exp.Execute(parameters);
// result will be equal to 12
```

_Note: The `Parse` method won't simplify expression automatically, it will return the complete representation of provided string expression._
_Note: The `Parse` method won't simplify the expression automatically, it will return the complete representation of provided string expression._

**Solve:**

This method parses string expression (like `Parse` method) and then calculates it (returns object which implements `IResult` interface).
This method parses string expression (like the `Parse` method) and then calculates it (returns object which implements the `IResult` interface).

There is two overloads of this method (common and generic). The common returns just `IResult` (you can access result by `Result` property). The generic allows to return specific implementation of `IResult` (eg. `NumberResult`).
There are two overloads of this method (common and generic). The "common" returns just `IResult` (you can access result by `Result` property). The generic allows to return specific implementation of `IResult` (eg. `NumberResult`).

```csharp
var processor = new Processor();
Expand All @@ -71,12 +71,12 @@ If your expression has any parameter, you need to assign a value to it (otherwis
```csharp
processor.Solve("x := 10");

// or explicitly throught Parameters property
// or explicitly through Parameters property
processor.Parameters.Variables.Add("x", 10);
```

_Note: The `Solve` method automatically simplifies expression, to control this behavior you can use `simplify` argument. It's useful for differentiation, because it will eliminate unnecessary expression nodes._
_Note: The `Solve` method automatically simplifies expression, to control this behavior you can use the `simplify` argument. It's useful for differentiation because it will eliminate unnecessary expression nodes._

**Simplify:**

Expand All @@ -102,7 +102,7 @@ processor.Differentiate("2x");
// will return "2"
```

You can specified variable (default is "x") of differentiation:
You can specify variable (default is "x") of differentiation:

```csharp
var processor = new Processor();
Expand All @@ -114,12 +114,14 @@ processor.Differentiate("2x + sin(y)", new Variable("x")); // will return "2"

### Processor

Version | Method | Mean | Allocated |
-------:|------- |-----------------:|------------:|
3.7.3 | Parse | 166,581.4 ns | 63770 B |
4.0.0 | Parse | **24,604.93 ns** | **4760 B** |
3.7.3 | Solve | 232,498.0 ns | 96952 B |
4.0.0 | Solve | **39,971.82 ns** | **10673 B** |
| Version | Method | Mean | Allocated |
| ------: | ------ | ------------: | --------: |
| 3.7.3 | Parse | 39,567.9 ns | 63736 B |
| 4.0.0 | Parse | 9,128.180 ns | 4760 B |
| 4.2.0 | Parse | 14,574.60 ns | 4760 B |
| 3.7.3 | Solve | 55,260.0 ns | 96920 B |
| 4.0.0 | Solve | 15,319.497 ns | 10672 B |
| 4.2.0 | Solve | 24,909.03 ns | 10672 B |

[More details](https://github.com/sys27/xFunc/wiki/Performance-Comparison)

Expand All @@ -135,7 +137,6 @@ xFunc is released under MIT License.

[@RonnyCSHARP](https://github.com/ronnycsharp)

[Fluent.Ribbon](https://github.com/fluentribbon/Fluent.Ribbon)
[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)
[Coverlet](https://github.com/coverlet-coverage/coverlet)
[ReportGenerator](https://github.com/danielpalme/ReportGenerator)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "4.1.0",
"version": "4.2.0-preview.{height}",
"assemblyVersion": {
"precision": "revision"
},
Expand Down
13 changes: 8 additions & 5 deletions xFunc Grammar.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// It's just a reference grammar for xFunc (The implementaion is not completely equal to grammar).

statement = unaryAssign
/ binaryAssign
/ assign
statement = assign
/ def
/ undef
/ if
Expand All @@ -26,7 +24,7 @@ binaryAssign = variable ('+=' / '-=' / '*=' / '/=' / '<<=' / '>>=') exp
ternary = conditional ('?' exp ':' exp)*

conditional = bitwise (('&&' / '||') bitwise)*
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / '=>' / '->' / 'impl' / '<=>' / '<->' / 'eq' / 'nor' / 'nand') equality)*
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / 'impl' / 'eq' / 'nor' / 'nand') equality)*
equality = shift (('==' / '!=' / '<' / '<=' / '>' / '>=') shift)*
shift = addSub (('<<' / '>>') addSub)*
addSub = mulDivMod (('+' / '-') mulDivMod)*
Expand All @@ -48,6 +46,8 @@ operand = complexnumber /
variable /
boolean /
bracketExp /
callExp /
lambda /
matrix /
vector

Expand All @@ -70,4 +70,7 @@ parameters = (statement (',' statement)*)*
vector = ('{' / '(') parameters ('}' / ')')
matrix = ('{' / '(') vector (',' vector) ('}' / ')')

functionDeclaration = id '(' (variable (',' variable)* / '') ')'
functionDeclaration = id '(' (variable (',' variable)* / '') ')'

lambda = '(' (id (',' id) / '') ')' '=>' exp
callExp = '(' lambda ')' '(' parameters ')'
51 changes: 51 additions & 0 deletions xFunc.Benchmark/Benchmarks/ConvertBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using xFunc.Maths.Expressions.Units.AngleUnits;
using xFunc.Maths.Expressions.Units.AreaUnits;
using xFunc.Maths.Expressions.Units.Converters;
using xFunc.Maths.Expressions.Units.LengthUnits;
using xFunc.Maths.Expressions.Units.MassUnits;
using xFunc.Maths.Expressions.Units.PowerUnits;
using xFunc.Maths.Expressions.Units.TemperatureUnits;
using xFunc.Maths.Expressions.Units.TimeUnits;
using xFunc.Maths.Expressions.Units.VolumeUnits;

namespace xFunc.Benchmark.Benchmarks;

public class ConvertBenchmark
{
private static IConverter converter = new Converter();

[Benchmark]
public object AngleConvert()
=> converter.Convert(AngleValue.Gradian(90), "deg");

[Benchmark]
public object PowerConvert()
=> converter.Convert(PowerValue.Kilowatt(1), "hp");

[Benchmark]
public object TemperatureConvert()
=> converter.Convert(TemperatureValue.Kelvin(1), "°F");

[Benchmark]
public object MassConvert()
=> converter.Convert(MassValue.Kilogram(1), "lb");

[Benchmark]
public object AreaConvert()
=> converter.Convert(AreaValue.Kilometer(1), "in^2");

[Benchmark]
public object LengthConvert()
=> converter.Convert(LengthValue.Kilometer(1), "in");

[Benchmark]
public object TimeConvert()
=> converter.Convert(TimeValue.Hour(1), "min");

[Benchmark]
public object VolumeConvert()
=> converter.Convert(VolumeValue.Gallon(1), "in^3");
}
2 changes: 1 addition & 1 deletion xFunc.Benchmark/Benchmarks/ProcessorBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Setup()

[Benchmark]
public IExpression Parse()
=> processor.Parse("(100.1 + 2(3sin(4cos(5tan(6ctg(10x)))) * 3) / (func(a, b, c) ^ 2)) - (cos(y) - 111.3) & (true | false -> true <-> false eq true) + (det({{1, 2}, {3, 4}}) * 10log(2, 3)) + re(3 + 2i) - im(2 - 9i) + (9 + 2i)");
=> processor.Parse("(100.1 + 2(3sin(4cos(5tan(6ctg(10x)))) * 3) / (func(a, b, c) ^ 2)) - (cos(y) - 111.3) & (true | false impl true eq false) + (det({{1, 2}, {3, 4}}) * 10log(2, 3)) + re(3 + 2i) - im(2 - 9i) + (9 + 2i)");

[Benchmark]
public NumberResult Solve()
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Main(string[] args)
.Run(args,
ManualConfig.Create(DefaultConfig.Instance)
.AddJob(Job.MediumRun
.WithToolchain(CsProjCoreToolchain.NetCoreApp60))
.WithToolchain(CsProjCoreToolchain.NetCoreApp70))
.AddDiagnoser(MemoryDiagnoser.Default)
.StopOnFirstError());
}
Expand Down
5 changes: 3 additions & 2 deletions xFunc.Benchmark/xFunc.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions xFunc.DotnetTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using xFunc.DotnetTool.Options;
using xFunc.Maths.Expressions.Parameters;

namespace xFunc.DotnetTool;

Expand Down
Loading

0 comments on commit 763296b

Please sign in to comment.