10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-07 06:33:39 +01:00
QCaml/Utils/Angular_momentum.ml

133 lines
3.2 KiB
OCaml
Raw Normal View History

2017-12-31 16:41:04 +01:00
exception AngularMomentumError of string
2017-12-30 19:06:07 +01:00
type t =
| S | P | D | F | G | H | I | J | K | L | M | N | O
let of_char = function
2017-12-30 19:12:20 +01:00
| 's' | 'S' -> S | 'p' | 'P' -> P
| 'd' | 'D' -> D | 'f' | 'F' -> F
| 'g' | 'G' -> G | 'h' | 'H' -> H
| 'i' | 'I' -> I | 'j' | 'J' -> J
| 'k' | 'K' -> K | 'l' | 'L' -> L
| 'm' | 'M' -> M | 'n' | 'N' -> N
2017-12-30 19:06:07 +01:00
| 'o' | 'O' -> O
2017-12-31 16:41:04 +01:00
| c -> raise (AngularMomentumError (String.make 1 c))
2017-12-30 19:06:07 +01:00
let to_string = function
2017-12-30 19:12:20 +01:00
| S -> "S" | P -> "P"
| D -> "D" | F -> "F"
| G -> "G" | H -> "H"
| I -> "I" | J -> "J"
| K -> "K" | L -> "L"
| M -> "M" | N -> "N"
2017-12-30 19:06:07 +01:00
| O -> "O"
2017-12-30 19:12:20 +01:00
let to_char = function
| S -> 'S' | P -> 'P'
| D -> 'D' | F -> 'F'
| G -> 'G' | H -> 'H'
| I -> 'I' | J -> 'J'
| K -> 'K' | L -> 'L'
| M -> 'M' | N -> 'N'
| O -> 'O'
let to_int = function
| S -> 0 | P -> 1
| D -> 2 | F -> 3
| G -> 4 | H -> 5
| I -> 6 | J -> 7
| K -> 8 | L -> 9
| M -> 10 | N -> 11
| O -> 12
let of_int = function
| 0 -> S | 1 -> P
| 2 -> D | 3 -> F
| 4 -> G | 5 -> H
| 6 -> I | 7 -> J
| 8 -> K | 9 -> L
| 10 -> M | 11 -> N
| 12 -> O
2017-12-31 16:41:04 +01:00
| c -> raise (AngularMomentumError (string_of_int c))
2017-12-30 19:12:20 +01:00
2017-12-30 19:06:07 +01:00
2018-01-17 18:19:38 +01:00
type kind =
2018-01-19 18:18:11 +01:00
| Singlet of t
| Doublet of (t*t)
| Triplet of (t*t*t)
| Quartet of (t*t*t*t)
2018-01-17 18:19:38 +01:00
2018-01-19 03:14:06 +01:00
let n_functions a =
let a =
to_int a
in
(a*a + 3*a + 2)/2
2018-01-17 18:19:38 +01:00
(** Returns an array of Zkeys corresponding to all possible angular momenta *)
let zkey_array a =
let keys_1d l =
let create_z (x,y,_) =
(x,y,l-(x+y))
in
let rec create_y accu xyz =
let (x,y,z) = xyz in
match y with
| 0 -> (create_z xyz)::accu
| i -> let ynew = y-1 in
create_y ( (create_z xyz)::accu) (x,ynew,z)
in
let rec create_x accu xyz =
let (x,y,z) = xyz in
match x with
| 0 -> (create_y [] xyz)@accu
| i -> let xnew = x-1 in
let ynew = l-xnew in
create_x ((create_y [] xyz)@accu) (xnew, ynew, z)
in
create_x [] (l,0,0)
|> List.rev
in
begin
match a with
2018-01-19 18:18:11 +01:00
| Singlet l1 ->
2018-01-19 20:20:19 +01:00
List.map (fun x -> Zkey.of_int_tuple (Zkey.Three x)) (keys_1d @@ to_int l1)
2018-01-19 03:14:06 +01:00
2018-01-19 18:18:11 +01:00
| Doublet (l1, l2) ->
2018-01-19 20:20:19 +01:00
List.map (fun a ->
List.map (fun b ->
2018-01-22 23:19:24 +01:00
Zkey.of_int_tuple (Zkey.Six (a,b))) (keys_1d @@ to_int l2)
) (keys_1d @@ to_int l1)
2018-01-19 18:18:11 +01:00
|> List.concat
| Triplet (l1, l2, l3) ->
2018-01-19 20:20:19 +01:00
List.map (fun a ->
List.map (fun b ->
List.map (fun c ->
Zkey.of_int_tuple (Zkey.Nine (a,b,c))) (keys_1d @@ to_int l3)
2018-01-19 18:18:11 +01:00
) (keys_1d @@ to_int l2)
|> List.concat
) (keys_1d @@ to_int l1)
|> List.concat
2018-01-17 18:19:38 +01:00
2018-01-19 18:18:11 +01:00
| Quartet (l1, l2, l3, l4) ->
2018-01-17 18:19:38 +01:00
2018-01-19 20:20:19 +01:00
List.map (fun a ->
List.map (fun b ->
List.map (fun c ->
List.map (fun d ->
Zkey.of_int_tuple (Zkey.Twelve (a,b,c,d))) (keys_1d @@ to_int l4)
2018-01-17 18:19:38 +01:00
) (keys_1d @@ to_int l3)
|> List.concat
) (keys_1d @@ to_int l2)
|> List.concat
) (keys_1d @@ to_int l1)
2018-01-19 03:14:06 +01:00
|> List.concat
2018-01-17 18:19:38 +01:00
end
|> Array.of_list