m3
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
21
SkeletonTest.csproj
Normal file
21
SkeletonTest.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.13.2"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Skeleton\Skeleton.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
22
SkeletonTest.sln
Normal file
22
SkeletonTest.sln
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkeletonTest", "SkeletonTest.csproj", "{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skeleton", "..\Skeleton\Skeleton.csproj", "{61DBA845-169F-473E-B084-09B6A0E3762C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{61DBA845-169F-473E-B084-09B6A0E3762C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{61DBA845-169F-473E-B084-09B6A0E3762C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{61DBA845-169F-473E-B084-09B6A0E3762C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{61DBA845-169F-473E-B084-09B6A0E3762C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
17
UnitTest1.cs
Normal file
17
UnitTest1.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace SkeletonTest;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
7
global.json
Normal file
7
global.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "6.0.0",
|
||||
"rollForward": "latestMinor",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
}
|
||||
27
tests/AffineSpaceTest.cs
Normal file
27
tests/AffineSpaceTest.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.AffineSpaces;
|
||||
using Skeleton.Algebra.DimensionProviders;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
|
||||
using AffineC2Space = Skeleton.Algebra.CategoryOf<IDim2>.OnField<Complex>.FAffineSpace;
|
||||
public static class AffineSpaceTest
|
||||
{
|
||||
[Test]
|
||||
public static void BasicAffineSpaceTest()
|
||||
{
|
||||
AffineC2Space ac2s =
|
||||
AffineSpace<C2, C22, C2Space, AffineC2Space>.Dispatch(
|
||||
new C2[] { new(1, 0) },
|
||||
new C2(1, 1)
|
||||
);
|
||||
Assert.IsTrue(ac2s.ContainsPoint(new C2(new Complex[]{2, 1} )));
|
||||
Assert.IsTrue(ac2s.ContainsPoint(new C2(new Complex[]{-7, 1})));
|
||||
Assert.IsTrue(ac2s.ContainsPoint(new C2(new Complex[]{0, 1})));
|
||||
Assert.IsFalse(ac2s.ContainsPoint(new C2(new Complex[]{1, 0})));
|
||||
Assert.IsFalse(ac2s.ContainsPoint(new C2(new Complex[]{0, 0})));
|
||||
Assert.That(ac2s.Dim, Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
|
||||
97
tests/AlgebraMiscTest.cs
Normal file
97
tests/AlgebraMiscTest.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Analysis.AnalyticFunctions.Polynomials.Implements;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class AlgebraMiscTest
|
||||
{
|
||||
|
||||
private static readonly Complex ii = new Complex(0, 1);
|
||||
[Test]
|
||||
public static void SolverTest()
|
||||
{
|
||||
var fff = new C2Polynomial(ii, ii, 1);
|
||||
var qrs = fff.Roots.ToArray();
|
||||
Assert.IsTrue(qrs.LSum().IsEqualApprox(-ii));
|
||||
Assert.IsTrue(qrs.LProd().IsEqualApprox(ii));
|
||||
|
||||
GeneralExt.SetTol(1E-7f);
|
||||
qrs = new C3Polynomial(ii, ii, 1, 1).Roots.ToArray();
|
||||
Assert.IsTrue(qrs.LSum().IsEqualApprox(-1));
|
||||
Assert.IsTrue(qrs.LProd().IsEqualApprox(-ii));
|
||||
Assert.IsTrue(qrs.ApproxContains(-1));
|
||||
Assert.IsTrue(qrs.ApproxContains((1 - ii) / Complex.Sqrt(2)));
|
||||
Assert.IsTrue(qrs.ApproxContains(-(1 - ii) / Complex.Sqrt(2)));
|
||||
|
||||
qrs = new C4Polynomial(ii, ii, 1, -ii, 1).Roots.ToArray();
|
||||
Assert.IsTrue(qrs.LSum().IsEqualApprox(ii));
|
||||
Assert.IsTrue(qrs.LProd().IsEqualApprox(ii));
|
||||
GeneralExt.ResetTol();
|
||||
}
|
||||
[Test]
|
||||
public static void KernelTest()
|
||||
{
|
||||
C22 mc22 = new C22(
|
||||
1 + ii, 2,
|
||||
0, 0
|
||||
);
|
||||
C2Space c2ks = mc22.Ker;
|
||||
Assert.IsTrue(c2ks.Rank == 1);
|
||||
Console.WriteLine((mc22 * c2ks[0]).Representation);
|
||||
Assert.IsTrue((mc22 * c2ks[0]).IsEqualApprox(C2.Zero));
|
||||
R22 mr22 = new R22(
|
||||
1, 3,
|
||||
0, 0
|
||||
);
|
||||
R2Space r2ks = mr22.Ker;
|
||||
Assert.IsTrue(r2ks.Rank == 1);
|
||||
Console.WriteLine((mr22 * r2ks[0]).Representation);
|
||||
Assert.IsTrue((mr22 * r2ks[0]).IsEqualApprox(R2.Zero));
|
||||
|
||||
C33 mc33 = new C33(
|
||||
3 + ii, 0, 1 - ii,
|
||||
0, 0, 0,
|
||||
0, 0, 0
|
||||
);
|
||||
C3Space c3ks = mc33.Ker;
|
||||
Assert.IsTrue(c3ks.Rank == 2);
|
||||
|
||||
Assert.IsTrue((mc33 * ((3.2 + 1.7 * ii) * c3ks[0] + (1.1 - 0.8 * ii) * c3ks[1])).IsEqualApprox(C3.Zero));
|
||||
Assert.IsTrue((mc33 * ((1.2 + 3.7 * ii) * c3ks[0] + (3.1 + 1.2 * ii) * c3ks[1])).IsEqualApprox(C3.Zero));
|
||||
R33 mr33 = new R33(
|
||||
3, 5, 1,
|
||||
3, 0, 1,
|
||||
0, 5, 0
|
||||
);
|
||||
R3Space r3ks = mr33.Ker;
|
||||
Assert.IsTrue(r3ks.Rank == 1);
|
||||
Assert.IsTrue((mr33 * r3ks[0]).IsEqualApprox(R3.Zero));
|
||||
C44 mc44 = new C44(
|
||||
1 + ii, 2 - ii, 0, 0,
|
||||
1 + ii, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 0, 0
|
||||
);
|
||||
C4Space c4ks = mc44.Ker;
|
||||
Assert.IsTrue(c4ks.Rank == 2);
|
||||
Assert.IsTrue((mc44 * (1.2 * c4ks[0] + 3.1 * c4ks[1])).IsEqualApprox(C4.Zero));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TransposeTest()
|
||||
{
|
||||
C22 a = new C22(
|
||||
1, 2,
|
||||
3, 4
|
||||
);
|
||||
C22 at = new C22(
|
||||
1, 3,
|
||||
2, 4
|
||||
);
|
||||
Assert.IsTrue(a.Transpose().IsEqualApprox(at));
|
||||
}
|
||||
}
|
||||
165
tests/CacheItemTest.cs
Normal file
165
tests/CacheItemTest.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Skeleton.DataStructure;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class CacheItemTest
|
||||
{
|
||||
|
||||
private class TestClass
|
||||
{
|
||||
public TestClass(int v) => Value = v;
|
||||
|
||||
public int UpdateCount { get; private set; } = 0;
|
||||
public int ReferenceCount { get; private set; } = 0;
|
||||
private int InnerValue { get; set; } = 0;
|
||||
public int Value {
|
||||
get
|
||||
{
|
||||
ReferenceCount += 1;
|
||||
return InnerValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
UpdateCount += 1;
|
||||
InnerValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static TestClass operator +(TestClass self, TestClass other) => new (self.Value + other.Value);
|
||||
public static TestClass operator *(TestClass self, TestClass other) => new(self.Value * other.Value);
|
||||
public static TestClass operator *(TestClass self, int other) => new(self.Value * other);
|
||||
public static TestClass operator +(TestClass self, int other) => new(self.Value + other);
|
||||
public static TestClass operator *(int other, TestClass self) => self * other;
|
||||
public static TestClass operator +(int other, TestClass self) => self + other;
|
||||
public static implicit operator TestClass(int x) => new (x);
|
||||
}
|
||||
|
||||
private class TestClass2
|
||||
{
|
||||
public TestClass2()
|
||||
{
|
||||
BA = new(x => Childs.Count);
|
||||
BB = new(x => Childs.Select(c => c.BA.GetFrom(x)).Sum());
|
||||
}
|
||||
public HashSet<TestClass2> Childs { get; set; } = new();
|
||||
public int A { get; set; }
|
||||
public CacheItem<int> BA { get; set; }
|
||||
public CacheItem<int> BB { get; set; }
|
||||
|
||||
public void Add(TestClass2 x)
|
||||
{
|
||||
BA.Expire();
|
||||
BB.Expire();
|
||||
Childs.Add(x);
|
||||
}
|
||||
|
||||
public void Remove(TestClass2 x)
|
||||
{
|
||||
BA.Expire();
|
||||
BB.Expire();
|
||||
Childs.Remove(x);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Test()
|
||||
{
|
||||
|
||||
CacheItem<TestClass> t0 = new CacheItem<TestClass>(_ => 0);
|
||||
CacheItem<TestClass> a = new CacheItem<TestClass>(_ => 1);
|
||||
CacheItem<TestClass> b = new CacheItem<TestClass>(x => a.GetFrom(x).Value * 2);
|
||||
CacheItem<TestClass> c =
|
||||
new CacheItem<TestClass>(x => b.GetFrom(x).Value * b.GetFrom(x).Value);
|
||||
CacheItem<TestClass> d = new CacheItem<TestClass>(x => b.GetFrom(x).Value - a.GetFrom(x).Value + t0.GetFrom(x));
|
||||
|
||||
Assert.IsTrue(a.Expired);
|
||||
Assert.IsTrue(b.Expired);
|
||||
Assert.IsTrue(c.Expired);
|
||||
Assert.IsTrue(d.Expired);
|
||||
Assert.That(a.Get.Value, Is.EqualTo(1));
|
||||
Assert.That(b.Get.Value, Is.EqualTo(2));
|
||||
Assert.That(c.Get.Value, Is.EqualTo(4));
|
||||
Assert.That(d.Get.Value, Is.EqualTo(1));
|
||||
a.UpdateCalculation(_ => 3);
|
||||
Assert.IsTrue(a.Expired);
|
||||
Assert.IsTrue(b.Expired);
|
||||
Assert.IsTrue(c.Expired);
|
||||
Assert.IsTrue(d.Expired);
|
||||
Assert.That(a.Get.Value, Is.EqualTo(3));
|
||||
Assert.That(b.Get.Value, Is.EqualTo(6));
|
||||
Assert.That(c.Get.Value, Is.EqualTo(36));
|
||||
Assert.That(d.Get.Value, Is.EqualTo(3));
|
||||
b.UpdateCalculation(_ => 9);
|
||||
Assert.IsFalse(a.Expired);
|
||||
Assert.IsTrue(b.Expired);
|
||||
Assert.IsTrue(c.Expired);
|
||||
Assert.IsTrue(d.Expired);
|
||||
Assert.That(a.Get.Value, Is.EqualTo(3));
|
||||
Assert.That(b.Get.Value, Is.EqualTo(9));
|
||||
Assert.That(c.Get.Value, Is.EqualTo(81));
|
||||
Assert.That(d.Get.Value, Is.EqualTo(6));
|
||||
c.UpdateCalculation(x => a.GetFrom(x) * b.GetFrom(x));
|
||||
Assert.IsFalse(a.Expired);
|
||||
Assert.IsFalse(b.Expired);
|
||||
Assert.IsTrue(c.Expired);
|
||||
Assert.IsFalse(d.Expired);
|
||||
Assert.That(a.Get.Value, Is.EqualTo(3));
|
||||
Assert.That(b.Get.Value, Is.EqualTo(9));
|
||||
Assert.That(c.Get.Value, Is.EqualTo(27));
|
||||
Assert.That(d.Get.Value, Is.EqualTo(6));
|
||||
d.UpdateCalculation(x => a.GetFrom(x) + b.GetFrom(x) + c.GetFrom(x));
|
||||
Assert.IsFalse(a.Expired);
|
||||
Assert.IsFalse(b.Expired);
|
||||
Assert.IsFalse(c.Expired);
|
||||
Assert.IsTrue(d.Expired);
|
||||
Assert.That(a.Get.Value, Is.EqualTo(3));
|
||||
Assert.That(b.Get.Value, Is.EqualTo(9));
|
||||
Assert.That(c.Get.Value, Is.EqualTo(27));
|
||||
Assert.That(d.Get.Value, Is.EqualTo(39));
|
||||
Assert.That(t0.Get.UpdateCount, Is.EqualTo(1));
|
||||
Assert.That(t0.Get.ReferenceCount, Is.EqualTo(3));
|
||||
int noUse = d.Get.Value;
|
||||
noUse += d.Get.Value;
|
||||
noUse += d.Get.Value;
|
||||
Assert.That(noUse, Is.EqualTo(117));
|
||||
Assert.That(t0.Get.ReferenceCount, Is.EqualTo(3));
|
||||
|
||||
|
||||
}
|
||||
[Test]
|
||||
public static void Test2()
|
||||
{
|
||||
CacheItem<int> a = new (_ => 1);
|
||||
CacheItem<int> b = new (_ => 3);
|
||||
CacheItem<int> c = new(x => a.GetFrom(x) + b.GetFrom(x));
|
||||
Assert.IsTrue(a.Expired);
|
||||
Assert.IsTrue(b.Expired);
|
||||
Assert.IsTrue(c.Expired);
|
||||
Assert.That(a.Get, Is.EqualTo(1));
|
||||
Assert.That(b.Get, Is.EqualTo(3));
|
||||
Assert.That(c.Get, Is.EqualTo(4));
|
||||
Assert.IsFalse(a.Expired);
|
||||
Assert.IsFalse(b.Expired);
|
||||
Assert.IsFalse(c.Expired);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Test3()
|
||||
{
|
||||
TestClass2 a = new();
|
||||
TestClass2 b = new();
|
||||
TestClass2 c = new();
|
||||
a.Add(b);
|
||||
a.Add(c);
|
||||
b.Add(c);
|
||||
Assert.That(a.BA.Get, Is.EqualTo(2));
|
||||
Assert.That(a.BB.Get, Is.EqualTo(1));
|
||||
a.Remove(b);
|
||||
Assert.That(a.BA.Get, Is.EqualTo(1));
|
||||
Assert.That(a.BB.Get, Is.EqualTo(0));
|
||||
Assert.That(b.BA.Get, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
39
tests/CayleySU3Test.cs
Normal file
39
tests/CayleySU3Test.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public class CayleySU3Test
|
||||
{
|
||||
|
||||
[DatapointSource]
|
||||
private static readonly LieSU3[] Data = 40.ScaleSamples(-1, 1).LieSU3LogSU3Samples().ToArray();
|
||||
private static Action<LieSU3> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
|
||||
[Theory]
|
||||
public static void TestCayleyForLieSU3(LieSU3 data)
|
||||
{
|
||||
Action<LieSU3> rawTest = x =>
|
||||
{
|
||||
U3 cN = x.CayleyNegative();
|
||||
Assert.IsTrue((cN * cN.Hermitian()).IsEqualApprox(C33.One));
|
||||
};
|
||||
rawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void TestCayleyUnitary(LieSU3 data)
|
||||
{
|
||||
U3 cN = data.CayleyNegative();
|
||||
U3 cP = data.CayleyPositive();
|
||||
var udN = cN.EigenDecomposition();
|
||||
var udP = cP.EigenDecomposition();
|
||||
Assert.IsTrue(cN.Det().IsEqualApprox(Complex.Conjugate(cP.Det())));
|
||||
Console.WriteLine($"{cN.Det()} =x= {cP.Det()}");
|
||||
Console.WriteLine($"{udN.J.Det()} =x= {udP.J.Det()}");
|
||||
}
|
||||
|
||||
}
|
||||
39
tests/CayleySU4Test.cs
Normal file
39
tests/CayleySU4Test.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class CayleySU4Test
|
||||
{
|
||||
[DatapointSource]
|
||||
private static readonly LieSU4[] Data = 40.ScaleSamples(-1, 1).LieSU4LogSU4Samples().ToArray();
|
||||
private static Action<LieSU4> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
|
||||
[Theory]
|
||||
public static void TestCayleyForLieSU4(LieSU4 data)
|
||||
{
|
||||
Action<LieSU4> rawTest = x =>
|
||||
{
|
||||
U4 cN = x.CayleyNegative();
|
||||
Assert.IsTrue((cN * cN.Hermitian()).IsEqualApprox(C44.One));
|
||||
};
|
||||
rawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void TestCayleyUnitary(LieSU4 data)
|
||||
{
|
||||
U4 cN = data.CayleyNegative();
|
||||
U4 cP = data.CayleyPositive();
|
||||
var udN = cN.EigenDecomposition();
|
||||
var udP = cP.EigenDecomposition();
|
||||
//Console.WriteLine((cN - cP.Conj()).PythonRepresentation);
|
||||
Assert.IsTrue(cN.Det().IsEqualApprox(Complex.Conjugate(cP.Det())));
|
||||
Console.WriteLine($"{cN.Det()} =x= {cP.Det()}");
|
||||
Console.WriteLine($"{udN.J.Det()} =x= {udP.J.Det()}");
|
||||
}
|
||||
|
||||
}
|
||||
36
tests/CayleyTransformationTest.cs
Normal file
36
tests/CayleyTransformationTest.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class CayleyTransformationTest
|
||||
{
|
||||
[DatapointSource]
|
||||
private static readonly LieSU2[] Data = 40.ScaleSamples(-1, 1).LieSU2LogSU2Samples().ToArray();
|
||||
private static Action<LieSU2> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
|
||||
[Theory]
|
||||
public static void TestCayleyForLieSU2(LieSU2 data)
|
||||
{
|
||||
Action<LieSU2> rawTest = x =>
|
||||
{
|
||||
U2 cN = x.CayleyNegative();
|
||||
Assert.IsTrue((cN * cN.Hermitian()).IsEqualApprox(C22.One));
|
||||
};
|
||||
rawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void TestCayleyUnitary(LieSU2 data)
|
||||
{
|
||||
U2 cN = data.CayleyNegative();
|
||||
U2 cP = data.CayleyPositive();
|
||||
var udN = cN.EigenDecomposition();
|
||||
var udP = cP.EigenDecomposition();
|
||||
Assert.IsTrue(cN.Det().IsEqualApprox(1));
|
||||
Assert.IsTrue(cP.Det().IsEqualApprox(1));
|
||||
Console.WriteLine($"{udN.J.Det()} =x= {udP.J.Det()}");
|
||||
}
|
||||
}
|
||||
138
tests/DecompositionTest.cs
Normal file
138
tests/DecompositionTest.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Algebra.ScalarFieldStructure;
|
||||
using Skeleton.DataStructure.Packs.MatrixDecompositions;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class DecompositionTest
|
||||
{
|
||||
[DatapointSource]
|
||||
public static readonly IEnumerable<C44> TestMatrices =
|
||||
100.ScaleSamples(-1, 1).C44InvertibleSamples();
|
||||
|
||||
private static readonly Action<C44> OnFail = x =>
|
||||
{
|
||||
|
||||
PLUPack<Complex, C44> res = x.PLUDecomposition();
|
||||
Console.WriteLine("======================================");
|
||||
Console.WriteLine(x.Representation);
|
||||
Console.WriteLine("-------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(x.Det());
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(res.Det);
|
||||
|
||||
Console.WriteLine("P");
|
||||
Console.WriteLine(res.P.Representation);
|
||||
Console.WriteLine("L");
|
||||
Console.WriteLine(res.L.Representation);
|
||||
Console.WriteLine("U");
|
||||
Console.WriteLine(res.U.Representation);
|
||||
Console.WriteLine("+++++++++");
|
||||
Console.WriteLine((res.P * res.L * res.U).Representation);
|
||||
Console.WriteLine("======================================");
|
||||
};
|
||||
|
||||
[Theory]
|
||||
public static void C44PLUTest(C44 data)
|
||||
{
|
||||
Action<C44> rawTest = x =>
|
||||
{
|
||||
PLUPack<Complex, C44> res = x.PLUDecomposition();
|
||||
Assert.IsTrue((res.P * res.L * res.U).IsEqualApprox(x));
|
||||
Assert.IsTrue(res.Det.IsEqualApprox(x.Det()));
|
||||
};
|
||||
rawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void R44PLUTest()
|
||||
{
|
||||
R44 t = new R44(
|
||||
1, 2, 4, 8,
|
||||
2, 8, 16, 64,
|
||||
2, 8, 32, 128,
|
||||
2, 8, 32, 256
|
||||
);
|
||||
PLUPack<double, R44> x = t.PLUDecomposition();
|
||||
Assert.IsTrue(RealFieldStructure.Structure.IsEqualApprox(x.Det, t.Det()));
|
||||
Assert.IsTrue((x.P * x.L * x.U).IsEqualApprox(t));
|
||||
|
||||
R44 tt = new R44(
|
||||
0, 1, 2, 1,
|
||||
1, 0, 0, 0,
|
||||
2, 1, 2, 1,
|
||||
1, 2, 4, 3
|
||||
);
|
||||
PLUPack<double, R44> xy = tt.PLUDecomposition();
|
||||
Console.WriteLine($"{tt.Det()} x {xy.Det}");
|
||||
Assert.IsTrue(RealFieldStructure.Structure.IsEqualApprox(tt.Det(), xy.Det));
|
||||
|
||||
Console.WriteLine(xy.L.Representation);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine((xy.P * xy.L * xy.U).Representation);
|
||||
Assert.IsTrue((xy.P * xy.L * xy.U).IsEqualApprox(tt));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void R22PLUTest()
|
||||
{
|
||||
R22 a = new R22(3, 6, 2, 1);
|
||||
var s = a.PLUDecomposition();
|
||||
Assert.IsTrue(s.Det.IsEqualApprox(-9));
|
||||
Assert.IsTrue((s.P * s.L * s.U).IsEqualApprox(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void R33PLUTest()
|
||||
{
|
||||
R33 a = new R33(
|
||||
1, 2, 3,
|
||||
3, 5, 7,
|
||||
2, 4, 1
|
||||
);
|
||||
var s = a.PLUDecomposition();
|
||||
Console.WriteLine("P");
|
||||
Console.WriteLine(s.P.Representation);
|
||||
Console.WriteLine("L");
|
||||
Console.WriteLine(s.L.Representation);
|
||||
Console.WriteLine("U");
|
||||
Console.WriteLine(s.U.Representation);
|
||||
Console.WriteLine($"{s.Det} x {a.Det()}");
|
||||
Assert.IsTrue(s.Det.IsEqualApprox(a.Det()));
|
||||
Assert.IsTrue((s.P * s.L * s.U).IsEqualApprox(a));
|
||||
|
||||
}
|
||||
[Test]
|
||||
public static void C33QRDcompositionTest()
|
||||
{
|
||||
C33 a = new (
|
||||
0, 3, 1,
|
||||
0, 4, -2,
|
||||
2, 1, 1
|
||||
);
|
||||
var w = a.QRDecomposition();
|
||||
Assert.IsTrue(w.Q.Property.IsOrthogonal);
|
||||
Assert.IsTrue(w.R.Property.IsUpperTriangle);
|
||||
Assert.IsTrue((w.Q * w.R).IsEqualApprox(a));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void C44QRDecompositionTest(C44 data)
|
||||
{
|
||||
Action<C44> rawTest = x =>
|
||||
{
|
||||
QRPair<C44> qr = x.QRDecomposition();
|
||||
Assert.IsTrue((qr.Q * qr.R).IsEqualApprox(x));
|
||||
Assert.IsTrue(qr.Q.Property.IsUnitary);
|
||||
Assert.IsTrue(qr.R.Property.IsUpperTriangle);
|
||||
};
|
||||
rawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
}
|
||||
9
tests/DraftTest.cs
Normal file
9
tests/DraftTest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public class DraftTest
|
||||
{
|
||||
[Test]
|
||||
public void QRDraftTest()
|
||||
{
|
||||
}
|
||||
}
|
||||
89
tests/EigenDecompositionTest.cs
Normal file
89
tests/EigenDecompositionTest.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.DataStructure.Packs.MatrixDecompositions;
|
||||
using Skeleton.Samples;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public class EigenDecompositionTest
|
||||
{
|
||||
private static readonly Complex I = Complex.ImaginaryOne;
|
||||
[DatapointSource]
|
||||
public static readonly C22[] DataPoints =
|
||||
30.ScaleSamples(-1, 1).C22InvertibleSamples().ToArray();
|
||||
|
||||
[Theory]
|
||||
public static void DecompositionIdentityTest(C22 data)
|
||||
{
|
||||
JDPair<C22> decomp = data.EigenDecomposition();
|
||||
C22 J = decomp.J;
|
||||
C22 D = decomp.D;
|
||||
Assert.IsTrue((J * D * J.Inv()).IsEqualApprox(data));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void UnitaryDecompositionTest(C22 data)
|
||||
{
|
||||
U2 unitaryData = new U2(data);
|
||||
Console.WriteLine(data.Representation);
|
||||
Assert.IsTrue((unitaryData * unitaryData.Hermitian()).IsEqualApprox(U2.One));
|
||||
Assert.IsTrue(unitaryData.Det().Magnitude.IsEqualApprox(1));
|
||||
JDPair<C22> decomp = unitaryData.EigenDecomposition();
|
||||
|
||||
C22 J = decomp.J;
|
||||
C22 D = decomp.D;
|
||||
Assert.IsTrue(D.Property.IsDiagonal);
|
||||
Assert.IsTrue((J * J.Hermitian()).IsEqualApprox(C22.One));
|
||||
Assert.IsTrue((J * D * J.Inv()).IsEqualApprox(unitaryData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void DecompositionTest()
|
||||
{
|
||||
C22 a = new C22(I, 1, 1, I);
|
||||
JDPair<C22> t = a.EigenDecomposition();
|
||||
C22 J = t.J;
|
||||
C22 D = t.D;
|
||||
Assert.IsTrue((J * D * J.Inv()).IsEqualApprox(a));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void UnitaryDecompositionCase0()
|
||||
{
|
||||
U2 m = new U2(
|
||||
-0.08908708063747477 + 0.44543540318737385 * I, 0.3008484477213831 + 0.8385350351383227 * I,
|
||||
-0.5345224838248488 + 0.7126966450997985 * I, 0.04608742177859454 - 0.45191277466233243 * I
|
||||
);
|
||||
JDPair<C22> t = m.EigenDecomposition();
|
||||
C22 J = t.J;
|
||||
C22 D = t.D;
|
||||
|
||||
Assert.IsTrue((J * D * J.Inv()).IsEqualApprox(m));
|
||||
Assert.IsTrue((J * J.Hermitian()).IsEqualApprox(C22.One));
|
||||
|
||||
|
||||
//C22 JH = J.Hermitian();
|
||||
D.SwapRow(1, 2);
|
||||
J.SwapColumn(1, 2);
|
||||
Console.WriteLine((J.Hermitian()*m*J).Representation);
|
||||
Console.WriteLine(" -- ");
|
||||
Console.WriteLine(D.Representation);
|
||||
//Assert.IsTrue((JH.Hermitian() * D * JH).IsEqualApprox(m));
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void UnitaryDecompositionCase1()
|
||||
{
|
||||
U2 m = new U2(
|
||||
0.8666666666666667 - 0.8666666666666667 * I, -0.4 + 0.46666666666666656 * I,
|
||||
-0.8666666666666667 - 0.6 * I, 0.6666666666666667
|
||||
);
|
||||
Assert.IsTrue((m * m.Hermitian()).IsEqualApprox(C22.One));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
274
tests/EigenValueTest.cs
Normal file
274
tests/EigenValueTest.cs
Normal file
@@ -0,0 +1,274 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Matrices;
|
||||
using Skeleton.Constants;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class EigenValueTest
|
||||
{
|
||||
[Test]
|
||||
public static void AlgebraicMultiplicityTest()
|
||||
{
|
||||
string dumpString =
|
||||
"<MATRIX><VECTOR><C><D>58,238,232,169,50,231,237,63</D><CSPLIT/><D>252,28,121,1,53,106,202,63</D></C><VSPLIT/><C><D>128,170,57,130,152,251,200,63</D><CSPLIT/><D>40,128,219,130,233,145,181,63</D></C><VSPLIT/><C><D>32,11,248,186,212,100,180,63</D><CSPLIT/><D>204,48,165,236,132,31,199,63</D></C></VECTOR><MSPLIT/><VECTOR><C><D>122,140,15,0,86,127,198,191</D><CSPLIT/><D>222,180,98,122,22,20,193,63</D></C><VSPLIT/><C><D>146,3,107,71,5,99,236,63</D><CSPLIT/><D>22,210,160,78,188,185,177,191</D></C><VSPLIT/><C><D>147,191,234,27,57,143,209,63</D><CSPLIT/><D>240,146,207,126,75,149,210,191</D></C></VECTOR><MSPLIT/><VECTOR><C><D>0,134,112,227,222,35,117,191</D><CSPLIT/><D>52,213,176,25,233,25,200,63</D></C><VSPLIT/><C><D>214,26,125,2,184,174,214,191</D><CSPLIT/><D>88,13,118,78,172,199,200,191</D></C><VSPLIT/><C><D>113,113,137,16,1,113,236,63</D><CSPLIT/><D>58,148,110,160,208,108,187,191</D></C></VECTOR></MATRIX>";
|
||||
SU3 x2 = Matrix<Complex, C3, C33>.Resolve(dumpString).MatrixCast<SU3>();
|
||||
x2.Log();
|
||||
SU3 x = new (
|
||||
0.9344724005272333 + 0.20636618205956114 * AlgebraConstant.I,
|
||||
0.19517809256224794 + 0.08425769276391348 * AlgebraConstant.I,
|
||||
0.07966355862303631 + 0.18064939074463948 * AlgebraConstant.I,
|
||||
-0.17576098444905935 + 0.13342553115709327 * AlgebraConstant.I,
|
||||
0.8870874781497256 - 0.069240349956836 * AlgebraConstant.I,
|
||||
0.2743666432024778 - 0.29036223777647674 * AlgebraConstant.I,
|
||||
-0.005161162050201451 + 0.18829072718077955 * AlgebraConstant.I,
|
||||
-0.35441398852382855 - 0.1935935385809937 * AlgebraConstant.I,
|
||||
0.888794452952011 - 0.10712913433833729 * AlgebraConstant.I
|
||||
);
|
||||
x.Log();
|
||||
Assert.IsTrue(x.IsEqualApprox(x2));
|
||||
SU3 xx = new (
|
||||
0.900968867902419 + 0.4338837391175583 * AlgebraConstant.I, 0, 0, 0,
|
||||
0.7844948739101761 - 0.07642217128558915 * AlgebraConstant.I,
|
||||
-0.43828707593371596 + 0.4320091244570258 * AlgebraConstant.I, 0,
|
||||
0.5823247448725786 + 0.1990611364725401 * AlgebraConstant.I,
|
||||
0.7399637958509763 - 0.27152557206488276 * AlgebraConstant.I
|
||||
);
|
||||
xx.Log();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void EigenValuesTest0()
|
||||
{
|
||||
C33 x = new (
|
||||
0.9344724005272333 + 0.20636618205956114 * AlgebraConstant.I,
|
||||
0.19517809256224794 + 0.08425769276391348 * AlgebraConstant.I,
|
||||
0.07966355862303631 + 0.18064939074463948 * AlgebraConstant.I,
|
||||
-0.17576098444905935 + 0.13342553115709327 * AlgebraConstant.I,
|
||||
0.8870874781497256 - 0.069240349956836 * AlgebraConstant.I,
|
||||
0.2743666432024778 - 0.29036223777647674 * AlgebraConstant.I,
|
||||
-0.005161162050201451 + 0.18829072718077955 * AlgebraConstant.I,
|
||||
-0.35441398852382855 - 0.1935935385809937 * AlgebraConstant.I,
|
||||
0.888794452952011 - 0.10712913433833729 * AlgebraConstant.I
|
||||
);
|
||||
|
||||
Console.WriteLine(x.PythonRepresentation);
|
||||
|
||||
|
||||
foreach (Complex ev in x.EigenValues())
|
||||
Console.WriteLine(ev);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void EigenValuesTest1()
|
||||
{
|
||||
// skew hermitian
|
||||
SU3 a = new SU3(//90 iterations needed 63ms
|
||||
-0.41682645597518747 - 0.04513264449558757 * AlgebraConstant.I,
|
||||
-0.562495137600655 - 0.25770471508224335 * AlgebraConstant.I,
|
||||
0.23593397061664254 - 0.6210808413637191 * AlgebraConstant.I,
|
||||
-0.05956034617712977 + 0.59806270818534 * AlgebraConstant.I,
|
||||
0.5101583950751629 + 0.16421725718762056 * AlgebraConstant.I,
|
||||
0.47668976878561187 - 0.3525784039791803 * AlgebraConstant.I,
|
||||
-0.5813526822815206 - 0.3535836125237688 * AlgebraConstant.I,
|
||||
0.5720026837092955 - 0.052645362620770714 * AlgebraConstant.I,
|
||||
-0.3928619416491455 - 0.2295834884879076 * AlgebraConstant.I
|
||||
);
|
||||
try
|
||||
{
|
||||
a.Log();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
[Test]
|
||||
public static void EigenValuesTest2()
|
||||
{
|
||||
SU4 x = new SU4(-0.779847526429233 - 0.2685329483801642 * AlgebraConstant.I,
|
||||
-0.3671906793704016 + 0.20504085759385277 * AlgebraConstant.I,
|
||||
0.1797326418785119 + 0.28869090035325307 * AlgebraConstant.I,
|
||||
-0.15699955803429697 + 0.05061643143068167 * AlgebraConstant.I,
|
||||
-0.12145228366009361 + 0.2219828375642076 * AlgebraConstant.I,
|
||||
-0.03499946085775628 + 0.2629095057479602 * AlgebraConstant.I,
|
||||
-0.567103313710783 + 0.2662838502567337 * AlgebraConstant.I,
|
||||
0.2878300706241982 - 0.6247136826282005 * AlgebraConstant.I,
|
||||
0.2853497437972582 - 0.01779705644091366 * AlgebraConstant.I,
|
||||
-0.41034837274261327 + 0.0923456495251366 * AlgebraConstant.I,
|
||||
0.6481741606884517 + 0.060846786206961295 * AlgebraConstant.I,
|
||||
0.4298166035109582 - 0.3643774085595283 * AlgebraConstant.I,
|
||||
0.05763481181747576 - 0.413083370206058 * AlgebraConstant.I,
|
||||
0.5679484644041604 + 0.5032930726822459 * AlgebraConstant.I,
|
||||
0.0980393693330078 + 0.24165407559606544 * AlgebraConstant.I,
|
||||
0.37281407453762927 + 0.20777930150098434 * AlgebraConstant.I
|
||||
);
|
||||
LieSU4 lsu4 = x.Log();
|
||||
try
|
||||
{
|
||||
lsu4.Exp();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public static void EigenValuesTest3()
|
||||
{
|
||||
SU4 a = new SU4(
|
||||
0.2780441294545625 + 0.19434718200997803 * AlgebraConstant.I,
|
||||
0.6094077829723441 - 0.1163734891346272 * AlgebraConstant.I,
|
||||
-0.5767312412823015 + 0.2533899606424308 * AlgebraConstant.I,
|
||||
0.010321491186588205 - 0.3210421623311934 * AlgebraConstant.I,
|
||||
0.8990123896499085 + 0.15176635070803396 * AlgebraConstant.I,
|
||||
-0.22706249712540277 + 0.11668385179642621 * AlgebraConstant.I,
|
||||
0.013997621769215651 - 0.22622336886409927 * AlgebraConstant.I,
|
||||
-0.12783033769259322 + 0.1893611837411106 * AlgebraConstant.I,
|
||||
0.07111120550135545 - 0.017687997567439967 * AlgebraConstant.I,
|
||||
0.39108090353805214 - 0.5931139251255253 * AlgebraConstant.I,
|
||||
0.23802672123855062 - 0.44783907804266015 * AlgebraConstant.I,
|
||||
0.41808364215728316 + 0.24060639687896418 * AlgebraConstant.I,
|
||||
0.09132385258653822 - 0.19988651308258049 * AlgebraConstant.I,
|
||||
0.1957076704935428 + 0.08292751430336807 * AlgebraConstant.I,
|
||||
0.4136701345595704 - 0.35137176475490917 * AlgebraConstant.I,
|
||||
-0.2812055078850708 - 0.7299761886250002 * AlgebraConstant.I
|
||||
);
|
||||
LieSU4 w = a.Log();
|
||||
try
|
||||
{
|
||||
w.Exp();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public static void EigenValuesTest4()
|
||||
{
|
||||
SU4 x = new SU4(
|
||||
0.25169715721780095 - 0.3262818747696454 * AlgebraConstant.I,
|
||||
-0.06215393129320365 - 0.4816491933228719 * AlgebraConstant.I,
|
||||
0.25169715721780095 - 0.3262818747696454 * AlgebraConstant.I,
|
||||
0.6152713907633685 + 0.2144047984418787 * AlgebraConstant.I,
|
||||
0.2787550780796054 + 0.22851703444051924 * AlgebraConstant.I,
|
||||
0.35445639658760586 - 0.570912274248332 * AlgebraConstant.I,
|
||||
-0.5660185516284082 - 0.06586284820255425 * AlgebraConstant.I,
|
||||
-0.10741084418381291 - 0.28678110892615927 * AlgebraConstant.I,
|
||||
-0.31804746877893 - 0.19600790769136783 * AlgebraConstant.I,
|
||||
0.23979550077869344 - 0.3936365944332084 * AlgebraConstant.I,
|
||||
0.5899535555161333 - 0.007539030384152989 * AlgebraConstant.I,
|
||||
-0.3590019428886613 - 0.413510129757416 * AlgebraConstant.I,
|
||||
-0.561714694163377 - 0.4951439798153037 * AlgebraConstant.I,
|
||||
0.2959147328215392 - 0.11204285633378004 * AlgebraConstant.I,
|
||||
-0.3917663713238493 + 0.06237659287659594 * AlgebraConstant.I,
|
||||
-0.04502121234778653 + 0.4240180093544583 * AlgebraConstant.I
|
||||
);
|
||||
var lx = x.Log();
|
||||
try
|
||||
{
|
||||
lx.Exp();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public static void EigenValuesTest5()
|
||||
{
|
||||
SU3 x =new SU3(0.17014139728794547 + 0.3089560143523728 * AlgebraConstant.I,
|
||||
0.12157066460524535 + 0.614463238212909 * AlgebraConstant.I,
|
||||
-0.6387486045542593 + 0.2743242765355136 * AlgebraConstant.I,
|
||||
0.4612629745700969 - 0.17640828090272623 * AlgebraConstant.I,
|
||||
-0.3694430944315643 - 0.574371297110632 * AlgebraConstant.I,
|
||||
-0.5028726148696543 + 0.19195086081111523 * AlgebraConstant.I,
|
||||
-0.5726265570862423 + 0.5511927965454999 * AlgebraConstant.I,
|
||||
-0.10137418504620699 - 0.36192290619805034 * AlgebraConstant.I,
|
||||
-0.04987454749860609 + 0.47384907010892335 * AlgebraConstant.I)
|
||||
;
|
||||
try
|
||||
{
|
||||
x.Log();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void EigenValuesTest6()
|
||||
{
|
||||
SU3 a =new (
|
||||
-0.7216998181876505 - 0.45142779443376374 * AlgebraConstant.I,
|
||||
0.34302665847902336 - 0.38787711146921394 * AlgebraConstant.I,
|
||||
0.04514277944337641 - 0.0721699818187651 * AlgebraConstant.I,
|
||||
0.341352669936687 + 0.3129132782650185 * AlgebraConstant.I,
|
||||
0.6595966877094065 - 0.46627939978443955 * AlgebraConstant.I,
|
||||
-0.36216794382181394 + 0.04374638704917619 * AlgebraConstant.I,
|
||||
-0.10338968932150652 - 0.22413506194952298 * AlgebraConstant.I,
|
||||
-0.24313232033505766 + 0.14243055739183164 * AlgebraConstant.I,
|
||||
-0.9249872548767164 - 0.06381877147098358 * AlgebraConstant.I
|
||||
);
|
||||
try
|
||||
{
|
||||
a.Log();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public static void EigenValuesTest7()
|
||||
{
|
||||
SU3 a =new (
|
||||
-0.7216998181876505 - 0.45142779443376374 * AlgebraConstant.I,
|
||||
0.34302665847902336 - 0.38787711146921394 * AlgebraConstant.I,
|
||||
0.04514277944337641 - 0.0721699818187651 * AlgebraConstant.I,
|
||||
0.341352669936687 + 0.3129132782650185 * AlgebraConstant.I,
|
||||
0.6595966877094065 - 0.46627939978443955 * AlgebraConstant.I,
|
||||
-0.36216794382181394 + 0.04374638704917619 * AlgebraConstant.I,
|
||||
-0.10338968932150652 - 0.22413506194952298 * AlgebraConstant.I,
|
||||
-0.24313232033505766 + 0.14243055739183164 * AlgebraConstant.I,
|
||||
-0.9249872548767164 - 0.06381877147098358 * AlgebraConstant.I
|
||||
);
|
||||
try
|
||||
{
|
||||
a.Log();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void EigenValuesTest8()
|
||||
{
|
||||
SU3 a = new(
|
||||
-0.11146503597864356 + 0.11568058336290889 * AlgebraConstant.I,
|
||||
-0.6151654715746724 + 0.5226703988252228 * AlgebraConstant.I,
|
||||
0.3491495237808594 + 0.4479679176067069 * AlgebraConstant.I,
|
||||
0.37604139249936874 - 0.026618308590304313 * AlgebraConstant.I,
|
||||
-0.47527192364669435 - 0.32098661165443476 * AlgebraConstant.I,
|
||||
0.4767287746734095 - 0.5492706126356045 * AlgebraConstant.I,
|
||||
0.015969670489228482 - 0.9120432307662227 * AlgebraConstant.I,
|
||||
0.13281746650969412 - 0.042787978404167926 * AlgebraConstant.I,
|
||||
0.3075231991383097 + 0.232121318115649 * AlgebraConstant.I
|
||||
);
|
||||
try
|
||||
{
|
||||
a.Log();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
tests/FieldStructureTest.cs
Normal file
12
tests/FieldStructureTest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Skeleton.Algebra.ScalarFieldStructure;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class FieldStructureTest
|
||||
{
|
||||
[Test]
|
||||
public static void EqualTest()
|
||||
{
|
||||
Assert.IsTrue(RealFieldStructure.Structure.IsEqualApprox(-1.6E-9, 0));
|
||||
}
|
||||
}
|
||||
114
tests/JordanPowerTest.cs
Normal file
114
tests/JordanPowerTest.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils.Helpers;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class JordanPowerTest
|
||||
{
|
||||
private static readonly Complex ii = new Complex(0, 1);
|
||||
[DatapointSource]
|
||||
public static readonly Complex[] Basic0TestData = 10.ScaleSamples(-1, 1).UCSamples().ToArray();
|
||||
[Theory]
|
||||
public static void J22TestBasic0(Complex eigenValue)
|
||||
{
|
||||
C22 block = new(
|
||||
eigenValue, 1,
|
||||
0, eigenValue
|
||||
);
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock2Power(eigenValue, 0).IsEqualApprox(C22.One));
|
||||
Assert.IsTrue(
|
||||
(
|
||||
AlgebraHelper.JordanBlock2Power(eigenValue, 3.4d) *
|
||||
AlgebraHelper.JordanBlock2Power(eigenValue, -3.4d)
|
||||
).IsEqualApprox(C22.One)
|
||||
);
|
||||
Assert.IsTrue(
|
||||
(
|
||||
AlgebraHelper.JordanBlock2Power(eigenValue, -2 - ii) *
|
||||
AlgebraHelper.JordanBlock2Power(eigenValue, 2 + ii)
|
||||
).IsEqualApprox(C22.One)
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void J22TestBasic1()
|
||||
{
|
||||
C22 u2 = new(
|
||||
1 + 2 * ii, 1,
|
||||
0, 1 + 2 * ii
|
||||
);
|
||||
Complex eigenValue = 1 + 2 * ii;
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock2Power(eigenValue, 3 - ii).IsEqualApprox(new C22(
|
||||
(-11 - 2 * ii) * Complex.Pow(1 + 2 * ii, -ii), (-5 + 15 * ii) * Complex.Pow(1 + 2 * ii, -ii),
|
||||
0, (-11 - 2 * ii) * Complex.Pow(1 + 2 * ii, -ii)
|
||||
)));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock2Power(eigenValue, 2).IsEqualApprox(u2*u2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void J22TestBasic2()
|
||||
{
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock2Power(0, 2).IsEqualApprox(C22.Zero));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock2Power(0, 0).IsEqualApprox(C22.One));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void J33TestBasic0(Complex eigenValue)
|
||||
{
|
||||
C33 uw = new(
|
||||
eigenValue, 1, 0,
|
||||
0, eigenValue, 1,
|
||||
0, 0, eigenValue
|
||||
);
|
||||
Assert.IsTrue(
|
||||
(
|
||||
AlgebraHelper.JordanBlock3Power(eigenValue, 4.2) * AlgebraHelper.JordanBlock3Power(eigenValue, -4.2)
|
||||
).IsEqualApprox(C33.One)
|
||||
);
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock3Power(eigenValue, 2).IsEqualApprox(uw * uw));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void J33TestBasic1()
|
||||
{
|
||||
C33 ux = new(
|
||||
0, 1, 0,
|
||||
0, 0, 1,
|
||||
0, 0, 0
|
||||
);
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock3Power(0, 0).IsEqualApprox(C33.One));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock3Power(0, 1).IsEqualApprox(ux));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock3Power(0, 2).IsEqualApprox(new C33(
|
||||
0, 0, 1,
|
||||
0, 0, 0,
|
||||
0, 0, 0
|
||||
)));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock3Power(0, 3).IsEqualApprox(C33.Zero));
|
||||
}
|
||||
[Theory]
|
||||
public static void J44Test(Complex eigenValue)
|
||||
{
|
||||
C44 uf = new(
|
||||
eigenValue, 1, 0, 0,
|
||||
0, eigenValue, 1, 0,
|
||||
0, 0, eigenValue, 1,
|
||||
0, 0, 0, eigenValue
|
||||
);
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock4Power(eigenValue, 0).IsEqualApprox(C44.One));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock4Power(eigenValue, 1).IsEqualApprox(uf));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock4Power(eigenValue, 2).IsEqualApprox(uf * uf));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock4Power(eigenValue, 3).IsEqualApprox(uf * uf * uf));
|
||||
Assert.IsTrue(AlgebraHelper.JordanBlock4Power(eigenValue, 4).IsEqualApprox(uf * uf * uf * uf));
|
||||
Assert.IsTrue(
|
||||
(
|
||||
uf * AlgebraHelper.JordanBlock4Power(eigenValue, 1.4)
|
||||
).IsEqualApprox(
|
||||
AlgebraHelper.JordanBlock4Power(eigenValue, 2.4)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
tests/LieSU3FastEigenValueTest.cs
Normal file
43
tests/LieSU3FastEigenValueTest.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Skeleton.Constants;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class LieSU3FastEigenValueTest
|
||||
{
|
||||
private static IEnumerable<Complex> FastEigen(LieSU3 a)
|
||||
{
|
||||
yield return (a[2, 3] - a[3, 2]) * Complex.ImaginaryOne;
|
||||
yield return (a[3, 1] - a[1, 3]) * Complex.ImaginaryOne;
|
||||
yield return (a[1, 2] - a[2, 1]) * Complex.ImaginaryOne;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void FastEigenTest()
|
||||
{
|
||||
LieSU3 a = new LieSU3(
|
||||
0.44879894874697296 * AlgebraConstant.I, 0, 0,
|
||||
0, 0 - 0.11636159072063412 * AlgebraConstant.I, -0.5651605390583659 + 0.3494531429928127 * AlgebraConstant.I,
|
||||
0, 0.5651605403306819 + 0.34945314093513263 * AlgebraConstant.I, 0 - 0.33243736223309456 * AlgebraConstant.I);
|
||||
|
||||
Console.WriteLine(a.PythonRepresentation);
|
||||
Console.WriteLine("===============");
|
||||
|
||||
Console.WriteLine((a + a.Hermitian()).Representation);
|
||||
Console.WriteLine("00000000000000000000");
|
||||
foreach (Complex ev in a.EigenValues())
|
||||
{
|
||||
Console.WriteLine(ev);
|
||||
}
|
||||
|
||||
Console.WriteLine("===================");
|
||||
foreach (Complex ev in FastEigen(a))
|
||||
{
|
||||
Console.WriteLine(ev);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
62
tests/LinkTest.cs
Normal file
62
tests/LinkTest.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Skeleton.DataStructure.Link;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class LinkTest
|
||||
{
|
||||
private class TestObj
|
||||
{
|
||||
public TestObj(int val) => Value = val;
|
||||
public int Value { get; set; } = 0;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Test()
|
||||
{
|
||||
Link<int> obj = new Link<int>();
|
||||
for (int i = 0; i <= 10; i++)
|
||||
obj.AddLast(i);
|
||||
int checker = 0;
|
||||
foreach (int val in obj)
|
||||
Assert.That(checker++, Is.EqualTo(val));
|
||||
|
||||
checker -= 1;
|
||||
foreach (int val in obj.Backward)
|
||||
Assert.That(checker--, Is.EqualTo(val));
|
||||
Link<TestObj> objA = new Link<TestObj>();
|
||||
for (int i = 0; i <= 10; i++)
|
||||
objA.AddLast(new TestObj(i));
|
||||
Assert.That(objA.Zip(obj).Count(x => x.First.Value - x.Second != 0), Is.EqualTo(0));
|
||||
LinkNode<TestObj> findObj = objA.Find(new TestObj(0));
|
||||
LinkNode<int> findInt = obj.Find(0);
|
||||
|
||||
Assert.That(LinkNode<TestObj>.Null, Is.EqualTo(findObj));
|
||||
Assert.That(LinkNode<int>.Null, Is.Not.EqualTo(findInt));
|
||||
findObj = objA.Find(objA.First.Value);
|
||||
Assert.That(LinkNode<TestObj>.Null, Is.Not.EqualTo(findObj));
|
||||
try
|
||||
{
|
||||
objA.Remove(findObj.Previous);
|
||||
Assert.Fail();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// pass
|
||||
}
|
||||
|
||||
objA.Remove(findObj.Next);
|
||||
objA.Remove(findObj.Next.Next);
|
||||
Assert.That(objA.Select(x => x.Value).Count(x => x==1 || x==3), Is.EqualTo(0));
|
||||
Assert.That(findInt.Value, Is.EqualTo(0));
|
||||
obj.Remove(findInt);
|
||||
obj.RemoveFirst();
|
||||
Assert.IsFalse(obj.Contains(0) || obj.Contains(1));
|
||||
Assert.That(findInt.Previous, Is.EqualTo(LinkNode<int>.Null));
|
||||
Assert.That(findInt.Next, Is.EqualTo(LinkNode<int>.Null));
|
||||
Assert.That(findInt.Parent, Is.EqualTo(Link<int>.Null));
|
||||
Assert.That(obj.Find(findInt.Value), Is.EqualTo(LinkNode<int>.Null));
|
||||
Console.WriteLine("Link Structure Test Pass");
|
||||
}
|
||||
}
|
||||
17
tests/MatrixExpLogTest.cs
Normal file
17
tests/MatrixExpLogTest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Skeleton.Constants;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class MatrixExpLogTest
|
||||
{
|
||||
[Test]
|
||||
public static void ExpTestCase0()
|
||||
{
|
||||
LieSU3 w = new LieSU3( 0.44879894874697296 * AlgebraConstant.I, 0, 0, 0,
|
||||
0 - 0.11636159072063412 * AlgebraConstant.I, -0.5651605390583659 + 0.3494531429928127 * AlgebraConstant.I,
|
||||
0, 0.5651605403306819 + 0.34945314093513263 * AlgebraConstant.I,
|
||||
0 - 0.33243736223309456 * AlgebraConstant.I);
|
||||
|
||||
w.Exp();
|
||||
}
|
||||
}
|
||||
17
tests/MiscTest.cs
Normal file
17
tests/MiscTest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class MiscTest
|
||||
{
|
||||
[Test]
|
||||
public static void LatexStringTest()
|
||||
{
|
||||
Assert.That(C33.One.LatexRepresentation,
|
||||
Is.EqualTo(@"\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}")
|
||||
);
|
||||
Console.WriteLine(C33.One.PythonRepresentation);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
66
tests/MultiplicationTest.cs
Normal file
66
tests/MultiplicationTest.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Skeleton.Constants;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class MultiplicationTest
|
||||
{
|
||||
[Test]
|
||||
public static void Dim2MultiplicationTest()
|
||||
{
|
||||
C22 a = C22.One;
|
||||
Assert.IsTrue((a*a).IsEqualApprox(a));
|
||||
C22 x = new(1, 2, 3, 4);
|
||||
Console.WriteLine((a * x).Representation);
|
||||
Assert.IsTrue((a*x).IsEqualApprox(x));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Dim3MultiplicationTest()
|
||||
{
|
||||
C33 a = C33.One;
|
||||
Assert.IsTrue((a * a).IsEqualApprox(a));
|
||||
C33 x = new (1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
Console.WriteLine((a * x).Representation);
|
||||
Assert.IsTrue((a * x).IsEqualApprox(x));
|
||||
C33 w = new C33(1, 2, 1, 0, 1, 0, 1, 2, 2);
|
||||
C33 q = x * w;
|
||||
Console.WriteLine(q.Representation);
|
||||
Assert.IsTrue(q.IsEqualApprox(new C33(4, 10, 7, 10, 25, 16, 16, 40, 25)));
|
||||
Console.WriteLine(w.Det());
|
||||
Console.WriteLine((w * w.Inv()).Representation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Dim3FatalTest()
|
||||
{
|
||||
C33 x = new C33(
|
||||
-0.06193827855776826 - 0.4250926599018542 * AlgebraConstant.I,
|
||||
0.007091160225072862 - 0.015294575102947128 * AlgebraConstant.I,
|
||||
0.003671134909589688 + 0.062258655745737884 * AlgebraConstant.I, 0,
|
||||
0.05141624933009378 + 0.4547441198263111 * AlgebraConstant.I,
|
||||
-0.03444137818239487 + 0.048372053040504 * AlgebraConstant.I, 0, 0,
|
||||
-0.08950750917735827 - 0.42794917138051874 * AlgebraConstant.I
|
||||
);
|
||||
C33 y = new C33(-0.7374752517963452,
|
||||
0.2076562987916279 - 0.4172252733550336 * AlgebraConstant.I,
|
||||
-0.485038065510323 + 0.060582677721435385 * AlgebraConstant.I,
|
||||
-0.24835727407388974 - 0.44965209824283314 * AlgebraConstant.I,
|
||||
0.08264445465163228 - 0.005898122053593788 * AlgebraConstant.I,
|
||||
0.5041613222759088 + 0.6892663653138651 * AlgebraConstant.I,
|
||||
-0.432000004242065 - 0.0750859792716085 * AlgebraConstant.I,
|
||||
-0.5195103580182339 + 0.7113691215039636 * AlgebraConstant.I,
|
||||
-0.17823093191240846 - 0.0058981220535937766 * AlgebraConstant.I);
|
||||
C33 correct = new C33(0.040128390403216 + 0.2869338899984155 * AlgebraConstant.I,
|
||||
-0.23592151696374444 - 0.09346927406396768 * AlgebraConstant.I,
|
||||
0.06962569868942127 + 0.1884924286446428 * AlgebraConstant.I,
|
||||
0.21021778660958712 - 0.15436909690665243 * AlgebraConstant.I,
|
||||
-0.009586327958581496 - 0.012351495059150161 * AlgebraConstant.I,
|
||||
-0.2810939191691945 + 0.25628563140294075 * AlgebraConstant.I,
|
||||
0.006534261732735796 + 0.1915948028305167 * AlgebraConstant.I,
|
||||
0.3509299042313585 + 0.1586511490659945 * AlgebraConstant.I,
|
||||
0.013428910328302401 + 0.07680170584013409 * AlgebraConstant.I);
|
||||
Assert.IsTrue((x* y).IsEqualApprox(correct));
|
||||
}
|
||||
|
||||
}
|
||||
142
tests/REFFTest.cs
Normal file
142
tests/REFFTest.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class REFFTest
|
||||
{
|
||||
|
||||
private static readonly Complex ii = new Complex(0, 1);
|
||||
|
||||
[Test]
|
||||
public static void M22RREFtest()
|
||||
{
|
||||
Assert.IsTrue(new R22(2, 3, 4, 5).RowReduce().ReducedForm.IsEqualApprox(R22.One));
|
||||
Assert.IsTrue(new R22(4, 8, 1, 2).RowReduce().ReducedForm.IsEqualApprox(new R22(1, 2, 0, 0)));
|
||||
Assert.IsTrue(new C22(2, 3, 4, 3 + 3 * ii).RowReduce().ReducedForm.IsEqualApprox(C22.One));
|
||||
Assert.IsTrue(new C22(1 + ii, 1, 2 + 2 * ii, 2).RowReduce().ReducedForm
|
||||
.IsEqualApprox(new C22(1, new Complex(0.5, -0.5), 0, 0)));
|
||||
}
|
||||
[Test]
|
||||
public static void M33RREFTest()
|
||||
{
|
||||
var s = new R33(
|
||||
2, 3, 4,
|
||||
0, 6, 7,
|
||||
8, 9, 0
|
||||
).RowReduce().ReducedForm.Representation;
|
||||
Assert.IsTrue(new R33(
|
||||
2, 3, 4,
|
||||
0, 6, 7,
|
||||
8, 9, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(R33.One));
|
||||
Assert.IsTrue(R33.Zero.RowReduce().ReducedForm.IsEqualApprox(R33.Zero));
|
||||
Assert.IsTrue(new C33(
|
||||
0, 2 + ii, 2 + 2 * ii,
|
||||
3 + ii, 0, 3 + 3 * ii,
|
||||
4 + 2 * ii, 2 + 6 * ii, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(C33.One)
|
||||
);
|
||||
Assert.IsTrue(new C33(
|
||||
0, 0, 2 + 2 * ii,
|
||||
3, 3 * ii, 1 + 2 * ii,
|
||||
6 + ii, 0, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(C33.One)
|
||||
);
|
||||
Console.WriteLine(
|
||||
new C33(
|
||||
0, 0, 2 + 2 * ii,
|
||||
3, 3 * ii, 1 + 2 * ii,
|
||||
0, 0, 0
|
||||
).RowReduce().ReducedForm.Representation);
|
||||
Console.WriteLine(
|
||||
new C33(
|
||||
0, 0, 2 + 2 * ii,
|
||||
3, 3 * ii, 1 + 2 * ii,
|
||||
0, 0, 0
|
||||
).Representation
|
||||
);
|
||||
Assert.IsTrue(
|
||||
new C33(
|
||||
0, 0, 2 + 2 * ii,
|
||||
3, 3 * ii, 1 + 2 * ii,
|
||||
0, 0, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(
|
||||
new C33(
|
||||
1, ii, 0,
|
||||
0, 0, 1,
|
||||
0, 0, 0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
[Test]
|
||||
public static void M44RREFTest()
|
||||
{
|
||||
Assert.IsTrue(
|
||||
new R44(
|
||||
0, 1, 0, 1,
|
||||
0, 0, 1, 0,
|
||||
1, 0, 1, 0,
|
||||
1, 1, 1, 1
|
||||
).RowReduce().ReducedForm.IsEqualApprox(
|
||||
new R44(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 1,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 0
|
||||
)
|
||||
)
|
||||
);
|
||||
Assert.IsTrue(
|
||||
new R44(
|
||||
0, 1, 0, 1,
|
||||
1, 0, 1, 0,
|
||||
0, 0, 1, 1,
|
||||
1, 1, 0, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(
|
||||
new R44(
|
||||
1, 0, 0, -1,
|
||||
0, 1, 0, 1,
|
||||
0, 0, 1, 1,
|
||||
0, 0, 0, 0
|
||||
)
|
||||
)
|
||||
);
|
||||
Assert.IsTrue(
|
||||
new R44(
|
||||
0, 1, 0, 1,
|
||||
1, 0, 1, 0,
|
||||
0, 0, 1, 1,
|
||||
1, 0, 1, 1
|
||||
).RowReduce().ReducedForm.IsEqualApprox(R44.One)
|
||||
);
|
||||
Assert.IsTrue(
|
||||
new C44(
|
||||
0, 1, 0, 1 + ii,
|
||||
1, 0, 1, 0,
|
||||
0, 0, 1, 1 + ii,
|
||||
1, 0, 1, 1
|
||||
).RowReduce().ReducedForm.IsEqualApprox(C44.One)
|
||||
);
|
||||
Assert.IsTrue(
|
||||
new C44(
|
||||
0, 1, 0, 1 + ii,
|
||||
1, 0, 1, 0,
|
||||
0, 0, 1, 1 + ii,
|
||||
1, 1, 0, 0
|
||||
).RowReduce().ReducedForm.IsEqualApprox(
|
||||
new C44(
|
||||
1, 0, 0, -1 - ii,
|
||||
0, 1, 0, 1 + ii,
|
||||
0, 0, 1, 1 + ii,
|
||||
0, 0, 0, 0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
35
tests/SUTestFix.cs
Normal file
35
tests/SUTestFix.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Constants;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class SUTestFix
|
||||
{
|
||||
[Test]
|
||||
public static void Dim2Test()
|
||||
{
|
||||
SU2 x = new SU2(
|
||||
-0.46729917700515705 - 0.4990694206607689 * AlgebraConstant.I,
|
||||
0.31791136143046506 - 0.5640806336119782 * AlgebraConstant.I,
|
||||
-0.25266772613116484 - 0.5961657614408675 * AlgebraConstant.I,
|
||||
-0.5330307462242154 + 0.669854044098976 * AlgebraConstant.I
|
||||
);
|
||||
|
||||
U2 y = new(
|
||||
-0.46729917700515705 - 0.4990694206607689 * AlgebraConstant.I,
|
||||
0.31791136143046506 - 0.5640806336119782 * AlgebraConstant.I,
|
||||
-0.25266772613116484 - 0.5961657614408675 * AlgebraConstant.I,
|
||||
-0.5330307462242154 + 0.669854044098976 * AlgebraConstant.I
|
||||
);
|
||||
Console.WriteLine(y.Det());
|
||||
Assert.IsTrue((x.U * x.U.Hermitian()).IsEqualApprox(C22.One));
|
||||
Assert.IsTrue(x.D.Det().IsEqualApprox(1));
|
||||
Console.WriteLine(x.D.PythonRepresentation);
|
||||
Assert.IsTrue((x.D * x.D.Hermitian()).IsEqualApprox(C22.One));
|
||||
Console.WriteLine((x * x.Hermitian()).Representation);
|
||||
U2 s = new(Complex.ImaginaryOne, 0, 0, 1);
|
||||
Console.WriteLine(s.Representation);
|
||||
}
|
||||
}
|
||||
332
tests/UnitaryMatrixFixTest.cs
Normal file
332
tests/UnitaryMatrixFixTest.cs
Normal file
@@ -0,0 +1,332 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Constants;
|
||||
using Skeleton.DataStructure.Packs.MatrixDecompositions;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class UnitaryMatrixFixTest
|
||||
{
|
||||
private static Complex I = Complex.ImaginaryOne;
|
||||
[DatapointSource]
|
||||
public static readonly ((SU2, SU3), SU4)[] DataSource =
|
||||
20.ScaleSamples(-1, 1).SU2U2FixSamples()
|
||||
.Zip(20.ScaleSamples(-1, 1).SU3U3FixSamples())
|
||||
.Zip(20.ScaleSamples(-1, 1).SU4U4FixSamples())
|
||||
.ToArray();
|
||||
public static readonly Action<((SU2, SU3), SU4 )> TheoryOnFail = data =>
|
||||
{
|
||||
Console.WriteLine("SU2 : ");
|
||||
Console.WriteLine(data.Item1.Item1.CSharpRepresentation);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("SU3 : ");
|
||||
Console.WriteLine(data.Item1.Item2.CSharpRepresentation);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("SU4 : ");
|
||||
Console.WriteLine(data.Item2.CSharpRepresentation);
|
||||
};
|
||||
|
||||
[Theory]
|
||||
public static void SUInverseTest(((SU2, SU3), SU4) data)
|
||||
{
|
||||
Action<((SU2, SU3), SU4)> rawTest = x =>
|
||||
{
|
||||
Assert.IsTrue((data.Item1.Item1 * data.Item1.Item1.Hermitian()).IsEqualApprox(SU2.One));
|
||||
Assert.IsTrue((data.Item1.Item2 * data.Item1.Item2.Hermitian()).IsEqualApprox(SU3.One));
|
||||
Assert.IsTrue((data.Item2 * data.Item2.Hermitian()).IsEqualApprox(SU4.One));
|
||||
Assert.IsTrue(data.Item1.Item1.Det().IsEqualApprox(1));
|
||||
Assert.IsTrue(data.Item1.Item2.Det().IsEqualApprox(1));
|
||||
Assert.IsTrue(data.Item2.Det().IsEqualApprox(1));
|
||||
};
|
||||
rawTest.OnFail(TheoryOnFail)(data);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void SUDetTest(((SU2, SU3), SU4 ) data)
|
||||
{
|
||||
Action<((SU2, SU3), SU4 )> rawTest = x =>
|
||||
{
|
||||
Assert.IsTrue(x.Item1.Item1.Det().IsEqualApprox(1));
|
||||
Assert.IsTrue(x.Item1.Item2.Det().IsEqualApprox(1));
|
||||
Assert.IsTrue(x.Item2.Det().IsEqualApprox(1));
|
||||
};
|
||||
rawTest.OnFail(TheoryOnFail)(data);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestCaseLog1()
|
||||
{
|
||||
SU3 w = new SU3(
|
||||
-0.43414368119414704 - 0.3030219371303422 * AlgebraConstant.I,
|
||||
-0.6127418264307304 + 0.25286635508954525 * AlgebraConstant.I,
|
||||
-0.43414368119414704 - 0.3030219371303422 * AlgebraConstant.I,
|
||||
0.046987016855900565 - 0.8467871869515173 * AlgebraConstant.I,
|
||||
0.32615156205229123 + 0.22966067483645397 * AlgebraConstant.I,
|
||||
-0.02528492855010553 + 0.3478296790879847 * AlgebraConstant.I,
|
||||
-0.00045687263698370763 + 0.020986691642148985 * AlgebraConstant.I,
|
||||
-0.3933715253014944 - 0.49673537894189806 * AlgebraConstant.I,
|
||||
-0.25733749617914226 + 0.7292801721498984 * AlgebraConstant.I
|
||||
);
|
||||
Console.WriteLine(w.PythonRepresentation);
|
||||
foreach (Complex e in w.EigenValues())
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void SULogTestWithInfo(((SU2, SU3), SU4) data)
|
||||
{
|
||||
|
||||
Action<((SU2, SU3), SU4)> rawTest = x =>
|
||||
{
|
||||
SU2 su2 = x.Item1.Item1;
|
||||
SU3 su3 = x.Item1.Item2;
|
||||
SU4 su4 = x.Item2;
|
||||
LieSU2 lsu2 = su2.Log();
|
||||
LieSU3 lsu3 = su3.Log();
|
||||
LieSU4 lsu4 = su4.Log();
|
||||
Assert.IsTrue((lsu2 + lsu2.Hermitian()).IsEqualApprox(LieSU2.Zero));
|
||||
Assert.IsTrue((lsu3 + lsu3.Hermitian()).IsEqualApprox(LieSU3.Zero));
|
||||
Assert.IsTrue((lsu4 + lsu4.Hermitian()).IsEqualApprox(LieSU4.Zero));
|
||||
Assert.IsTrue(lsu2.Exp().IsEqualApprox(su2));
|
||||
Assert.IsTrue(lsu3.Exp().IsEqualApprox(su3));
|
||||
Assert.IsTrue(lsu4.Exp().IsEqualApprox(su4));
|
||||
JDPair<C22> su2jd = su2.EigenDecomposition();
|
||||
JDPair<C33> su3jd = su3.EigenDecomposition();
|
||||
JDPair<C44> su4jd = su4.EigenDecomposition();
|
||||
Assert.IsTrue(su2jd.J.Property.IsUnitary);
|
||||
Assert.IsTrue(su2jd.D.Property.IsDiagonal);
|
||||
Assert.IsTrue(su3jd.J.Property.IsUnitary);
|
||||
Assert.IsTrue(su3jd.D.Property.IsDiagonal);
|
||||
Assert.IsTrue(su4jd.J.Property.IsUnitary);
|
||||
Assert.IsTrue(su4jd.D.Property.IsDiagonal);
|
||||
};
|
||||
rawTest.OnFail(TheoryOnFail)(data);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void Test()
|
||||
{
|
||||
Complex I = Complex.ImaginaryOne;
|
||||
U4 a = new U4
|
||||
(
|
||||
1 - I, 2, 2 - I, 1,
|
||||
0.5 - 0.2 * I, 0.3 + 0.6 * I, 0, 0.5 - I,
|
||||
1, 0.5 * I, 0.2, 1,
|
||||
-1, 0.17, -I, 0.5
|
||||
);
|
||||
Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C44.One));
|
||||
|
||||
C22 detTest = new C22(
|
||||
-0.5248906591678238 - 0.46656947481584343 * I, -0.5832118435198043 - 0.40824829046386296 * I,
|
||||
-0.20478420312558956 + 0.6818109351122588 * I, 0.12287052187535442 - 0.6914478387887567 * I
|
||||
);
|
||||
|
||||
Complex det = detTest.Det();
|
||||
Console.WriteLine(det);
|
||||
SU2 s = new SU2(detTest);
|
||||
Assert.IsTrue(s.IsEqualApprox(detTest));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void SpecialUnitary3FixTest1()
|
||||
{
|
||||
C33 a = new C33(
|
||||
-0.8344241263333791 + 0.14125364989618228 * I,
|
||||
0.3979647225046099 + 0.10267910479132439 * I,
|
||||
-0.2695958755702797 - 0.20538483084288184 * I,
|
||||
0.10270407527842709 + 0.23498654396460977 * I,
|
||||
-0.46971624837084525 + 0.009803966198906888 * I,
|
||||
-0.2762868099299291 - 0.7982288669289679 * I,
|
||||
-0.1566381273590656 + 0.43986529519615497 * I,
|
||||
-0.32271904441622734 + 0.711480166775819 * I,
|
||||
0.3738133333164022 + 0.17859171769725135 * I
|
||||
);
|
||||
Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One));
|
||||
SU3 x = new SU3(a);
|
||||
Assert.IsTrue(x.IsEqualApprox(a));
|
||||
Assert.IsTrue(C33.One.IsEqualApprox(SU3.One));
|
||||
}
|
||||
[Test]
|
||||
public static void SpecialUnitary3FixTest2()
|
||||
{
|
||||
C33 a = new C33(
|
||||
0.6061825098286314+ 0.10783196232158024*I, 0.6061825098286314+ 0.10783196232158024*I, -0.4498631268405351+ -0.19862837780320783*I,
|
||||
-0.6568857886321278+ -0.22500493921050202*I, 0.47985711358680355+ -0.14696145689209753*I, -0.10472054107867565+ -0.5050217094625823*I,
|
||||
0.23603845886157196+ 0.2882268492733082*I, 0.2598386072534029+ -0.5491251329056467*I, 0.6806580836521512+ -0.16988581178893247*I
|
||||
);
|
||||
Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One));
|
||||
SU3 x = new (a);
|
||||
Assert.IsTrue(x.IsEqualApprox(a));
|
||||
Assert.IsTrue(C33.One.IsEqualApprox(SU3.One));
|
||||
SU3 w = x * x.Hermitian();
|
||||
Assert.IsTrue(w.IsEqualApprox(SU3.One));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public static void SU3LogTest()
|
||||
{
|
||||
SU3 su3 = new SU3(
|
||||
0.43880880579145365 + 0.4826787201166997 * I,
|
||||
-0.18868449661415526 + 0.08337476972576609 * I,
|
||||
-0.6187083532866604 + 0.386153942347259 * I,
|
||||
0.229915402311903 + 0.45786532090422916 * I,
|
||||
-0.5044885559677506 -0.35535447248372876 * I,
|
||||
0.5951789213359455 -0.049747392633063936 * I,
|
||||
-0.5575061719574842 -0.03395893150141599 * I,
|
||||
-0.6042388381998404 + 0.4599529657529451 * I,
|
||||
0.03170390883139444 + 0.33221561834354146 * I
|
||||
);
|
||||
var s = su3.EigenValues();
|
||||
foreach (var ww in s)
|
||||
{
|
||||
Console.WriteLine(ww);
|
||||
}
|
||||
su3.Log();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void SU3LogTest2()
|
||||
{
|
||||
SU3 su3 = new SU3(
|
||||
0.4937714754442013 - 0.4646561845580912 * AlgebraConstant.I,
|
||||
-0.14614611621330553 + 0.41587751673335 * AlgebraConstant.I,
|
||||
-0.012919030698169187 + 0.588051581603912 * AlgebraConstant.I,
|
||||
0.13505669912495313 - 0.4703431006220462 * AlgebraConstant.I,
|
||||
0.15249862197642505 + 0.29511683029437247 * AlgebraConstant.I,
|
||||
-0.45478294858532825 - 0.6658526504918636 * AlgebraConstant.I,
|
||||
0.5188919616439376 + 0.17768665692615007 * AlgebraConstant.I,
|
||||
0.808792602160577 - 0.20295801845230327 * AlgebraConstant.I,
|
||||
0.03656022128630781 + 0.05004501720898871 * AlgebraConstant.I
|
||||
);
|
||||
|
||||
|
||||
JDPair<C33> m = su3.EigenDecomposition();
|
||||
|
||||
JDPair<C33> m2 = new C33(su3).EigenDecomposition();
|
||||
|
||||
Assert.IsTrue((m2.J * m2.D * m2.J.Inv()).IsEqualApprox(su3));
|
||||
|
||||
Assert.IsTrue((3*m2.J * m2.D* (3*m2.J).Inv()).IsEqualApprox(su3));
|
||||
|
||||
Assert.IsTrue((m2.J * m2.D * m2.J.Hermitian()).IsEqualApprox(su3));
|
||||
LieSU3 liesu3 = su3.Log();
|
||||
Assert.IsTrue((liesu3 + liesu3.Hermitian()).IsEqualApprox(C33.Zero));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void SU4LogTest()
|
||||
{
|
||||
SU4 su4 = new SU4(0.45072482088586524 + 0.27865646969165264 * AlgebraConstant.I,
|
||||
0.07667985664042455 + 0.09190673071148733 * AlgebraConstant.I,
|
||||
-0.5332772326406708 + 0.07080730152604346 * AlgebraConstant.I,
|
||||
0.5274046775262898 + 0.37056320040313995 * AlgebraConstant.I,
|
||||
-0.4623957942103865 + 0.31861769835507636 * AlgebraConstant.I,
|
||||
0.6026572282164275 + 0.47186229531018825 * AlgebraConstant.I,
|
||||
0.0191713535917341 + 0.1346996762038341 * AlgebraConstant.I,
|
||||
0.1996150097908485 - 0.2011602237839163 * AlgebraConstant.I,
|
||||
0.04582996729252195 - 0.5319939115492593 * AlgebraConstant.I,
|
||||
0.4960154168100462 + 0.006509621425514242 * AlgebraConstant.I,
|
||||
-0.5376174494271012 - 0.25702509390564265 * AlgebraConstant.I,
|
||||
-0.33718335844444186 - 0.004624418942781844 * AlgebraConstant.I,
|
||||
0.07929681587672294 - 0.3353575803409654 * AlgebraConstant.I,
|
||||
0.38838405973345197 - 0.0539235128607073 * AlgebraConstant.I,
|
||||
0.5740544383528434 - 0.0863554086982751 * AlgebraConstant.I,
|
||||
0.25288029939241385 + 0.571448321880945 * AlgebraConstant.I
|
||||
);
|
||||
|
||||
LieSU4 logsu4 = su4.Log();
|
||||
JDPair<C44> jd = logsu4.EigenDecomposition();
|
||||
Assert.IsTrue((jd.J * jd.J.Hermitian()).IsEqualApprox(C44.One));
|
||||
Assert.IsTrue((jd.J * jd.D * jd.J.Hermitian()).IsEqualApprox(logsu4));
|
||||
//Assert.IsTrue((jd.J * jd.D.Cast<DiagC4>().Exp() * jd.J.Hermitian()).IsEqualApprox(su4));
|
||||
SU4 reSu4 = logsu4.Exp();
|
||||
Console.WriteLine(logsu4.Representation);
|
||||
C44 diff = su4 - reSu4;
|
||||
Console.WriteLine(diff.Representation);
|
||||
Assert.IsTrue(diff.IsEqualApprox(C44.Zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void SU3LogTest1()
|
||||
{
|
||||
SU3 x = new SU3(-0.5096864513722845 + 0.35895029419766383 * AlgebraConstant.I,
|
||||
-0.1025054220036705 + 0.5278183063575951 * AlgebraConstant.I,
|
||||
-0.14481308363606185 - 0.5489116981121851 * AlgebraConstant.I,
|
||||
-0.7192720743250333 + 0.06808924629719765 * AlgebraConstant.I,
|
||||
-0.006404658955073139 - 0.38316562727295783 * AlgebraConstant.I,
|
||||
-0.3681608010982957 + 0.4422807305204407 * AlgebraConstant.I,
|
||||
0.013691228875589531 + 0.29866117168064876 * AlgebraConstant.I,
|
||||
0.11264521695659047 - 0.7425325659192611 * AlgebraConstant.I,
|
||||
0.10301124567873082 - 0.5796198596425894 * AlgebraConstant.I);
|
||||
var y = x.Log();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void SU4LogTest1()
|
||||
{
|
||||
SU4 a = new(
|
||||
-0.31253198215981287 - 0.02457353062456953 * AlgebraConstant.I,
|
||||
-0.5267358593447475 + 0.10009306644137611 * AlgebraConstant.I,
|
||||
-0.035129316946956535 - 0.553074351435815 * AlgebraConstant.I,
|
||||
-0.035129316946956535 - 0.553074351435815 * AlgebraConstant.I,
|
||||
-0.5484569859172659 - 0.27914026415033194 * AlgebraConstant.I,
|
||||
0.38962143155247475 - 0.43104340756555526 * AlgebraConstant.I,
|
||||
-0.4851039108678516 - 0.19592876498814477 * AlgebraConstant.I,
|
||||
0.005614822340410733 + 0.09963411503559771 * AlgebraConstant.I,
|
||||
0.07823740825921774 + 0.561524042062162 * AlgebraConstant.I,
|
||||
0.06321304712372701 - 0.009482901116921749 * AlgebraConstant.I,
|
||||
-0.01069113674146091 - 0.6055208814017898 * AlgebraConstant.I,
|
||||
0.3173675882181361 + 0.45496353603884643 * AlgebraConstant.I,
|
||||
0.02943925931373012 + 0.44799390330075195 * AlgebraConstant.I,
|
||||
0.5783329903883969 - 0.19071594293121222 * AlgebraConstant.I,
|
||||
0.22752926448976618 - 0.02492795956249927 * AlgebraConstant.I,
|
||||
-0.0926951657537998 - 0.6054831218418562 * AlgebraConstant.I
|
||||
);
|
||||
var lsu4 = a.Log();
|
||||
var su4re = lsu4.Exp();
|
||||
Console.WriteLine(a.PythonRepresentation);
|
||||
Console.WriteLine(lsu4.PythonRepresentation);
|
||||
Assert.IsTrue(a.IsEqualApprox(su4re));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void JordanDecompositionTest()
|
||||
{
|
||||
SU3 w = new (
|
||||
0.1036048648622136 + 0.5408740338576743 * AlgebraConstant.I,
|
||||
0.4432415500820873 + 0.4151980097462197 * AlgebraConstant.I,
|
||||
0.01869569355724507 + 0.5722930398855379 * AlgebraConstant.I,
|
||||
-0.4032232290278416 + 0.3341725890039726 * AlgebraConstant.I,
|
||||
-0.136458135263608 + 0.25227653117517135 * AlgebraConstant.I,
|
||||
0.7247389557561302 - 0.3438442721332704 * AlgebraConstant.I,
|
||||
0.6109251580048909 - 0.2218816601768873 * AlgebraConstant.I,
|
||||
-0.4598461047916449 + 0.5808828023191596 * AlgebraConstant.I,
|
||||
0.16688553120192343 + 0.0283712803216739 * AlgebraConstant.I);
|
||||
var jd = w.EigenDecomposition();
|
||||
Assert.IsTrue(jd.J.Property.IsUnitary);
|
||||
Console.WriteLine(jd.D.PythonRepresentation);
|
||||
Console.WriteLine(jd.D.PythonRepresentation);
|
||||
Console.WriteLine((jd.J * w * jd.J.Hermitian()).PythonRepresentation);
|
||||
Assert.IsTrue((jd.J.Hermitian() * w * jd.J).IsEqualApprox(jd.D));
|
||||
Assert.IsTrue((jd.J * jd.D * jd.J.Hermitian()).IsEqualApprox(w));
|
||||
Assert.IsTrue(jd.D.Property.IsDiagonal);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void LieAdditionFixTest()
|
||||
{
|
||||
LieU2 x = new(-5 * Complex.ImaginaryOne, 0, 0, 8 * Complex.ImaginaryOne);
|
||||
Console.WriteLine(x.Representation);
|
||||
}
|
||||
}
|
||||
|
||||
73
tests/UnitaryTest.cs
Normal file
73
tests/UnitaryTest.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Skeleton.Constants;
|
||||
using Skeleton.Samples;
|
||||
using Skeleton.Utils;
|
||||
using Skeleton.Utils.Helpers;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
public static class UnitaryTest
|
||||
{
|
||||
[DatapointSource]
|
||||
public static readonly (((U2, U3), U4),((U2, U3), U4))[] DataSource =
|
||||
20.ScaleSamples(-1, 1).U2FixSamples()
|
||||
.Zip(20.ScaleSamples(-1, 1).U3FixSamples())
|
||||
.Zip(20.ScaleSamples(-1, 1).U4FixSamples())
|
||||
.ShuffleZip()
|
||||
.ToArray();
|
||||
|
||||
private static readonly Action<(((U2, U3), U4), ((U2, U3), U4))> OnFail = data =>
|
||||
{
|
||||
Console.WriteLine("U2a");
|
||||
Console.WriteLine(data.Item1.Item1.Item1.CSharpRepresentation);
|
||||
Console.WriteLine("U2b");
|
||||
Console.WriteLine(data.Item2.Item1.Item1.CSharpRepresentation);
|
||||
|
||||
Console.WriteLine("U3a");
|
||||
Console.WriteLine(data.Item1.Item1.Item2.CSharpRepresentation);
|
||||
Console.WriteLine("U3b");
|
||||
Console.WriteLine(data.Item2.Item1.Item2.CSharpRepresentation);
|
||||
|
||||
Console.WriteLine("U4a");
|
||||
Console.WriteLine(data.Item1.Item2.CSharpRepresentation);
|
||||
Console.WriteLine("U4b");
|
||||
Console.WriteLine(data.Item2.Item2.CSharpRepresentation);
|
||||
};
|
||||
[Theory]
|
||||
public static void UnitarySumTest((((U2, U3), U4),((U2, U3), U4)) data)
|
||||
{
|
||||
Action<(((U2, U3), U4),((U2, U3), U4))> RawTest = x =>
|
||||
{
|
||||
U2 u2a = x.Item1.Item1.Item1;
|
||||
U2 u2b = x.Item2.Item1.Item1;
|
||||
U3 u3a = x.Item1.Item1.Item2;
|
||||
U3 u3b = x.Item2.Item1.Item2;
|
||||
U4 u4a = x.Item1.Item2;
|
||||
U4 u4b = x.Item2.Item2;
|
||||
|
||||
C22 usum2 = (u2a + u2b) / 2;
|
||||
C33 usum3 = (u3a + u3b) / 2;
|
||||
C44 usum4 = (u4a + u4b) / 2;
|
||||
|
||||
};
|
||||
RawTest.OnFail(OnFail)(data);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestCase1()
|
||||
{
|
||||
U2 a =
|
||||
new U2(0.0062267406142450105 + 0.20498679086126248 * AlgebraConstant.I,
|
||||
-0.6788633254166565 + 0.7050434232570095 * AlgebraConstant.I,
|
||||
0.291888812926916 + 0.9342069172093728 * AlgebraConstant.I,
|
||||
0.09724224588774737 - 0.18056107648378417 * AlgebraConstant.I);
|
||||
U2 b =
|
||||
new U2(-0.1507802507678838 + 0.6503988948104069 * AlgebraConstant.I,
|
||||
0.6289570055207475 - 0.39832107503137504 * AlgebraConstant.I,
|
||||
0.12334244229189144 - 0.7341888282569051 * AlgebraConstant.I,
|
||||
0.5410827924876593 - 0.3911301804591161 * AlgebraConstant.I);
|
||||
C22 j = (a + b)/2;
|
||||
Console.WriteLine((j * j.Hermitian()).Representation);
|
||||
}
|
||||
}
|
||||
41
tests/Usings.cs
Normal file
41
tests/Usings.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
global using NUnit.Framework;
|
||||
global using C2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<System.Numerics.Complex>.FVector;
|
||||
global using C3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<System.Numerics.Complex>.FVector;
|
||||
global using C4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<System.Numerics.Complex>.FVector;
|
||||
|
||||
global using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
|
||||
global using R3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<double>.FVector;
|
||||
global using R4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<double>.FVector;
|
||||
|
||||
global using C22 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<System.Numerics.Complex>.FMatrix;
|
||||
global using C33 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<System.Numerics.Complex>.FMatrix;
|
||||
global using C44 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<System.Numerics.Complex>.FMatrix;
|
||||
|
||||
global using R22 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FMatrix;
|
||||
global using R33 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<double>.FMatrix;
|
||||
global using R44 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<double>.FMatrix;
|
||||
|
||||
global using U2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.FUnitaryMatrix;
|
||||
global using U3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.FUnitaryMatrix;
|
||||
global using U4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.FUnitaryMatrix;
|
||||
|
||||
global using SU2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.FSpecialUnitaryMatrix;
|
||||
global using SU3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.FSpecialUnitaryMatrix;
|
||||
global using SU4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.FSpecialUnitaryMatrix;
|
||||
|
||||
global using LieU2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.FLieUnitaryMatrix;
|
||||
global using LieU3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.FLieUnitaryMatrix;
|
||||
global using LieU4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.FLieUnitaryMatrix;
|
||||
|
||||
global using LieSU2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.FSpecialLieUnitaryMatrix;
|
||||
global using LieSU3 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.FSpecialLieUnitaryMatrix;
|
||||
global using LieSU4 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.FSpecialLieUnitaryMatrix;
|
||||
|
||||
global using C2Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<System.Numerics.Complex>.FVectorSpace;
|
||||
global using C3Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<System.Numerics.Complex>.FVectorSpace;
|
||||
global using C4Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<System.Numerics.Complex>.FVectorSpace;
|
||||
|
||||
global using R2Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVectorSpace;
|
||||
global using R3Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim3>.OnField<double>.FVectorSpace;
|
||||
global using R4Space = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim4>.OnField<double>.FVectorSpace;
|
||||
|
||||
110
tests/VectorSpaceTest.cs
Normal file
110
tests/VectorSpaceTest.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace SkeletonTest.tests;
|
||||
|
||||
/// <summary>
|
||||
/// test for vector spaces
|
||||
/// </summary>
|
||||
public static class VectorSpaceTest
|
||||
{
|
||||
private static readonly Complex ii = new Complex(0, 1);
|
||||
[Test]
|
||||
public static void Dim2Test()
|
||||
{
|
||||
R2Space r2a = new R2Space(new List<R2>() { new R2(3, 2) });
|
||||
Assert.IsTrue(r2a.Rank == 1);
|
||||
Assert.IsTrue(r2a.ContainsVector(new R2(9, 6)));
|
||||
Assert.IsTrue(!r2a.ContainsVector(new R2(1,0)));
|
||||
R2Space r2ac = r2a.OrthogonalComplementSpace;
|
||||
Assert.IsTrue(r2ac.ContainsVector(new R2(2, -3)));
|
||||
C2Space c2a = new C2Space(new List<C2>() { new C2(1 - ii, 1 + ii) });
|
||||
Assert.IsTrue(c2a.Rank == 1);
|
||||
Assert.IsTrue(c2a.ContainsVector(new C2(2 - 2 * ii, 2 + 2 * ii)));
|
||||
Assert.IsTrue(!c2a.ContainsVector(new C2(1 + ii, 0)));
|
||||
C2Space c2ac = c2a.OrthogonalComplementSpace;
|
||||
Assert.IsTrue(c2ac.ContainsVector(new C2(ii, 1)));
|
||||
}
|
||||
[Test]
|
||||
public static void Dim3Test()
|
||||
{
|
||||
R3Space r3a = new R3Space(new List<R3>() { new R3(1, 1, 1), new R3(1, 1, 0) });
|
||||
Assert.IsTrue(r3a.Rank == 2);
|
||||
Assert.IsTrue(r3a.ContainsVector(new R3(2,2,1)));
|
||||
Assert.IsTrue(r3a.ContainsVector(new R3(3,3,3)));
|
||||
Assert.IsTrue(r3a.OrthogonalComplementSpace.ContainsVector(new R3(-2, 2, 0)));
|
||||
C3Space c3a = new C3Space(new List<C3>() { new C3(1 + ii, 1 - ii, ii), new C3(1, 0, 1) });
|
||||
Assert.IsTrue(c3a.Rank == 2);
|
||||
Assert.IsTrue(c3a.OrthogonalComplementSpace.Rank == 1);
|
||||
Assert.IsTrue(c3a.ContainsVector(new C3(2 + ii, 1 - ii, 1 + ii)));
|
||||
Assert.IsTrue(c3a.OrthogonalComplementSpace.ContainsVector(new C3(-2, 1-ii, 2)));
|
||||
}
|
||||
[Test]
|
||||
public static void Dim4Test()
|
||||
{
|
||||
|
||||
R4Space r4a = new R4Space(new List<R4>() { new R4(1, 1, 0, 0), new R4(0, 1, 0, 1) });
|
||||
Assert.IsTrue(r4a.Rank==2);
|
||||
Assert.IsTrue(r4a.OrthogonalComplementSpace.Rank==2);
|
||||
Assert.IsTrue(r4a.ContainsVector(new R4(1, 0, 0, -1)));
|
||||
Assert.IsTrue(r4a.OrthogonalComplementSpace.ContainsVector(new R4(0, 0, 1, 0)));
|
||||
Assert.IsTrue(r4a.OrthogonalComplementSpace.ContainsVector(new R4(1,-1,0,1)));
|
||||
C44 a = new C44(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, ii,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
C44 b = new C44(
|
||||
ii, 1, -1, -ii,
|
||||
1, -1, 0, 0,
|
||||
ii, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
);
|
||||
C4Space c4a = new C4Space(new List<C4>()
|
||||
{
|
||||
new C4(ii, 1, -1, -ii),
|
||||
new C4(1, -1, 0, 0),
|
||||
new C4(ii, 0, 0, 0)
|
||||
});
|
||||
Assert.IsTrue(c4a.Rank == 3);
|
||||
Assert.IsTrue(c4a.OrthogonalComplementSpace.Rank == 1);
|
||||
Assert.IsTrue(c4a.ContainsVector(new C4(1+ii,-1,0,0)));
|
||||
Assert.IsTrue(c4a.ContainsVector(new C4(1+ii,0,-1, -ii)));
|
||||
Assert.IsTrue(c4a.ContainsVector(new C4(1+2*ii,0,-1, -ii)));
|
||||
Assert.IsTrue(c4a.OrthogonalComplementSpace.ContainsVector(new C4(0, 0, ii, 1)));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void ContainsVectorTest()
|
||||
{
|
||||
C3Space c3s = new (new C3[] { new(1, 4, 2), new(2, 4, 1) });
|
||||
Assert.IsFalse(c3s.ContainsVector(new (0.62469505d, -0.46852129, 0.62469505)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void UnionTest()
|
||||
{
|
||||
C3Space c3s1 = new (new C3[] { new(1, 4, 2) });
|
||||
C3Space c3s2 = new(new C3[] { new(2, 4, 1) });
|
||||
C3Space union = c3s1.UnionWith(c3s2);
|
||||
Assert.That(union.Rank, Is.EqualTo(2));
|
||||
Assert.IsTrue(union.ContainsVector(new(1, 4, 2)));
|
||||
Assert.IsTrue(union.ContainsVector(new(2, 4, 1)));
|
||||
Assert.IsTrue(union.ContainsVector(new (3, 8, 3)));
|
||||
Assert.IsFalse(union.ContainsVector(new(0.62469505d, -0.46852129, 0.62469505)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void OrthogonalComplementTest()
|
||||
{
|
||||
C3Space space = new(new C3[] { new(1, -3d/4d, 1) });
|
||||
C3Space otcSpace = space.OrthogonalComplementSpace;
|
||||
Assert.IsTrue(otcSpace.ContainsVector(new(1, 4, 2)));
|
||||
Assert.IsTrue(otcSpace.ContainsVector(new(2, 4, 1)));
|
||||
Assert.That(otcSpace.Rank, Is.EqualTo(2));
|
||||
Assert.IsFalse(otcSpace.ContainsVector(new(0.62469505d, -0.46852129, 0.62469505)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user