-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from HamletTanyavong/dev
Update documentation
- Loading branch information
Showing
13 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: HamletTanyavong | ||
patreon: HamletTanyavong |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1 align="center">Mathematics.NET</h1> | ||
|
||
<p align="center">Mathematics.NET is a C# class library that provides tools for solving mathematical problems.</p> | ||
|
||
[![GitHub](https://img.shields.io/github/license/HamletTanyavong/Mathematics.NET?style=flat-square&logo=github&labelColor=87cefa&color=ffd700)](https://github.com/HamletTanyavong/Mathematics.NET) | ||
[![GitHub Repo Stars](https://img.shields.io/github/stars/HamletTanyavong/Mathematics.NET?color=87cefa&style=flat-square&logo=github)](https://github.com/HamletTanyavong/Mathematics.NET/stargazers) | ||
[![NuGet](https://img.shields.io/nuget/v/Physics.NET.Mathematics?style=flat-square&logo=nuget)](https://www.nuget.org/packages/Physics.NET.Mathematics) | ||
[![NuGet](https://img.shields.io/nuget/dt/Physics.NET.Mathematics?style=flat-square&logo=nuget)](https://www.nuget.org/packages/Physics.NET.Mathematics) | ||
|
||
## Documentation | ||
|
||
Please visit the [documentation site](https://mathematics.hamlettanyavong.com) for detailed information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Numeric Types | ||
|
||
There are three numeric types that can be used to represent complex, real, and rational numbers in Mathematics.NET. | ||
|
||
All Mathematics.NET numbers implement the [IComplex<T, U>](https://mathematics.hamlettanyavong.com/api/Mathematics.NET.Core.IComplex-2.html) interface. Particularly useful is the fact that, unlike .NET runtime's [INumberBase\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/INumberBase.cs), `IComplex<T, U>` defines the `Conjugate` method; this is incredibly helpful in avoiding code duplication for calculations involving complex and real numbers. | ||
|
||
## Floating-Point Types | ||
|
||
Floating-point Mathematics.NET numbers may be backed any number that implements [IFloatingPointIee754\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPointIeee754.cs) and [IMinMaxValue\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/IMinMaxValue.cs), or more specifically, [float](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Single.cs), [double](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Double.cs), and [decimal](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Decimal.cs). | ||
|
||
### Complex Numbers | ||
|
||
To create a complex number, we choose a backing type, in this case `double`, and write | ||
```csharp | ||
Complex<double> z = new(3, 4); | ||
``` | ||
This represents the number $ z = 3+i4 $. We can also specify only one number to create a complex number with no imaginary part | ||
```csharp | ||
Complex<double> z = 3; | ||
``` | ||
which represents $ z = 3 $. | ||
|
||
### Real Numbers | ||
|
||
Likewise, to create a real number, write | ||
```csharp | ||
Real<double> z = 1; | ||
``` | ||
With real numbers, we can also get maximum and minimum values which will depend on the backing type. | ||
```csharp | ||
Console.WriteLine("Max value with float backing type: {0}", Real<float>.MaxValue); | ||
Console.WriteLine("Max value with double backing type: {0}", Real<double>.MaxValue); | ||
``` | ||
This will output `Max value with float backing type: 3.4028235E+38` | ||
and `Max value with double backing type: 1.7976931348623157E+308`. | ||
|
||
## Binary Types | ||
|
||
Rational numbers are the only Mathematics.NET type in this category. | ||
|
||
### Rational Numbers | ||
|
||
Rational numbers require two backing types, one that implements [IBinaryInteger\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/IBinaryInteger.cs) and one that implements both [IFloatingPointIee754\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPointIeee754.cs) and [IMinMaxValue\<T\>](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Numerics/IMinMaxValue.cs). | ||
|
||
With this information, we can create the following rational numbers: | ||
```csharp | ||
Rational<int, double> a = 2; | ||
Rational<byte, float> b = new(2, 3); | ||
Rational<BigInteger, double> c = new(3, 4); | ||
``` | ||
which represent $ a = 2 $, $ b = 2/3 $, and $ c = 3/4 $. | ||
|
||
The first type parameter indicates that the constructor only accepts values of that type. In these cases, `a` must be an int, `b` must be a byte, and `c` must be a BigInteger. The second parameter indicates the desired floating-point type with which we want to represent the rational number. We can get this value in two ways, e.g. | ||
```csharp | ||
Console.WriteLine(b.Value); | ||
Console.WriteLine((float)b); | ||
``` | ||
which will both output `0.6666667`. | ||
|
||
> [!CAUTION] | ||
> The floating-point representation of rational numbers may not be accurate in all cases. | ||
We can also convert a floating-point number into a rational number with an explicit cast | ||
```csharp | ||
Console.WriteLine((Rational<int, double>)3.14); | ||
``` | ||
> [!NOTE] | ||
> The conversion conversion is not guaranteed to create the "best" fraction; for instance, the value $ 0.3333333333333333 $ will not produce $ 1/3 $ but instead produce $ 8333333333333331 / 25000000000000000 $. | ||
Be aware that there are performance penalties with converting rationals to and from real numbers. An overflow exception will also be thrown if a value being converted cannot be represented by the target type. |
15 changes: 11 additions & 4 deletions
15
docs/articles/getstarted/installation.md → docs/articles/get_started/installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
# Installation | ||
|
||
Mathematics.NET is available to download from [nuget](https://www.nuget.org). | ||
Mathematics.NET is available to download from [nuget](https://www.nuget.org/packages/Physics.NET.Mathematics). | ||
|
||
## Polyglot Notebooks | ||
# [Package Reference](#tab/package-reference) | ||
|
||
To use Mathematics.NET in you project, add the following line to your .csproj file: | ||
```xml | ||
<PackageReference Include="Physics.NET.Mathematics" Version="" /> | ||
``` | ||
|
||
# [Polyglot Notebooks](#tab/polyglot-notebooks) | ||
|
||
Please have [Visual Studio Code](https://code.visualstudio.com/) installed as well as the [Polyglot Notebooks](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) extension installed to begin using Mathematics.NET. When that is complete, create a new .ipynb file and add the following line to import the package: | ||
```csharp | ||
#r "nuget: Mathematics.NET" | ||
#r "nuget: Physics.NET.Mathematics" | ||
``` | ||
To get a specific version of Mathematics.NET, use, for example, | ||
```csharp | ||
#r "nuget: Mathematics.NET, 1.0.0" | ||
#r "nuget: Physics.NET.Mathematics, 0.1.0-alpha.1" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// <copyright file="Extensions.cs" company="Mathematics.NET"> | ||
// Mathematics.NET | ||
// https://github.com/HamletTanyavong/Mathematics.NET | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2023 Hamlet Tanyavong | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// </copyright> | ||
|
||
using System.Numerics; | ||
|
||
namespace Mathematics.NET.Core; | ||
|
||
public static class Extensions | ||
{ | ||
public static Rational<T, U> Reduce<T, U>(this Rational<T, U> r) | ||
where T : IBinaryInteger<T> | ||
where U : IFloatingPointIeee754<U>, IMinMaxValue<U> | ||
=> Rational<T, U>.Reduce(r); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters