From aceb9ba7b1b7551257a133ec9ee76161bb3b3a4f Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:29:49 -0500 Subject: [PATCH 01/22] Define and implement multiplicative identity --- .../LinearAlgebra/Abstractions/ISquareMatrix.cs | 3 +++ src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs | 4 +++- src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs | 3 +++ src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs index f9ee7dfd..09b7993b 100644 --- a/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs @@ -34,6 +34,9 @@ public interface ISquareMatrix where T : ITwoDimensionalArrayRepresentable where U : IComplex { + /// Gets the multiplicative identiy matrix + static abstract T Identity { get; } + /// Represents a value that is not a matrix /// This result will be returned when trying to invert a singular matrix static abstract T NaM { get; } diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs index 2e2b4af6..f5081066 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs @@ -39,6 +39,8 @@ public struct Matrix2x2 ISquareMatrix, T> where T : IComplex { + private static readonly Matrix2x2 s_identity = CreateDiagonal(T.One, T.One); + public const int Components = 4; public const int E1Components = 2; public const int E2Components = 2; @@ -67,6 +69,7 @@ public Matrix2x2(T e11, T e12, T e21, T e22) static int IArrayRepresentable.Components => Components; static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; + static Matrix2x2 ISquareMatrix, T>.Identity => s_identity; static Matrix2x2 ISquareMatrix, T>.NaM => NaM; // @@ -98,7 +101,6 @@ public Matrix2x2(T e11, T e12, T e21, T e22) } } - // // Operators // diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs index d6ad369d..c889b716 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs @@ -39,6 +39,8 @@ public struct Matrix3x3 ISquareMatrix, T> where T : IComplex { + private static readonly Matrix3x3 s_identity = CreateDiagonal(T.One, T.One, T.One); + public const int Components = 9; public const int E1Components = 3; public const int E2Components = 3; @@ -82,6 +84,7 @@ public Matrix3x3( static int IArrayRepresentable.Components => Components; static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; + static Matrix3x3 ISquareMatrix, T>.Identity => s_identity; static Matrix3x3 ISquareMatrix, T>.NaM => NaM; // diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs b/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs index 19ab2988..000b1723 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs @@ -41,6 +41,8 @@ public struct Matrix4x4 ISquareMatrix, T> where T : IComplex { + private static readonly Matrix4x4 s_identity = CreateDiagonal(T.One, T.One, T.One, T.One); + public const int Components = 16; public const int E1Components = 4; public const int E2Components = 4; @@ -101,6 +103,7 @@ public Matrix4x4( static int IArrayRepresentable.Components => Components; static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; + static Matrix4x4 ISquareMatrix, T>.Identity => s_identity; static Matrix4x4 ISquareMatrix, T>.NaM => NaM; // From cba95e9f292358d31a1cf96507154cf90eab1d46 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:39:58 -0500 Subject: [PATCH 02/22] Add attribute --- src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs | 2 ++ src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs index f5081066..0806f0f6 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs @@ -27,6 +27,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using Mathematics.NET.LinearAlgebra.Abstractions; @@ -34,6 +35,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a 2x2 matrix /// A type that implements +[StructLayout(LayoutKind.Sequential)] public struct Matrix2x2 : ITwoDimensionalArrayRepresentable, T>, ISquareMatrix, T> diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs index c889b716..67c9295b 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs @@ -27,6 +27,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using Mathematics.NET.LinearAlgebra.Abstractions; @@ -34,6 +35,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a 3x3 matrix /// A type that implements +[StructLayout(LayoutKind.Sequential)] public struct Matrix3x3 : ITwoDimensionalArrayRepresentable, T>, ISquareMatrix, T> From 06c3409e0725f59c7495621e47fabc87d37d5911 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 03:55:09 -0500 Subject: [PATCH 03/22] Create IVector interface - Update existing vectors to use this interface --- .../IOneDimensionalArrayRepresentable.cs | 13 ----- .../LinearAlgebra/Abstractions/IVector.cs | 51 +++++++++++++++++++ src/Mathematics.NET/LinearAlgebra/Vector2.cs | 2 +- src/Mathematics.NET/LinearAlgebra/Vector3.cs | 2 +- src/Mathematics.NET/LinearAlgebra/Vector4.cs | 2 +- 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/Mathematics.NET/LinearAlgebra/Abstractions/IVector.cs diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/IOneDimensionalArrayRepresentable.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/IOneDimensionalArrayRepresentable.cs index d066add1..3cb01227 100644 --- a/src/Mathematics.NET/LinearAlgebra/Abstractions/IOneDimensionalArrayRepresentable.cs +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/IOneDimensionalArrayRepresentable.cs @@ -25,7 +25,6 @@ // SOFTWARE. // -using Mathematics.NET.Core.Operations; using Mathematics.NET.Core.Relations; namespace Mathematics.NET.LinearAlgebra.Abstractions; @@ -35,10 +34,6 @@ namespace Mathematics.NET.LinearAlgebra.Abstractions; /// A type that implements public interface IOneDimensionalArrayRepresentable : IArrayRepresentable, - IAdditionOperation, - ISubtractionOperation, - IHadamardProductOperation, - IInnerProductOperation, IEqualityRelation, IFormattable where T : IOneDimensionalArrayRepresentable @@ -51,12 +46,4 @@ public interface IOneDimensionalArrayRepresentable /// An index /// The element at the index U this[int index] { get; set; } - - /// Compute the $ L^2 $-norm of the vector - /// The norm - Real Norm(); - - /// Normalize the vector - /// The normalized vector - T Normalize(); } diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/IVector.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/IVector.cs new file mode 100644 index 00000000..0de72b31 --- /dev/null +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/IVector.cs @@ -0,0 +1,51 @@ +// +// 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. +// + +using Mathematics.NET.Core.Operations; + +namespace Mathematics.NET.LinearAlgebra.Abstractions; + +/// Defines support for vectors +/// The type that implements the interface +/// A type that implements +public interface IVector + : IOneDimensionalArrayRepresentable, + IAdditionOperation, + ISubtractionOperation, + IHadamardProductOperation, + IInnerProductOperation + where T : IVector + where U : IComplex +{ + /// Compute the $ L^2 $-norm of the vector + /// The norm + Real Norm(); + + /// Normalize the vector + /// The normalized vector + T Normalize(); +} diff --git a/src/Mathematics.NET/LinearAlgebra/Vector2.cs b/src/Mathematics.NET/LinearAlgebra/Vector2.cs index 5885f51e..3bc2b5e3 100644 --- a/src/Mathematics.NET/LinearAlgebra/Vector2.cs +++ b/src/Mathematics.NET/LinearAlgebra/Vector2.cs @@ -36,7 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a vector with two components /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Vector2 : IOneDimensionalArrayRepresentable, T> +public struct Vector2 : IVector, T> where T : IComplex { /// The first element of the vector diff --git a/src/Mathematics.NET/LinearAlgebra/Vector3.cs b/src/Mathematics.NET/LinearAlgebra/Vector3.cs index 80693387..ec103a13 100644 --- a/src/Mathematics.NET/LinearAlgebra/Vector3.cs +++ b/src/Mathematics.NET/LinearAlgebra/Vector3.cs @@ -36,7 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a vector with three components /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Vector3 : IOneDimensionalArrayRepresentable, T> +public struct Vector3 : IVector, T> where T : IComplex { /// The first element of the vector diff --git a/src/Mathematics.NET/LinearAlgebra/Vector4.cs b/src/Mathematics.NET/LinearAlgebra/Vector4.cs index 6ec56da9..304ea0a4 100644 --- a/src/Mathematics.NET/LinearAlgebra/Vector4.cs +++ b/src/Mathematics.NET/LinearAlgebra/Vector4.cs @@ -36,7 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a vector with four components /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Vector4 : IOneDimensionalArrayRepresentable, T> +public struct Vector4 : IVector, T> where T : IComplex { /// The first element of the vector From dacd01577de5329ad093392b0c6f29cd22d49763 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 05:01:12 -0500 Subject: [PATCH 04/22] Create IMatrix and ISquareMatrix interfaces - Update existing matrices to use this interface --- .../LinearAlgebra/Abstractions/IMatrix.cs | 55 +++++++++++++++++++ .../Abstractions/ISquareMatrix.cs | 17 ++---- .../ITwoDimensionalArrayRepresentable.cs | 4 -- .../LinearAlgebra/Matrix2x2.cs | 6 +- .../LinearAlgebra/Matrix3x3.cs | 6 +- .../LinearAlgebra/Matrix4x4.cs | 6 +- 6 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 src/Mathematics.NET/LinearAlgebra/Abstractions/IMatrix.cs diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/IMatrix.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/IMatrix.cs new file mode 100644 index 00000000..db28e073 --- /dev/null +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/IMatrix.cs @@ -0,0 +1,55 @@ +// +// 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. +// + +using Mathematics.NET.Core.Operations; + +namespace Mathematics.NET.LinearAlgebra.Abstractions; + +/// Defines support for matrices +/// The type that implements the interface +/// A type that implements +public interface IMatrix + : ITwoDimensionalArrayRepresentable, + IAdditionOperation, + ISubtractionOperation, + IMultiplicationOperation + where T : IMatrix + where U : IComplex +{ + /// Represents a value that is not a matrix + /// This will be returned, for instance, when trying to invert a singular matrix + static abstract T NaM { get; } + + /// Check if a value is not a matrix + /// The value to check + /// if the value is not a matrix; otherwise, + static abstract bool IsNaM(T matrix); + + /// Compute the transpose of the matrix + /// The transpose + T Transpose(); +} diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs index 09b7993b..8d7705b7 100644 --- a/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs @@ -28,32 +28,23 @@ namespace Mathematics.NET.LinearAlgebra.Abstractions; /// Defines support for square matrices -/// A type that implements +/// A type that implements /// A type that implements -public interface ISquareMatrix - where T : ITwoDimensionalArrayRepresentable +public interface ISquareMatrix : IMatrix + where T : ISquareMatrix where U : IComplex { /// Gets the multiplicative identiy matrix static abstract T Identity { get; } - /// Represents a value that is not a matrix - /// This result will be returned when trying to invert a singular matrix - static abstract T NaM { get; } - /// Compute the determinant of the matrix /// The determinant U Determinant(); /// Compute the inverse of the matrix - /// The inverse if the matrix is invertible; otherwise, + /// The inverse if the matrix is invertible; otherwise, T Inverse(); - /// Check if a value is not a matrix - /// The value to check - /// if the value is not a matrix; otherwise, - static abstract bool IsNaM(T matrix); - /// Compute the trace of the matrix /// The trace U Trace(); diff --git a/src/Mathematics.NET/LinearAlgebra/Abstractions/ITwoDimensionalArrayRepresentable.cs b/src/Mathematics.NET/LinearAlgebra/Abstractions/ITwoDimensionalArrayRepresentable.cs index 176f41bc..641931cf 100644 --- a/src/Mathematics.NET/LinearAlgebra/Abstractions/ITwoDimensionalArrayRepresentable.cs +++ b/src/Mathematics.NET/LinearAlgebra/Abstractions/ITwoDimensionalArrayRepresentable.cs @@ -25,7 +25,6 @@ // SOFTWARE. // -using Mathematics.NET.Core.Operations; using Mathematics.NET.Core.Relations; namespace Mathematics.NET.LinearAlgebra.Abstractions; @@ -35,9 +34,6 @@ namespace Mathematics.NET.LinearAlgebra.Abstractions; /// A type that implements public interface ITwoDimensionalArrayRepresentable : IArrayRepresentable, - IAdditionOperation, - ISubtractionOperation, - IMultiplicationOperation, IEqualityRelation, IFormattable where T : ITwoDimensionalArrayRepresentable diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs index 0806f0f6..69904fdf 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix2x2.cs @@ -36,9 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a 2x2 matrix /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Matrix2x2 - : ITwoDimensionalArrayRepresentable, T>, - ISquareMatrix, T> +public struct Matrix2x2 : ISquareMatrix, T> where T : IComplex { private static readonly Matrix2x2 s_identity = CreateDiagonal(T.One, T.One); @@ -72,7 +70,7 @@ public Matrix2x2(T e11, T e12, T e21, T e22) static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; static Matrix2x2 ISquareMatrix, T>.Identity => s_identity; - static Matrix2x2 ISquareMatrix, T>.NaM => NaM; + static Matrix2x2 IMatrix, T>.NaM => NaM; // // Indexer diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs index 67c9295b..f82f4c38 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix3x3.cs @@ -36,9 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a 3x3 matrix /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Matrix3x3 - : ITwoDimensionalArrayRepresentable, T>, - ISquareMatrix, T> +public struct Matrix3x3 : ISquareMatrix, T> where T : IComplex { private static readonly Matrix3x3 s_identity = CreateDiagonal(T.One, T.One, T.One); @@ -87,7 +85,7 @@ public Matrix3x3( static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; static Matrix3x3 ISquareMatrix, T>.Identity => s_identity; - static Matrix3x3 ISquareMatrix, T>.NaM => NaM; + static Matrix3x3 IMatrix, T>.NaM => NaM; // // Indexer diff --git a/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs b/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs index 000b1723..7c51b2ce 100644 --- a/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs +++ b/src/Mathematics.NET/LinearAlgebra/Matrix4x4.cs @@ -36,9 +36,7 @@ namespace Mathematics.NET.LinearAlgebra; /// Represents a 4x4 matrix /// A type that implements [StructLayout(LayoutKind.Sequential)] -public struct Matrix4x4 - : ITwoDimensionalArrayRepresentable, T>, - ISquareMatrix, T> +public struct Matrix4x4 : ISquareMatrix, T> where T : IComplex { private static readonly Matrix4x4 s_identity = CreateDiagonal(T.One, T.One, T.One, T.One); @@ -104,7 +102,7 @@ public Matrix4x4( static int ITwoDimensionalArrayRepresentable, T>.E1Components => E1Components; static int ITwoDimensionalArrayRepresentable, T>.E2Components => E2Components; static Matrix4x4 ISquareMatrix, T>.Identity => s_identity; - static Matrix4x4 ISquareMatrix, T>.NaM => NaM; + static Matrix4x4 IMatrix, T>.NaM => NaM; // // Indexer From b7008cff5c95633c80d7b64928917163e7d14e9d Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:47:39 -0500 Subject: [PATCH 05/22] Create ISymbol.cs --- src/Mathematics.NET/Symbols/ISymbol.cs | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Mathematics.NET/Symbols/ISymbol.cs diff --git a/src/Mathematics.NET/Symbols/ISymbol.cs b/src/Mathematics.NET/Symbols/ISymbol.cs new file mode 100644 index 00000000..711e99b5 --- /dev/null +++ b/src/Mathematics.NET/Symbols/ISymbol.cs @@ -0,0 +1,37 @@ +// +// 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. +// + +namespace Mathematics.NET.Symbols; + +// TODO: Create source generator for symbols + +/// Defines support for mathematical symbols +public interface ISymbol +{ + /// Get a string representation of this symbol + static abstract string DisplayString { get; } +} From 2a7a55b8c8a3698db95dd057e8d2f5afa2bb1f52 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:47:48 -0500 Subject: [PATCH 06/22] Create Mu.cs --- src/Mathematics.NET/Symbols/Mu.cs | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Mathematics.NET/Symbols/Mu.cs diff --git a/src/Mathematics.NET/Symbols/Mu.cs b/src/Mathematics.NET/Symbols/Mu.cs new file mode 100644 index 00000000..dfdc4a93 --- /dev/null +++ b/src/Mathematics.NET/Symbols/Mu.cs @@ -0,0 +1,37 @@ +// +// 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. +// + +namespace Mathematics.NET.Symbols; + +/// Represents the Greek letter mu, $ \mu $ +public readonly struct Mu : ISymbol +{ + /// + public const string DisplayString = "mu"; + + static string ISymbol.DisplayString => DisplayString; +} From cf3ff30f69ee7c2a75f4c01c005a475768467789 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:50:58 -0500 Subject: [PATCH 07/22] Create Nu.cs --- src/Mathematics.NET/Symbols/Nu.cs | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Mathematics.NET/Symbols/Nu.cs diff --git a/src/Mathematics.NET/Symbols/Nu.cs b/src/Mathematics.NET/Symbols/Nu.cs new file mode 100644 index 00000000..1b07c960 --- /dev/null +++ b/src/Mathematics.NET/Symbols/Nu.cs @@ -0,0 +1,37 @@ +// +// 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. +// + +namespace Mathematics.NET.Symbols; + +/// Represents the Greek letter nu, $ \nu $ +public readonly struct Nu : ISymbol +{ + /// + public const string DisplayString = "nu"; + + static string ISymbol.DisplayString => DisplayString; +} From a6c5d909ed7c5b3546d1979be2ff50996edf85d5 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:51:08 -0500 Subject: [PATCH 08/22] Create IIndexPosition.cs --- .../Abstractions/IIndexPosition.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndexPosition.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndexPosition.cs b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndexPosition.cs new file mode 100644 index 00000000..f8b688e7 --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndexPosition.cs @@ -0,0 +1,35 @@ +// +// 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. +// + +namespace Mathematics.NET.DifferentialGeometry.Abstractions; + +/// Represents an index position +public interface IIndexPosition +{ + /// Get a string representation of the index position + static abstract string DisplayString { get; } +} From 4eeb27ae4303be7468b1da048bb3fc94599710db Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:51:14 -0500 Subject: [PATCH 09/22] Create Upper.cs --- .../DifferentialGeometry/Upper.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Upper.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Upper.cs b/src/Mathematics.NET/DifferentialGeometry/Upper.cs new file mode 100644 index 00000000..384ed853 --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Upper.cs @@ -0,0 +1,39 @@ +// +// 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. +// + +using Mathematics.NET.DifferentialGeometry.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents an upper index position +public readonly struct Upper : IIndexPosition +{ + /// + public const string DisplayString = "Upper"; + + static string IIndexPosition.DisplayString => DisplayString; +} From 084912d9a86089c2a6021bc85826fa43f9858f1a Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:53:16 -0500 Subject: [PATCH 10/22] Create Lower.cs --- .../DifferentialGeometry/Lower.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Lower.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Lower.cs b/src/Mathematics.NET/DifferentialGeometry/Lower.cs new file mode 100644 index 00000000..da4dbf8b --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Lower.cs @@ -0,0 +1,39 @@ +// +// 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. +// + +using Mathematics.NET.DifferentialGeometry.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents a lower index position +public readonly struct Lower : IIndexPosition +{ + /// + public const string DisplayString = "Lower"; + + static string IIndexPosition.DisplayString => DisplayString; +} From 919359a11a6cfca25238da1918e2554ae2ced1e0 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:53:23 -0500 Subject: [PATCH 11/22] Create IIndex.cs --- .../Abstractions/IIndex.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndex.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndex.cs b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndex.cs new file mode 100644 index 00000000..d089200c --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IIndex.cs @@ -0,0 +1,35 @@ +// +// 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. +// + +namespace Mathematics.NET.DifferentialGeometry.Abstractions; + +/// Defines support for tensor indices +public interface IIndex : IFormattable +{ + /// Gets an instance of this struct + static abstract IIndex Instance { get; } +} From 750f94486c3943736f7525dfeba74a36c9bf92b9 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:53:28 -0500 Subject: [PATCH 12/22] Create Index.cs --- .../DifferentialGeometry/Index.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Index.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Index.cs b/src/Mathematics.NET/DifferentialGeometry/Index.cs new file mode 100644 index 00000000..b8248c18 --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Index.cs @@ -0,0 +1,49 @@ +// +// 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. +// + +using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.Symbols; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents a tensor index +/// An index position +/// A symbol +public struct Index : IIndex + where T : IIndexPosition + where U : ISymbol +{ + public static IIndex Instance => new Index(); + + // + // Formatting + // + + public override string ToString() => ToString(null, null); + + public string ToString(string? format, IFormatProvider? provider) => $"{T.DisplayString} {U.DisplayString}"; +} From 11a333b060a72737486d720345a66eecb97d06fa Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:54:21 -0500 Subject: [PATCH 13/22] Create NoIndex.cs --- .../DifferentialGeometry/NoIndex.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/NoIndex.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/NoIndex.cs b/src/Mathematics.NET/DifferentialGeometry/NoIndex.cs new file mode 100644 index 00000000..f35d911c --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/NoIndex.cs @@ -0,0 +1,44 @@ +// +// 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. +// + +using Mathematics.NET.DifferentialGeometry.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Indicates that no specific index is specified +public struct NoIndex : IIndex +{ + public static IIndex Instance => new NoIndex(); + + // + // Formatting + // + + public override string ToString() => ToString(null, null); + + public string ToString(string? format, IFormatProvider? formatProvider) => "No index"; +} From a781d32afddfff74435783d10c646043c2da0278 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:54:53 -0500 Subject: [PATCH 14/22] Update MultiplyByScalarAction.cs - Add documentation comment --- .../Core/ParallelActions/MultiplyByScalarAction.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mathematics.NET/Core/ParallelActions/MultiplyByScalarAction.cs b/src/Mathematics.NET/Core/ParallelActions/MultiplyByScalarAction.cs index b0c7b9c7..ae4ddcf8 100644 --- a/src/Mathematics.NET/Core/ParallelActions/MultiplyByScalarAction.cs +++ b/src/Mathematics.NET/Core/ParallelActions/MultiplyByScalarAction.cs @@ -42,6 +42,8 @@ public MultiplyByScalarAction(T factor) _factor = factor; } + /// Executes the action on an item of type + /// The item [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Invoke(ref T item) => item *= _factor; } From aede0758740dddf577e952bd099140bd0827b31c Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:55:00 -0500 Subject: [PATCH 15/22] Create IRankOneTensor.cs --- .../Abstractions/IRankOneTensor.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankOneTensor.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankOneTensor.cs b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankOneTensor.cs new file mode 100644 index 00000000..2381d3a8 --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankOneTensor.cs @@ -0,0 +1,49 @@ +// +// 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. +// + +using Mathematics.NET.LinearAlgebra.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry.Abstractions; + +/// Defines support for rank-one tensors +/// The type that implements the interface +/// A backing type that implements +/// A type that implements +/// An index +public interface IRankOneTensor : IOneDimensionalArrayRepresentable + where T : IRankOneTensor + where U : IVector + where V : IComplex + where W : IIndex +{ + /// Get the index associated with this rank one tensor + IIndex Index { get; } + + /// Convert a value that implements to one of type + /// The value to convert + static abstract implicit operator T(U input); +} From 2e26a1b6be655b3916421802a2f9e4edc33c7d5e Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:55:20 -0500 Subject: [PATCH 16/22] Create IRankTwoTensor.cs --- .../DifferentialGeometry/RankOneTensor.cs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/RankOneTensor.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/RankOneTensor.cs b/src/Mathematics.NET/DifferentialGeometry/RankOneTensor.cs new file mode 100644 index 00000000..8fadac1f --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/RankOneTensor.cs @@ -0,0 +1,117 @@ +// +// 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. +// + +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using Mathematics.NET.Core.Operations; +using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.LinearAlgebra.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents a rank-one tensor +/// A backing type that implements +/// A type that implements +/// An index +[StructLayout(LayoutKind.Sequential)] +public struct RankOneTensor + : IRankOneTensor, T, U, V>, + IAdditionOperation, RankOneTensor>, + ISubtractionOperation, RankOneTensor> + where T : IVector + where U : IComplex + where V : IIndex +{ + private T _vector; + + public RankOneTensor(T vector) + { + _vector = vector; + } + + // + // IArrayRepresentable & relevant interfaces + // + + public static int Components => T.Components; + + public static int E1Components => T.E1Components; + + // + // IRankOneTensor interface + // + + public readonly IIndex Index => V.Instance; + + // + // Indexer + // + + public U this[int index] + { + get => _vector[index]; + set => _vector[index] = value; + } + + // + // Operators + // + + public static RankOneTensor operator +(RankOneTensor left, RankOneTensor right) + => new(left._vector + right._vector); + + public static RankOneTensor operator -(RankOneTensor left, RankOneTensor right) + => new(left._vector - right._vector); + + // + // Equality + // + + public static bool operator ==(RankOneTensor left, RankOneTensor right) + => left._vector == right._vector; + + public static bool operator !=(RankOneTensor left, RankOneTensor right) + => left._vector != right._vector; + + public override bool Equals([NotNullWhen(true)] object? obj) => obj is RankOneTensor other && Equals(other); + + public bool Equals(RankOneTensor value) => _vector.Equals(value._vector); + + public override int GetHashCode() => HashCode.Combine(_vector); + + // + // Formatting + // + + public string ToString(string? format, IFormatProvider? provider) => _vector.ToString(format, provider); + + // + // Implicit operators + // + + public static implicit operator RankOneTensor(T input) => new(input); +} From 39298558263378764a5d0a25a13d6abea6f73fb2 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:55:26 -0500 Subject: [PATCH 17/22] Create IRankTwoTensor.cs --- .../Abstractions/IRankTwoTensor.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankTwoTensor.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankTwoTensor.cs b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankTwoTensor.cs new file mode 100644 index 00000000..2f0dd76a --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/Abstractions/IRankTwoTensor.cs @@ -0,0 +1,51 @@ +// +// 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. +// + +using Mathematics.NET.LinearAlgebra.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry.Abstractions; + +/// Defines support for rank-two tensors +/// The type that implements the interface +/// A backing type that implements +/// A type that implements +/// An index +/// An index +public interface IRankTwoTensor : ITwoDimensionalArrayRepresentable + where T : IRankTwoTensor + where U : ISquareMatrix + where V : IComplex + where W : IIndex + where X : IIndex +{ + /// Get the indices associated with this rank two tensor + IIndex[] Indices { get; } + + /// Convert a value that implements to one of type + /// The value to convert + static abstract implicit operator T(U input); +} From 329fc05f8b7cfaa5cf01526fd37d519a5bd6f7a9 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:55:32 -0500 Subject: [PATCH 18/22] Create RankTwoTensor.cs --- .../DifferentialGeometry/RankTwoTensor.cs | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/RankTwoTensor.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/RankTwoTensor.cs b/src/Mathematics.NET/DifferentialGeometry/RankTwoTensor.cs new file mode 100644 index 00000000..5505ea7a --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/RankTwoTensor.cs @@ -0,0 +1,121 @@ +// +// 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. +// + +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using Mathematics.NET.Core.Operations; +using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.LinearAlgebra.Abstractions; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents a rank-two tensors +/// A backing type that implements +/// A type that implements +/// The first index +/// The second index +[StructLayout(LayoutKind.Sequential)] +public struct RankTwoTensor + : IRankTwoTensor, T, U, V, W>, + IAdditionOperation, RankTwoTensor>, + ISubtractionOperation, RankTwoTensor> + where T : ISquareMatrix + where U : IComplex + where V : IIndex + where W : IIndex +{ + private T _matrix; + + public RankTwoTensor(T matrix) + { + _matrix = matrix; + } + + // + // IRankTwoTensor interface + // + + public readonly IIndex[] Indices => new IIndex[2] { V.Instance, W.Instance }; + + // + // IArrayRepresentable & relevant interfaces + // + + public static int Components => T.Components; + + public static int E1Components => T.E1Components; + + public static int E2Components => T.E2Components; + + // + // Indexer + // + + public U this[int row, int column] + { + get => _matrix[row, column]; + set => _matrix[row, column] = value; + } + + // + // Operators + // + + public static RankTwoTensor operator +(RankTwoTensor left, RankTwoTensor right) + => left._matrix + right._matrix; + + public static RankTwoTensor operator -(RankTwoTensor left, RankTwoTensor right) + => left._matrix - right._matrix; + + // + // Equality + // + + public static bool operator ==(RankTwoTensor left, RankTwoTensor right) + => left._matrix == right._matrix; + + public static bool operator !=(RankTwoTensor left, RankTwoTensor right) + => left._matrix != right._matrix; + + public override bool Equals([NotNullWhen(true)] object? obj) => obj is RankTwoTensor other && Equals(other); + + public bool Equals(RankTwoTensor value) => _matrix.Equals(value._matrix); + + public override int GetHashCode() => HashCode.Combine(_matrix); + + // + // Formatting + // + + public string ToString(string? format, IFormatProvider? provider) => _matrix.ToString(format, provider); + + // + // Implicit operators + // + + public static implicit operator RankTwoTensor(T input) => new(input); +} From 7a91e159582357654cf9cf0649be779c7a504ba7 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 06:57:44 -0500 Subject: [PATCH 19/22] Create MetricTensor.cs --- .../DifferentialGeometry/MetricTensor.cs | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs new file mode 100644 index 00000000..50f65e78 --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs @@ -0,0 +1,127 @@ +// +// 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. +// + +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using Mathematics.NET.Core.Operations; +using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.LinearAlgebra.Abstractions; +using Mathematics.NET.Symbols; + +namespace Mathematics.NET.DifferentialGeometry; + +/// Represents a metric tensor +/// A backing type that implements +/// A type that implements +/// An index position +/// The first index +/// The second index +[StructLayout(LayoutKind.Sequential)] +public struct MetricTensor + : IRankTwoTensor, T, U, Index, Index>, + IAdditionOperation, RankTwoTensor, Index>>, + ISubtractionOperation, RankTwoTensor, Index>> + where T : ISquareMatrix + where U : IComplex + where V : IIndexPosition + where W : ISymbol + where X : ISymbol +{ + public static readonly MetricTensor Euclidean = T.Identity; + + private T _matrix; + + public MetricTensor(T matrix) + { + _matrix = matrix; + } + + // + // IRankTwoTensor interface + // + + public readonly IIndex[] Indices => new IIndex[2] { Index.Instance, Index.Instance }; + + // + // IArrayRepresentable & relevant interfaces + // + + public static int Components => T.Components; + + public static int E1Components => T.E1Components; + + public static int E2Components => T.E2Components; + + // + // Indexer + // + + public U this[int row, int column] + { + get => _matrix[row, column]; + set => _matrix[row, column] = value; + } + + // + // Operators + // + + public static RankTwoTensor, Index> operator +(MetricTensor left, MetricTensor right) + => left._matrix + right._matrix; + + public static RankTwoTensor, Index> operator -(MetricTensor left, MetricTensor right) + => left._matrix - right._matrix; + + // + // Equality + // + + public static bool operator ==(MetricTensor left, MetricTensor right) + => left._matrix == right._matrix; + + public static bool operator !=(MetricTensor left, MetricTensor right) + => left._matrix == right._matrix; + + public override bool Equals([NotNullWhen(true)] object? obj) => obj is MetricTensor other && Equals(other); + + public bool Equals(MetricTensor value) => _matrix.Equals(value._matrix); + + public override int GetHashCode() => HashCode.Combine(_matrix); + + // + // Formatting + // + + public string ToString(string? format, IFormatProvider? provider) => _matrix.ToString(format, provider); + + // + // Implicit operators + // + + public static implicit operator MetricTensor(T input) => new(input); +} + From c98d49983a87412ebc6d0d963bae98f5b7ffdb11 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 07:02:39 -0500 Subject: [PATCH 20/22] Create DifGeo.cs --- .../DifferentialGeometry/DifGeo.cs | 207 ++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 src/Mathematics.NET/DifferentialGeometry/DifGeo.cs diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs new file mode 100644 index 00000000..0698609c --- /dev/null +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -0,0 +1,207 @@ +// +// 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. +// + +using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.LinearAlgebra; +using Mathematics.NET.LinearAlgebra.Abstractions; +using Mathematics.NET.Symbols; + +namespace Mathematics.NET.DifferentialGeometry; + +/// A class containing differential geometry operations +public static class DifGeo +{ + /// Contract two rank-one tensors: $ a_\mu b^\mu $ + /// The backing type of the tensors + /// A type that implements + /// A symbol + /// A tensor with a lower index + /// A tensor with an upper index + /// A scalar + public static U Contract(RankOneTensor> a, RankOneTensor> b) + where T : IVector + where U : IComplex + where V : ISymbol + { + U result = U.Zero; + for (int i = 0; i < T.E1Components; i++) + { + result += a[i] * b[i]; + } + return result; + } + + /// Contract two rank-one tensors: $ a^\mu b_\mu $ + /// The backing type of the tensors + /// A type that implements + /// A symbol + /// A tensor with an upper index + /// A tensor with a lower index + /// A scalar + public static U Contract(RankOneTensor> a, RankOneTensor> b) + where T : IVector + where U : IComplex + where V : ISymbol + { + U result = U.Zero; + for (int i = 0; i < T.E1Components; i++) + { + result += a[i] * b[i]; + } + return result; + } + + /// Contract a metric tensor and a rank-one tensor: $ g_{\mu\nu}x^\nu $ + /// A type that implements + /// The first index + /// The second index + /// A metric tensor + /// A rank-one tensor + /// A rank-one tensor + public static RankOneTensor, T, Index> Contract( + MetricTensor, T, Lower, I1, I2> g, + RankOneTensor, T, Index> x) + where T : IComplex + where I1 : ISymbol + where I2 : ISymbol + { + Vector4 vector = new(); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + vector[i] += g[i, j] * x[j]; + } + } + return new(vector); + } + + /// Contract a metric tensor and a rank-one tensor: $ g_{\mu\nu}x^\mu $ + /// A type that implements + /// The first index + /// The second index + /// A metric tensor + /// A rank-one tensor + /// A rank-one tensor + public static RankOneTensor, T, Index> Contract( + MetricTensor, T, Lower, I1, I2> g, + RankOneTensor, T, Index> x) + where T : IComplex + where I1 : ISymbol + where I2 : ISymbol + { + Vector4 vector = new(); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + vector[i] += g[j, i] * x[j]; + } + } + return new(vector); + } + + /// Contract a metric tensor and a rank-one tensor: $ g^{\mu\nu}x_\nu $ + /// A type that implements + /// The first index + /// The second index + /// A metric tensor + /// A rank-one tensor + /// A rank-one tensor + public static RankOneTensor, T, Index> Contract( + MetricTensor, T, Upper, I1, I2> g, + RankOneTensor, T, Index> x) + where T : IComplex + where I1 : ISymbol + where I2 : ISymbol + { + Vector4 vector = new(); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + vector[i] += g[i, j] * x[j]; + } + } + return new(vector); + } + + /// Contract a metric tensor and a rank-one tensor: $ g^{\mu\nu}x_\mu $ + /// A type that implements + /// The first index + /// The second index + /// A metric tensor + /// A rank-one tensor + /// A rank-one tensor + public static RankOneTensor, T, Index> Contract( + MetricTensor, T, Upper, I1, I2> g, + RankOneTensor, T, Index> x) + where T : IComplex + where I1 : ISymbol + where I2 : ISymbol + { + Vector4 vector = new(); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + vector[i] += g[j, i] * x[j]; + } + } + return new(vector); + } + + /// + /// Compute the tensor product of two rank-one tensors with four elements. + /// + /// This operation is written as $$ a\otimes b $$. + /// + /// A type that implements + /// The first index + /// The second index + /// The first tensor + /// The second tensor + /// A rank two tensor + public static RankTwoTensor, T, I1, I2> TensorProduct(RankOneTensor, T, I1> a, RankOneTensor, T, I2> b) + where T : IComplex + where I1 : IIndex + where I2 : IIndex + { + Matrix4x4 matrix = new(); + + // TODO: Parallelize + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + matrix[i, j] = a[i] * b[j]; + } + } + + return new(matrix); + } +} From a819ab891653a6eb8443e2951c7e02ac8412ab32 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:11:40 -0500 Subject: [PATCH 21/22] Update DerivativesBuilder.cs - Rename parameter --- .../SourceBuilders/DerivativesBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mathematics.NET.SourceGenerators/SourceBuilders/DerivativesBuilder.cs b/src/Mathematics.NET.SourceGenerators/SourceBuilders/DerivativesBuilder.cs index 4ee72477..71f7fa40 100644 --- a/src/Mathematics.NET.SourceGenerators/SourceBuilders/DerivativesBuilder.cs +++ b/src/Mathematics.NET.SourceGenerators/SourceBuilders/DerivativesBuilder.cs @@ -38,9 +38,9 @@ public sealed class DerivativesBuilder private readonly string _assemblyName; private readonly ImmutableArray _methodInformation; - public DerivativesBuilder(Compilation compilationUnitSyntax, ImmutableArray methodInformation) + public DerivativesBuilder(Compilation compilation, ImmutableArray methodInformation) { - _assemblyName = compilationUnitSyntax.AssemblyName!; + _assemblyName = compilation.AssemblyName!; _methodInformation = methodInformation; } From 900f99dffdba1d7a1aff8ff3c53387b9f16ce9d4 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:57:15 -0500 Subject: [PATCH 22/22] Update documentation site - Add Guide section and move to it everything in the Articles section - Add custom template - Various minor changes --- .../articles/differential_geometry/tensors.md | 3 + docs/articles/intro.md | 2 +- docs/articles/toc.yml | 10 +--- docs/docfx.json | 17 ++---- .../fundamentals/numeric-types.md | 0 .../get_started/installation.md | 0 docs/guide/intro.md | 3 + docs/guide/toc.yml | 10 ++++ docs/template/public/main.css | 58 +++++++++++++++++++ docs/template/public/main.js | 15 +++++ docs/toc.yml | 7 ++- 11 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 docs/articles/differential_geometry/tensors.md rename docs/{articles => guide}/fundamentals/numeric-types.md (100%) rename docs/{articles => guide}/get_started/installation.md (100%) create mode 100644 docs/guide/intro.md create mode 100644 docs/guide/toc.yml create mode 100644 docs/template/public/main.css create mode 100644 docs/template/public/main.js diff --git a/docs/articles/differential_geometry/tensors.md b/docs/articles/differential_geometry/tensors.md new file mode 100644 index 00000000..1d21ed3e --- /dev/null +++ b/docs/articles/differential_geometry/tensors.md @@ -0,0 +1,3 @@ +# Tensors + +[work in progress] diff --git a/docs/articles/intro.md b/docs/articles/intro.md index 1250a50b..123cbbdc 100644 --- a/docs/articles/intro.md +++ b/docs/articles/intro.md @@ -1,3 +1,3 @@ # Mathematics.NET Articles -Welcome to Mathematics.NET. +This section is dedicated to highlighting areas of math covered in this library. diff --git a/docs/articles/toc.yml b/docs/articles/toc.yml index 6aa3a720..1be43761 100644 --- a/docs/articles/toc.yml +++ b/docs/articles/toc.yml @@ -1,10 +1,6 @@ - name: Introduction href: intro.md -- name: Get Started +- name: Differential Geometry items: - - name: Installation - href: get_started/installation.md -- name: Fundamentals - items: - - name: Numeric Types - href: fundamentals/numeric-types.md + - name: Tensors + href: differential_geometry/tensors.md diff --git a/docs/docfx.json b/docs/docfx.json index 66202be3..7f5ad5dd 100644 --- a/docs/docfx.json +++ b/docs/docfx.json @@ -23,18 +23,8 @@ "build": { "content": [ { - "files": [ - "api/**.yml", - "api/index.md" - ] - }, - { - "files": [ - "articles/**.md", - "articles/**/toc.yml", - "toc.yml", - "*.md" - ] + "files": [ "**/*.{md,yml}" ], + "exclude": [ "_site/**", "obj/**" ] } ], "resource": [ @@ -49,7 +39,8 @@ "fileMetadataFiles": [], "template": [ "default", - "modern" + "modern", + "template" ], "postProcessors": [ "ExtractSearchIndex" ], "keepFileLink": false, diff --git a/docs/articles/fundamentals/numeric-types.md b/docs/guide/fundamentals/numeric-types.md similarity index 100% rename from docs/articles/fundamentals/numeric-types.md rename to docs/guide/fundamentals/numeric-types.md diff --git a/docs/articles/get_started/installation.md b/docs/guide/get_started/installation.md similarity index 100% rename from docs/articles/get_started/installation.md rename to docs/guide/get_started/installation.md diff --git a/docs/guide/intro.md b/docs/guide/intro.md new file mode 100644 index 00000000..32db6ab2 --- /dev/null +++ b/docs/guide/intro.md @@ -0,0 +1,3 @@ +# Mathematics.NET Guide + +Welcome to Mathematics.NET. diff --git a/docs/guide/toc.yml b/docs/guide/toc.yml new file mode 100644 index 00000000..6aa3a720 --- /dev/null +++ b/docs/guide/toc.yml @@ -0,0 +1,10 @@ +- name: Introduction + href: intro.md +- name: Get Started + items: + - name: Installation + href: get_started/installation.md +- name: Fundamentals + items: + - name: Numeric Types + href: fundamentals/numeric-types.md diff --git a/docs/template/public/main.css b/docs/template/public/main.css new file mode 100644 index 00000000..a93fbd59 --- /dev/null +++ b/docs/template/public/main.css @@ -0,0 +1,58 @@ +:root, [data-bs-theme="dark"] { + --bg-color-primary: #161616; + --bg-color-secondary: #082424; +} + +[data-bs-theme="light"] { + --bg-color-primary: #e4e4e4; + --bg-color-secondary: #b4f8f8; +} + +header { + --bs-border-width: 0px; +} + +body { + background-color: var(--bg-color-primary); +} + + body > footer { + display: flex; + align-items: center; + padding: 0rem; + height: 3rem; + } + +footer { + background-color: var(--bg-color-secondary); + font-size: 0.75rem; +} + + footer.border-top{ + border-top: 0px; + } + +a { + text-decoration: none; +} + + a:hover { + text-decoration: underline; + } + +.bg-body { + background-color: var(--bg-color-secondary); +} + +.dropdown a:hover { + text-decoration: none; +} + +.dropdown-menu[data-bs-popper] { + background-color: var(--bg-color-secondary); + margin-top: 1.125rem; +} + + .dropdown-menu a:hover { + text-decoration: none; + } diff --git a/docs/template/public/main.js b/docs/template/public/main.js new file mode 100644 index 00000000..406f4a3a --- /dev/null +++ b/docs/template/public/main.js @@ -0,0 +1,15 @@ +export default { + defaultTheme: 'dark', + iconLinks: [ + { + icon: 'github', + href: 'https://github.com/HamletTanyavong/Mathematics.NET', + title: 'GitHub' + }, + { + icon: 'heart', + href: 'https://github.com/sponsors/HamletTanyavong', + title: 'Sponsor' + } + ] +} diff --git a/docs/toc.yml b/docs/toc.yml index 59f80104..eeecad23 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -1,5 +1,6 @@ +- name: Guide + href: guide/ +- name: API + href: api/ - name: Articles href: articles/ -- name: Api Documentation - href: api/ - homepage: api/index.md