mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-12-22 12:23:31 +01:00
Removing org-mode
This commit is contained in:
parent
c4b022aeee
commit
e59d016ae7
@ -1,30 +1,15 @@
|
||||
(** Type *)
|
||||
|
||||
|
||||
(* ~tot~ always contains ~x+y+z~. *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Type][Type:2]] *)
|
||||
type t = {
|
||||
x : int ;
|
||||
y : int ;
|
||||
z : int ;
|
||||
tot : int ;
|
||||
tot : int ; (* ~tot~ always contains ~x+y+z~. *)
|
||||
}
|
||||
(* Type:2 ends here *)
|
||||
|
||||
|
||||
(** Conversions *)
|
||||
|
||||
(* Example:
|
||||
* #+begin_example
|
||||
* Powers.of_int_tuple (2,3,1);;
|
||||
* - : Powers.t = x^2 + y^3 + z^1
|
||||
*
|
||||
* Powers.(to_int_tuple (of_int_tuple (2,3,1)));;
|
||||
* - : int * int * int = (2, 3, 1)
|
||||
* #+end_example *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Conversions][Conversions:2]] *)
|
||||
let of_int_tuple t =
|
||||
let result =
|
||||
match t with
|
||||
@ -39,29 +24,10 @@ let of_int_tuple t =
|
||||
|
||||
|
||||
let to_int_tuple { x ; y ; z ; _ } = (x,y,z)
|
||||
(* Conversions:2 ends here *)
|
||||
|
||||
|
||||
(** Operations *)
|
||||
|
||||
(* | ~get~ | Returns the value of the power for $x$, $y$ or $z$
|
||||
* | ~incr~ | Returns a new ~Powers.t~ with the power on the given axis incremented |
|
||||
* | ~decr~ | Returns a new ~Powers.t~ with the power on the given axis decremented. As opposed to ~of_int_tuple~, the values may become negative|
|
||||
*
|
||||
* Example:
|
||||
* #+begin_example
|
||||
* Powers.get Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : int = 3
|
||||
*
|
||||
* Powers.incr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : Powers.t = x^2 + y^4 + z^1
|
||||
*
|
||||
* Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : Powers.t = x^2 + y^2 + z^1
|
||||
* #+end_example *)
|
||||
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Operations][Operations:2]] *)
|
||||
let get coord t =
|
||||
match coord with
|
||||
| Coordinate.X -> t.x
|
||||
@ -79,9 +45,10 @@ let decr coord t =
|
||||
| Coordinate.X -> let r = t.x-1 in { t with x = r ; tot = t.tot-1 }
|
||||
| Coordinate.Y -> let r = t.y-1 in { t with y = r ; tot = t.tot-1 }
|
||||
| Coordinate.Z -> let r = t.z-1 in { t with z = r ; tot = t.tot-1 }
|
||||
(* Operations:2 ends here *)
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Printers][Printers:2]] *)
|
||||
|
||||
(** Printers *)
|
||||
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[x^%d + y^%d + z^%d@]" t.x t.y t.z
|
||||
(* Printers:2 ends here *)
|
||||
|
||||
|
@ -1,36 +1,58 @@
|
||||
(* Type
|
||||
*
|
||||
* <<<~Powers.t~>>> *)
|
||||
(** Powers *)
|
||||
|
||||
(* Contains powers of $x$, $y$ and $z$ describing the polynomials in
|
||||
* atomic basis sets.
|
||||
*)
|
||||
|
||||
(** Type *)
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Type][Type:1]] *)
|
||||
type t = private {
|
||||
x : int ;
|
||||
y : int ;
|
||||
z : int ;
|
||||
tot : int ;
|
||||
tot : int ; (* ~tot~ always contains ~x+y+z~. *)
|
||||
}
|
||||
(* Type:1 ends here *)
|
||||
|
||||
(* Conversions *)
|
||||
(** Conversions *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Conversions][Conversions:1]] *)
|
||||
val of_int_tuple : int * int * int -> t
|
||||
(** Powers.of_int_tuple (2,3,1);;
|
||||
* - : Powers.t = x^2 + y^3 + z^1
|
||||
*)
|
||||
|
||||
val to_int_tuple : t -> int * int * int
|
||||
(* Conversions:1 ends here *)
|
||||
|
||||
(* Operations *)
|
||||
(** Powers.(to_int_tuple (of_int_tuple (2,3,1)));;
|
||||
* - : int * int * int = (2, 3, 1)
|
||||
*)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Operations][Operations:1]] *)
|
||||
(** Operations *)
|
||||
|
||||
val get : Coordinate.axis -> t -> int
|
||||
(** Returns the value of the power for $x$, $y$ or $z$.
|
||||
*
|
||||
* Powers.get Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : int = 3
|
||||
*
|
||||
*)
|
||||
|
||||
val incr : Coordinate.axis -> t -> t
|
||||
(** Returns a new ~Powers.t~ with the power on the given axis incremented.
|
||||
*
|
||||
* Powers.incr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : Powers.t = x^2 + y^4 + z^1
|
||||
*)
|
||||
|
||||
val decr : Coordinate.axis -> t -> t
|
||||
(* Operations:1 ends here *)
|
||||
|
||||
(* Printers *)
|
||||
(** Returns a new ~Powers.t~ with the power on the given axis decremented.
|
||||
* As opposed to ~of_int_tuple~, the values may become negative.
|
||||
*
|
||||
* Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
* - : Powers.t = x^2 + y^2 + z^1
|
||||
*)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/powers.org::*Printers][Printers:1]] *)
|
||||
(** Printers *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(* Printers:1 ends here *)
|
||||
|
@ -1,8 +1,10 @@
|
||||
(* [[file:~/QCaml/common/range.org::*Type][Type:2]] *)
|
||||
type t = int list
|
||||
(* Type:2 ends here *)
|
||||
(** Type *)
|
||||
|
||||
type t = int list
|
||||
|
||||
|
||||
(** Conversion *)
|
||||
|
||||
(* [[file:~/QCaml/common/range.org::*Conversion][Conversion:2]] *)
|
||||
let to_int_list r = r
|
||||
|
||||
let expand_range r =
|
||||
@ -41,9 +43,9 @@ let to_string l =
|
||||
(List.map string_of_int l
|
||||
|> String.concat ",") ^
|
||||
"]"
|
||||
(* Conversion:2 ends here *)
|
||||
|
||||
(* [[file:~/QCaml/common/range.org::*Printers][Printers:2]] *)
|
||||
|
||||
(** Printers *)
|
||||
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
(* Printers:2 ends here *)
|
||||
|
@ -1,23 +1,26 @@
|
||||
(* Type
|
||||
(* Range *)
|
||||
|
||||
(* A range is a sorted list of integers in an interval.
|
||||
*
|
||||
* <<<~Range.t~>>> *)
|
||||
* - ~"[a-b]"~ : range between a and b (included)
|
||||
* - ~"[a]"~ : the list with only one integer a
|
||||
* - ~"a"~ : equivalent to "[a]"
|
||||
* - ~"[36-53,72-107,126-131]"~ represents the list of integers
|
||||
* [ 37 ; 37 ; 38 ; ... ; 52 ; 53 ; 72 ; 73 ; ... ; 106 ; 107 ; 126 ; 127 ; ... ; 130 ; 131 ].
|
||||
*)
|
||||
|
||||
(** Type *)
|
||||
|
||||
(* [[file:~/QCaml/common/range.org::*Type][Type:1]] *)
|
||||
type t
|
||||
(* Type:1 ends here *)
|
||||
|
||||
(* Conversion *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/range.org::*Conversion][Conversion:1]] *)
|
||||
(** Conversion *)
|
||||
|
||||
val of_string : string -> t
|
||||
val to_string : t -> string
|
||||
val to_int_list : t -> int list
|
||||
(* Conversion:1 ends here *)
|
||||
|
||||
(* Printers *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/range.org::*Printers][Printers:1]] *)
|
||||
(** Printers *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(* Printers:1 ends here *)
|
||||
|
@ -1,22 +1,14 @@
|
||||
(** Spin *)
|
||||
|
||||
(** Type *)
|
||||
|
||||
(* Note :
|
||||
* ~Alfa~ if written with an 'f' instead of 'ph' because it has the same number of
|
||||
* letters as ~Beta~, so the alignment of the code is nicer. *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Type][Type:2]] *)
|
||||
type t = (* m_s *)
|
||||
| Alfa (* {% $m_s = +1/2$ %} *)
|
||||
| Beta (* {% $m_s = -1/2$ %} *)
|
||||
(* Type:2 ends here *)
|
||||
|
||||
|
||||
(** Functions *)
|
||||
|
||||
(* Returns the opposite spin *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Functions][Functions:2]] *)
|
||||
let other = function
|
||||
| Alfa -> Beta
|
||||
| Beta -> Alfa
|
||||
@ -24,9 +16,9 @@ let other = function
|
||||
let to_string = function
|
||||
| Alfa -> "Alpha"
|
||||
| Beta -> "Beta "
|
||||
(* Functions:2 ends here *)
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Printers][Printers:2]] *)
|
||||
|
||||
(** Printers *)
|
||||
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
(* Printers:2 ends here *)
|
||||
|
@ -1,21 +1,23 @@
|
||||
(* Type
|
||||
*
|
||||
* <<<~Spin.t~>>> *)
|
||||
(** Spin *)
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Type][Type:1]] *)
|
||||
(* Electron spin *)
|
||||
|
||||
|
||||
(** Type *)
|
||||
type t = Alfa | Beta
|
||||
(* Type:1 ends here *)
|
||||
|
||||
(* Functions *)
|
||||
(** Note :
|
||||
~Alfa~ if written with an 'f' instead of 'ph' because it has the same
|
||||
number of letters as ~Beta~, so the alignment of the code is nicer.
|
||||
*)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Functions][Functions:1]] *)
|
||||
(** Functions *)
|
||||
|
||||
val other : t -> t
|
||||
(* Functions:1 ends here *)
|
||||
|
||||
(* Printers *)
|
||||
(** Returns the opposite spin. *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/spin.org::*Printers][Printers:1]] *)
|
||||
(** Printers *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(* Printers:1 ends here *)
|
||||
|
@ -1,5 +1,36 @@
|
||||
(* [[file:~/QCaml/common/zkey.org::*Types][Types:2]] *)
|
||||
type t =
|
||||
(** ZKey *)
|
||||
|
||||
(*
|
||||
* Encodes the powers of x, y, z in a compact form, suitable for being
|
||||
* used as keys in a hash table.
|
||||
*
|
||||
* Internally, the ~Zkey.t~ is made of two integers, ~left~ and ~right~.
|
||||
* The small integers x, y and z are stored compactly in this 126-bits
|
||||
* space:
|
||||
*
|
||||
* Example:
|
||||
* Left Right
|
||||
* 3 [--------------------------------------------------------------] [------------------|---------------|---------------|---------------]
|
||||
* x y z
|
||||
*
|
||||
* 6 [--------------------------------------------------------------] [---|----------|----------|----------|----------|----------|---------]
|
||||
* x1 y1 z1 x2 y2 z2
|
||||
*
|
||||
* 9 [---------------------------------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
|
||||
* x1 y1 z1 x2 y2 z2 x3 y3 z3
|
||||
*
|
||||
* 12 [---|----------|----------|----------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
|
||||
* x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
|
||||
*
|
||||
*
|
||||
* The values of x,y,z should be positive and should not exceed 32767 for
|
||||
* ~kind=3~. For all other kinds kinds the values should not exceed 1023.
|
||||
*
|
||||
*)
|
||||
|
||||
(** Types *)
|
||||
|
||||
type t =
|
||||
{
|
||||
mutable left : int;
|
||||
mutable right : int;
|
||||
@ -8,46 +39,31 @@ type t =
|
||||
|
||||
open Powers
|
||||
|
||||
type kind =
|
||||
type kind =
|
||||
| Three of Powers.t
|
||||
| Four of (int * int * int * int)
|
||||
| Six of (Powers.t * Powers.t)
|
||||
| Nine of (Powers.t * Powers.t * Powers.t)
|
||||
| Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)
|
||||
(* Types:2 ends here *)
|
||||
|
||||
|
||||
|
||||
(* | ~of_powers_three~ | Create from a ~Powers.t~ |
|
||||
* | ~of_powers_six~ | Create from two ~Powers.t~ |
|
||||
* | ~of_powers_nine~ | Create from three ~Powers.t~ |
|
||||
* | ~of_powers_twelve~ | Create from four ~Powers.t~ |
|
||||
* | ~of_powers~ | Create using the ~kind~ type |
|
||||
* | ~of_int_array~ | Convert from an ~int~ array |
|
||||
* | ~of_int_four~ | Create from four ~ints~ |
|
||||
* | ~to_int_array~ | Convert to an ~int~ array |
|
||||
* | ~to_powers~ | Convert to an ~Powers.t~ array |
|
||||
* | ~to_string~ | Pretty printing | *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Conversions][Conversions:2]] *)
|
||||
(** Creates a Zkey. *)
|
||||
let make ~kind right =
|
||||
{ left = 0 ; right ; kind }
|
||||
|
||||
(** Move [right] to [left] and set [right = x] *)
|
||||
let (<|) z x =
|
||||
let (<|) z x =
|
||||
z.left <- z.right;
|
||||
z.right <- x;
|
||||
z
|
||||
|
||||
(** Shift left [right] by 10 bits, and add [x]. *)
|
||||
let (<<) z x =
|
||||
let (<<) z x =
|
||||
z.right <- (z.right lsl 10) lor x ;
|
||||
z
|
||||
|
||||
(** Shift left [right] by 10 bits, and add [x]. *)
|
||||
let (<+) z x =
|
||||
let (<+) z x =
|
||||
z.right <- (z.right lsl 15) lor x ;
|
||||
z
|
||||
|
||||
@ -71,34 +87,34 @@ let of_int_four i j k l =
|
||||
let of_powers_six { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:6 a << b << c << d << e << f
|
||||
make ~kind:6 a << b << c << d << e << f
|
||||
|
||||
|
||||
let of_powers_nine { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ }
|
||||
{ x=g ; y=h ; z=i ; _ } =
|
||||
{ x=g ; y=h ; z=i ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f lor g lor h lor i in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:9 a << b << c << d << e << f
|
||||
<| g << h << i
|
||||
<| g << h << i
|
||||
|
||||
|
||||
let of_powers_twelve { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ }
|
||||
{ x=g ; y=h ; z=i ; _ } { x=j ; y=k ; z=l ; _ } =
|
||||
{ x=g ; y=h ; z=i ; _ } { x=j ; y=k ; z=l ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f
|
||||
lor g lor h lor i lor j lor k lor l
|
||||
in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:12 a << b << c << d << e << f
|
||||
<| g << h << i << j << k << l
|
||||
|
||||
|
||||
let of_powers a =
|
||||
let of_powers a =
|
||||
match a with
|
||||
| Three a -> of_powers_three a
|
||||
| Six (a,b) -> of_powers_six a b
|
||||
@ -117,7 +133,7 @@ let of_int_array = function
|
||||
|
||||
|
||||
(** Transform the Zkey into an int array *)
|
||||
let to_int_array { left ; right ; kind } =
|
||||
let to_int_array { left ; right ; kind } =
|
||||
match kind with
|
||||
| 3 -> [|
|
||||
mask15 land (right lsr 30) ;
|
||||
@ -132,7 +148,7 @@ let to_int_array { left ; right ; kind } =
|
||||
mask15 land right
|
||||
|]
|
||||
|
||||
| 6 -> [|
|
||||
| 6 -> [|
|
||||
mask10 land (right lsr 50) ;
|
||||
mask10 land (right lsr 40) ;
|
||||
mask10 land (right lsr 30) ;
|
||||
@ -172,7 +188,7 @@ let to_int_array { left ; right ; kind } =
|
||||
|
||||
|
||||
(** Transform the Zkey into an int tuple *)
|
||||
let to_powers { left ; right ; kind } =
|
||||
let to_powers { left ; right ; kind } =
|
||||
match kind with
|
||||
| 3 -> Three (Powers.of_int_tuple (
|
||||
mask15 land (right lsr 30) ,
|
||||
@ -180,7 +196,7 @@ let to_powers { left ; right ; kind } =
|
||||
mask15 land right
|
||||
))
|
||||
|
||||
| 6 -> Six (Powers.of_int_tuple
|
||||
| 6 -> Six (Powers.of_int_tuple
|
||||
( mask10 land (right lsr 50) ,
|
||||
mask10 land (right lsr 40) ,
|
||||
mask10 land (right lsr 30)),
|
||||
@ -190,7 +206,7 @@ let to_powers { left ; right ; kind } =
|
||||
mask10 land right )
|
||||
)
|
||||
|
||||
| 12 -> Twelve (Powers.of_int_tuple
|
||||
| 12 -> Twelve (Powers.of_int_tuple
|
||||
( mask10 land (left lsr 50) ,
|
||||
mask10 land (left lsr 40) ,
|
||||
mask10 land (left lsr 30)),
|
||||
@ -208,7 +224,7 @@ let to_powers { left ; right ; kind } =
|
||||
mask10 land right )
|
||||
)
|
||||
|
||||
| 9 -> Nine (Powers.of_int_tuple
|
||||
| 9 -> Nine (Powers.of_int_tuple
|
||||
( mask10 land (left lsr 20) ,
|
||||
mask10 land (left lsr 10) ,
|
||||
mask10 land left ) ,
|
||||
@ -223,17 +239,9 @@ let to_powers { left ; right ; kind } =
|
||||
)
|
||||
|
||||
| _ -> invalid_arg (__FILE__^": to_powers")
|
||||
(* Conversions:2 ends here *)
|
||||
|
||||
|
||||
|
||||
(* | ~hash~ | Associates a nonnegative integer to any Zkey |
|
||||
* | ~equal~ | The equal function. True if two Zkeys are equal |
|
||||
* | ~compare~ | Comparison function, used for sorting | *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Functions for hash tables][Functions for hash tables:2]] *)
|
||||
let hash = Hashtbl.hash
|
||||
let hash = Hashtbl.hash
|
||||
|
||||
let equal
|
||||
{ right = r1 ; left = l1 ; kind = k1 }
|
||||
@ -259,9 +267,7 @@ let to_string { left ; right ; kind } =
|
||||
|> Array.to_list
|
||||
|> String.concat ", "
|
||||
) ^ " >"
|
||||
(* Functions for hash tables:2 ends here *)
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Printers][Printers:2]] *)
|
||||
(** Printers *)
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
(* Printers:2 ends here *)
|
||||
|
@ -1,9 +1,6 @@
|
||||
(* Types
|
||||
*
|
||||
* <<<~Zkey.t~>>> *)
|
||||
(** Types *)
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Types][Types:1]] *)
|
||||
type t
|
||||
type t
|
||||
|
||||
type kind =
|
||||
| Three of Powers.t
|
||||
@ -11,36 +8,54 @@ type kind =
|
||||
| Six of (Powers.t * Powers.t)
|
||||
| Nine of (Powers.t * Powers.t * Powers.t)
|
||||
| Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)
|
||||
(* Types:1 ends here *)
|
||||
|
||||
(* Conversions *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Conversions][Conversions:1]] *)
|
||||
(** Conversions *)
|
||||
|
||||
val of_powers_three : Powers.t -> t
|
||||
(** Create from a ~Powers.t~ *)
|
||||
|
||||
val of_powers_six : Powers.t -> Powers.t -> t
|
||||
(** Create from two ~Powers.t~ *)
|
||||
|
||||
val of_powers_nine : Powers.t -> Powers.t -> Powers.t -> t
|
||||
(** Create from three ~Powers.t~ *)
|
||||
|
||||
val of_powers_twelve : Powers.t -> Powers.t -> Powers.t -> Powers.t -> t
|
||||
(** Create from four ~Powers.t~ *)
|
||||
|
||||
val of_powers : kind -> t
|
||||
(** Create using the ~kind~ type *)
|
||||
|
||||
val of_int_array : int array -> t
|
||||
(** Convert from an ~int~ array *)
|
||||
|
||||
val of_int_four : int -> int -> int -> int -> t
|
||||
(** Create from four ~ints~ *)
|
||||
|
||||
val to_int_array : t -> int array
|
||||
(** Convert to an ~int~ array *)
|
||||
|
||||
val to_powers : t -> kind
|
||||
(** Convert to an ~Powers.t~ array *)
|
||||
|
||||
val to_string : t -> string
|
||||
(* Conversions:1 ends here *)
|
||||
|
||||
(* Functions for hash tables *)
|
||||
(** Pretty printing *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Functions for hash tables][Functions for hash tables:1]] *)
|
||||
(** Functions for hash tables *)
|
||||
|
||||
val hash : t -> int
|
||||
(** Associates a nonnegative integer to any Zkey *)
|
||||
|
||||
val equal : t -> t -> bool
|
||||
(** The equal function. True if two Zkeys are equal *)
|
||||
|
||||
val compare : t -> t -> int
|
||||
(* Functions for hash tables:1 ends here *)
|
||||
|
||||
(* Printers *)
|
||||
(** Comparison function, used for sorting *)
|
||||
|
||||
|
||||
(* [[file:~/QCaml/common/zkey.org::*Printers][Printers:1]] *)
|
||||
(** Printers *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(* Printers:1 ends here *)
|
||||
|
||||
|
@ -1,4 +1,2 @@
|
||||
(* [[file:~/QCaml/common/zmap.org::*Type][Type:2]] *)
|
||||
module Zmap = Hashtbl.Make(Zkey)
|
||||
include Zmap
|
||||
(* Type:2 ends here *)
|
||||
|
@ -1,7 +1,6 @@
|
||||
(* Type
|
||||
*
|
||||
* <<<~Zmap.t~>>> *)
|
||||
(** ZMap *)
|
||||
|
||||
(* [[file:~/QCaml/common/zmap.org::*Type][Type:1]] *)
|
||||
(* A hash table where the keys are ~Zkey~ *)
|
||||
|
||||
(** Type *)
|
||||
include module type of Hashtbl.Make(Zkey)
|
||||
(* Type:1 ends here *)
|
||||
|
@ -1,131 +0,0 @@
|
||||
#+begin_src elisp tangle: no :results none :exports none
|
||||
(setq pwd (file-name-directory buffer-file-name))
|
||||
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
|
||||
(setq lib (concat pwd "lib/"))
|
||||
(setq testdir (concat pwd "test/"))
|
||||
(setq mli (concat lib name ".mli"))
|
||||
(setq ml (concat lib name ".ml"))
|
||||
(setq test-ml (concat testdir name ".ml"))
|
||||
(org-babel-tangle)
|
||||
#+end_src
|
||||
|
||||
* Powers
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes :comments both
|
||||
:END:
|
||||
|
||||
Contains powers of $x$, $y$ and $z$ describing the polynomials in atomic basis sets.
|
||||
|
||||
** Type
|
||||
|
||||
<<<~Powers.t~>>>
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
type t = private {
|
||||
x : int ;
|
||||
y : int ;
|
||||
z : int ;
|
||||
tot : int ;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
~tot~ always contains ~x+y+z~.
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
type t = {
|
||||
x : int ;
|
||||
y : int ;
|
||||
z : int ;
|
||||
tot : int ;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** Conversions
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val of_int_tuple : int * int * int -> t
|
||||
val to_int_tuple : t -> int * int * int
|
||||
#+end_src
|
||||
|
||||
Example:
|
||||
#+begin_example
|
||||
Powers.of_int_tuple (2,3,1);;
|
||||
- : Powers.t = x^2 + y^3 + z^1
|
||||
|
||||
Powers.(to_int_tuple (of_int_tuple (2,3,1)));;
|
||||
- : int * int * int = (2, 3, 1)
|
||||
#+end_example
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let of_int_tuple t =
|
||||
let result =
|
||||
match t with
|
||||
| (x,y,z) -> { x ; y ; z ; tot=x+y+z }
|
||||
in
|
||||
if result.x < 0 ||
|
||||
result.y < 0 ||
|
||||
result.z < 0 ||
|
||||
result.tot < 0 then
|
||||
invalid_arg (__FILE__^": of_int_tuple");
|
||||
result
|
||||
|
||||
|
||||
let to_int_tuple { x ; y ; z ; _ } = (x,y,z)
|
||||
#+end_src
|
||||
|
||||
** Operations
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val get : Coordinate.axis -> t -> int
|
||||
val incr : Coordinate.axis -> t -> t
|
||||
val decr : Coordinate.axis -> t -> t
|
||||
#+end_src
|
||||
|
||||
| ~get~ | Returns the value of the power for $x$, $y$ or $z$
|
||||
| ~incr~ | Returns a new ~Powers.t~ with the power on the given axis incremented |
|
||||
| ~decr~ | Returns a new ~Powers.t~ with the power on the given axis decremented. As opposed to ~of_int_tuple~, the values may become negative|
|
||||
|
||||
Example:
|
||||
#+begin_example
|
||||
Powers.get Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
- : int = 3
|
||||
|
||||
Powers.incr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
- : Powers.t = x^2 + y^4 + z^1
|
||||
|
||||
Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
|
||||
- : Powers.t = x^2 + y^2 + z^1
|
||||
#+end_example
|
||||
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let get coord t =
|
||||
match coord with
|
||||
| Coordinate.X -> t.x
|
||||
| Coordinate.Y -> t.y
|
||||
| Coordinate.Z -> t.z
|
||||
|
||||
let incr coord t =
|
||||
match coord with
|
||||
| Coordinate.X -> let r = t.x+1 in { t with x = r ; tot = t.tot+1 }
|
||||
| Coordinate.Y -> let r = t.y+1 in { t with y = r ; tot = t.tot+1 }
|
||||
| Coordinate.Z -> let r = t.z+1 in { t with z = r ; tot = t.tot+1 }
|
||||
|
||||
let decr coord t =
|
||||
match coord with
|
||||
| Coordinate.X -> let r = t.x-1 in { t with x = r ; tot = t.tot-1 }
|
||||
| Coordinate.Y -> let r = t.y-1 in { t with y = r ; tot = t.tot-1 }
|
||||
| Coordinate.Z -> let r = t.z-1 in { t with z = r ; tot = t.tot-1 }
|
||||
#+end_src
|
||||
|
||||
|
||||
** Printers
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val pp : Format.formatter -> t -> unit
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[x^%d + y^%d + z^%d@]" t.x t.y t.z
|
||||
#+end_src
|
||||
|
@ -1,97 +0,0 @@
|
||||
#+begin_src elisp tangle: no :results none :exports none
|
||||
(setq pwd (file-name-directory buffer-file-name))
|
||||
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
|
||||
(setq lib (concat pwd "lib/"))
|
||||
(setq testdir (concat pwd "test/"))
|
||||
(setq mli (concat lib name ".mli"))
|
||||
(setq ml (concat lib name ".ml"))
|
||||
(setq test-ml (concat testdir name ".ml"))
|
||||
(org-babel-tangle)
|
||||
#+end_src
|
||||
|
||||
* Range
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes :comments both
|
||||
:END:
|
||||
|
||||
A range is a sorted list of integers in an interval.
|
||||
|
||||
- ~"[a-b]"~ : range between a and b (included)
|
||||
- ~"[a]"~ : the list with only one integer a
|
||||
- ~"a"~ : equivalent to "[a]"
|
||||
- ~"[36-53,72-107,126-131]"~ represents the list of integers
|
||||
[ 37 ; 37 ; 38 ; ... ; 52 ; 53 ; 72 ; 73 ; ... ; 106 ; 107 ; 126 ; 127 ; ... ; 130 ; 131 ].
|
||||
|
||||
** Type
|
||||
|
||||
<<<~Range.t~>>>
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
type t
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
type t = int list
|
||||
#+end_src
|
||||
|
||||
** Conversion
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val of_string : string -> t
|
||||
val to_string : t -> string
|
||||
val to_int_list : t -> int list
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let to_int_list r = r
|
||||
|
||||
let expand_range r =
|
||||
match String.split_on_char '-' r with
|
||||
| s :: f :: [] ->
|
||||
begin
|
||||
let start = int_of_string s
|
||||
and finish = int_of_string f
|
||||
in
|
||||
assert (start <= finish) ;
|
||||
let rec do_work = function
|
||||
| i when i=finish -> [ i ]
|
||||
| i -> i::(do_work (i+1))
|
||||
in do_work start
|
||||
end
|
||||
| r :: [] -> [int_of_string r]
|
||||
| [] -> []
|
||||
| _ -> invalid_arg "Only one range expected"
|
||||
|
||||
|
||||
let of_string s =
|
||||
match s.[0] with
|
||||
| '0' .. '9' -> [ int_of_string s ]
|
||||
| _ ->
|
||||
assert (s.[0] = '[') ;
|
||||
assert (s.[(String.length s)-1] = ']') ;
|
||||
let s = String.sub s 1 ((String.length s) - 2) in
|
||||
let l = String.split_on_char ',' s in
|
||||
let l = List.map expand_range l in
|
||||
List.concat l
|
||||
|> List.sort_uniq compare
|
||||
|
||||
|
||||
let to_string l =
|
||||
"[" ^
|
||||
(List.map string_of_int l
|
||||
|> String.concat ",") ^
|
||||
"]"
|
||||
|
||||
#+end_src
|
||||
|
||||
|
||||
** Printers
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val pp : Format.formatter -> t -> unit
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
#+end_src
|
||||
|
@ -1,64 +0,0 @@
|
||||
#+begin_src elisp tangle: no :results none :exports none
|
||||
(setq pwd (file-name-directory buffer-file-name))
|
||||
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
|
||||
(setq lib (concat pwd "lib/"))
|
||||
(setq testdir (concat pwd "test/"))
|
||||
(setq mli (concat lib name ".mli"))
|
||||
(setq ml (concat lib name ".ml"))
|
||||
(setq test-ml (concat testdir name ".ml"))
|
||||
(org-babel-tangle)
|
||||
#+end_src
|
||||
|
||||
* Spin
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes :comments both
|
||||
:END:
|
||||
|
||||
Electron spin
|
||||
|
||||
** Type
|
||||
|
||||
<<<~Spin.t~>>>
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
type t = Alfa | Beta
|
||||
#+end_src
|
||||
|
||||
Note :
|
||||
~Alfa~ if written with an 'f' instead of 'ph' because it has the same number of
|
||||
letters as ~Beta~, so the alignment of the code is nicer.
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
type t = (* m_s *)
|
||||
| Alfa (* {% $m_s = +1/2$ %} *)
|
||||
| Beta (* {% $m_s = -1/2$ %} *)
|
||||
#+end_src
|
||||
|
||||
** Functions
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val other : t -> t
|
||||
#+end_src
|
||||
|
||||
Returns the opposite spin
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let other = function
|
||||
| Alfa -> Beta
|
||||
| Beta -> Alfa
|
||||
|
||||
let to_string = function
|
||||
| Alfa -> "Alpha"
|
||||
| Beta -> "Beta "
|
||||
#+end_src
|
||||
|
||||
** Printers
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val pp : Format.formatter -> t -> unit
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
#+end_src
|
||||
|
348
common/zkey.org
348
common/zkey.org
@ -1,348 +0,0 @@
|
||||
#+begin_src elisp tangle: no :results none :exports none
|
||||
(setq pwd (file-name-directory buffer-file-name))
|
||||
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
|
||||
(setq lib (concat pwd "lib/"))
|
||||
(setq testdir (concat pwd "test/"))
|
||||
(setq mli (concat lib name ".mli"))
|
||||
(setq ml (concat lib name ".ml"))
|
||||
(setq test-ml (concat testdir name ".ml"))
|
||||
(org-babel-tangle)
|
||||
#+end_src
|
||||
|
||||
* Zkey
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes :comments both
|
||||
:END:
|
||||
|
||||
Encodes the powers of x, y, z in a compact form, suitable for being
|
||||
used as keys in a hash table.
|
||||
|
||||
Internally, the ~Zkey.t~ is made of two integers, ~left~ and ~right~.
|
||||
The small integers x, y and z are stored compactly in this 126-bits
|
||||
space:
|
||||
|
||||
Example:
|
||||
#+begin_example
|
||||
Left Right
|
||||
3 [--------------------------------------------------------------] [------------------|---------------|---------------|---------------]
|
||||
x y z
|
||||
|
||||
6 [--------------------------------------------------------------] [---|----------|----------|----------|----------|----------|---------]
|
||||
x1 y1 z1 x2 y2 z2
|
||||
|
||||
9 [---------------------------------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
|
||||
x1 y1 z1 x2 y2 z2 x3 y3 z3
|
||||
|
||||
12 [---|----------|----------|----------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
|
||||
x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
|
||||
#+end_example
|
||||
|
||||
The values of x,y,z should be positive and should not exceed 32767 for
|
||||
~kind=3~. For all other kinds kinds the values should not exceed 1023.
|
||||
|
||||
** Types
|
||||
|
||||
<<<~Zkey.t~>>>
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
type t
|
||||
|
||||
type kind =
|
||||
| Three of Powers.t
|
||||
| Four of (int * int * int * int)
|
||||
| Six of (Powers.t * Powers.t)
|
||||
| Nine of (Powers.t * Powers.t * Powers.t)
|
||||
| Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
type t =
|
||||
{
|
||||
mutable left : int;
|
||||
mutable right : int;
|
||||
kind : int ;
|
||||
}
|
||||
|
||||
open Powers
|
||||
|
||||
type kind =
|
||||
| Three of Powers.t
|
||||
| Four of (int * int * int * int)
|
||||
| Six of (Powers.t * Powers.t)
|
||||
| Nine of (Powers.t * Powers.t * Powers.t)
|
||||
| Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)
|
||||
#+end_src
|
||||
|
||||
** Conversions
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val of_powers_three : Powers.t -> t
|
||||
val of_powers_six : Powers.t -> Powers.t -> t
|
||||
val of_powers_nine : Powers.t -> Powers.t -> Powers.t -> t
|
||||
val of_powers_twelve : Powers.t -> Powers.t -> Powers.t -> Powers.t -> t
|
||||
val of_powers : kind -> t
|
||||
val of_int_array : int array -> t
|
||||
val of_int_four : int -> int -> int -> int -> t
|
||||
val to_int_array : t -> int array
|
||||
val to_powers : t -> kind
|
||||
val to_string : t -> string
|
||||
#+end_src
|
||||
|
||||
| ~of_powers_three~ | Create from a ~Powers.t~ |
|
||||
| ~of_powers_six~ | Create from two ~Powers.t~ |
|
||||
| ~of_powers_nine~ | Create from three ~Powers.t~ |
|
||||
| ~of_powers_twelve~ | Create from four ~Powers.t~ |
|
||||
| ~of_powers~ | Create using the ~kind~ type |
|
||||
| ~of_int_array~ | Convert from an ~int~ array |
|
||||
| ~of_int_four~ | Create from four ~ints~ |
|
||||
| ~to_int_array~ | Convert to an ~int~ array |
|
||||
| ~to_powers~ | Convert to an ~Powers.t~ array |
|
||||
| ~to_string~ | Pretty printing |
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
(** Creates a Zkey. *)
|
||||
let make ~kind right =
|
||||
{ left = 0 ; right ; kind }
|
||||
|
||||
(** Move [right] to [left] and set [right = x] *)
|
||||
let (<|) z x =
|
||||
z.left <- z.right;
|
||||
z.right <- x;
|
||||
z
|
||||
|
||||
(** Shift left [right] by 10 bits, and add [x]. *)
|
||||
let (<<) z x =
|
||||
z.right <- (z.right lsl 10) lor x ;
|
||||
z
|
||||
|
||||
(** Shift left [right] by 10 bits, and add [x]. *)
|
||||
let (<+) z x =
|
||||
z.right <- (z.right lsl 15) lor x ;
|
||||
z
|
||||
|
||||
|
||||
let of_powers_three { x=a ; y=b ; z=c ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c in
|
||||
alpha >= 0 && alpha < (1 lsl 15)
|
||||
);
|
||||
make ~kind:3 a <+ b <+ c
|
||||
|
||||
|
||||
let of_int_four i j k l =
|
||||
assert (
|
||||
let alpha = i lor j lor k lor l in
|
||||
alpha >= 0 && alpha < (1 lsl 15)
|
||||
);
|
||||
make ~kind:4 i <+ j <+ k <+ l
|
||||
|
||||
|
||||
let of_powers_six { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:6 a << b << c << d << e << f
|
||||
|
||||
|
||||
let of_powers_nine { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ }
|
||||
{ x=g ; y=h ; z=i ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f lor g lor h lor i in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:9 a << b << c << d << e << f
|
||||
<| g << h << i
|
||||
|
||||
|
||||
let of_powers_twelve { x=a ; y=b ; z=c ; _ } { x=d ; y=e ; z=f ; _ }
|
||||
{ x=g ; y=h ; z=i ; _ } { x=j ; y=k ; z=l ; _ } =
|
||||
assert (
|
||||
let alpha = a lor b lor c lor d lor e lor f
|
||||
lor g lor h lor i lor j lor k lor l
|
||||
in
|
||||
alpha >= 0 && alpha < (1 lsl 10)
|
||||
);
|
||||
make ~kind:12 a << b << c << d << e << f
|
||||
<| g << h << i << j << k << l
|
||||
|
||||
|
||||
let of_powers a =
|
||||
match a with
|
||||
| Three a -> of_powers_three a
|
||||
| Six (a,b) -> of_powers_six a b
|
||||
| Twelve (a,b,c,d) -> of_powers_twelve a b c d
|
||||
| Nine (a,b,c) -> of_powers_nine a b c
|
||||
| _ -> invalid_arg "of_powers"
|
||||
|
||||
|
||||
let mask10 = 0x3ff
|
||||
and mask15 = 0x7fff
|
||||
|
||||
|
||||
let of_int_array = function
|
||||
| [| a ; b ; c ; d |] -> of_int_four a b c d
|
||||
| _ -> invalid_arg "of_int_array"
|
||||
|
||||
|
||||
(** Transform the Zkey into an int array *)
|
||||
let to_int_array { left ; right ; kind } =
|
||||
match kind with
|
||||
| 3 -> [|
|
||||
mask15 land (right lsr 30) ;
|
||||
mask15 land (right lsr 15) ;
|
||||
mask15 land right
|
||||
|]
|
||||
|
||||
| 4 -> [|
|
||||
mask15 land (right lsr 45) ;
|
||||
mask15 land (right lsr 30) ;
|
||||
mask15 land (right lsr 15) ;
|
||||
mask15 land right
|
||||
|]
|
||||
|
||||
| 6 -> [|
|
||||
mask10 land (right lsr 50) ;
|
||||
mask10 land (right lsr 40) ;
|
||||
mask10 land (right lsr 30) ;
|
||||
mask10 land (right lsr 20) ;
|
||||
mask10 land (right lsr 10) ;
|
||||
mask10 land right
|
||||
|]
|
||||
|
||||
| 12 -> [|
|
||||
mask10 land (left lsr 50) ;
|
||||
mask10 land (left lsr 40) ;
|
||||
mask10 land (left lsr 30) ;
|
||||
mask10 land (left lsr 20) ;
|
||||
mask10 land (left lsr 10) ;
|
||||
mask10 land left ;
|
||||
mask10 land (right lsr 50) ;
|
||||
mask10 land (right lsr 40) ;
|
||||
mask10 land (right lsr 30) ;
|
||||
mask10 land (right lsr 20) ;
|
||||
mask10 land (right lsr 10) ;
|
||||
mask10 land right
|
||||
|]
|
||||
|
||||
| 9 -> [|
|
||||
mask10 land (left lsr 20) ;
|
||||
mask10 land (left lsr 10) ;
|
||||
mask10 land left ;
|
||||
mask10 land (right lsr 50) ;
|
||||
mask10 land (right lsr 40) ;
|
||||
mask10 land (right lsr 30) ;
|
||||
mask10 land (right lsr 20) ;
|
||||
mask10 land (right lsr 10) ;
|
||||
mask10 land right
|
||||
|]
|
||||
| _ -> invalid_arg (__FILE__^": to_int_array")
|
||||
|
||||
|
||||
|
||||
(** Transform the Zkey into an int tuple *)
|
||||
let to_powers { left ; right ; kind } =
|
||||
match kind with
|
||||
| 3 -> Three (Powers.of_int_tuple (
|
||||
mask15 land (right lsr 30) ,
|
||||
mask15 land (right lsr 15) ,
|
||||
mask15 land right
|
||||
))
|
||||
|
||||
| 6 -> Six (Powers.of_int_tuple
|
||||
( mask10 land (right lsr 50) ,
|
||||
mask10 land (right lsr 40) ,
|
||||
mask10 land (right lsr 30)),
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (right lsr 20) ,
|
||||
mask10 land (right lsr 10) ,
|
||||
mask10 land right )
|
||||
)
|
||||
|
||||
| 12 -> Twelve (Powers.of_int_tuple
|
||||
( mask10 land (left lsr 50) ,
|
||||
mask10 land (left lsr 40) ,
|
||||
mask10 land (left lsr 30)),
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (left lsr 20) ,
|
||||
mask10 land (left lsr 10) ,
|
||||
mask10 land left ) ,
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (right lsr 50) ,
|
||||
mask10 land (right lsr 40) ,
|
||||
mask10 land (right lsr 30)),
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (right lsr 20) ,
|
||||
mask10 land (right lsr 10) ,
|
||||
mask10 land right )
|
||||
)
|
||||
|
||||
| 9 -> Nine (Powers.of_int_tuple
|
||||
( mask10 land (left lsr 20) ,
|
||||
mask10 land (left lsr 10) ,
|
||||
mask10 land left ) ,
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (right lsr 50) ,
|
||||
mask10 land (right lsr 40) ,
|
||||
mask10 land (right lsr 30)),
|
||||
Powers.of_int_tuple
|
||||
( mask10 land (right lsr 20) ,
|
||||
mask10 land (right lsr 10) ,
|
||||
mask10 land right )
|
||||
)
|
||||
|
||||
| _ -> invalid_arg (__FILE__^": to_powers")
|
||||
|
||||
|
||||
#+end_src
|
||||
|
||||
** Functions for hash tables
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val hash : t -> int
|
||||
val equal : t -> t -> bool
|
||||
val compare : t -> t -> int
|
||||
#+end_src
|
||||
|
||||
| ~hash~ | Associates a nonnegative integer to any Zkey |
|
||||
| ~equal~ | The equal function. True if two Zkeys are equal |
|
||||
| ~compare~ | Comparison function, used for sorting |
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let hash = Hashtbl.hash
|
||||
|
||||
let equal
|
||||
{ right = r1 ; left = l1 ; kind = k1 }
|
||||
{ right = r2 ; left = l2 ; kind = k2 } =
|
||||
r1 = r2 && l1 = l2 && k1 = k2
|
||||
|
||||
|
||||
let compare
|
||||
{ right = r1 ; left = l1 ; kind = k1 }
|
||||
{ right = r2 ; left = l2 ; kind = k2 } =
|
||||
if k1 <> k2 then invalid_arg (__FILE__^": cmp");
|
||||
if r1 < r2 then -1
|
||||
else if r1 > r2 then 1
|
||||
else if l1 < l2 then -1
|
||||
else if l1 > l2 then 1
|
||||
else 0
|
||||
|
||||
|
||||
let to_string { left ; right ; kind } =
|
||||
"< " ^ string_of_int left ^ string_of_int right ^ " | " ^ (
|
||||
to_int_array { left ; right ; kind }
|
||||
|> Array.map string_of_int
|
||||
|> Array.to_list
|
||||
|> String.concat ", "
|
||||
) ^ " >"
|
||||
#+end_src
|
||||
|
||||
** Printers
|
||||
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
val pp : Format.formatter -> t -> unit
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let pp ppf t =
|
||||
Format.fprintf ppf "@[%s@]" (to_string t)
|
||||
#+end_src
|
@ -1,30 +0,0 @@
|
||||
#+begin_src elisp tangle: no :results none :exports none
|
||||
(setq pwd (file-name-directory buffer-file-name))
|
||||
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
|
||||
(setq lib (concat pwd "lib/"))
|
||||
(setq testdir (concat pwd "test/"))
|
||||
(setq mli (concat lib name ".mli"))
|
||||
(setq ml (concat lib name ".ml"))
|
||||
(setq test-ml (concat testdir name ".ml"))
|
||||
(org-babel-tangle)
|
||||
#+end_src
|
||||
|
||||
* Zmap
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes :comments both
|
||||
:END:
|
||||
|
||||
A hash table where the keys are ~Zkey~
|
||||
|
||||
** Type
|
||||
|
||||
<<<~Zmap.t~>>>
|
||||
#+begin_src ocaml :tangle (eval mli)
|
||||
include module type of Hashtbl.Make(Zkey)
|
||||
#+end_src
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
module Zmap = Hashtbl.Make(Zkey)
|
||||
include Zmap
|
||||
#+end_src
|
||||
|
@ -1,8 +1,6 @@
|
||||
(* [[file:~/QCaml/top/install_printers.org::*Intall printers][Intall printers:3]] *)
|
||||
let printers =
|
||||
[
|
||||
"Common.Charge.pp" ;
|
||||
"Common.Coordinate.pp" ;
|
||||
"Common.Powers.pp" ;
|
||||
"Common.Range.pp" ;
|
||||
"Common.Spin.pp" ;
|
||||
|
Loading…
Reference in New Issue
Block a user