add namespace for all assets
This commit is contained in:
@@ -11,19 +11,12 @@ using C33 = CategoryOf<IDim3>.OnField<Complex>.FMatrix;
|
|||||||
public static class ComplexMatrixExtension
|
public static class ComplexMatrixExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
private struct C22B
|
private struct C22B(Complex a, Complex b, Complex c, Complex d)
|
||||||
{
|
{
|
||||||
public C22B(Complex a, Complex b, Complex c, Complex d)
|
public Complex X11 = a;
|
||||||
{
|
public Complex X12 = b;
|
||||||
X11 = a;
|
public Complex X21 = c;
|
||||||
X12 = b;
|
public Complex X22 = d;
|
||||||
X21 = c;
|
|
||||||
X22 = d;
|
|
||||||
}
|
|
||||||
public Complex X11;
|
|
||||||
public Complex X12;
|
|
||||||
public Complex X21;
|
|
||||||
public Complex X22;
|
|
||||||
|
|
||||||
public static C22B operator +(C22B a, C22B b) =>
|
public static C22B operator +(C22B a, C22B b) =>
|
||||||
new(a.X11 + b.X11, a.X12 + b.X12, a.X21 + b.X21, a.X22 + b.X22);
|
new(a.X11 + b.X11, a.X12 + b.X12, a.X21 + b.X21, a.X22 + b.X22);
|
||||||
@@ -96,14 +89,16 @@ public static class ComplexMatrixExtension
|
|||||||
C22B w = t + FastFullMul(cPd - a, Ds_CsA);
|
C22B w = t + FastFullMul(cPd - a, Ds_CsA);
|
||||||
C22B wPv = w + v;
|
C22B wPv = w + v;
|
||||||
|
|
||||||
C33 res = new();
|
C33 res = new()
|
||||||
res[1, 1] = t.X11 + self[1, 3] * other[3, 1];
|
{
|
||||||
res[1, 2] = t.X12 + self[1, 3] * other[3, 2];
|
[1, 1] = t.X11 + self[1, 3] * other[3, 1],
|
||||||
res[2, 1] = t.X21 + self[2, 3] * other[3, 1];
|
[1, 2] = t.X12 + self[1, 3] * other[3, 2],
|
||||||
res[2, 2] = t.X22 + self[2, 3] * other[3, 2];
|
[2, 1] = t.X21 + self[2, 3] * other[3, 1],
|
||||||
|
[2, 2] = t.X22 + self[2, 3] * other[3, 2],
|
||||||
|
[1, 3] = wPv.X11 + (self[1, 3] - self[3, 3] - cSa.X11) * other[3, 3],
|
||||||
|
[2, 3] = wPv.X21 + (self[2, 3] - cSa.X21) * other[3, 3]
|
||||||
|
};
|
||||||
|
|
||||||
res[1, 3] = wPv.X11 + (self[1, 3] - self[3, 3] - cSa.X11) * other[3, 3];
|
|
||||||
res[2, 3] = wPv.X21 + (self[2, 3] - cSa.X21) * other[3, 3];
|
|
||||||
C22B wPu = w + u;
|
C22B wPu = w + u;
|
||||||
res[3, 1] = wPu.X11 + self[3, 3] * (other[3, 1] - other[1, 1] + CsD.X11);
|
res[3, 1] = wPu.X11 + self[3, 3] * (other[3, 1] - other[1, 1] + CsD.X11);
|
||||||
res[3, 2] = wPu.X12 + self[3, 3] * (other[3, 2] - other[1, 2] + CsD.X12);
|
res[3, 2] = wPu.X12 + self[3, 3] * (other[3, 2] - other[1, 2] + CsD.X12);
|
||||||
|
|||||||
@@ -3,17 +3,8 @@ using Skeleton.DataStructure.Packs.MatrixDecompositions;
|
|||||||
|
|
||||||
namespace Skeleton.Algebra.AdditionalProperties.Extensions;
|
namespace Skeleton.Algebra.AdditionalProperties.Extensions;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// additional methods for complex normal matrix
|
|
||||||
/// </summary>
|
|
||||||
public static class ComplexNormalMatrixExtension
|
public static class ComplexNormalMatrixExtension
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// unitary decomposition of complex normal matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <typeparam name="TDim"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static JDPair<CategoryOf<TDim>.OnField<Complex>.FMatrix> UnitaryDecomposition<TDim>
|
public static JDPair<CategoryOf<TDim>.OnField<Complex>.FMatrix> UnitaryDecomposition<TDim>
|
||||||
(this CategoryOf<TDim>.OnField<Complex>.FNormalMatrix a, bool order = false)
|
(this CategoryOf<TDim>.OnField<Complex>.FNormalMatrix a, bool order = false)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
namespace Skeleton.Algebra.AdditionalProperties;
|
namespace Skeleton.Algebra.AdditionalProperties;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// matrix property invariant under unitary similarity
|
|
||||||
/// </summary>
|
|
||||||
public interface IUnitaryInvariantMatrix { }
|
public interface IUnitaryInvariantMatrix { }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public interface IUnitaryInvariantMatrix<TUnitaryInvariant> :
|
public interface IUnitaryInvariantMatrix<TUnitaryInvariant> :
|
||||||
IUnitaryInvariantMatrix
|
IUnitaryInvariantMatrix
|
||||||
where TUnitaryInvariant : IUnitaryInvariantMatrix<TUnitaryInvariant>,new() { }
|
where TUnitaryInvariant : IUnitaryInvariantMatrix<TUnitaryInvariant>,new() { }
|
||||||
|
|||||||
@@ -7,40 +7,24 @@ using Skeleton.DataStructure.Packs.LinearSystems;
|
|||||||
|
|
||||||
namespace Skeleton.Algebra.AffineSpaces;
|
namespace Skeleton.Algebra.AffineSpaces;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// general affine space
|
|
||||||
/// </summary>
|
|
||||||
public abstract class AffineSpace : FixableTensor
|
public abstract class AffineSpace : FixableTensor
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class AffineSpace<TAffine> : AffineSpace
|
public abstract class AffineSpace<TAffine> : AffineSpace
|
||||||
where TAffine : AffineSpace<TAffine>, new()
|
where TAffine : AffineSpace<TAffine>, new()
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// intersection of two affine space
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="otherSpace"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TAffine Intersection(TAffine otherSpace);
|
public abstract TAffine Intersection(TAffine otherSpace);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class AffineSpace<TSpace, TAffine> : AffineSpace<TAffine>
|
public abstract class AffineSpace<TSpace, TAffine> : AffineSpace<TAffine>
|
||||||
where TSpace : VectorSpace<TSpace>, new()
|
where TSpace : VectorSpace<TSpace>, new()
|
||||||
where TAffine : AffineSpace<TSpace, TAffine>, new()
|
where TAffine : AffineSpace<TSpace, TAffine>, new()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// underlying vector space
|
|
||||||
/// </summary>
|
|
||||||
public TSpace BaseSpace { get; set; } = new();
|
public TSpace BaseSpace { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class AffineSpace<TMatrix, TSpace, TAffine> : AffineSpace<TSpace, TAffine>
|
public abstract class AffineSpace<TMatrix, TSpace, TAffine> : AffineSpace<TSpace, TAffine>
|
||||||
where TMatrix : Matrix<TMatrix>, new()
|
where TMatrix : Matrix<TMatrix>, new()
|
||||||
where TSpace : VectorSpace<TMatrix, TSpace>, new()
|
where TSpace : VectorSpace<TMatrix, TSpace>, new()
|
||||||
@@ -49,42 +33,22 @@ public abstract class AffineSpace<TMatrix, TSpace, TAffine> : AffineSpace<TSpace
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class AffineSpace<TVector, TMatrix, TSpace, TAffine> : AffineSpace<TMatrix, TSpace, TAffine>
|
public abstract class AffineSpace<TVector, TMatrix, TSpace, TAffine> : AffineSpace<TMatrix, TSpace, TAffine>
|
||||||
where TVector : Vector<TVector>, new()
|
where TVector : Vector<TVector>, new()
|
||||||
where TMatrix : Matrix<TVector, TMatrix>, new()
|
where TMatrix : Matrix<TVector, TMatrix>, new()
|
||||||
where TSpace : VectorSpace<TVector, TMatrix, TSpace>, new()
|
where TSpace : VectorSpace<TVector, TMatrix, TSpace>, new()
|
||||||
where TAffine : AffineSpace<TVector, TMatrix, TSpace, TAffine>, new()
|
where TAffine : AffineSpace<TVector, TMatrix, TSpace, TAffine>, new()
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// bias vector
|
|
||||||
/// </summary>
|
|
||||||
public TVector Bias { get; set; } = new();
|
public TVector Bias { get; set; } = new();
|
||||||
/// <summary>
|
|
||||||
/// if a point is container in the space
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="p"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool ContainsPoint(TVector p) => BaseSpace.ContainsVector(p - Bias);
|
public bool ContainsPoint(TVector p) => BaseSpace.ContainsVector(p - Bias);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// construct
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <param name="b"></param>
|
|
||||||
public void Fill(TSpace s, TVector b)
|
public void Fill(TSpace s, TVector b)
|
||||||
{
|
{
|
||||||
BaseSpace = s;
|
BaseSpace = s;
|
||||||
Bias = b;
|
Bias = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// generate affine space from a space and a bias vector
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <param name="b"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static TAffine Dispatch(TSpace s, TVector b)
|
public static TAffine Dispatch(TSpace s, TVector b)
|
||||||
{
|
{
|
||||||
TAffine res = new ();
|
TAffine res = new ();
|
||||||
@@ -92,12 +56,6 @@ public abstract class AffineSpace<TVector, TMatrix, TSpace, TAffine> : AffineSpa
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// generate affine space from a set of basis and a bias vector
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="basis"></param>
|
|
||||||
/// <param name="b"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static TAffine Dispatch(IEnumerable<TVector> basis, TVector b)
|
public static TAffine Dispatch(IEnumerable<TVector> basis, TVector b)
|
||||||
{
|
{
|
||||||
TSpace s = VectorSpace<TVector, TMatrix, TSpace>.Dispatch(basis);
|
TSpace s = VectorSpace<TVector, TMatrix, TSpace>.Dispatch(basis);
|
||||||
@@ -106,7 +64,6 @@ public abstract class AffineSpace<TVector, TMatrix, TSpace, TAffine> : AffineSpa
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class AffineSpace<TScalar, TVector, TMatrix, TSpace, TAffine> : AffineSpace<TVector, TMatrix, TSpace, TAffine>
|
public abstract class AffineSpace<TScalar, TVector, TMatrix, TSpace, TAffine> : AffineSpace<TVector, TMatrix, TSpace, TAffine>
|
||||||
where TVector : Vector<TScalar, TVector>, new()
|
where TVector : Vector<TScalar, TVector>, new()
|
||||||
where TMatrix : Matrix<TScalar, TVector, TMatrix>, new()
|
where TMatrix : Matrix<TScalar, TVector, TMatrix>, new()
|
||||||
@@ -115,8 +72,6 @@ public abstract class AffineSpace<TScalar, TVector, TMatrix, TSpace, TAffine> :
|
|||||||
where TScalar : notnull
|
where TScalar : notnull
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public LinearSystem<TScalar, TVector, TMatrix> InverseSystem {
|
public LinearSystem<TScalar, TVector, TMatrix> InverseSystem {
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -130,7 +85,6 @@ public abstract class AffineSpace<TScalar, TVector, TMatrix, TSpace, TAffine> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override TAffine Intersection(TAffine otherSpace)
|
public override TAffine Intersection(TAffine otherSpace)
|
||||||
{
|
{
|
||||||
LinearSystem<TScalar, TVector, TMatrix> sa = InverseSystem;
|
LinearSystem<TScalar, TVector, TMatrix> sa = InverseSystem;
|
||||||
|
|||||||
@@ -6,13 +6,9 @@ public partial class CategoryOf<TDimension>
|
|||||||
{
|
{
|
||||||
public static partial class OnField<TScalar>
|
public static partial class OnField<TScalar>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
|
||||||
public class FAffineSpace : AffineSpace<TScalar, FVector, FMatrix, FVectorSpace, FAffineSpace>
|
public class FAffineSpace : AffineSpace<TScalar, FVector, FMatrix, FVectorSpace, FAffineSpace>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
|
||||||
public FAffineSpace() { }
|
public FAffineSpace() { }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override int Dim => FDim;
|
public override int Dim => FDim;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,30 +4,20 @@ using Skeleton.Utils.Helpers;
|
|||||||
|
|
||||||
namespace Skeleton.Algebra.Extensions;
|
namespace Skeleton.Algebra.Extensions;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static class GeneralExt
|
public static class GeneralExt
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
private static readonly ThreadLocal<Stack<double>> TolCache = new(() => new Stack<double>());
|
private static readonly ThreadLocal<Stack<double>> TolCache = new(() => new Stack<double>());
|
||||||
|
|
||||||
[ThreadStatic] private static double TolValue;
|
[ThreadStatic] private static double TolValue;
|
||||||
|
|
||||||
private static double Tol => TolCache.Value!.TryPeek(out TolValue) ? TolValue : 1E-8D;
|
private static double Tol => TolCache.Value!.TryPeek(out TolValue) ? TolValue : 1E-8D;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="t"></param>
|
|
||||||
public static void SetTol(double t)
|
public static void SetTol(double t)
|
||||||
{
|
{
|
||||||
TolCache.Value!.Push(t);
|
TolCache.Value!.Push(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static void ResetTol()
|
public static void ResetTol()
|
||||||
{
|
{
|
||||||
TolCache.Value!.Pop();
|
TolCache.Value!.Pop();
|
||||||
@@ -43,31 +33,17 @@ public static class GeneralExt
|
|||||||
return Math.Abs(x) < Tol;
|
return Math.Abs(x) < Tol;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool CZero(this Complex x)
|
public static bool CZero(this Complex x)
|
||||||
{
|
{
|
||||||
return x.Real.CZero() && x.Imaginary.CZero();
|
return x.Real.CZero() && x.Imaginary.CZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsEqualApprox(this float l, float r)
|
public static bool IsEqualApprox(this float l, float r)
|
||||||
{
|
{
|
||||||
return (l - r).CZero();
|
return (l - r).CZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsSignificantlyGreaterThen(this double l, double r)
|
public static bool IsSignificantlyGreaterThen(this double l, double r)
|
||||||
{
|
{
|
||||||
if (l.IsEqualApprox(r))
|
if (l.IsEqualApprox(r))
|
||||||
@@ -75,12 +51,6 @@ public static class GeneralExt
|
|||||||
return l > r;
|
return l > r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsSignificantlyLessThen(this double l, double r)
|
public static bool IsSignificantlyLessThen(this double l, double r)
|
||||||
{
|
{
|
||||||
if (l.IsEqualApprox(r))
|
if (l.IsEqualApprox(r))
|
||||||
@@ -88,29 +58,14 @@ public static class GeneralExt
|
|||||||
return l < r;
|
return l < r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsEqualApprox(this double l, double r)
|
public static bool IsEqualApprox(this double l, double r)
|
||||||
{
|
{
|
||||||
return (l - r).CZero();
|
return (l - r).CZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsEqualApprox(this Complex l, Complex r)
|
public static bool IsEqualApprox(this Complex l, Complex r)
|
||||||
=> l.Real.IsEqualApprox(r.Real) && l.Imaginary.IsEqualApprox(r.Imaginary);
|
=> l.Real.IsEqualApprox(r.Real) && l.Imaginary.IsEqualApprox(r.Imaginary);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Complex LSum(this IEnumerable<Complex> l)
|
public static Complex LSum(this IEnumerable<Complex> l)
|
||||||
{
|
{
|
||||||
Complex res = Complex.Zero;
|
Complex res = Complex.Zero;
|
||||||
@@ -119,10 +74,6 @@ public static class GeneralExt
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static float LSum(this IEnumerable<float> l)
|
public static float LSum(this IEnumerable<float> l)
|
||||||
{
|
{
|
||||||
float res = 0;
|
float res = 0;
|
||||||
@@ -131,10 +82,6 @@ public static class GeneralExt
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static double LSum(this IEnumerable<double> l)
|
public static double LSum(this IEnumerable<double> l)
|
||||||
{
|
{
|
||||||
double res = 0;
|
double res = 0;
|
||||||
@@ -143,10 +90,6 @@ public static class GeneralExt
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Complex LProd(this IEnumerable<Complex> l)
|
public static Complex LProd(this IEnumerable<Complex> l)
|
||||||
{
|
{
|
||||||
Complex res = Complex.One;
|
Complex res = Complex.One;
|
||||||
@@ -155,11 +98,6 @@ public static class GeneralExt
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="k"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool ApproxContains(this IEnumerable<Complex> l, Complex k)
|
public static bool ApproxContains(this IEnumerable<Complex> l, Complex k)
|
||||||
{
|
{
|
||||||
foreach (Complex x in l)
|
foreach (Complex x in l)
|
||||||
@@ -168,11 +106,6 @@ public static class GeneralExt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="k"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool ApproxContains(this IEnumerable<float> l, float k)
|
public static bool ApproxContains(this IEnumerable<float> l, float k)
|
||||||
{
|
{
|
||||||
foreach (float x in l)
|
foreach (float x in l)
|
||||||
@@ -181,11 +114,6 @@ public static class GeneralExt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <param name="k"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool ApproxContains(this IEnumerable<double> l, double k)
|
public static bool ApproxContains(this IEnumerable<double> l, double k)
|
||||||
{
|
{
|
||||||
foreach (double x in l)
|
foreach (double x in l)
|
||||||
@@ -194,10 +122,6 @@ public static class GeneralExt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="r"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Dictionary<Complex, int> RoughGroup(this IEnumerable<Complex> r)
|
public static Dictionary<Complex, int> RoughGroup(this IEnumerable<Complex> r)
|
||||||
{
|
{
|
||||||
List<List<Complex>> clusters = new List<List<Complex>>();
|
List<List<Complex>> clusters = new List<List<Complex>>();
|
||||||
@@ -228,11 +152,7 @@ public static class GeneralExt
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// group complex numbers by count
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="l"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Dictionary<TScalar, int> Group<TScalar>(this IEnumerable<TScalar> l)
|
public static Dictionary<TScalar, int> Group<TScalar>(this IEnumerable<TScalar> l)
|
||||||
where TScalar : notnull
|
where TScalar : notnull
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,83 +3,53 @@ using Skeleton.Algebra.Extensions;
|
|||||||
|
|
||||||
namespace Skeleton.Algebra.FieldStructures;
|
namespace Skeleton.Algebra.FieldStructures;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
[CustomFieldStructure]
|
[CustomFieldStructure]
|
||||||
public class ComplexFieldStructure : FieldStructure<Complex>
|
public class ComplexFieldStructure : FieldStructure<Complex>
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public static readonly ComplexFieldStructure Structure = new();
|
public static readonly ComplexFieldStructure Structure = new();
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Addition(Complex self, Complex other) => self + other;
|
public override Complex Addition(Complex self, Complex other) => self + other;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex AdditionUnit => 0d;
|
public override Complex AdditionUnit => 0d;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Multiplication(Complex self, Complex other) => self * other;
|
public override Complex Multiplication(Complex self, Complex other) => self * other;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex MultiplicationUnit => 1d;
|
public override Complex MultiplicationUnit => 1d;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex AdditionInverse(Complex self) => -self;
|
public override Complex AdditionInverse(Complex self) => -self;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex MultiplicationInverse(Complex self) => 1d / self;
|
public override Complex MultiplicationInverse(Complex self) => 1d / self;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Subtraction(Complex self, Complex other) => self - other;
|
public override Complex Subtraction(Complex self, Complex other) => self - other;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Division(Complex self, Complex other) => self / other;
|
public override Complex Division(Complex self, Complex other) => self / other;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool IsEqualApprox(Complex self, Complex other, double? absTol = null, double? relTol = null)
|
public override bool IsEqualApprox(Complex self, Complex other, double? absTol = null, double? relTol = null)
|
||||||
|
|
||||||
=> RealFieldStructure.Structure.IsEqualApprox(self.Real, other.Real, absTol, relTol) &&
|
=> RealFieldStructure.Structure.IsEqualApprox(self.Real, other.Real, absTol, relTol) &&
|
||||||
RealFieldStructure.Structure.IsEqualApprox(self.Imaginary, other.Imaginary, absTol, relTol);
|
RealFieldStructure.Structure.IsEqualApprox(self.Imaginary, other.Imaginary, absTol, relTol);
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Fix(Complex x)
|
public override Complex Fix(Complex x)
|
||||||
=> base.Fix(new Complex(
|
=> base.Fix(new Complex(
|
||||||
RealFieldStructure.Structure.Fix(x.Real),
|
RealFieldStructure.Structure.Fix(x.Real),
|
||||||
RealFieldStructure.Structure.Fix(x.Imaginary)
|
RealFieldStructure.Structure.Fix(x.Imaginary)
|
||||||
));
|
));
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Conj(Complex self) => Complex.Conjugate(self);
|
public override Complex Conj(Complex self) => Complex.Conjugate(self);
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override double AsReal(Complex x) => x.Real;
|
public override double AsReal(Complex x) => x.Real;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex FromReal(double x) => x;
|
public override Complex FromReal(double x) => x;
|
||||||
|
|
||||||
private const string PlusSign = "+";
|
private const string PlusSign = "+";
|
||||||
private const string EmptyString = "";
|
private const string EmptyString = "";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string RawRepresentation(Complex x)
|
public override string RawRepresentation(Complex x)
|
||||||
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
||||||
? RealFieldStructure.Structure.Representation(x.Real)
|
? RealFieldStructure.Structure.Representation(x.Real)
|
||||||
: $"{x.Real}{(x.Imaginary > 0 ? PlusSign : EmptyString)}{x.Imaginary}i";
|
: $"{x.Real}{(x.Imaginary > 0 ? PlusSign : EmptyString)}{x.Imaginary}i";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string RawPythonRepresentation(Complex x)
|
public override string RawPythonRepresentation(Complex x)
|
||||||
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
||||||
? RealFieldStructure.Structure.Representation(x.Real)
|
? RealFieldStructure.Structure.Representation(x.Real)
|
||||||
: $"{x.Real}{(x.Imaginary > 0 ? PlusSign : EmptyString)}{x.Imaginary}j";
|
: $"{x.Real}{(x.Imaginary > 0 ? PlusSign : EmptyString)}{x.Imaginary}j";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string RawCSharpRepresentation(Complex x)
|
public override string RawCSharpRepresentation(Complex x)
|
||||||
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
=> RealFieldStructure.Structure.IsEqualApprox(x.Imaginary, 0d)
|
||||||
? RealFieldStructure.Structure.Representation(x.Real)
|
? RealFieldStructure.Structure.Representation(x.Real)
|
||||||
: $"{x.Real}{(x.Imaginary >= 0 ? PlusSign : EmptyString)}{x.Imaginary}*AlgebraConstant.I";
|
: $"{x.Real}{(x.Imaginary >= 0 ? PlusSign : EmptyString)}{x.Imaginary}*AlgebraConstant.I";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string DumpString(Complex x)
|
public override string DumpString(Complex x)
|
||||||
=> "<C>" +
|
=> "<C>" +
|
||||||
RealFieldStructure.Structure.DumpString(x.Real) +
|
RealFieldStructure.Structure.DumpString(x.Real) +
|
||||||
@@ -87,7 +57,6 @@ public class ComplexFieldStructure : FieldStructure<Complex>
|
|||||||
RealFieldStructure.Structure.DumpString(x.Imaginary) +
|
RealFieldStructure.Structure.DumpString(x.Imaginary) +
|
||||||
"</C>";
|
"</C>";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Resolve(string dumpString)
|
public override Complex Resolve(string dumpString)
|
||||||
{
|
{
|
||||||
double[] restored = dumpString
|
double[] restored = dumpString
|
||||||
@@ -99,26 +68,19 @@ public class ComplexFieldStructure : FieldStructure<Complex>
|
|||||||
return new Complex(restored[0], restored[1]);
|
return new Complex(restored[0], restored[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override double MaxError(Complex a)
|
public override double MaxError(Complex a)
|
||||||
=> Math.Max(Math.Abs(a.Real), Math.Abs(a.Imaginary));
|
=> Math.Max(Math.Abs(a.Real), Math.Abs(a.Imaginary));
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex ComplexCast(Complex a) => a;
|
public override Complex ComplexCast(Complex a) => a;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex RealMul(Complex a, double b) => a * b;
|
public override Complex RealMul(Complex a, double b) => a * b;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex SquareRoot(Complex a) => Complex.Sqrt(a);
|
public override Complex SquareRoot(Complex a) => Complex.Sqrt(a);
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex FromComplex(Complex a) => a;
|
public override Complex FromComplex(Complex a) => a;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Log(Complex x) => Complex.Log(x);
|
public override Complex Log(Complex x) => Complex.Log(x);
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Complex Exp(Complex x) => Complex.Exp(x);
|
public override Complex Exp(Complex x) => Complex.Exp(x);
|
||||||
|
|
||||||
public override Complex Sign(Complex x)
|
public override Complex Sign(Complex x)
|
||||||
|
|||||||
@@ -1,120 +1,50 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection.Metadata;
|
|
||||||
using Skeleton.Algebra.Extensions;
|
using Skeleton.Algebra.Extensions;
|
||||||
using Skeleton.DataStructure.Packs;
|
using Skeleton.DataStructure.Packs;
|
||||||
|
|
||||||
namespace Skeleton.Algebra.FieldStructures;
|
namespace Skeleton.Algebra.FieldStructures;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// operations / structure of the field
|
|
||||||
/// </summary>
|
|
||||||
public abstract class FieldStructure
|
public abstract class FieldStructure
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public abstract class FieldStructure<TScalar> : FieldStructure
|
public abstract class FieldStructure<TScalar> : FieldStructure
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// return the singleton base on type
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static FieldStructure<TScalar> Dispatch()
|
public static FieldStructure<TScalar> Dispatch()
|
||||||
{
|
{
|
||||||
return FieldStructureRegistry.GetOperation<TScalar>();
|
return FieldStructureRegistry.GetOperation<TScalar>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// addition in field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar Addition(TScalar self, TScalar other);
|
public abstract TScalar Addition(TScalar self, TScalar other);
|
||||||
/// <summary>
|
|
||||||
/// addition unit of the field<br/>
|
|
||||||
/// a + unit = a for any a in field
|
|
||||||
/// </summary>
|
|
||||||
public abstract TScalar AdditionUnit { get; }
|
public abstract TScalar AdditionUnit { get; }
|
||||||
/// <summary>
|
|
||||||
/// multiplication in field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar Multiplication(TScalar self, TScalar other);
|
public abstract TScalar Multiplication(TScalar self, TScalar other);
|
||||||
/// <summary>
|
|
||||||
/// multiplication unit of the field<br/>
|
|
||||||
/// unit * a = a for any a in the field except the addition unit
|
|
||||||
/// </summary>
|
|
||||||
public abstract TScalar MultiplicationUnit { get; }
|
public abstract TScalar MultiplicationUnit { get; }
|
||||||
/// <summary>
|
|
||||||
/// inverse of element under addition<br/>
|
|
||||||
/// a + AddInv(a) = unit(addition) for any a in field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar AdditionInverse(TScalar self);
|
public abstract TScalar AdditionInverse(TScalar self);
|
||||||
/// <summary>
|
|
||||||
/// inverse of element under multiplication<br/>
|
|
||||||
/// a * MulInv(a) = unit(multiplication) for any a in field except the addition unit
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar MultiplicationInverse(TScalar self);
|
public abstract TScalar MultiplicationInverse(TScalar self);
|
||||||
/// <summary>
|
|
||||||
/// a + AddInv(b)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Subtraction(TScalar self, TScalar other)
|
public virtual TScalar Subtraction(TScalar self, TScalar other)
|
||||||
=> Addition(self, AdditionInverse(other));
|
=> Addition(self, AdditionInverse(other));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a * MulInv(b)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Division(TScalar self, TScalar other)
|
public virtual TScalar Division(TScalar self, TScalar other)
|
||||||
=> Multiplication(self, MultiplicationInverse(other));
|
=> Multiplication(self, MultiplicationInverse(other));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// conjugate of the scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar Conj(TScalar self);
|
public abstract TScalar Conj(TScalar self);
|
||||||
/// <summary>
|
|
||||||
/// if two elements are close to each other in the field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <param name="absTol"></param>
|
|
||||||
/// <param name="relTol"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract bool IsEqualApprox(TScalar self, TScalar other, double? absTol=null, double? relTol = null);
|
public abstract bool IsEqualApprox(TScalar self, TScalar other, double? absTol=null, double? relTol = null);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// tolerance to check if two scalars are close
|
|
||||||
/// </summary>
|
|
||||||
public double AbsoluteTolerance { get; set; } = 1E-8d;
|
public double AbsoluteTolerance { get; set; } = 1E-8d;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public double RelativeTolerance { get; set; } = 1E-5d;
|
public double RelativeTolerance { get; set; } = 1E-5d;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// if calculation in field won't introduce error, override this and leave it empty
|
|
||||||
/// otherwise, provide method to reduce the error here
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Fix(TScalar x)
|
public virtual TScalar Fix(TScalar x)
|
||||||
{
|
{
|
||||||
if (IsEqualApprox(x, AdditionUnit))
|
if (IsEqualApprox(x, AdditionUnit))
|
||||||
@@ -124,132 +54,40 @@ public abstract class FieldStructure<TScalar> : FieldStructure
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// homomorphism from scalar field to real<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual double AsReal(TScalar x) => IsEqualApprox(x, AdditionUnit) ? 0 : 1;
|
public virtual double AsReal(TScalar x) => IsEqualApprox(x, AdditionUnit) ? 0 : 1;
|
||||||
/// <summary>
|
|
||||||
/// conjugated square xx* when field is real/complex
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public double ConjX2(TScalar x) => AsReal(Multiplication(x, Conj(x)));
|
public double ConjX2(TScalar x) => AsReal(Multiplication(x, Conj(x)));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// homomorphism from real to scalar<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar FromReal(double x) => x.IsEqualApprox(0) ? AdditionUnit : MultiplicationUnit;
|
public virtual TScalar FromReal(double x) => x.IsEqualApprox(0) ? AdditionUnit : MultiplicationUnit;
|
||||||
/// <summary>
|
|
||||||
/// readable string representation of data
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string Representation(TScalar x) => RawRepresentation(Fix(x));
|
public string Representation(TScalar x) => RawRepresentation(Fix(x));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// representation of the original data, without fix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual string RawRepresentation(TScalar x) => $"{x}";
|
public virtual string RawRepresentation(TScalar x) => $"{x}";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// code to construct object in python
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string PythonRepresentation(TScalar x) => RawPythonRepresentation(Fix(x));
|
public string PythonRepresentation(TScalar x) => RawPythonRepresentation(Fix(x));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// code to construct scalar object in python<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual string RawPythonRepresentation(TScalar x) => "";
|
public virtual string RawPythonRepresentation(TScalar x) => "";
|
||||||
/// <summary>
|
|
||||||
/// code to construct the object in c#
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string CSharpRepresentation(TScalar x) => RawCSharpRepresentation(Fix(x));
|
public string CSharpRepresentation(TScalar x) => RawCSharpRepresentation(Fix(x));
|
||||||
/// <summary>
|
|
||||||
/// C# string for the original data
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract string RawCSharpRepresentation(TScalar x);
|
public abstract string RawCSharpRepresentation(TScalar x);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// dump the object as string which can be restored exactly<br/>
|
|
||||||
/// ignore if not applicable<br/>
|
|
||||||
/// if override can not contain following string as substring<br/>
|
|
||||||
/// <D> </D> <C> </C> <CSPLIT/><br/>
|
|
||||||
/// <VECTOR> <VSPLIT/> </VECTOR><br/>
|
|
||||||
/// <MATRIX> <MSPLIT/> </MSPLIT>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual string DumpString(TScalar x) => "";
|
public virtual string DumpString(TScalar x) => "";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// method to restore a value from dump string<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dumpString"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Resolve(string dumpString) => AdditionUnit;
|
public virtual TScalar Resolve(string dumpString) => AdditionUnit;
|
||||||
/// <summary>
|
|
||||||
/// max diff from zero
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract double MaxError(TScalar a);
|
public abstract double MaxError(TScalar a);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// homomorphism from field to complex<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual Complex ComplexCast(TScalar a) => IsEqualApprox(a, AdditionUnit) ? 0 : 1;
|
public virtual Complex ComplexCast(TScalar a) => IsEqualApprox(a, AdditionUnit) ? 0 : 1;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// K x R -> K<br/>
|
|
||||||
/// ignore if not applicable
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <param name="b"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar RealMul(TScalar a, double b) => a;
|
public virtual TScalar RealMul(TScalar a, double b) => a;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// for y in field, find x such that x*x = y
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract TScalar SquareRoot(TScalar a);
|
public abstract TScalar SquareRoot(TScalar a);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Absolute value
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public TScalar Abs(TScalar a) => SquareRoot(Multiplication(a, Conj(a)));
|
public TScalar Abs(TScalar a) => SquareRoot(Multiplication(a, Conj(a)));
|
||||||
/// <summary>
|
|
||||||
/// a x^2 + b x + c = unit(add)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <param name="b"></param>
|
|
||||||
/// <param name="c"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public QuadraticRoots<TScalar> QuadraticRoot(TScalar a, TScalar b, TScalar c)
|
public QuadraticRoots<TScalar> QuadraticRoot(TScalar a, TScalar b, TScalar c)
|
||||||
{
|
{
|
||||||
TScalar invB = AdditionInverse(b);
|
TScalar invB = AdditionInverse(b);
|
||||||
@@ -263,11 +101,6 @@ public abstract class FieldStructure<TScalar> : FieldStructure
|
|||||||
return new QuadraticRoots<TScalar>(x1, x2);
|
return new QuadraticRoots<TScalar>(x1, x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Sign(TScalar x) => MultiplicationUnit;
|
public virtual TScalar Sign(TScalar x) => MultiplicationUnit;
|
||||||
|
|
||||||
internal TScalar WilkinsonShift(TScalar a11, TScalar a12, TScalar a21, TScalar a22)
|
internal TScalar WilkinsonShift(TScalar a11, TScalar a12, TScalar a21, TScalar a22)
|
||||||
@@ -328,26 +161,10 @@ public abstract class FieldStructure<TScalar> : FieldStructure
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// homomorphism from complex to this field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar FromComplex(Complex a) => AdditionUnit;
|
public virtual TScalar FromComplex(Complex a) => AdditionUnit;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// log of the element in the field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Log(TScalar x) => AdditionUnit;
|
public virtual TScalar Log(TScalar x) => AdditionUnit;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// exp of the element in the field
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TScalar Exp(TScalar x) => MultiplicationUnit;
|
public virtual TScalar Exp(TScalar x) => MultiplicationUnit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
namespace Skeleton.Algebra.FieldStructures;
|
namespace Skeleton.Algebra.FieldStructures;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public static class FieldStructureRegistry
|
public static class FieldStructureRegistry
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Register customer field structure
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="structure"></param>
|
|
||||||
/// <typeparam name="TScalar"></typeparam>
|
|
||||||
public static void Register<TScalar>(FieldStructure<TScalar> structure)
|
public static void Register<TScalar>(FieldStructure<TScalar> structure)
|
||||||
=> FieldStructureRegistry<TScalar>.Structure = structure;
|
=> FieldStructureRegistry<TScalar>.Structure = structure;
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,9 @@ using System.Collections;
|
|||||||
|
|
||||||
namespace Skeleton.DataStructure.Link;
|
namespace Skeleton.DataStructure.Link;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Linked List
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TObject"></typeparam>
|
|
||||||
public class Link<TObject> : IEnumerable<TObject>
|
public class Link<TObject> : IEnumerable<TObject>
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// singleton for default value
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Link<TObject> Null = new();
|
public static readonly Link<TObject> Null = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public Link()
|
public Link()
|
||||||
{
|
{
|
||||||
Head = new LinkHead<TObject>();
|
Head = new LinkHead<TObject>();
|
||||||
@@ -27,35 +16,16 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Count = 0;
|
Count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// First item
|
|
||||||
/// </summary>
|
|
||||||
public LinkNode<TObject> First => Head.Next;
|
public LinkNode<TObject> First => Head.Next;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Last item
|
|
||||||
/// </summary>
|
|
||||||
public LinkNode<TObject> Last => Tail.Previous;
|
public LinkNode<TObject> Last => Tail.Previous;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// number of items
|
|
||||||
/// </summary>
|
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// head of linked list
|
|
||||||
/// </summary>
|
|
||||||
private LinkHead<TObject> Head { get; }
|
private LinkHead<TObject> Head { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// tail of linked list
|
|
||||||
/// </summary>
|
|
||||||
private LinkTail<TObject> Tail { get; }
|
private LinkTail<TObject> Tail { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// iterator in reverse direction
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public IEnumerable<TObject> Backward
|
public IEnumerable<TObject> Backward
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -73,10 +43,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public IEnumerator<TObject> GetEnumerator()
|
public IEnumerator<TObject> GetEnumerator()
|
||||||
{
|
{
|
||||||
LinkNode<TObject> iter = Head.Next;
|
LinkNode<TObject> iter = Head.Next;
|
||||||
@@ -96,10 +62,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// add item next to head
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
public void AddFirst(TObject obj)
|
public void AddFirst(TObject obj)
|
||||||
{
|
{
|
||||||
LinkNode<TObject> node = new LinkNode<TObject>(obj);
|
LinkNode<TObject> node = new LinkNode<TObject>(obj);
|
||||||
@@ -111,10 +73,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Count += 1;
|
Count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// add item before tail
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
public void AddLast(TObject obj)
|
public void AddLast(TObject obj)
|
||||||
{
|
{
|
||||||
LinkNode<TObject> node = new LinkNode<TObject>(obj);
|
LinkNode<TObject> node = new LinkNode<TObject>(obj);
|
||||||
@@ -126,12 +84,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Count += 1;
|
Count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// add item after specific node
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="node"></param>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public void AddAfter(LinkNode<TObject> node, TObject obj)
|
public void AddAfter(LinkNode<TObject> node, TObject obj)
|
||||||
{
|
{
|
||||||
if (node.Parent != this)
|
if (node.Parent != this)
|
||||||
@@ -145,21 +97,11 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Count += 1;
|
Count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// add item before specific node
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="node"></param>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
public void AddBefore(LinkNode<TObject> node, TObject obj)
|
public void AddBefore(LinkNode<TObject> node, TObject obj)
|
||||||
{
|
{
|
||||||
AddAfter(node.Previous, obj);
|
AddAfter(node.Previous, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public LinkNode<TObject> Find(TObject value)
|
public LinkNode<TObject> Find(TObject value)
|
||||||
{
|
{
|
||||||
LinkNode<TObject> iter = Head.Next;
|
LinkNode<TObject> iter = Head.Next;
|
||||||
@@ -177,12 +119,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
return LinkNode<TObject>.Null;
|
return LinkNode<TObject>.Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// find the node by selector
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="selector"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public LinkNode<TObject> Find(Func<TObject, bool> selector)
|
public LinkNode<TObject> Find(Func<TObject, bool> selector)
|
||||||
{
|
{
|
||||||
LinkNode<TObject> iter = Head.Next;
|
LinkNode<TObject> iter = Head.Next;
|
||||||
@@ -200,11 +136,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
return LinkNode<TObject>.Null;
|
return LinkNode<TObject>.Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// remove specific node
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="node"></param>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public void Remove(LinkNode<TObject> node)
|
public void Remove(LinkNode<TObject> node)
|
||||||
{
|
{
|
||||||
if (!ReferenceEquals(node.Parent, this))
|
if (!ReferenceEquals(node.Parent, this))
|
||||||
@@ -219,11 +150,6 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Count -= 1;
|
Count -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// remove the first item
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public TObject RemoveFirst()
|
public TObject RemoveFirst()
|
||||||
{
|
{
|
||||||
LinkNode<TObject> res = First;
|
LinkNode<TObject> res = First;
|
||||||
@@ -233,11 +159,7 @@ public class Link<TObject> : IEnumerable<TObject>
|
|||||||
Remove(res);
|
Remove(res);
|
||||||
return resValue;
|
return resValue;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// remove the last item
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public TObject RemoveLast()
|
public TObject RemoveLast()
|
||||||
{
|
{
|
||||||
LinkNode<TObject> res = Last;
|
LinkNode<TObject> res = Last;
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
namespace Skeleton.Utils.RandomEngines;
|
namespace Skeleton.Utils.RandomEngines;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static class Normal
|
public static class Normal
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static double? ExNormal;
|
public static double? ExNormal;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static double Get()
|
public static double Get()
|
||||||
{
|
{
|
||||||
if (ExNormal != null)
|
if (ExNormal != null)
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
using Skeleton.DataStructure;
|
|
||||||
|
|
||||||
namespace Skeleton.Utils.RandomEngines;
|
namespace Skeleton.Utils.RandomEngines;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static class RandomSource
|
public static class RandomSource
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public static ThreadLocal<Random> Rnd = new(() => new Random());
|
public static ThreadLocal<Random> Rnd = new(() => new Random());
|
||||||
|
|
||||||
public static void SetSeed(int seed)
|
public static void SetSeed(int seed)
|
||||||
@@ -15,9 +9,6 @@ public static class RandomSource
|
|||||||
Rnd.Value = new Random(seed);
|
Rnd.Value = new Random(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static double Get()
|
public static double Get()
|
||||||
{
|
{
|
||||||
return Rnd.Value.NextDouble();
|
return Rnd.Value.NextDouble();
|
||||||
|
|||||||
Reference in New Issue
Block a user