10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-07 22:53:57 +01:00
quantum_package/ocaml/Determinant.ml

55 lines
1.2 KiB
OCaml
Raw Normal View History

2014-10-29 00:12:45 +01:00
open Core.Std;;
open Qptypes;;
type t = int64 array with sexp
let to_int64_array (x:t) = (x:int64 array)
;;
let of_int64_array n_int x =
assert ((Array.length x) = (N_int_number.to_int n_int)*2) ;
x
;;
let to_alpha_beta x =
let x = to_int64_array x in
let n_int = (Array.length x)/2 in
( Array.init n_int ~f:(fun i -> x.(i)) ,
Array.init n_int ~f:(fun i -> x.(i+n_int)) )
;;
let to_bitlist_couple x =
let (xa,xb) = to_alpha_beta x in
let xa = to_int64_array xa
|> Array.to_list
|> Bitlist.of_int64_list
and xb = to_int64_array xb
|> Array.to_list
|> Bitlist.of_int64_list
in (xa,xb)
;;
let of_bitlist_couple (xa,xb) =
let ba = Bitlist.to_int64_list xa in
let bb = Bitlist.to_int64_list xb in
let n_int = Bitlist.n_int_of_mo_tot_num (List.length ba) in
of_int64_array n_int (Array.of_list (ba@bb))
;;
let bitlist_to_string ~mo_tot_num x =
List.map x ~f:(fun i -> match i with
| Bit.Zero -> "-"
| Bit.One -> "+" )
|> String.concat
2014-10-29 00:50:59 +01:00
|> String.sub ~pos:0 ~len:(MO_number.to_int mo_tot_num)
2014-10-29 00:12:45 +01:00
;;
let to_string ~mo_tot_num x =
let (xa,xb) = to_bitlist_couple x in
[ bitlist_to_string ~mo_tot_num:mo_tot_num xa ;
bitlist_to_string ~mo_tot_num:mo_tot_num xb ]
|> String.concat ~sep:"\n"
;;