This commit is contained in:
h z
2024-06-21 21:59:13 +08:00
commit 614bc59897
28 changed files with 2049 additions and 0 deletions

View 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);
}
}