10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-06 22:23:42 +01:00

Working on determinants

This commit is contained in:
Anthony Scemama 2019-02-15 23:37:52 +01:00
parent 7dbbf1a352
commit 796c696a8a

View File

@ -1,86 +1,40 @@
type phase_type = type t =
| Plus
| Minus
type spin_determinant_type =
{ {
bitstring : Z.t ; alpha : Spindeterminant.t ;
phase : phase_type; beta : Spindeterminant.t ;
}
type determinant_type =
{
alpha : Z.t ;
beta : Z.t ;
phase : phase_type;
} }
type t = determinant_type
let alpha t = t.alpha
let beta t = t.beta
let phase t =
match Spindeterminant.(phase t.alpha, phase t.beta) with
| Phase.Pos, Phase.Pos
| Phase.Neg, Phase.Neg -> Phase.Pos
| _ -> Phase.Neg
let spindet_of_list l = let of_spindeterminants a b =
let rec aux accu nperm = function {
| [] -> accu, if nperm mod 2 = 0 then Plus else Minus alpha = a ;
| i :: rest -> beta = b
let i = pred i in }
let x = Z.(shift_left one i) in
let accu = Z.logor accu x in
let nperm =
let mask = Z.(x-one) in
let r = Z.logand accu mask in
if r = Z.zero then
nperm
else
nperm + (Z.popcount r)
in
aux accu nperm rest
in
List.rev l
|> aux Z.zero 0
(* TODO Phase *)
let rec to_list spindet =
let rec aux accu z =
if z <> Z.zero then
let element = (Z.(trailing_zeros z)+1) in
aux (element::accu) Z.(z land (pred z))
else List.rev accu
in aux [] spindet
let of_lists a b = let of_lists a b =
let alpha, phase_a = {
spindet_of_list a alpha = Spindeterminant.of_list a ;
in beta = Spindeterminant.of_list b
let beta, phase_b = }
spindet_of_list b
in
let phase =
match phase_a, phase_b with
| Plus , Plus -> Plus
| Minus, Minus-> Plus
| _ -> Minus
in
{ alpha ; beta ; phase }
let alpha det = det.alpha
let beta det = det.beta
let sgn det =
match det.phase with
| Plus -> 1.
| Minus -> -1.
let pp_spindet ppf spindet =
String.init (Z.numbits spindet) (fun i -> if (Z.testbit spindet i) then '+' else '-')
|> Format.fprintf ppf "@[<v> @[<h> %s @]@]"
let pp_det ppf det = let pp_det ppf t =
Format.fprintf ppf "@[<v> a: %a @; b: %a @]@." pp_spindet det.alpha pp_spindet det.beta Format.fprintf ppf "@[<v> a: %a @; b: %a @]@."
Spindeterminant.pp_spindet t.alpha
Spindeterminant.pp_spindet t.beta
let test_case () = let test_case () =