Skip to content

Commit 763296b

Browse files
authored
Merge branch 'dev' into feature/simplification-rule
2 parents c15b667 + c32663a commit 763296b

File tree

211 files changed

+3520
-2460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+3520
-2460
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dotnet_diagnostic.CA1200.severity = warning
4646
dotnet_diagnostic.CA1303.severity = warning
4747
dotnet_diagnostic.CA1304.severity = warning
4848
dotnet_diagnostic.CA1305.severity = warning
49-
dotnet_diagnostic.CA1308.severity = warning
49+
dotnet_diagnostic.CA1308.severity = none
5050
dotnet_diagnostic.CA1310.severity = warning
5151
dotnet_diagnostic.CA1507.severity = warning
5252
dotnet_diagnostic.CA1508.severity = warning

.github/workflows/codeql.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "dev", master ]
6+
pull_request:
7+
branches: [ "dev", master ]
8+
schedule:
9+
- cron: '44 18 * * 3'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'csharp' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v2
33+
with:
34+
languages: ${{ matrix.language }}
35+
36+
- name: Setup .NET Core SDK
37+
uses: actions/[email protected]
38+
with:
39+
dotnet-version: "7.0.x"
40+
41+
- run: |
42+
dotnet restore xFunc.sln
43+
dotnet build -c Release xFunc.sln
44+
45+
- name: Perform CodeQL Analysis
46+
uses: github/codeql-action/analyze@v2
47+
with:
48+
category: "/language:${{matrix.language}}"

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"coverage.cobertura.xml": true,
1616
"xFunc": true,
1717
"desktop.ini": true
18-
}
19-
}
18+
},
19+
"dotnet.defaultSolution": "xFunc.sln"
20+
}

CI/azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323

2424
steps:
2525
- task: UseDotNet@2
26-
displayName: 'Install .NET 6'
26+
displayName: 'Install .NET 7'
2727
inputs:
2828
packageType: 'sdk'
29-
version: '6.0.x'
29+
version: '7.0.x'
3030

3131
- task: DotNetCoreCLI@2
3232
displayName: 'dotnet restore'
@@ -71,7 +71,7 @@ jobs:
7171

7272
- task: PublishPipelineArtifact@1
7373
inputs:
74-
path: xFunc.Maths/bin/Release/netstandard2.1
74+
path: xFunc.Maths/bin/Release/net6.0
7575
artifact: xFunc.Maths
7676

7777
- task: PublishPipelineArtifact@1

Directory.Packages.props

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project>
2+
<ItemGroup>
3+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
4+
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.5.119" />
5+
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
6+
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
7+
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
8+
<PackageVersion Include="BenchmarkDotNet" Version="0.13.2" />
9+
10+
<PackageVersion Include="coverlet.msbuild" Version="3.2.0" />
11+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
12+
<PackageVersion Include="Moq" Version="4.18.3" />
13+
<PackageVersion Include="ReportGenerator" Version="5.1.12" />
14+
<PackageVersion Include="xunit" Version="2.4.2" />
15+
<PackageVersion Include="xunit.analyzers" Version="1.1.0" />
16+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
17+
</ItemGroup>
18+
</Project>

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Note: The WPF application (xFunc UI) was migrated to a separate repository [xFun
1919
* Derivative and simplifying expressions;
2020
* Plotting graphs;
2121
* Truth tables;
22-
* Supported Framework: .NET Standard 2.1+;
22+
* Supported Framework: .NET 6+;
2323

2424
## Usage
2525

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

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

5454
**Solve:**
5555

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

58-
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`).
58+
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`).
5959

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

74-
// or explicitly throught Parameters property
74+
// or explicitly through Parameters property
7575
7676
processor.Parameters.Variables.Add("x", 10);
7777
```
7878

79-
_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._
79+
_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._
8080

8181
**Simplify:**
8282

@@ -102,7 +102,7 @@ processor.Differentiate("2x");
102102
// will return "2"
103103
```
104104

105-
You can specified variable (default is "x") of differentiation:
105+
You can specify variable (default is "x") of differentiation:
106106

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

115115
### Processor
116116

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

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

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

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

138-
[Fluent.Ribbon](https://github.com/fluentribbon/Fluent.Ribbon)
139140
[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)
140141
[Coverlet](https://github.com/coverlet-coverage/coverlet)
141142
[ReportGenerator](https://github.com/danielpalme/ReportGenerator)

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "4.1.0",
3+
"version": "4.2.0-preview.{height}",
44
"assemblyVersion": {
55
"precision": "revision"
66
},

xFunc Grammar.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// It's just a reference grammar for xFunc (The implementaion is not completely equal to grammar).
22

3-
statement = unaryAssign
4-
/ binaryAssign
5-
/ assign
3+
statement = assign
64
/ def
75
/ undef
86
/ if
@@ -26,7 +24,7 @@ binaryAssign = variable ('+=' / '-=' / '*=' / '/=' / '<<=' / '>>=') exp
2624
ternary = conditional ('?' exp ':' exp)*
2725

2826
conditional = bitwise (('&&' / '||') bitwise)*
29-
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / '=>' / '->' / 'impl' / '<=>' / '<->' / 'eq' / 'nor' / 'nand') equality)*
27+
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / 'impl' / 'eq' / 'nor' / 'nand') equality)*
3028
equality = shift (('==' / '!=' / '<' / '<=' / '>' / '>=') shift)*
3129
shift = addSub (('<<' / '>>') addSub)*
3230
addSub = mulDivMod (('+' / '-') mulDivMod)*
@@ -48,6 +46,8 @@ operand = complexnumber /
4846
variable /
4947
boolean /
5048
bracketExp /
49+
callExp /
50+
lambda /
5151
matrix /
5252
vector
5353

@@ -70,4 +70,7 @@ parameters = (statement (',' statement)*)*
7070
vector = ('{' / '(') parameters ('}' / ')')
7171
matrix = ('{' / '(') vector (',' vector) ('}' / ')')
7272

73-
functionDeclaration = id '(' (variable (',' variable)* / '') ')'
73+
functionDeclaration = id '(' (variable (',' variable)* / '') ')'
74+
75+
lambda = '(' (id (',' id) / '') ')' '=>' exp
76+
callExp = '(' lambda ')' '(' parameters ')'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using xFunc.Maths.Expressions.Units.AngleUnits;
5+
using xFunc.Maths.Expressions.Units.AreaUnits;
6+
using xFunc.Maths.Expressions.Units.Converters;
7+
using xFunc.Maths.Expressions.Units.LengthUnits;
8+
using xFunc.Maths.Expressions.Units.MassUnits;
9+
using xFunc.Maths.Expressions.Units.PowerUnits;
10+
using xFunc.Maths.Expressions.Units.TemperatureUnits;
11+
using xFunc.Maths.Expressions.Units.TimeUnits;
12+
using xFunc.Maths.Expressions.Units.VolumeUnits;
13+
14+
namespace xFunc.Benchmark.Benchmarks;
15+
16+
public class ConvertBenchmark
17+
{
18+
private static IConverter converter = new Converter();
19+
20+
[Benchmark]
21+
public object AngleConvert()
22+
=> converter.Convert(AngleValue.Gradian(90), "deg");
23+
24+
[Benchmark]
25+
public object PowerConvert()
26+
=> converter.Convert(PowerValue.Kilowatt(1), "hp");
27+
28+
[Benchmark]
29+
public object TemperatureConvert()
30+
=> converter.Convert(TemperatureValue.Kelvin(1), "°F");
31+
32+
[Benchmark]
33+
public object MassConvert()
34+
=> converter.Convert(MassValue.Kilogram(1), "lb");
35+
36+
[Benchmark]
37+
public object AreaConvert()
38+
=> converter.Convert(AreaValue.Kilometer(1), "in^2");
39+
40+
[Benchmark]
41+
public object LengthConvert()
42+
=> converter.Convert(LengthValue.Kilometer(1), "in");
43+
44+
[Benchmark]
45+
public object TimeConvert()
46+
=> converter.Convert(TimeValue.Hour(1), "min");
47+
48+
[Benchmark]
49+
public object VolumeConvert()
50+
=> converter.Convert(VolumeValue.Gallon(1), "in^3");
51+
}

xFunc.Benchmark/Benchmarks/ProcessorBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void Setup()
1515

1616
[Benchmark]
1717
public IExpression Parse()
18-
=> 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)");
18+
=> 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)");
1919

2020
[Benchmark]
2121
public NumberResult Solve()

0 commit comments

Comments
 (0)