diff --git a/tests/unit/test_spin.cpp b/tests/unit/test_spin.cpp index d02a702d0..5b52a1aaa 100644 --- a/tests/unit/test_spin.cpp +++ b/tests/unit/test_spin.cpp @@ -8,6 +8,7 @@ #include "catch.hpp" #include "test_config.hpp" +#include "utils.hpp" TEST_CASE("Spin", "[spin]") { using namespace sequant; @@ -152,15 +153,10 @@ TEST_CASE("Spin", "[spin]") { REQUIRE(result->is()); canonicalize(result); REQUIRE(result->size() == 2); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ \\bigl({{{2}}{g^{{p_3}{p_4}}_{{p_1}{p_2}}}} - " - L"{{{2}}{g^{{p_4}{p_3}}_{{p_1}" - L"{p_2}}}}\\bigr) }"); - else - REQUIRE(to_latex(result) == - L"{ \\bigl( - {{{2}}{g^{{p_4}{p_3}}_{{p_1}{p_2}}}} + " - L"{{{2}}{g^{{p_3}{p_4}}_{{p_1}{p_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL(result, + L"{ \\bigl({{{2}}{g^{{p_3}{p_4}}_{{p_1}{p_2}}}} - " + L"{{{2}}{g^{{p_4}{p_3}}_{{p_1}" + L"{p_2}}}}\\bigr) }"); } SECTION("Product") { @@ -223,28 +219,17 @@ TEST_CASE("Spin", "[spin]") { canonicalize(result); REQUIRE(result->is()); REQUIRE(result->size() == 5); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(result) == - L"{ \\bigl( - " - L"{{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}} + {{" - L"{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}} " - L"+ {{{2}}{f^{" - L"{a_1}}_{{i_1}}}{t^{{i_1}}_{{a_1}}}} - " - L"{{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}" - L"}_{{a_1}}}{t^{{i_1}}_{{a_2}}}} + " - L"{{{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}" - L"}_{{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(result) == - L"{ \\bigl({{{2}}{f^{{a_1}}_{{i_1}}}{t^{{i_1}}_{{a_1}}}} + " - L"{{{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}} " - L"- {{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}} - " - L"{{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}}_{{a_1}}}{t^{{i_1}}_{{a_2}}" - L"}} + " - L"{{{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}}_{{a_1}}}{t^{{i_2}}_{{" - L"a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl( - " + L"{{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}} + {{" + L"{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}} " + L"+ {{{2}}{f^{" + L"{a_1}}_{{i_1}}}{t^{{i_1}}_{{a_1}}}} - " + L"{{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}" + L"}_{{a_1}}}{t^{{i_1}}_{{a_2}}}} + " + L"{{{2}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}" + L"}_{{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); } // Sum SECTION("Expand Antisymmetrizer"){// 0-body @@ -486,38 +471,21 @@ SECTION("Expand Symmetrizer") { REQUIRE(result->size() == 6); result->canonicalize(); rapid_simplify(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(result) == - L"{ " - L"\\bigl({{{4}}{g^{{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5}}_{{i_4}{i_5}}}{t^{{i_5}}_{{a_1}}}{t^{{i_3}}_{{" + L"a_4}}}{t^{{i_2}}_{{a_5}}}{t^{{i_1}{i_4}}_{{a_2}{a_3}}}} + " + L"{{{4}}{g^{{a_4}{a_5}}_{{i_4}{i_5}}}{t^{{i_4}}_{{a_2}}}{t^{{i_1}}_{{" + L"a_4}}}{t^{{i_3}}_{{a_5}}}{t^{{i_2}{i_5}}_{{a_1}{a_3}}}} + " + L"{{{4}}{g^{{a_4}{a_5}}_{{i_4}{i_5}}}{t^{{i_4}}_{{a_3}}}{t^{{i_1}}_{{" + L"a_4}}}{t^{{i_2}}_{{a_5}}}{t^{{i_3}{i_5}}_{{a_1}{a_2}}}}\\bigr) }"); } } @@ -556,7 +524,8 @@ SECTION("Symmetrize expression") { factorize_S(input, {{L"i_1", L"a_1"}, {L"i_2", L"a_2"}}, true); REQUIRE(result->is() == false); REQUIRE(to_latex(result) == - L"{{S^{{a_1}{a_2}}_{{i_1}{i_2}}}{g^{{i_1}{a_3}}_{{i_3}{i_4}}}{t^{{i_3}}_{{a_1}}}{t^{{i_4}}_{{a_2}}}{t^{{i_2}}_{{a_3}}}}"); + L"{{S^{{a_1}{a_2}}_{{i_1}{i_2}}}{g^{{i_1}{a_3}}_{{i_3}{i_4}}}{t^{{" + L"i_3}}_{{a_1}}}{t^{{i_4}}_{{a_2}}}{t^{{i_2}}_{{a_3}}}}"); } { @@ -581,7 +550,8 @@ SECTION("Symmetrize expression") { REQUIRE(result->is() == false); REQUIRE( to_latex(result) == - L"{{{2}}{S^{{a_1}{a_2}}_{{i_1}{i_2}}}{g^{{a_3}{a_4}}_{{i_3}{i_4}}}{t^{{i_4}}_{{a_2}}}{t^{{i_3}}_{{a_3}}}{t^{{i_1}{i_2}}_{{a_1}{a_4}}}}"); + L"{{{2}}{S^{{a_1}{a_2}}_{{i_1}{i_2}}}{g^{{a_3}{a_4}}_{{i_3}{i_4}}}{t^{{" + L"i_4}}_{{a_2}}}{t^{{i_3}}_{{a_3}}}{t^{{i_1}{i_2}}_{{a_1}{a_4}}}}"); } } @@ -598,32 +568,20 @@ SECTION("Transform expression") { expand(result); rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(result) == - L"{ \\bigl({{{2}}{g^{{a_2}{i_1}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}} - " - L"{{g^{{i_1}{a_2}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(result) == - L"{ \\bigl( - {{g^{{a_2}{i_1}}_{{a_1}{i_2}}}{t^{{i_2}}_{{a_2}}}} + " - L"{{{2}}{g^{{i_1}{a_2}}_{{a_1}{i_2}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl({{{2}}{g^{{a_2}{i_1}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}} - " + L"{{g^{{i_1}{a_2}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); container::map idxmap = {{Index{L"i_1"}, Index{L"i_2"}}, {Index{L"i_2"}, Index{L"i_1"}}}; auto transformed_result = transform_expr(result, idxmap); REQUIRE(transformed_result->is()); REQUIRE(transformed_result->size() == 2); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(transformed_result) == - L"{ \\bigl({{{2}}{g^{{a_2}{i_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}} - " - L"{{g^{{i_2}{a_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(transformed_result) == - L"{ \\bigl( - {{g^{{a_2}{i_2}}_{{a_1}{i_1}}}{t^{{i_1}}_{{a_2}}}} + " - L"{{{2}}{g^{{i_2}{a_2}}_{{a_1}{i_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + transformed_result, + L"{ \\bigl({{{2}}{g^{{a_2}{i_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}} - " + L"{{g^{{i_2}{a_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); } SECTION("Swap bra kets") { @@ -682,14 +640,10 @@ SECTION("Closed-shell spintrace CCD") { const auto input = ex(ExprPtrList{parse_expr( L"1/4 g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_1,i_2}", Symmetry::antisymm)}); auto result = closed_shell_CC_spintrace(input); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(result == parse_expr(L"- g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_2,i_1} + " - L"2 g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_1,i_2}", - Symmetry::nonsymm)); - else - REQUIRE(result == parse_expr(L"2 g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_1,i_2} - " - L"g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_2,i_1}", - Symmetry::nonsymm)); + REQUIRE_SUM_EQUAL(result, to_latex(parse_expr( + L"- g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_2,i_1} + " + L"2 g{i_1,i_2;a_1,a_2} t{a_1,a_2;i_1,i_2}", + Symmetry::nonsymm))); } } @@ -721,32 +675,20 @@ SECTION("Closed-shell spintrace CCSD") { ex(rational{1, 2}) * spintrace(input, {{L"i_1", L"a_1"}}); simplify(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(result) == - L"{ \\bigl({{{2}}{g^{{a_2}{i_1}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}} - " - L"{{g^{{i_1}{a_2}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(result) == - L"{ \\bigl( - {{g^{{a_2}{i_1}}_{{a_1}{i_2}}}{t^{{i_2}}_{{a_2}}}} + " - L"{{{2}}{g^{{i_1}{a_2}}_{{a_1}{i_2}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl({{{2}}{g^{{a_2}{i_1}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}} - " + L"{{g^{{i_1}{a_2}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); container::map idxmap = {{Index{L"i_1"}, Index{L"i_2"}}, {Index{L"i_2"}, Index{L"i_1"}}}; auto transformed_result = transform_expr(result, idxmap); REQUIRE(transformed_result->is()); REQUIRE(transformed_result->size() == 2); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(transformed_result) == - L"{ \\bigl({{{2}}{g^{{a_2}{i_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}} - " - L"{{g^{{i_2}{a_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(transformed_result) == - L"{ \\bigl( - {{g^{{a_2}{i_2}}_{{a_1}{i_1}}}{t^{{i_1}}_{{a_2}}}} + " - L"{{{2}}{g^{{i_2}{a_2}}_{{a_1}{i_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + transformed_result, + L"{ \\bigl({{{2}}{g^{{a_2}{i_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}} - " + L"{{g^{{i_2}{a_2}}_{{i_1}{a_1}}}{t^{{i_1}}_{{a_2}}}}\\bigr) }"); } { @@ -794,12 +736,13 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{{2}}{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_2}{i_3}}_{{a_1}{a_2}}" - L"}} + " - L"{{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_3}{i_2}}_{{a_1}{a_2}}}}" - L"\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl( - " + L"{{{2}}{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_2}{i_3}}_{{a_1}{a_2}}" + L"}} + " + L"{{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_3}{i_2}}_{{a_1}{a_2}}}}" + L"\\bigr) }"); } { @@ -817,17 +760,12 @@ SECTION("Closed-shell spintrace CCSD") { rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ " - L"\\bigl({{{2}}{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}{i_2}}_{{a_3}{a_2}}}} - " - L"{{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}{i_2}}_{{a_2}{a_3}}}}\\bigr) }"); - else - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{g^{{a_3}{a_2}}_{{a_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_2}{a_3}}}} + " - L"{{{2}}{g^{{a_3}{a_2}}_{{a_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_2}{a_3}}" - L"}}\\bigr) }"); + REQUIRE_SUM_EQUAL(result, + L"{ " + L"\\bigl({{{2}}{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}{i_" + L"2}}_{{a_3}{a_2}}}} - " + L"{{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}{i_2}}_{{a_2}{a_" + L"3}}}}\\bigr) }"); } { @@ -843,16 +781,10 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE( - to_latex(result) == - L"{ \\bigl({{{2}}{f^{{a_2}}_{{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}} - " - L"{{f^{{a_2}}_{{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}}\\bigr) }"); - else - REQUIRE( - to_latex(result) == - L"{ \\bigl( - {{f^{{a_2}}_{{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}} + " - L"{{{2}}{f^{{a_2}}_{{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl({{{2}}{f^{{a_2}}_{{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}} - " + L"{{f^{{a_2}}_{{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}}}\\bigr) }"); } { @@ -868,10 +800,13 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - REQUIRE(to_latex(result) == - L"{ " - L"\\bigl({{{2}}{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}{t^{{i_1}}_{{a_3}}}} - " - L"{{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}}_{{a_2}}}{t^{{i_2}}_{{a_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ " + L"\\bigl({{{2}}{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_2}}_{{a_2}}}{t^{" + L"{i_1}}_{{a_3}}}} - " + L"{{g^{{a_2}{a_3}}_{{i_2}{a_1}}}{t^{{i_1}}_{{a_2}}}{t^{{i_2}}_{{a_" + L"3}}}}\\bigr) }"); } { @@ -887,8 +822,13 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - REQUIRE(to_latex(result) == - L"{ \\bigl( - {{{2}}{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}}{t^{{i_3}}_{{a_2}}}} + {{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_2}}_{{a_2}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl( - " + L"{{{2}}{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}}{t^{{i_3}}_" + L"{{a_2}}}} + " + L"{{g^{{i_1}{a_2}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_2}}_{{a_" + L"2}}}}\\bigr) }"); } { @@ -904,10 +844,11 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{f^{{a_2}}_{{i_2}}}{t^{{i_2}}_{{a_1}}}{t^{{i_1}}_{{a_2}}}}" - L"\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl( - " + L"{{f^{{a_2}}_{{i_2}}}{t^{{i_2}}_{{a_1}}}{t^{{i_1}}_{{a_2}}}}" + L"\\bigr) }"); } { @@ -925,18 +866,12 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ " - L"\\bigl({{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}}{t^{{i_1}{i_3}}_{{a_3}{a_2}}}} - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_1}{i_2}}_{{a_3}{a_2}}}}\\bigr) }"); - else - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{" - L"i_2}{i_1}}_{{a_2}{a_3}}}} + " - L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}}{t^{{i_3}{" - L"i_1}}_{{a_2}{a_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL(result, + L"{ " + L"\\bigl({{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}" + L"}{t^{{i_1}{i_3}}_{{a_3}{a_2}}}} - " + L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{" + L"t^{{i_1}{i_2}}_{{a_3}{a_2}}}}\\bigr) }"); } { @@ -954,11 +889,14 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - REQUIRE(to_latex(result) == - L"{ \\bigl(" - L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_1}}_{{a_2}}}{t^{{i_3}{i_2}}_{{a_1}{a_3}}}} - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_1}}_{{a_3}}}{t^{{i_3}{i_2}}_{{a_1}{a_2}}}}" - L"\\bigr) }"); + REQUIRE_SUM_EQUAL( + result, + L"{ \\bigl(" + L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_1}}_{{a_2}}}{t^{{i_3}{i_2}}_" + L"{{a_1}{a_3}}}} - " + L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_1}}_{{a_3}}}{t^{{i_3}{" + L"i_2}}_{{a_1}{a_2}}}}" + L"\\bigr) }"); } { @@ -976,25 +914,20 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ \\bigl(" - L"{{{4}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_3}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}}}" - L" + {{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_3}}}{t^{{i_3}{i_1}}_{{a_1}{a_2}}}}" - L" - {{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_2}}}{t^{{i_3}{i_1}}_{{a_1}{a_3}}}}" - L" - {{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_3}}}}" - L"\\bigr) }"); - else - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_3}}}{t^{{i_1}" - L"{i_3}}_{{a_1}{a_2}}}} + " - L"{{{4}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_2}}}{t^{{i_1}" - L"{i_3}}_{{a_1}{a_3}}}} - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_2}}}{t^{{i_3}" - L"{i_1}}_{{a_1}{a_3}}}} + " - L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_2}}}{t^{{i_2}{i_1}" - L"}_{{a_1}{a_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL(result, + L"{ \\bigl(" + L"{{{4}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_3}}}{" + L"t^{{i_1}{i_2}}_{{a_1}{a_2}}}}" + L" + " + L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_3}}}{t^{{" + L"i_3}{i_1}}_{{a_1}{a_2}}}}" + L" - " + L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_2}}}{" + L"t^{{i_3}{i_1}}_{{a_1}{a_3}}}}" + L" - " + L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_2}}}{" + L"t^{{i_1}{i_2}}_{{a_1}{a_3}}}}" + L"\\bigr) }"); } { @@ -1011,20 +944,14 @@ SECTION("Closed-shell spintrace CCSD") { expand(result); rapid_simplify(result); canonicalize(result); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ " - L"\\bigl( - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_2}}_{{a_2}}}{t^{{i_1}}_{{a_3}}}} + " - L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_1}}_{{a_2}}}{t^{{i_2}}_{{a_3}}}}" - L"\\bigr) }"); - else - REQUIRE(to_latex(result) == - L"{ \\bigl( - " - L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{i_2}" - L"}_{{a_2}}}{t^{{i_1}}_{{a_3}}}} + " - L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_2}}_{{a_1}}}{t^{{i_3}}_{{" - L"a_2}}}{t^{{i_1}}_{{a_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL(result, + L"{ " + L"\\bigl( - " + L"{{{2}}{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{" + L"t^{{i_2}}_{{a_2}}}{t^{{i_1}}_{{a_3}}}} + " + L"{{g^{{a_2}{a_3}}_{{i_2}{i_3}}}{t^{{i_3}}_{{a_1}}}{t^{{" + L"i_1}}_{{a_2}}}{t^{{i_2}}_{{a_3}}}}" + L"\\bigr) }"); } } // CCSD R1 @@ -1047,28 +974,17 @@ SECTION("Closed-shell spintrace CCSDT terms") { input, {{L"i_1", L"a_1"}, {L"i_2", L"a_2"}, {L"i_3", L"a_3"}}); simplify(result); REQUIRE(result->size() == 4); - if constexpr (hash_version() == hash::Impl::BoostPre181) - REQUIRE(to_latex(result) == - L"{ " - L"\\bigl({{{2}}{S^{{a_1}{a_2}{a_3}}_{{i_1}{i_2}{i_3}}}{f^{" - L"{i_3}}_{{i_4}}}{t^{{i_4}{i_1}{i_2}}_{{a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_3}}_{{i_1}{i_2}{i_3}}}{f^{{i_3}}_" + L"{{i_4}}}{t^{{i_1}{i_4}{i_2}}_{{a_1}{a_2}{a_3}}}} + " + L"{{{4}}{S^{{a_1}{a_2}{a_3}}_{{i_1}{i_2}{i_3}}}{f^{{i_3}}_{{i_4}}" + L"}{t^{{i_1}{i_2}{i_4}}_{{a_1}{a_2}{a_3}}}} - " + L"{{{2}}{S^{{a_1}{a_2}{a_3}}_{{i_1}{i_2}{i_3}}}{f^{{i_3}}_{{i_4}}" + L"}{t^{{i_2}{i_1}{i_4}}_{{a_1}{a_2}{a_3}}}}\\bigr) }"); } { // f * t3 @@ -1378,7 +1294,8 @@ SECTION("Open-shell spin-tracing") { auto ft3 = f * t3; ft3->canonicalize(); REQUIRE(to_latex(ft3) == - L"{{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↑_3}{i↓_2}}_{{a↑_3}{a↑_2}{a↓_2}}}}"); + L"{{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↑_3}{i↓_2}}_{{a↑_3}{a↑_2}{a↓_2}" + L"}}}"); } // g @@ -1456,26 +1373,20 @@ SECTION("Open-shell spin-tracing") { REQUIRE(to_latex(result[0]) == L"{{{\\frac{1}{12}}}{f^{{a↑_4}}_{{a↑_1}}}{\\bar{t}^{{i↑_1}{i↑_2}{" L"i↑_3}}_{{a↑_2}{a↑_3}{a↑_4}}}}"); - if constexpr (hash_version() == hash::Impl::BoostPre181) { - REQUIRE(to_latex(result[1]) == - L"{ \\bigl( - " - L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_1}{i↑_2}{i↓_3}}_" - L"{{a↑_2}{a↑_3}{a↓_3}}}} + " - L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_2}{i↑_1}{i↓_3}}_" - L"{{a↑_2}{a↑_3}{a↓_3}}}}\\bigr) }"); - } else - REQUIRE(to_latex(result[1]) == - L"{ \\bigl( - " - L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_1}{i↑_2}{i↓_3}}_" - L"{{a↑_2}{a↑_3}{a↓_3}}}} + " - L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_2}{i↑_1}{i↓_3}}_" - L"{{a↑_2}{a↑_3}{a↓_3}}}}\\bigr) }"); - REQUIRE(to_latex(result[2]) == - L"{ \\bigl( - " - L"{{{\\frac{1}{12}}}{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↓_3}{i↓_2}}_" - L"{{a↑_2}{a↓_2}{a↓_3}}}} + " - L"{{{\\frac{1}{12}}}{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↓_2}{i↓_3}}_{{" - L"a↑_2}{a↓_2}{a↓_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result[1], + L"{ \\bigl( - " + L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_1}{i↑_2}{i↓_3}}_" + L"{{a↑_2}{a↑_3}{a↓_3}}}} + " + L"{{{\\frac{1}{12}}}{f^{{a↑_3}}_{{a↑_1}}}{t^{{i↑_2}{i↑_1}{i↓_3}}_" + L"{{a↑_2}{a↑_3}{a↓_3}}}}\\bigr) }"); + REQUIRE_SUM_EQUAL( + result[2], + L"{ \\bigl( - " + L"{{{\\frac{1}{12}}}{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↓_3}{i↓_2}}_" + L"{{a↑_2}{a↓_2}{a↓_3}}}} + " + L"{{{\\frac{1}{12}}}{f^{{a↑_2}}_{{a↑_1}}}{t^{{i↑_1}{i↓_2}{i↓_3}}_{{" + L"a↑_2}{a↓_2}{a↓_3}}}}\\bigr) }"); REQUIRE(to_latex(result[3]) == L"{{{\\frac{1}{12}}}{f^{{a↓_4}}_{{a↓_1}}}{\\bar{t}^{{i↓_1}{i↓_2}{" L"i↓_3}}_{{a↓_2}{a↓_3}{a↓_4}}}}"); diff --git a/tests/unit/test_wick.cpp b/tests/unit/test_wick.cpp index d429d047f..caf7241c2 100644 --- a/tests/unit/test_wick.cpp +++ b/tests/unit/test_wick.cpp @@ -9,6 +9,7 @@ #include "catch.hpp" #include "test_config.hpp" +#include "utils.hpp" #include @@ -869,22 +870,13 @@ SECTION("Expression Reduction") { std::wcout << L"spinfree H2*T2 = " << to_latex(wick_result_2) << std::endl; - if constexpr (hash_version() == hash::Impl::BoostPre181) { - REQUIRE( - to_latex(wick_result_2) == - L"{ \\bigl( - " - L"{{{4}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}" - L"}} + " - L"{{{8}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}" - L"}}\\bigr) }"); - } else { - REQUIRE(to_latex(wick_result_2) == - L"{ " - L"\\bigl({{{8}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{" - L"a_1}{a_2}}}} - " - L"{{{4}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_" - L"2}}}}\\bigr) }"); - } + REQUIRE_SUM_EQUAL( + wick_result_2, + L"{ \\bigl( - " + L"{{{4}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_2}{i_1}}_{{a_1}{a_2}}" + L"}} + " + L"{{{8}}{g^{{a_1}{a_2}}_{{i_1}{i_2}}}{t^{{i_1}{i_2}}_{{a_1}{a_2}}" + L"}}\\bigr) }"); } }); diff --git a/tests/unit/utils.hpp b/tests/unit/utils.hpp new file mode 100644 index 000000000..8b1aa4483 --- /dev/null +++ b/tests/unit/utils.hpp @@ -0,0 +1,27 @@ +#ifndef SEQUANT_TESTS_UTILS_HPP_ +#define SEQUANT_TESTS_UTILS_HPP_ + +#include + +#include +#include + +/// Checks all permutations of summands in order to match the LaTeX +/// representation to the given string. We do this as the order of summands is +/// dependent on the used hash function (which messes with tests) but ultimately +/// the order of summands does not matter whatsoever. Thus, it is sufficient to +/// test whether some permutation of summands yields the desired LaTeX +/// representation. +#define REQUIRE_SUM_EQUAL(sum, str) \ + REQUIRE(sum.is()); \ + if (to_latex(sum) != str) { \ + for (sequant::intmax_t i = 0; i < sequant::factorial(sum->size()); ++i) { \ + std::next_permutation(sum->begin(), sum->end()); \ + if (to_latex(sum) == str) { \ + break; \ + } \ + } \ + } \ + REQUIRE(to_latex(sum) == std::wstring(str)) + +#endif