10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-07 14:43:41 +01:00
QCaml/CI/Determinant.ml

220 lines
6.0 KiB
OCaml
Raw Normal View History

2019-02-15 23:37:52 +01:00
type t =
2018-07-20 19:02:56 +02:00
{
2019-02-18 12:41:54 +01:00
alfa : Spindeterminant.t ;
beta : Spindeterminant.t ;
2018-07-20 19:02:56 +02:00
}
2019-02-18 12:41:54 +01:00
type hole = int
type particle = int
2018-07-20 19:02:56 +02:00
2019-02-18 12:41:54 +01:00
let alfa t = t.alfa
2018-07-20 19:02:56 +02:00
2019-02-15 23:37:52 +01:00
let beta t = t.beta
2018-07-20 19:02:56 +02:00
2019-03-26 01:20:17 +01:00
let vac n =
2019-02-18 12:41:54 +01:00
{
2019-03-26 01:20:17 +01:00
alfa = Spindeterminant.vac n;
beta = Spindeterminant.vac n;
2019-02-18 12:41:54 +01:00
}
2019-02-15 23:37:52 +01:00
let phase t =
2019-02-18 12:41:54 +01:00
match Spindeterminant.(phase t.alfa, phase t.beta) with
2019-02-15 23:37:52 +01:00
| Phase.Pos, Phase.Pos
| Phase.Neg, Phase.Neg -> Phase.Pos
| _ -> Phase.Neg
2018-07-20 19:02:56 +02:00
2019-02-15 23:37:52 +01:00
let of_spindeterminants a b =
{
2019-02-18 12:41:54 +01:00
alfa = a ;
2019-02-15 23:37:52 +01:00
beta = b
}
2018-07-20 19:02:56 +02:00
2019-02-18 12:41:54 +01:00
let is_none t = Spindeterminant.(is_none t.alfa || is_none t.beta)
2019-02-18 19:45:41 +01:00
let negate_phase t =
{ t with alfa = Spindeterminant.negate_phase t.alfa }
2019-12-03 18:52:03 +01:00
let set_phase p t =
{ alfa = Spindeterminant.set_phase p t.alfa ;
beta = Spindeterminant.set_phase Phase.Pos t.beta
}
2019-02-18 19:45:41 +01:00
2019-02-22 19:19:11 +01:00
let degree_alfa t t' =
Spindeterminant.degree t.alfa t'.alfa
let degree_beta t t' =
Spindeterminant.degree t.beta t'.beta
2019-02-22 00:18:32 +01:00
let degrees t t' =
2019-02-22 19:19:11 +01:00
degree_alfa t t', degree_beta t t'
2019-02-22 00:18:32 +01:00
let degree t t' =
2019-02-22 19:19:11 +01:00
(degree_alfa t t') + (degree_beta t t')
2019-02-22 00:18:32 +01:00
2019-03-26 01:20:17 +01:00
let of_lists n a b =
let alfa = Spindeterminant.of_list n a
and beta = Spindeterminant.of_list n b
2019-02-18 12:41:54 +01:00
in of_spindeterminants alfa beta
2019-12-03 18:52:03 +01:00
let to_lists t =
Spindeterminant.to_list t.alfa,
Spindeterminant.to_list t.beta
2019-02-18 12:41:54 +01:00
let creation spin p t =
match spin with
| Spin.Alfa -> { t with alfa = Spindeterminant.creation p t.alfa }
| Spin.Beta -> { t with beta = Spindeterminant.creation p t.beta }
let annihilation spin h t =
match spin with
| Spin.Alfa -> { t with alfa = Spindeterminant.annihilation h t.alfa }
| Spin.Beta -> { t with beta = Spindeterminant.annihilation h t.beta }
let single_excitation spin h p t =
match spin with
| Spin.Alfa -> { t with alfa = Spindeterminant.single_excitation h p t.alfa }
| Spin.Beta -> { t with beta = Spindeterminant.single_excitation h p t.beta }
let double_excitation spin h p spin' h' p' t =
match spin, spin' with
| Spin.(Alfa, Beta) -> { alfa = Spindeterminant.single_excitation h p t.alfa ;
beta = Spindeterminant.single_excitation h' p' t.beta }
| Spin.(Beta, Alfa) -> { beta = Spindeterminant.single_excitation h p t.beta ;
alfa = Spindeterminant.single_excitation h' p' t.alfa }
| Spin.(Alfa, Alfa) -> { t with alfa = Spindeterminant.double_excitation h p h' p' t.alfa }
| Spin.(Beta, Beta) -> { t with beta = Spindeterminant.double_excitation h p h' p' t.beta }
2018-07-20 19:02:56 +02:00
2019-12-03 18:52:03 +01:00
let compare = compare
2018-07-20 19:02:56 +02:00
2019-12-03 12:25:31 +01:00
let pp n ppf t =
2019-02-20 19:43:16 +01:00
Format.fprintf ppf "@[<v>@[phase:%a@]@;@[a:%a@]@;@[b:%a@]@]@."
2019-12-03 12:25:31 +01:00
Phase.pp (phase t)
(Spindeterminant.pp n) t.alfa
(Spindeterminant.pp n) t.beta
2018-07-20 19:02:56 +02:00
2019-02-18 12:41:54 +01:00
2018-07-20 19:02:56 +02:00
let test_case () =
let test_creation () =
let l_a = [ 1 ; 2 ; 3 ; 5 ; 64 ]
and l_b = [ 2 ; 3 ; 5 ; 65 ] in
2019-03-26 01:20:17 +01:00
let det = of_lists 66 l_a l_b in
2019-02-18 12:41:54 +01:00
let z_a = alfa det
2018-07-20 19:02:56 +02:00
and z_b = beta det in
2019-02-18 12:41:54 +01:00
Alcotest.(check (list int )) "alfa" (Spindeterminant.to_list z_a) l_a;
2019-02-16 10:09:42 +01:00
Alcotest.(check (list int )) "beta" (Spindeterminant.to_list z_b) l_b;
Alcotest.(check bool) "phase" (phase det = Phase.Pos) true;
2018-07-20 19:02:56 +02:00
in
2019-02-16 10:09:42 +01:00
2018-07-20 19:02:56 +02:00
let test_phase () =
let l_a = [ 1 ; 2 ; 3 ; 64 ; 5 ]
and l_b = [ 2 ; 3 ; 5 ; 65 ] in
2019-03-26 01:20:17 +01:00
let det = of_lists 66 l_a l_b in
2019-02-16 10:09:42 +01:00
Alcotest.(check bool) "phase" (phase det = Phase.Neg) true;
2018-07-20 19:02:56 +02:00
let l_a = [ 1 ; 2 ; 3 ; 64 ; 5 ]
and l_b = [ 3 ; 2 ; 5 ; 65 ] in
2019-03-26 01:20:17 +01:00
let det = of_lists 66 l_a l_b in
2019-02-16 10:09:42 +01:00
Alcotest.(check bool) "phase" (phase det = Phase.Pos) true;
2018-07-20 19:02:56 +02:00
let l_a = [ 1 ; 3 ; 2 ; 64 ; 5 ]
and l_b = [ 3 ; 2 ; 5 ; 65 ] in
2019-03-26 01:20:17 +01:00
let det = of_lists 66 l_a l_b in
2019-02-16 10:09:42 +01:00
Alcotest.(check bool) "phase" (phase det = Phase.Neg) true;
2018-07-20 19:02:56 +02:00
let l_a = [ 1 ; 3 ; 2 ; 64 ; 5 ]
and l_b = [ 3 ; 2 ; 65 ; 5 ] in
2019-03-26 01:20:17 +01:00
let det = of_lists 66 l_a l_b in
2019-02-16 10:09:42 +01:00
Alcotest.(check bool) "phase" (phase det = Phase.Pos) true;
2018-07-20 19:02:56 +02:00
in
2019-02-18 12:41:54 +01:00
let test_operators () =
let det =
let open Spin in
creation Alfa 1 @@ creation Alfa 3 @@ creation Alfa 2 @@ creation Alfa 5 @@
2019-03-26 01:20:17 +01:00
creation Beta 1 @@ creation Beta 3 @@ creation Beta 4 @@ creation Beta 5 @@ vac 10
2019-02-18 12:41:54 +01:00
in
Alcotest.(check bool) "creation 1" true
2019-03-26 01:20:17 +01:00
(det = of_lists 10 [ 1 ; 3 ; 2 ; 5 ] [1 ; 3 ; 4 ; 5 ] );
2019-02-18 12:41:54 +01:00
let det' =
single_excitation Spin.Alfa 3 6 det
in
Alcotest.(check bool) "single_exc 1" true
2019-03-26 01:20:17 +01:00
(det' = of_lists 10 [ 1 ; 6 ; 2 ; 5 ] [1 ; 3 ; 4 ; 5 ] );
2019-02-18 12:41:54 +01:00
let det' =
single_excitation Spin.Beta 3 6 det
in
Alcotest.(check bool) "single_exc 2" true
2019-03-26 01:20:17 +01:00
(det' = of_lists 10 [ 1 ; 3 ; 2 ; 5 ] [1 ; 6 ; 4 ; 5 ] );
2019-02-18 12:41:54 +01:00
let det' =
single_excitation Spin.Alfa 4 6 det
in
Alcotest.(check bool) "single_exc 3" true (is_none det');
let det' =
single_excitation Spin.Beta 1 5 det
in
Alcotest.(check bool) "single_exc 4" true (is_none det');
let det' =
double_excitation Spin.Alfa 3 6 Spin.Alfa 2 7 det
in
2019-03-26 01:20:17 +01:00
let det'' = of_lists 10 [ 1 ; 6 ; 7 ; 5 ] [1 ; 3 ; 4 ; 5 ] in
2019-02-18 12:41:54 +01:00
Alcotest.(check bool) "double_exc 1" true (det' = det'');
let det' =
double_excitation Spin.Beta 3 6 Spin.Beta 5 7 det
in
Alcotest.(check bool) "double_exc 2" true
2019-03-26 01:20:17 +01:00
(det' = of_lists 10 [ 1 ; 3 ; 2 ; 5 ] [1 ; 6 ; 4 ; 7 ] );
2019-02-18 12:41:54 +01:00
let det' =
double_excitation Spin.Alfa 3 6 Spin.Beta 5 7 det
in
Alcotest.(check bool) "double_exc 3" true
2019-03-26 01:20:17 +01:00
(det' = of_lists 10 [ 1 ; 6 ; 2 ; 5 ] [1 ; 3 ; 4 ; 7 ] );
2019-02-18 12:41:54 +01:00
let det' =
double_excitation Spin.Beta 5 7 Spin.Alfa 3 6 det
in
Alcotest.(check bool) "double_exc 4" true
2019-03-26 01:20:17 +01:00
(det' = of_lists 10 [ 1 ; 6 ; 2 ; 5 ] [1 ; 3 ; 4 ; 7 ] );
2019-02-18 12:41:54 +01:00
let det' =
double_excitation Spin.Alfa 4 6 Spin.Alfa 2 7 det
in
Alcotest.(check bool) "double_exc 5" true (is_none det');
let det' =
double_excitation Spin.Beta 1 5 Spin.Alfa 2 7 det
in
Alcotest.(check bool) "double_exc 6" true (is_none det');
in
2018-07-20 19:02:56 +02:00
[
"Creation", `Quick, test_creation;
2019-02-16 10:09:42 +01:00
"Phase", `Quick, test_phase;
2019-02-18 12:41:54 +01:00
"Operators",`Quick, test_operators;
2018-07-20 19:02:56 +02:00
]