def test_1031_subs(): t, x, y, z = sp.symbols("t x y z") q_sym = QHStates([QH([t, x, y, x * y * z])]) q_z = q_sym.subs({t: 1, x: 2, y: 3, z: 4}) print("t x y xyz sub 1 2 3 4: ", q_z) assert q_z.equals(QHStates([QH([1, 2, 3, 24])]))
def test_1472_Lorentz_next_boost(): with pytest.raises(ValueError): QH.Lorentz_next_boost(Q, q4321) next_boost = QH.Lorentz_next_boost(Q, q1324) print(f"next_boost: {next_boost}") assert next_boost.t != 0 boost = q2244.rotation_and_or_boost(next_boost) assert math.isclose(boost.square().t, q2244.square().t)
def test_1130_identity(): I2 = QHStates().identity(2, operator=True) print("Operator Idenity, diagonal 2x2", I2) assert I2.qs[0].equals(QH().q_1()) assert I2.qs[1].equals(QH().q_0()) I2 = QHStates().identity(2) print("Idenity on 2 state ket", I2) assert I2.qs[0].equals(QH().q_1()) assert I2.qs[1].equals(QH().q_1())
def test_1471_Lorentz_next_rotation(): with pytest.raises(ValueError): QH.Lorentz_next_rotation(Q, q4321) next_rotation = QH.Lorentz_next_rotation(Q, q1324) print("next_rotation: ", next_rotation) assert next_rotation.t == 0 rot = q2244.rotation_and_or_boost(next_rotation) assert math.isclose(rot.t, 2) assert math.isclose(rot.square().t, q2244.square().t) next_rotation = QH.Lorentz_next_rotation(Q, Q) assert next_rotation.equals(Q.vector().normalize())
def test_1570_ln(): assert Q.ln().exp().equals(Q) assert Q.ln().equals( QH([ 1.7005986908310777, -0.5151902926640850, -0.7727854389961275, -1.0303805853281700, ])) assert P.ln().equals( QH([1.6094379124341003, 1.2566370614359172, -0.9424777960769379, 0])) assert R.ln().equals(QH([1.0986122886681098, 0, 0, 0])) assert C.ln().equals(QH([1.4978661367769954, 1.1071487177940904, 0, 0]))
def test_1100_q_random(): q_z = QH().q_random() print("q_random():", q_z) assert -1 <= q_z.t <= 1 assert -1 <= q_z.x <= 1 assert -1 <= q_z.y <= 1 assert -1 <= q_z.z <= 1
def test_1060_q_1(): q_z: QH = QH.q_1() print("q_1: ", q_z) assert q_z.t == 1 assert q_z.x == 0 assert q_z.y == 0 assert q_z.z == 0
def test_1460_rotate(): q_z = Q.rotate(QH([0, 1, 0, 0])) print("rotate: ", q_z) assert q_z.t == 1 assert q_z.x == -2 assert q_z.y == 3 assert q_z.z == 4
def test_1580_q_2_q(): assert Q.q_2_q(P).equals( QH([ -0.0197219653530713, -0.2613955437374326, 0.6496281248064009, -0.3265786562423951, ]))
def test_1470_rotation_and_or_boost(): q1_sq = Q.square() beta: float = 0.003 gamma = 1 / math.sqrt(1 - beta**2) h = QH([gamma, gamma * beta, 0, 0]) q_z = Q.rotation_and_or_boost(h) q_z2 = q_z.square() print("q1_sq: ", q1_sq) print("boosted: ", q_z) print("boosted squared: ", q_z2) assert round(q_z2.t, 5) == round(q1_sq.t, 5)
def test_1304_rotation_and_or_boost(): q1_sq = Q_states.square() beta = 0.003 gamma = 1 / math.sqrt(1 - beta**2) h = QHStates([QH([gamma, gamma * beta, 0, 0])]) q_z = Q_states.rotation_and_or_boost(h) q_z2 = q_z.square() print("q1_sq: ", q1_sq) print("boosted: ", q_z) print("boosted squared: ", q_z2) assert round(q_z2.qs[0].t, 5) == round(q1_sq.qs[0].t, 5)
def test_1550_tanh(): assert QH([0, 0, 0, 0]).tanh().equals(QH().q_0()) assert Q.tanh().equals( QH([ 1.0248695360556623, 0.1022956817887642, 0.1534435226831462, 0.2045913635775283, ])) assert P.tanh().equals(QH([0, -2.7044120049972684, 2.0283090037479505, 0])) assert R.tanh().equals(QH([0.9950547536867305, 0, 0, 0])) assert C.tanh().equals(QH([1.0046823121902353, 0.0364233692474038, 0, 0]))
def test_1520_tan(): assert QH([0, 0, 0, 0]).tan().equals(QH().q_0()) assert Q.tan().equals( QH([ 0.0000382163172501, -0.3713971716439372, -0.5570957574659058, -0.7427943432878743, ])) assert P.tan().equals(QH([0, 0.7999273634100760, -0.5999455225575570, 0])) assert R.tan().equals(QH([-0.1425465430742778, 0, 0, 0])) assert C.tan().equals(QH([-0.0005079806234700, 1.0004385132020521, 0, 0]))
def test_1530_sinh(): assert QH([0, 0, 0, 0]).sinh().equals(QH().q_0()) assert Q.sinh().equals( QH([ 0.7323376060463428, 0.4482074499805421, 0.6723111749708131, 0.8964148999610841, ])) assert P.sinh().equals(QH([0, -0.7671394197305108, 0.5753545647978831, 0])) assert R.sinh().equals(QH([10.0178749274099026, 0, 0, 0])) assert C.sinh().equals(QH([-2.3706741693520015, -2.8472390868488278, 0, 0]))
def test_1560_exp(): assert QH([0, 0, 0, 0]).exp().equals(QH().q_1()) assert Q.exp().equals( QH([ 1.6939227236832994, 0.7895596245415588, 1.1843394368123383, 1.5791192490831176, ])) assert P.exp().equals( QH([0.2836621854632263, -0.7671394197305108, 0.5753545647978831, 0])) assert R.exp().equals(QH([20.0855369231876679, 0, 0, 0])) assert C.exp().equals(QH([-4.8298093832693851, -5.5920560936409816, 0, 0]))
def test_1510_cos(): assert QH([0, 0, 0, 0]).cos().equals(QH().q_1()) assert Q.cos().equals( QH([ 58.9336461679439481, 34.0861836904655959, 51.1292755356983974, 68.1723673809311919, ])) assert P.cos().equals(QH([74.2099485247878476, 0, 0, 0])) assert R.cos().equals(QH([-0.9899924966004454, 0, 0, 0])) assert C.cos().equals( QH([-11.3642347064010600, -24.8146514856341867, 0, 0]))
def test_1540_cosh(): assert QH([0, 0, 0, 0]).cosh().equals(QH().q_1()) assert Q.cosh().equals( QH([ 0.9615851176369565, 0.3413521745610167, 0.5120282618415251, 0.6827043491220334, ])) assert P.cosh().equals(QH([0.2836621854632263, 0, 0, 0])) assert R.cosh().equals(QH([10.0676619957777653, 0, 0, 0])) assert C.cosh().equals(QH([-2.4591352139173837, -2.7448170067921538, 0, 0]))
def test_1500_sin(): assert QH([0, 0, 0, 0]).sin().equals(QH().q_0()) assert Q.sin().equals( QH([ 91.7837157840346691, -21.8864868530291758, -32.8297302795437673, -43.7729737060583517, ])) assert P.sin().equals(QH([0, 59.3625684622310033, -44.5219263466732542, 0])) assert R.sin().equals(QH([0.1411200080598672, 0, 0, 0])) assert C.sin().equals(QH([24.8313058489463785, -11.3566127112181743, 0, 0]))
def test_1250_product_AOp4i(): AOp4i = A.product(Op4i) print("A Op4i: ", AOp4i) assert AOp4i.qs[0].equals(QH([0, 16, 0, 0])) assert AOp4i.qs[1].equals(QH([-4, 0, 0, 0]))
def test_1210_product_OpB(): OpB: QHStates = Op.product(B) print("Op B: ", OpB) assert OpB.qs[0].equals(QH([0, 10, 3, 0])) assert OpB.qs[1].equals(QH([-18, 0, 0, 1]))
def test_1230_product_AOpB(): AOpB = A.product(Op).product(B) print("A Op B: ", AOpB) assert AOpB.equals(QHStates([QH([0, 22, 11, 0])]))
def test_1150_product_AA(): Aket = deepcopy(A).ket() AA = A.product(Aket) print("<A|A>: ", AA) assert AA.equals(QHStates([QH([17, 0, 0, 0])]))
def test_1170_product_AOp(): AOp: QHStates = A.product(Op) print("A Op: ", AOp) assert AOp.qs[0].equals(QH([11, 0, 0, 0])) assert AOp.qs[1].equals(QH([0, 0, 5, 0])) assert AOp.qs[2].equals(QH([4, 0, 0, 0]))
def test_1140_product(): assert b.product(o).equals( QHStates([QH([10, 0, 0, 0]), QH([20, 0, 0, 0]), QH([30, 0, 0, 0])])) assert b.product(k).equals(QHStates([QH([32, 0, 0, 0])])) assert b.product(o).product(k).equals(QHStates([QH([320, 0, 0, 0])])) assert b.product(b).equals( QHStates([QH([1, 0, 0, 0]), QH([4, 0, 0, 0]), QH([9, 0, 0, 0])])) assert o.product(k).equals( QHStates([QH([40, 0, 0, 0]), QH([50, 0, 0, 0]), QH([60, 0, 0, 0])])) assert o.product(o).equals(QHStates([QH([100, 0, 0, 0])])) assert k.product(k).equals( QHStates([QH([16, 0, 0, 0]), QH([25, 0, 0, 0]), QH([36, 0, 0, 0])])) assert k.product(b).equals( QHStates([ QH([4, 0, 0, 0]), QH([5, 0, 0, 0]), QH([6, 0, 0, 0]), QH([8, 0, 0, 0]), QH([10, 0, 0, 0]), QH([12, 0, 0, 0]), QH([12, 0, 0, 0]), QH([15, 0, 0, 0]), QH([18, 0, 0, 0]), ]))
def test_1010_subs(): q_z = q_sym.subs({t: 1, x: 2, y: 3, z: 4}) print("t x y xyz sub 1 2 3 4: ", q_z) assert q_z.equals(QH([1, 2, 3, 24]))
def test_txyz_2_representation(): qr = QH(Q12.txyz_2_representation("")) assert qr.equals(Q12) qr = QH(Q12.txyz_2_representation("polar")) assert qr.equals(QH([2.23606797749979, 1.10714871779409, 0, 0])) qr = QH(Q1123.txyz_2_representation("spherical")) assert qr.equals( QH([1.0, 3.7416573867739413, 0.640522312679424, 1.10714871779409]))
def test_1270_product_Op4iB(): Op4iB = Op4i.product(B) print("Op4i B: ", Op4iB) assert Op4iB.qs[0].equals(QH([0, 6, 0, 4])) assert Op4iB.qs[1].equals(QH([0, 9, -8, 0]))
def test_representation_2_txyz(): qr = QH(Q12.representation_2_txyz("")) assert qr.equals(Q12) qr = QH(Q12.representation_2_txyz("polar")) assert qr.equals(QH([-0.4161468365471424, 0.9092974268256817, 0, 0])) qr = QH(Q1123.representation_2_txyz("spherical")) assert qr.equals( QH([ 1.0, -0.9001976297355174, 0.12832006020245673, -0.4161468365471424, ]))
def test_1290_product_AOp4iB(): AOp4iB = A.product(Op4i).product(B) print("A* Op4i B: ", AOp4iB) assert AOp4iB.equals(QHStates([QH([-9, 24, 0, 8])]))
def test_1120_diagonal(): Op4iDiag2 = Op_scalar.diagonal(2) print("Op4i on a diagonal 2x2", Op4iDiag2) assert Op4iDiag2.qs[0].equals(q_i4) assert Op4iDiag2.qs[1].equals(QH().q_0())