10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-09-26 19:40:56 +02:00

Shorter documentation

This commit is contained in:
Anthony Scemama 2020-12-27 23:08:12 +01:00
parent e7c9abd0d3
commit 36e7dbc7bd
21 changed files with 698 additions and 1262 deletions

View File

@ -48,18 +48,37 @@ open Powers
** Conversions ** Conversions
*** ~of_char~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val of_char : char -> t val of_char : char -> t
val to_char : t -> char
val to_int : t -> int
val of_int : int -> t
val to_string : t -> string
#+end_src #+end_src
Returns an ~Angular_momentum.t~ when a shell is given as a character | ~of_char~ | Returns an ~Angular_momentum.t~ when a shell is given as a character (case insensitive) |
(case insensitive): | ~to_char~ | Converts the angular momentum into a char |
| ~of_int~ | Returns a shell given an $l$ value. |
| ~to_int~ | Returns the $l_{max}$ value of the shell |
| ~to_string~ | Converts the angular momentum into a string |
#+begin_example #+begin_example
Angular_momentum.of_char 'p' -> Angular_momentum.P Angular_momentum.of_char 'p';;
- : Angular_momentum.t = Qcaml.Common.Angular_momentum.P
Angular_momentum.(to_char P);;
- : char = 'P'
Angular_momentum.of_int 2;;
- : Angular_momentum.t = Qcaml.Common.Angular_momentum.D
Angular_momentum.(to_int D);;
- : int = 2
Angular_momentum.(to_string D);;
- : string = "D"
#+end_example #+end_example
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
@ -72,21 +91,7 @@ let of_char = function
| 'm' | 'M' -> M | 'n' | 'N' -> N | 'm' | 'M' -> M | 'n' | 'N' -> N
| 'o' | 'O' -> O | 'o' | 'O' -> O
| c -> raise (Angular_momentum_error (String.make 1 c)) | c -> raise (Angular_momentum_error (String.make 1 c))
#+end_src
*** ~to_string~
#+begin_src ocaml :tangle (eval mli)
val to_string : t -> string
#+end_src
Converts the angular momentum into a string:
#+begin_example
Angular_momentum.(to_string D) -> "D"
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let to_string = function let to_string = function
| S -> "S" | P -> "P" | S -> "S" | P -> "P"
| D -> "D" | F -> "F" | D -> "D" | F -> "F"
@ -95,21 +100,8 @@ let to_string = function
| K -> "K" | L -> "L" | K -> "K" | L -> "L"
| M -> "M" | N -> "N" | M -> "M" | N -> "N"
| O -> "O" | Int i -> string_of_int i | O -> "O" | Int i -> string_of_int i
#+end_src
*** ~to_char~
#+begin_src ocaml :tangle (eval mli)
val to_char : t -> char
#+end_src
Converts the angular momentum into a char:
#+begin_example
Angular_momentum.(to_char D) -> 'D'
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let to_char = function let to_char = function
| S -> 'S' | P -> 'P' | S -> 'S' | P -> 'P'
| D -> 'D' | F -> 'F' | D -> 'D' | F -> 'F'
@ -118,21 +110,8 @@ let to_char = function
| K -> 'K' | L -> 'L' | K -> 'K' | L -> 'L'
| M -> 'M' | N -> 'N' | M -> 'M' | N -> 'N'
| O -> 'O' | Int _ -> '_' | O -> 'O' | Int _ -> '_'
#+end_src
*** ~to_int~
#+begin_src ocaml :tangle (eval mli)
val to_int : t -> int
#+end_src
Returns the $l_{max}$ value of the shell:
#+begin_example
Angular_momentum.(to_char D) -> 2
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let to_int = function let to_int = function
| S -> 0 | P -> 1 | S -> 0 | P -> 1
| D -> 2 | F -> 3 | D -> 2 | F -> 3
@ -141,21 +120,8 @@ let to_int = function
| K -> 8 | L -> 9 | K -> 8 | L -> 9
| M -> 10 | N -> 11 | M -> 10 | N -> 11
| O -> 12 | Int i -> i | O -> 12 | Int i -> i
#+end_src
*** ~of_int~
#+begin_src ocaml :tangle (eval mli)
val of_int : int -> t
#+end_src
Returns a shell given an $l$ value.
#+begin_example
Angular_momentum.of_int 3 -> Angular_momentum.F
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let of_int = function let of_int = function
| 0 -> S | 1 -> P | 0 -> S | 1 -> P
| 2 -> D | 3 -> F | 2 -> D | 3 -> F
@ -168,17 +134,24 @@ let of_int = function
** Shell functions ** Shell functions
*** ~n_functions~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val n_functions : t -> int val n_functions : t -> int
val zkey_array : kind -> Zkey.t array
#+end_src #+end_src
Returns the number of cartesian functions in a shell. | ~n_functions~ | Returns the number of cartesian functions in a shell. |
| ~zkey_array~ | Array of ~Zkey.t~, where each element is a a key associated with the the powers of $x,y,z$. |
#+begin_example #+begin_example
Angular_momentum.n_functions D -> 6 Angular_momentum.(n_functions D) ;;
- : int = 6
Angular_momentum.( zkey_array (Doublet (P,S)) );;
- : Zkey.t array =
[| {Zkey.left = 0; right = 1125899906842624} ;
{Zkey.left = 0; right = 1099511627776} ;
{Zkey.left = 0; right = 1073741824} |]
#+end_example #+end_example
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
@ -187,36 +160,8 @@ let n_functions a =
to_int a to_int a
in in
(a*a + 3*a + 2)/2 (a*a + 3*a + 2)/2
#+end_src
*** ~zkey_array~
#+begin_src ocaml :tangle (eval mli)
val zkey_array : kind -> Zkey.t array
#+end_src
Array of ~Zkey.t~, where each element is a a key associated with the
the powers of $x,y,z$.
#+begin_example
Angular_momentum.( zkey_array Doublet (P,S) ) ->
[| {Zkey.left = 0; right = 1125899906842624} ;
{Zkey.left = 0; right = 1099511627776} ;
{Zkey.left = 0; right = 1073741824} |]
=
let s,x,y,z =
Powers.( of_int_tuple (0,0,0),
of_int_tuple (1,0,0),
of_int_tuple (0,1,0),
of_int_tuple (0,0,1) )
in
Array.map (fun (a,b) -> {!Zkey.of_powers_six} a b)
[| (x,s) ; (y,s) ; (z,s) |]
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let zkey_array_memo : (kind, Zkey.t array) Hashtbl.t = let zkey_array_memo : (kind, Zkey.t array) Hashtbl.t =
Hashtbl.create 13 Hashtbl.create 13
@ -301,6 +246,14 @@ val ( + ) : t -> t -> t
val ( - ) : t -> t -> t val ( - ) : t -> t -> t
#+end_src #+end_src
#+begin_example
Angular_momentum.(D + P);;
- : Angular_momentum.t = Qcaml.Common.Angular_momentum.F
Angular_momentum.(F - P);;
- : Angular_momentum.t = Qcaml.Common.Angular_momentum.D
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let ( + ) a b = let ( + ) a b =
of_int ( (to_int a) + (to_int b) ) of_int ( (to_int a) + (to_int b) )
@ -311,9 +264,10 @@ let ( - ) a b =
** Printers ** Printers
Printers can print as a string (~pp_string~) or as an integer (~pp_int~). Printers can print as a string (default) or as an integer.
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val pp : Format.formatter -> t -> unit
val pp_string : Format.formatter -> t -> unit val pp_string : Format.formatter -> t -> unit
val pp_int : Format.formatter -> t -> unit val pp_int : Format.formatter -> t -> unit
#+end_src #+end_src
@ -324,7 +278,8 @@ let pp_string ppf x =
let pp_int ppf x = let pp_int ppf x =
Format.fprintf ppf "@[%d@]" (to_int x) Format.fprintf ppf "@[%d@]" (to_int x)
let pp = pp_string
#+end_src #+end_src
** TODO Tests ** TODO Tests

View File

@ -14,11 +14,11 @@
:header-args: :noweb yes :comments both :header-args: :noweb yes :comments both
:END: :END:
We define here a data type to handle bit strings efficiently. We define here a data type to handle bit strings efficiently. When
When the bit string contains less than 64 bits, it is stored the bit string contains less than 64 bits, it is stored internally
internally in a 63-bit integer and uses bitwise instructions. in a 63-bit integer and uses bitwise instructions. When more than
When more than 63 bits are required, the =zarith= library is used to 63 bits are required, the =zarith= library is used to consider the
consider the bit string as a multi-precision integer. bit string as a multi-precision integer.
** Single-integer implementation :noexport: ** Single-integer implementation :noexport:
@ -110,7 +110,8 @@ type t =
#+begin_src ocaml :tangle (eval test-ml) #+begin_src ocaml :tangle (eval test-ml)
open Common.Bitstring open Common.Bitstring
let check msg x = Alcotest.(check bool) msg true x let check_bool = Alcotest.(check bool)
let check msg x = check_bool msg true x
let test_all () = let test_all () =
let x = 8745687 in let x = 8745687 in
let one_x = of_int x in let one_x = of_int x in
@ -120,13 +121,57 @@ let test_all () =
** General implementation ** General implementation
*** ~of_int~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val of_int : int -> t val of_int : int -> t
val of_z : Z.t -> t
val zero : int -> t
val is_zero : t -> bool
val numbits : t -> int
val testbit : t -> int -> bool
val neg : t -> t
val shift_left : t -> int -> t
val shift_right : t -> int -> t
val shift_left_one : int -> int -> t
val logor : t -> t -> t
val logxor : t -> t -> t
val logand : t -> t -> t
val lognot : t -> t
val plus_one : t -> t
val minus_one : t -> t
val hamdist : t -> t -> int
val trailing_zeros : t -> int
val popcount : t -> int
val to_list : ?accu:(int list) -> t -> int list
val permutations : int -> int -> t list
#+end_src #+end_src
Creates a bit string from an ~int~. | ~of_int~ | Creates a bit string from an ~int~ |
| ~of_z~ | Creates a bit string from an ~Z.t~ multi-precision integer |
| ~zero~ | ~zero n~ creates a zero bit string with ~n~ bits |
| ~is_zero~ | True if all the bits of the bit string are zero. |
| ~numbits~ | Returns the number of bits used to represent the bit string |
| ~testbit~ | ~testbit t n~ is true if the ~n~-th bit of the bit string ~t~ is set to ~1~ |
| ~neg~ | Returns the negative of the integer interpretation of the bit string |
| ~shift_left~ | ~shift_left t n~ returns a new bit strings with all the bits shifted ~n~ positions to the left |
| ~shift_right~ | ~shift_right t n~ returns a new bit strings with all the bits shifted ~n~ positions to the right |
| ~shift_left_one~ | ~shift_left_one size n~ returns a new bit strings with the ~n~-th bit set to one. It is equivalent as shifting ~1~ by ~n~ bits to the left, ~size~ is the total number of bits of the bit string |
| ~logor~ | Bitwise logical or |
| ~logxor~ | Bitwise logical exclusive or |
| ~logand~ | Bitwise logical and |
| ~lognot~ | Bitwise logical negation |
| ~plus_one~ | Takes the integer representation of the bit string and adds one |
| ~minus_one~ | Takes the integer representation of the bit string and removes one |
| ~hamdist~ | Returns the Hamming distance, i.e. the number of bits differing between two bit strings |
| ~trailing_zeros~ | Returns the number of trailing zeros in the bit string |
| ~permutations~ | ~permutations m n~ generates the list of all possible ~n~-bit strings with ~m~ bits set to ~1~. Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]] |
| ~popcount~ | Returns the number of bits set to one in the bit string |
| ~to_list~ | Converts a bit string into a list of integers indicating the positions where the bits are set to ~1~. The first value for the position is not ~0~ but ~1~ |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let of_int x = let of_int x =
@ -134,16 +179,9 @@ let of_int x =
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "of_x" true (one_x = (of_int x)); check_bool "of_x" true (one_x = (of_int x));
#+end_src #+end_src
*** ~of_z~
#+begin_src ocaml :tangle (eval mli)
val of_z : Z.t -> t
#+end_src
Creates a bit string from an ~Z.t~ multi-precision integer.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let of_z x = let of_z x =
@ -151,16 +189,9 @@ let of_z x =
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "of_z" true (one_x = (of_z (Z.of_int x))); check_bool "of_z" true (one_x = (of_z (Z.of_int x)));
#+end_src #+end_src
*** ~zero~
#+begin_src ocaml :tangle (eval mli)
val zero : int -> t
#+end_src
~zero n~ creates a zero bit string with ~n~ bits.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let zero = function let zero = function
@ -168,13 +199,6 @@ let zero = function
| _ -> Many (Many.zero) | _ -> Many (Many.zero)
#+end_src #+end_src
*** ~numbits~
#+begin_src ocaml :tangle (eval mli)
val numbits : t -> int
#+end_src
Returns the number of bits used to represent the bit string.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let numbits = function let numbits = function
@ -182,13 +206,6 @@ let numbits = function
| Many x -> Many.numbits x | Many x -> Many.numbits x
#+end_src #+end_src
*** ~is_zero~
#+begin_src ocaml :tangle (eval mli)
val is_zero : t -> bool
#+end_src
True if all the bits of the bit string are zero.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let is_zero = function let is_zero = function
@ -196,17 +213,6 @@ let is_zero = function
| Many x -> Many.is_zero x | Many x -> Many.is_zero x
#+end_src #+end_src
*** ~neg~
#+begin_src ocaml :tangle (eval mli)
val neg : t -> t
#+end_src
Returns the negative of the integer interpretation of the bit string.
#+begin_example
neg (of_int x) = neg (of_int (-x))
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let neg = function let neg = function
@ -214,14 +220,6 @@ let neg = function
| Many x -> Many (Many.neg x) | Many x -> Many (Many.neg x)
#+end_src #+end_src
*** ~shift_left~
#+begin_src ocaml :tangle (eval mli)
val shift_left : t -> int -> t
#+end_src
~shift_left t n~ returns a new bit strings with all the bits
shifted ~n~ positions to the left.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let shift_left x i = match x with let shift_left x i = match x with
@ -230,20 +228,11 @@ let shift_left x i = match x with
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3);
Alcotest.(check bool) "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3);
Alcotest.(check bool) "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100);
#+end_src #+end_src
*** ~shift_right~
#+begin_src ocaml :tangle (eval mli)
val shift_right : t -> int -> t
#+end_src
~shift_right t n~ returns a new bit strings with all the bits
shifted ~n~ positions to the right.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let shift_right x i = match x with let shift_right x i = match x with
| One x -> One (One.shift_right x i) | One x -> One (One.shift_right x i)
@ -251,20 +240,10 @@ let shift_right x i = match x with
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3);
Alcotest.(check bool) "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3);
#+end_src #+end_src
*** ~shift_left_one~
#+begin_src ocaml :tangle (eval mli)
val shift_left_one : int -> int -> t
#+end_src
~shift_left_one size n~ returns a new bit strings with the ~n~-th
bit set to one.
It is equivalent as shifting ~1~ by ~n~ bits to the left.
~size~ is the total number of bits of the bit string.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let shift_left_one = function let shift_left_one = function
@ -274,18 +253,10 @@ let shift_left_one = function
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3); check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3);
Alcotest.(check bool) "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200); check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200);
#+end_src #+end_src
*** ~testbit~
#+begin_src ocaml :tangle (eval mli)
val testbit : t -> int -> bool
#+end_src
~testbit t n~ is true if the ~n~-th bit of the bit string ~t~ is
set to ~1~.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let testbit = function let testbit = function
@ -294,21 +265,14 @@ let testbit = function
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "testbit1" true (testbit (of_int 8) 3); check_bool "testbit1" true (testbit (of_int 8) 3);
Alcotest.(check bool) "testbit2" false (testbit (of_int 8) 2); check_bool "testbit2" false (testbit (of_int 8) 2);
Alcotest.(check bool) "testbit3" false (testbit (of_int 8) 4); check_bool "testbit3" false (testbit (of_int 8) 4);
Alcotest.(check bool) "testbit4" true (testbit (of_z (Z.of_int 8)) 3); check_bool "testbit4" true (testbit (of_z (Z.of_int 8)) 3);
Alcotest.(check bool) "testbit5" false (testbit (of_z (Z.of_int 8)) 2); check_bool "testbit5" false (testbit (of_z (Z.of_int 8)) 2);
Alcotest.(check bool) "testbit6" false (testbit (of_z (Z.of_int 8)) 4); check_bool "testbit6" false (testbit (of_z (Z.of_int 8)) 4);
#+end_src #+end_src
*** ~logor~
#+begin_src ocaml :tangle (eval mli)
val logor : t -> t -> t
#+end_src
Bitwise logical or.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let logor a b = let logor a b =
@ -319,17 +283,10 @@ let logor a b =
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2)); check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2));
Alcotest.(check bool) "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2))); check_bool "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2)));
#+end_src #+end_src
*** ~logxor~
#+begin_src ocaml :tangle (eval mli)
val logxor : t -> t -> t
#+end_src
Bitwise logical exclusive or.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let logxor a b = let logxor a b =
@ -340,17 +297,10 @@ let logxor a b =
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2)); check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2));
Alcotest.(check bool) "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2))); check_bool "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2)));
#+end_src #+end_src
*** ~logand~
#+begin_src ocaml :tangle (eval mli)
val logand : t -> t -> t
#+end_src
Bitwise logical and.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let logand a b = let logand a b =
@ -362,17 +312,10 @@ let logand a b =
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3)); check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3));
Alcotest.(check bool) "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3))); check_bool "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3)));
#+end_src #+end_src
*** ~lognot~
#+begin_src ocaml :tangle (eval mli)
val lognot : t -> t
#+end_src
Bitwise logical negation.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let lognot = function let lognot = function
@ -380,13 +323,6 @@ let lognot = function
| Many x -> Many (Many.lognot x) | Many x -> Many (Many.lognot x)
#+end_src #+end_src
*** ~minus_one~
#+begin_src ocaml :tangle (eval mli)
val minus_one : t -> t
#+end_src
Takes the integer representation of the bit string and removes one.
#+begin_example #+begin_example
minus_one (of_int 10) = of_int 9 minus_one (of_int 10) = of_int 9
@ -398,14 +334,6 @@ let minus_one = function
| Many x -> Many (Many.minus_one x) | Many x -> Many (Many.minus_one x)
#+end_src #+end_src
*** ~plus_one~
#+begin_src ocaml :tangle (eval mli)
val plus_one : t -> t
#+end_src
Takes the integer representation of the bit string and adds one.
#+begin_example #+begin_example
plus_one (of_int 10) = of_int 11 plus_one (of_int 10) = of_int 11
@ -416,13 +344,6 @@ let plus_one = function
| Many x -> Many (Many.plus_one x) | Many x -> Many (Many.plus_one x)
#+end_src #+end_src
*** ~trailing_zeros~
#+begin_src ocaml :tangle (eval mli)
val trailing_zeros : t -> int
#+end_src
Returns the number of trailing zeros in the bit string.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let trailing_zeros = function let trailing_zeros = function
@ -430,14 +351,6 @@ let trailing_zeros = function
| Many x -> Many.trailing_zeros x | Many x -> Many.trailing_zeros x
#+end_src #+end_src
*** ~hamdist~
#+begin_src ocaml :tangle (eval mli)
val hamdist : t -> t -> int
#+end_src
Returns the Hamming distance, i.e. the number of bits differing
between two bit strings.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let hamdist a b = match a, b with let hamdist a b = match a, b with
@ -446,13 +359,6 @@ let hamdist a b = match a, b with
| _ -> invalid_arg "Bitstring.hamdist" | _ -> invalid_arg "Bitstring.hamdist"
#+end_src #+end_src
*** ~popcount~
#+begin_src ocaml :tangle (eval mli)
val popcount : t -> int
#+end_src
Returns the number of bits set to one in the bit string.
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let popcount = function let popcount = function
@ -460,15 +366,6 @@ let popcount = function
| Many x -> Many.popcount x | Many x -> Many.popcount x
#+end_src #+end_src
*** ~to_list~
#+begin_src ocaml :tangle (eval mli)
val to_list : ?accu:(int list) -> t -> int list
#+end_src
Converts a bit string into a list of integers indicating the
positions where the bits are set to ~1~. The first value for the
position is not ~0~ but ~1~.
#+begin_example #+begin_example
Bitstring.to_list (of_int 5);; Bitstring.to_list (of_int 5);;
@ -486,19 +383,9 @@ let rec to_list ?(accu=[]) = function
#+end_src #+end_src
#+begin_src ocaml :tangle (eval test-ml) :exports none #+begin_src ocaml :tangle (eval test-ml) :exports none
Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
#+end_src #+end_src
*** ~permutations~
#+begin_src ocaml :tangle (eval mli)
val permutations : int -> int -> t list
#+end_src
~permutations m n~ generates the list of all possible ~n~-bit
strings with ~m~ bits set to ~1~.
Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]].
#+begin_example #+begin_example
Bitstring.permutations 2 4 Bitstring.permutations 2 4
|> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;

View File

@ -29,38 +29,24 @@ type t = float
** Conversions ** Conversions
*** ~of_float~ / ~to_float~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val of_float : float -> t val of_float : float -> t
val to_float : t -> float val to_float : t -> float
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
external of_float : float -> t = "%identity"
external to_float : t -> float = "%identity"
#+end_src
*** ~of_int~ / ~to_int~
#+begin_src ocaml :tangle (eval mli)
val of_int : int -> t val of_int : int -> t
val to_int : t -> int val to_int : t -> int
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
let of_int = float_of_int
let to_int = int_of_float
#+end_src
*** ~of_string~ / ~to_string~
#+begin_src ocaml :tangle (eval mli)
val of_string: string -> t val of_string: string -> t
val to_string: t -> string val to_string: t -> string
#+end_src #+end_src
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
external of_float : float -> t = "%identity"
external to_float : t -> float = "%identity"
let of_int = float_of_int
let to_int = int_of_float
let of_string = float_of_string let of_string = float_of_string
let to_string x = let to_string x =

View File

@ -214,23 +214,20 @@ let output_long max_width x =
** Query functions ** Query functions
*** ~anon_args~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val get : long_opt -> string option
val get_bool : long_opt -> bool
val anon_args : unit -> string list val anon_args : unit -> string list
#+end_src #+end_src
Returns the list of anonymous arguments | ~get~ | Returns the argument associated with a long option |
| ~get_bool~ | True if the ~Optional~ argument is present in the command-line |
| ~anon_args~ | Returns the list of anonymous arguments |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let anon_args () = !anon_args_ref let anon_args () = !anon_args_ref
#+end_src
*** ~help~ :noexport:
Prints the documentation of the program.
#+begin_src ocaml :tangle (eval ml) :exports none
let help () = let help () =
(* Print the header *) (* Print the header *)
@ -296,31 +293,13 @@ let help () =
(* Print footer *) (* Print footer *)
output_text !footer_doc; output_text !footer_doc;
Format.printf "@." Format.printf "@."
#+end_src
*** ~get~
#+begin_src ocaml :tangle (eval mli)
val get : long_opt -> string option
#+end_src
Returns the argument associated with a long option.
#+begin_src ocaml :tangle (eval ml) :exports none
let get x = let get x =
try Some (Hashtbl.find dict x) try Some (Hashtbl.find dict x)
with Not_found -> None with Not_found -> None
#+end_src
*** ~get_bool~
#+begin_src ocaml :tangle (eval mli)
val get_bool : long_opt -> bool
#+end_src
True if the ~Optional~ argument is present in the command-line
#+begin_src ocaml :tangle (eval ml) :exports none
let get_bool x = Hashtbl.mem dict x let get_bool x = Hashtbl.mem dict x
#+end_src #+end_src

View File

@ -18,41 +18,21 @@
** Thresholds ** Thresholds
*** ~epsilon~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val epsilon : float val epsilon : float
#+end_src
Value below which a float is considered null. Default is
\epsilon = 2.10^{-15}.
#+begin_src ocaml :tangle (eval ml) :exports none
let epsilon = 2.e-15
#+end_src
*** ~integrals_cutoff~
#+begin_src ocaml :tangle (eval mli)
val integrals_cutoff : float val integrals_cutoff : float
#+end_src #+end_src
Cutoff value for integrals. Default is \epsilon . | ~epsilon~ | Value below which a float is considered null. Default is \epsilon = 2.10^{-15} |
| ~integrals_cutoff~ | Cutoff value for integrals. Default is \epsilon |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let epsilon = 2.e-15
let integrals_cutoff = epsilon let integrals_cutoff = epsilon
#+end_src #+end_src
** Mathematical constants ** Mathematical constants
| ~pi~ | $\pi = 3.141~592~653~589~793~12$ |
| ~two_pi~ | $2 \pi$ |
| ~sq_pi~ | $\sqrt{\pi}$ |
| ~sq_pi_over_two~ | $\sqrt{\pi} / 2$ |
| ~pi_inv~ | $1 / \pi$ |
| ~two_over_sq_pi~ | $2 / \sqrt{\pi}$ |
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val pi : float val pi : float
val two_pi : float val two_pi : float
@ -62,6 +42,13 @@ val pi_inv : float
val two_over_sq_pi : float val two_over_sq_pi : float
#+end_src #+end_src
| ~pi~ | $\pi = 3.141~592~653~589~793~12$ |
| ~two_pi~ | $2 \pi$ |
| ~sq_pi~ | $\sqrt{\pi}$ |
| ~sq_pi_over_two~ | $\sqrt{\pi} / 2$ |
| ~pi_inv~ | $1 / \pi$ |
| ~two_over_sq_pi~ | $2 / \sqrt{\pi}$ |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let pi = acos (-1.) let pi = acos (-1.)
let two_pi = 2. *. pi let two_pi = 2. *. pi
@ -71,14 +58,8 @@ let pi_inv = 1. /. pi
let two_over_sq_pi = 2. /. sq_pi let two_over_sq_pi = 2. /. sq_pi
#+end_src #+end_src
** Physical constants ** Physical constants
| ~a0~ | Bohr's radius : $a_0 = 0.529~177~210~67(23)$ angstrom |
| ~a0_inv~ | $1 / a_0$ |
| ~ha_to_ev~ | Hartree to eV conversion factor : $27.211~386~02(17)$ |
| ~ev_to_ha~ | eV to Hartree conversion factor : 1 / ~ha_to_ev~ |
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val a0 : float val a0 : float
val a0_inv : float val a0_inv : float
@ -86,6 +67,11 @@ val ha_to_ev : float
val ev_to_ha : float val ev_to_ha : float
#+end_src #+end_src
| ~a0~ | Bohr's radius : $a_0 = 0.529~177~210~67(23)$ angstrom |
| ~a0_inv~ | $1 / a_0$ |
| ~ha_to_ev~ | Hartree to eV conversion factor : $27.211~386~02(17)$ |
| ~ev_to_ha~ | eV to Hartree conversion factor : 1 / ~ha_to_ev~ |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let a0 = 0.529_177_210_67 let a0 = 0.529_177_210_67
let a0_inv = 1. /. a0 let a0_inv = 1. /. a0

View File

@ -44,210 +44,140 @@ type axis = X | Y | Z
<<types>> <<types>>
#+end_src #+end_src
** Creation / conversion ** Creation
*** ~make~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val make : 'a point -> t val make : 'a point -> t
val make_angstrom : 'a point -> angstrom point
val zero : bohr point
#+end_src #+end_src
Creates a point in atomic units. | ~make~ | Creates a point in atomic units |
| ~make_angstrom~ | Creates a point in angstrom |
| ~zero~ | $(0., 0., 0.)$ |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
external make : 'a point -> t = "%identity" external make : 'a point -> t = "%identity"
#+end_src
*** ~make_angstrom~
#+begin_src ocaml :tangle (eval mli)
val make_angstrom : 'a point -> angstrom point
#+end_src
Creates a point in angstrom.
#+begin_src ocaml :tangle (eval ml) :exports none
external make_angstrom : 'a point -> angstrom point = "%identity" external make_angstrom : 'a point -> angstrom point = "%identity"
let zero =
make { x = 0. ; y = 0. ; z = 0. }
#+end_src #+end_src
*** ~bohr_to_angstrom~ ** Conversion
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val bohr_to_angstrom : bohr point -> angstrom point val bohr_to_angstrom : bohr point -> angstrom point
val angstrom_to_bohr : angstrom point -> bohr point
#+end_src #+end_src
Converts a point in bohr to angstrom. | ~bohr_to_angstrom~ | Converts a point in bohr to angstrom |
| ~angstrom_to_bohr~ | Converts a point in angstrom to bohr |
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let b_to_a b = Constants.a0 *. b let b_to_a b = Constants.a0 *. b
let bohr_to_angstrom { x ; y ; z } = let bohr_to_angstrom { x ; y ; z } =
make { x = b_to_a x ; make { x = b_to_a x ;
y = b_to_a y ; y = b_to_a y ;
z = b_to_a z ; } z = b_to_a z ; }
#+end_src
*** ~angstrom_to_bohr~
#+begin_src ocaml :tangle (eval mli)
val angstrom_to_bohr : angstrom point -> bohr point
#+end_src
Converts a point in angstrom to bohr.
#+begin_src ocaml :tangle (eval ml) :exports none
let a_to_b a = Constants.a0_inv *. a let a_to_b a = Constants.a0_inv *. a
let angstrom_to_bohr { x ; y ; z } = let angstrom_to_bohr { x ; y ; z } =
make { x = a_to_b x ; make { x = a_to_b x ;
y = a_to_b y ; y = a_to_b y ;
z = a_to_b z ; } z = a_to_b z ; }
#+end_src #+end_src
*** ~zero~ ** Vector operations
#+begin_src ocaml :tangle (eval mli)
val zero : bohr point
#+end_src
~zero~ = (0., 0., 0.)
#+begin_src ocaml :tangle (eval ml) :exports none
let zero =
make { x = 0. ; y = 0. ; z = 0. }
#+end_src
*** ~get~
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)
val neg : t -> t
val get : axis -> bohr point -> float val get : axis -> bohr point -> float
val dot : t -> t -> float
val norm : t -> float
val ( |. ) : float -> t -> t
val ( |+ ) : t -> t -> t
val ( |- ) : t -> t -> t
#+end_src #+end_src
Extracts the projection of the coordinate on an axis. | ~neg~ | Negative of a point |
| ~get~ | Extracts the projection of the coordinate on an axis |
| ~dot~ | Dot product |
| ~norm~ | $\ell{^2}$ norm of the vector |
| ~¦.~ | Scales the vector by a constant |
| ~¦+~ | Adds two vectors |
| ~¦-~ | Subtracts two vectors |
#+begin_example #+begin_example
Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.}
Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;; Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;;
- : float = 2. - : float = 2.
Coordinate.(
2. |. { x=1. ; y=2. ; z=3. }
) ;;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.}
Coordinate.(
{ x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. }
);;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = 3.; y = 5.; z = 4.}
Coordinate.(
{ x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. }
);;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -1.; z = 2.}
#+end_example #+end_example
#+begin_src ocaml :tangle (eval ml) :exports none #+begin_src ocaml :tangle (eval ml) :exports none
let get axis { x ; y ; z } = let get axis { x ; y ; z } =
match axis with match axis with
| X -> x | X -> x
| Y -> y | Y -> y
| Z -> z | Z -> z
#+end_src
** Vector operations
*** Scale
#+begin_src ocaml :tangle (eval mli)
val ( |. ) : float -> t -> t
#+end_src
#+begin_example
Coordinate.(
2. |. { x=1. ; y=2. ; z=3. }
) ;;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.}
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let ( |. ) s { x ; y ; z } = let ( |. ) s { x ; y ; z } =
make { x = s *. x ; make { x = s *. x ;
y = s *. y ; y = s *. y ;
z = s *. z ; } z = s *. z ; }
#+end_src
*** Add
#+begin_src ocaml :tangle (eval mli)
val ( |+ ) : t -> t -> t
#+end_src
#+begin_example
Coordinate.(
{ x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. }
);;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = 3.; y = 5.; z = 4.}
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let ( |+ ) let ( |+ )
{ x = x1 ; y = y1 ; z = z1 } { x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } = { x = x2 ; y = y2 ; z = z2 } =
make { x = x1 +. x2 ; make { x = x1 +. x2 ;
y = y1 +. y2 ; y = y1 +. y2 ;
z = z1 +. z2 ; } z = z1 +. z2 ; }
#+end_src
*** Subtract
#+begin_src ocaml :tangle (eval mli)
val ( |- ) : t -> t -> t
#+end_src
#+begin_example
Coordinate.(
{ x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. }
);;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -1.; z = 2.}
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let ( |- ) let ( |- )
{ x = x1 ; y = y1 ; z = z1 } { x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } = { x = x2 ; y = y2 ; z = z2 } =
make { x = x1 -. x2 ; make { x = x1 -. x2 ;
y = y1 -. y2 ; y = y1 -. y2 ;
z = z1 -. z2 ; } z = z1 -. z2 ; }
#+end_src
*** Negative
#+begin_src ocaml :tangle (eval mli)
val neg : t -> t
#+end_src
#+begin_example
Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.}
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let neg a = -1. |. a let neg a = -1. |. a
#+end_src
*** Dot product
#+begin_src ocaml :tangle (eval mli)
val dot : t -> t -> float
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
let dot let dot
{ x = x1 ; y = y1 ; z = z1 } { x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } = { x = x2 ; y = y2 ; z = z2 } =
x1 *. x2 +. x1 *. x2 +.
y1 *. y2 +. y1 *. y2 +.
z1 *. z2 z1 *. z2
#+end_src
*** Norm
#+begin_src ocaml :tangle (eval mli)
val norm : t -> float
#+end_src
$\ell{^2}$ norm of the vector.
#+begin_src ocaml :tangle (eval ml) :exports none
let norm u = let norm u =
sqrt ( dot u u ) sqrt ( dot u u )
#+end_src #+end_src
** Printers ** Printers
#+begin_src ocaml :tangle (eval mli) #+begin_src ocaml :tangle (eval mli)

View File

@ -25,15 +25,31 @@ open Powers
(* Returns an ~Angular_momentum.t~ when a shell is given as a character (* | ~of_char~ | Returns an ~Angular_momentum.t~ when a shell is given as a character (case insensitive) |
* (case insensitive): * | ~to_char~ | Converts the angular momentum into a char |
* | ~of_int~ | Returns a shell given an $l$ value. |
* | ~to_int~ | Returns the $l_{max}$ value of the shell |
* | ~to_string~ | Converts the angular momentum into a string |
* *
* #+begin_example * #+begin_example
* Angular_momentum.of_char 'p' -> Angular_momentum.P * Angular_momentum.of_char 'p';;
* - : Angular_momentum.t = Qcaml.Common.Angular_momentum.P
*
* Angular_momentum.(to_char P);;
* - : char = 'P'
*
* Angular_momentum.of_int 2;;
* - : Angular_momentum.t = Qcaml.Common.Angular_momentum.D
*
* Angular_momentum.(to_int D);;
* - : int = 2
*
* Angular_momentum.(to_string D);;
* - : string = "D"
* #+end_example *) * #+end_example *)
(* [[file:../angular_momentum.org::*~of_char~][~of_char~:2]] *) (* [[file:../angular_momentum.org::*Conversions][Conversions:2]] *)
let of_char = function let of_char = function
| 's' | 'S' -> S | 'p' | 'P' -> P | 's' | 'S' -> S | 'p' | 'P' -> P
| 'd' | 'D' -> D | 'f' | 'F' -> F | 'd' | 'D' -> D | 'f' | 'F' -> F
@ -43,18 +59,7 @@ let of_char = function
| 'm' | 'M' -> M | 'n' | 'N' -> N | 'm' | 'M' -> M | 'n' | 'N' -> N
| 'o' | 'O' -> O | 'o' | 'O' -> O
| c -> raise (Angular_momentum_error (String.make 1 c)) | c -> raise (Angular_momentum_error (String.make 1 c))
(* ~of_char~:2 ends here *)
(* Converts the angular momentum into a string:
*
* #+begin_example
* Angular_momentum.(to_string D) -> "D"
* #+end_example *)
(* [[file:../angular_momentum.org::*~to_string~][~to_string~:2]] *)
let to_string = function let to_string = function
| S -> "S" | P -> "P" | S -> "S" | P -> "P"
| D -> "D" | F -> "F" | D -> "D" | F -> "F"
@ -63,18 +68,8 @@ let to_string = function
| K -> "K" | L -> "L" | K -> "K" | L -> "L"
| M -> "M" | N -> "N" | M -> "M" | N -> "N"
| O -> "O" | Int i -> string_of_int i | O -> "O" | Int i -> string_of_int i
(* ~to_string~:2 ends here *)
(* Converts the angular momentum into a char:
*
* #+begin_example
* Angular_momentum.(to_char D) -> 'D'
* #+end_example *)
(* [[file:../angular_momentum.org::*~to_char~][~to_char~:2]] *)
let to_char = function let to_char = function
| S -> 'S' | P -> 'P' | S -> 'S' | P -> 'P'
| D -> 'D' | F -> 'F' | D -> 'D' | F -> 'F'
@ -83,18 +78,8 @@ let to_char = function
| K -> 'K' | L -> 'L' | K -> 'K' | L -> 'L'
| M -> 'M' | N -> 'N' | M -> 'M' | N -> 'N'
| O -> 'O' | Int _ -> '_' | O -> 'O' | Int _ -> '_'
(* ~to_char~:2 ends here *)
(* Returns the $l_{max}$ value of the shell:
*
* #+begin_example
* Angular_momentum.(to_char D) -> 2
* #+end_example *)
(* [[file:../angular_momentum.org::*~to_int~][~to_int~:2]] *)
let to_int = function let to_int = function
| S -> 0 | P -> 1 | S -> 0 | P -> 1
| D -> 2 | F -> 3 | D -> 2 | F -> 3
@ -103,18 +88,8 @@ let to_int = function
| K -> 8 | L -> 9 | K -> 8 | L -> 9
| M -> 10 | N -> 11 | M -> 10 | N -> 11
| O -> 12 | Int i -> i | O -> 12 | Int i -> i
(* ~to_int~:2 ends here *)
(* Returns a shell given an $l$ value.
*
* #+begin_example
* Angular_momentum.of_int 3 -> Angular_momentum.F
* #+end_example *)
(* [[file:../angular_momentum.org::*~of_int~][~of_int~:2]] *)
let of_int = function let of_int = function
| 0 -> S | 1 -> P | 0 -> S | 1 -> P
| 2 -> D | 3 -> F | 2 -> D | 3 -> F
@ -123,49 +98,34 @@ let of_int = function
| 8 -> K | 9 -> L | 8 -> K | 9 -> L
| 10 -> M | 11 -> N | 10 -> M | 11 -> N
| 12 -> O | i -> Int i | 12 -> O | i -> Int i
(* ~of_int~:2 ends here *) (* Conversions:2 ends here *)
(* Returns the number of cartesian functions in a shell. (* | ~n_functions~ | Returns the number of cartesian functions in a shell. |
* | ~zkey_array~ | Array of ~Zkey.t~, where each element is a a key associated with the the powers of $x,y,z$. |
* *
* #+begin_example * #+begin_example
* Angular_momentum.n_functions D -> 6 * Angular_momentum.(n_functions D) ;;
* - : int = 6
*
* Angular_momentum.( zkey_array (Doublet (P,S)) );;
* - : Zkey.t array =
* [| {Zkey.left = 0; right = 1125899906842624} ;
* {Zkey.left = 0; right = 1099511627776} ;
* {Zkey.left = 0; right = 1073741824} |]
*
* #+end_example *) * #+end_example *)
(* [[file:../angular_momentum.org::*~n_functions~][~n_functions~:2]] *) (* [[file:../angular_momentum.org::*Shell functions][Shell functions:2]] *)
let n_functions a = let n_functions a =
let a = let a =
to_int a to_int a
in in
(a*a + 3*a + 2)/2 (a*a + 3*a + 2)/2
(* ~n_functions~:2 ends here *)
(* Array of ~Zkey.t~, where each element is a a key associated with the
* the powers of $x,y,z$.
*
* #+begin_example
* Angular_momentum.( zkey_array Doublet (P,S) ) ->
* [| {Zkey.left = 0; right = 1125899906842624} ;
* {Zkey.left = 0; right = 1099511627776} ;
* {Zkey.left = 0; right = 1073741824} |]
* =
*
* let s,x,y,z =
* Powers.( of_int_tuple (0,0,0),
* of_int_tuple (1,0,0),
* of_int_tuple (0,1,0),
* of_int_tuple (0,0,1) )
* in
* Array.map (fun (a,b) -> {!Zkey.of_powers_six} a b)
* [| (x,s) ; (y,s) ; (z,s) |]
* #+end_example *)
(* [[file:../angular_momentum.org::*~zkey_array~][~zkey_array~:2]] *)
let zkey_array_memo : (kind, Zkey.t array) Hashtbl.t = let zkey_array_memo : (kind, Zkey.t array) Hashtbl.t =
Hashtbl.create 13 Hashtbl.create 13
@ -241,7 +201,18 @@ let zkey_array a =
in in
Hashtbl.add zkey_array_memo a result; Hashtbl.add zkey_array_memo a result;
result result
(* ~zkey_array~:2 ends here *) (* Shell functions:2 ends here *)
(* #+begin_example
* Angular_momentum.(D + P);;
* - : Angular_momentum.t = Qcaml.Common.Angular_momentum.F
*
* Angular_momentum.(F - P);;
* - : Angular_momentum.t = Qcaml.Common.Angular_momentum.D
* #+end_example *)
(* [[file:../angular_momentum.org::*Arithmetic][Arithmetic:2]] *) (* [[file:../angular_momentum.org::*Arithmetic][Arithmetic:2]] *)
let ( + ) a b = let ( + ) a b =
@ -257,4 +228,6 @@ let pp_string ppf x =
let pp_int ppf x = let pp_int ppf x =
Format.fprintf ppf "@[%d@]" (to_int x) Format.fprintf ppf "@[%d@]" (to_int x)
let pp = pp_string
(* Printers:2 ends here *) (* Printers:2 ends here *)

View File

@ -16,54 +16,26 @@ type kind =
| Quartet of (t * t * t * t) | Quartet of (t * t * t * t)
(* types ends here *) (* types ends here *)
(* ~of_char~ *) (* Conversions *)
(* [[file:../angular_momentum.org::*~of_char~][~of_char~:1]] *) (* [[file:../angular_momentum.org::*Conversions][Conversions:1]] *)
val of_char : char -> t val of_char : char -> t
(* ~of_char~:1 ends here *)
(* ~to_string~ *)
(* [[file:../angular_momentum.org::*~to_string~][~to_string~:1]] *)
val to_string : t -> string
(* ~to_string~:1 ends here *)
(* ~to_char~ *)
(* [[file:../angular_momentum.org::*~to_char~][~to_char~:1]] *)
val to_char : t -> char val to_char : t -> char
(* ~to_char~:1 ends here *)
(* ~to_int~ *)
(* [[file:../angular_momentum.org::*~to_int~][~to_int~:1]] *)
val to_int : t -> int val to_int : t -> int
(* ~to_int~:1 ends here *)
(* ~of_int~ *)
(* [[file:../angular_momentum.org::*~of_int~][~of_int~:1]] *)
val of_int : int -> t val of_int : int -> t
(* ~of_int~:1 ends here *)
(* ~n_functions~ *) val to_string : t -> string
(* Conversions:1 ends here *)
(* Shell functions *)
(* [[file:../angular_momentum.org::*~n_functions~][~n_functions~:1]] *) (* [[file:../angular_momentum.org::*Shell functions][Shell functions:1]] *)
val n_functions : t -> int val n_functions : t -> int
(* ~n_functions~:1 ends here *)
(* ~zkey_array~ *)
(* [[file:../angular_momentum.org::*~zkey_array~][~zkey_array~:1]] *)
val zkey_array : kind -> Zkey.t array val zkey_array : kind -> Zkey.t array
(* ~zkey_array~:1 ends here *) (* Shell functions:1 ends here *)
(* Arithmetic *) (* Arithmetic *)
@ -75,10 +47,11 @@ val ( - ) : t -> t -> t
(* Printers (* Printers
* *
* Printers can print as a string (~pp_string~) or as an integer (~pp_int~). *) * Printers can print as a string (default) or as an integer. *)
(* [[file:../angular_momentum.org::*Printers][Printers:1]] *) (* [[file:../angular_momentum.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
val pp_string : Format.formatter -> t -> unit val pp_string : Format.formatter -> t -> unit
val pp_int : Format.formatter -> t -> unit val pp_int : Format.formatter -> t -> unit
(* Printers:1 ends here *) (* Printers:1 ends here *)

View File

@ -81,249 +81,173 @@ type t =
(* Creates a bit string from an ~int~. *) (* | ~of_int~ | Creates a bit string from an ~int~ |
* | ~of_z~ | Creates a bit string from an ~Z.t~ multi-precision integer |
* | ~zero~ | ~zero n~ creates a zero bit string with ~n~ bits |
* | ~is_zero~ | True if all the bits of the bit string are zero. |
* | ~numbits~ | Returns the number of bits used to represent the bit string |
* | ~testbit~ | ~testbit t n~ is true if the ~n~-th bit of the bit string ~t~ is set to ~1~ |
* | ~neg~ | Returns the negative of the integer interpretation of the bit string |
* | ~shift_left~ | ~shift_left t n~ returns a new bit strings with all the bits shifted ~n~ positions to the left |
* | ~shift_right~ | ~shift_right t n~ returns a new bit strings with all the bits shifted ~n~ positions to the right |
* | ~shift_left_one~ | ~shift_left_one size n~ returns a new bit strings with the ~n~-th bit set to one. It is equivalent as shifting ~1~ by ~n~ bits to the left, ~size~ is the total number of bits of the bit string |
* | ~logor~ | Bitwise logical or |
* | ~logxor~ | Bitwise logical exclusive or |
* | ~logand~ | Bitwise logical and |
* | ~lognot~ | Bitwise logical negation |
* | ~plus_one~ | Takes the integer representation of the bit string and adds one |
* | ~minus_one~ | Takes the integer representation of the bit string and removes one |
* | ~hamdist~ | Returns the Hamming distance, i.e. the number of bits differing between two bit strings |
* | ~trailing_zeros~ | Returns the number of trailing zeros in the bit string |
* | ~permutations~ | ~permutations m n~ generates the list of all possible ~n~-bit strings with ~m~ bits set to ~1~. Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]] |
* | ~popcount~ | Returns the number of bits set to one in the bit string |
* | ~to_list~ | Converts a bit string into a list of integers indicating the positions where the bits are set to ~1~. The first value for the position is not ~0~ but ~1~ | *)
(* [[file:../bitstring.org::*~of_int~][~of_int~:2]] *) (* [[file:../bitstring.org::*General implementation][General implementation:2]] *)
let of_int x = let of_int x =
One (One.of_int x) One (One.of_int x)
(* ~of_int~:2 ends here *) (* General implementation:2 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:4]] *)
(* Creates a bit string from an ~Z.t~ multi-precision integer. *)
(* [[file:../bitstring.org::*~of_z~][~of_z~:2]] *)
let of_z x = let of_z x =
if Z.numbits x < 64 then One (Z.to_int x) else Many (Many.of_z x) if Z.numbits x < 64 then One (Z.to_int x) else Many (Many.of_z x)
(* ~of_z~:2 ends here *) (* General implementation:4 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:6]] *)
(* ~zero n~ creates a zero bit string with ~n~ bits. *)
(* [[file:../bitstring.org::*~zero~][~zero~:2]] *)
let zero = function let zero = function
| n when n < 64 -> One (One.zero) | n when n < 64 -> One (One.zero)
| _ -> Many (Many.zero) | _ -> Many (Many.zero)
(* ~zero~:2 ends here *) (* General implementation:6 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:7]] *)
(* Returns the number of bits used to represent the bit string. *)
(* [[file:../bitstring.org::*~numbits~][~numbits~:2]] *)
let numbits = function let numbits = function
| One x -> One.numbits x | One x -> One.numbits x
| Many x -> Many.numbits x | Many x -> Many.numbits x
(* ~numbits~:2 ends here *) (* General implementation:7 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:8]] *)
(* True if all the bits of the bit string are zero. *)
(* [[file:../bitstring.org::*~is_zero~][~is_zero~:2]] *)
let is_zero = function let is_zero = function
| One x -> One.is_zero x | One x -> One.is_zero x
| Many x -> Many.is_zero x | Many x -> Many.is_zero x
(* ~is_zero~:2 ends here *) (* General implementation:8 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:9]] *)
(* Returns the negative of the integer interpretation of the bit string.
*
* #+begin_example
* neg (of_int x) = neg (of_int (-x))
* #+end_example *)
(* [[file:../bitstring.org::*~neg~][~neg~:2]] *)
let neg = function let neg = function
| One x -> One (One.neg x) | One x -> One (One.neg x)
| Many x -> Many (Many.neg x) | Many x -> Many (Many.neg x)
(* ~neg~:2 ends here *) (* General implementation:9 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:10]] *)
(* ~shift_left t n~ returns a new bit strings with all the bits
* shifted ~n~ positions to the left. *)
(* [[file:../bitstring.org::*~shift_left~][~shift_left~:2]] *)
let shift_left x i = match x with let shift_left x i = match x with
| One x -> One (One.shift_left x i) | One x -> One (One.shift_left x i)
| Many x -> Many (Many.shift_left x i) | Many x -> Many (Many.shift_left x i)
(* ~shift_left~:2 ends here *) (* General implementation:10 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:12]] *)
(* ~shift_right t n~ returns a new bit strings with all the bits
* shifted ~n~ positions to the right. *)
(* [[file:../bitstring.org::*~shift_right~][~shift_right~:2]] *)
let shift_right x i = match x with let shift_right x i = match x with
| One x -> One (One.shift_right x i) | One x -> One (One.shift_right x i)
| Many x -> Many (Many.shift_right x i) | Many x -> Many (Many.shift_right x i)
(* ~shift_right~:2 ends here *) (* General implementation:12 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:14]] *)
(* ~shift_left_one size n~ returns a new bit strings with the ~n~-th
* bit set to one.
* It is equivalent as shifting ~1~ by ~n~ bits to the left.
* ~size~ is the total number of bits of the bit string. *)
(* [[file:../bitstring.org::*~shift_left_one~][~shift_left_one~:2]] *)
let shift_left_one = function let shift_left_one = function
| n when n < 64 -> fun i -> One (One.shift_left_one i) | n when n < 64 -> fun i -> One (One.shift_left_one i)
| _ -> fun i -> Many (Many.shift_left_one i) | _ -> fun i -> Many (Many.shift_left_one i)
(* ~shift_left_one~:2 ends here *) (* General implementation:14 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:16]] *)
(* ~testbit t n~ is true if the ~n~-th bit of the bit string ~t~ is
* set to ~1~. *)
(* [[file:../bitstring.org::*~testbit~][~testbit~:2]] *)
let testbit = function let testbit = function
| One x -> One.testbit x | One x -> One.testbit x
| Many x -> Many.testbit x | Many x -> Many.testbit x
(* ~testbit~:2 ends here *) (* General implementation:16 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:18]] *)
(* Bitwise logical or. *)
(* [[file:../bitstring.org::*~logor~][~logor~:2]] *)
let logor a b = let logor a b =
match a,b with match a,b with
| One a, One b -> One (One.logor a b) | One a, One b -> One (One.logor a b)
| Many a, Many b -> Many (Many.logor a b) | Many a, Many b -> Many (Many.logor a b)
| _ -> invalid_arg "Bitstring.logor" | _ -> invalid_arg "Bitstring.logor"
(* ~logor~:2 ends here *) (* General implementation:18 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:20]] *)
(* Bitwise logical exclusive or. *)
(* [[file:../bitstring.org::*~logxor~][~logxor~:2]] *)
let logxor a b = let logxor a b =
match a,b with match a,b with
| One a, One b -> One (One.logxor a b) | One a, One b -> One (One.logxor a b)
| Many a, Many b -> Many (Many.logxor a b) | Many a, Many b -> Many (Many.logxor a b)
| _ -> invalid_arg "Bitstring.logxor" | _ -> invalid_arg "Bitstring.logxor"
(* ~logxor~:2 ends here *) (* General implementation:20 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:22]] *)
(* Bitwise logical and. *)
(* [[file:../bitstring.org::*~logand~][~logand~:2]] *)
let logand a b = let logand a b =
match a,b with match a,b with
| One a, One b -> One (One.logand a b) | One a, One b -> One (One.logand a b)
| Many a, Many b -> Many (Many.logand a b) | Many a, Many b -> Many (Many.logand a b)
| _ -> invalid_arg "Bitstring.logand" | _ -> invalid_arg "Bitstring.logand"
(* ~logand~:2 ends here *) (* General implementation:22 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:24]] *)
(* Bitwise logical negation. *)
(* [[file:../bitstring.org::*~lognot~][~lognot~:2]] *)
let lognot = function let lognot = function
| One x -> One (One.lognot x) | One x -> One (One.lognot x)
| Many x -> Many (Many.lognot x) | Many x -> Many (Many.lognot x)
(* ~lognot~:2 ends here *) (* General implementation:24 ends here *)
(* Takes the integer representation of the bit string and removes one.
* (* #+begin_example
* #+begin_example
* minus_one (of_int 10) = of_int 9 * minus_one (of_int 10) = of_int 9
* #+end_example *) * #+end_example *)
(* [[file:../bitstring.org::*~minus_one~][~minus_one~:2]] *) (* [[file:../bitstring.org::*General implementation][General implementation:25]] *)
let minus_one = function let minus_one = function
| One x -> One (One.minus_one x) | One x -> One (One.minus_one x)
| Many x -> Many (Many.minus_one x) | Many x -> Many (Many.minus_one x)
(* ~minus_one~:2 ends here *) (* General implementation:25 ends here *)
(* Takes the integer representation of the bit string and adds one.
* (* #+begin_example
* #+begin_example
* plus_one (of_int 10) = of_int 11 * plus_one (of_int 10) = of_int 11
* #+end_example *) * #+end_example *)
(* [[file:../bitstring.org::*~plus_one~][~plus_one~:2]] *) (* [[file:../bitstring.org::*General implementation][General implementation:26]] *)
let plus_one = function let plus_one = function
| One x -> One (One.plus_one x) | One x -> One (One.plus_one x)
| Many x -> Many (Many.plus_one x) | Many x -> Many (Many.plus_one x)
(* ~plus_one~:2 ends here *) (* General implementation:26 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:27]] *)
(* Returns the number of trailing zeros in the bit string. *)
(* [[file:../bitstring.org::*~trailing_zeros~][~trailing_zeros~:2]] *)
let trailing_zeros = function let trailing_zeros = function
| One x -> One.trailing_zeros x | One x -> One.trailing_zeros x
| Many x -> Many.trailing_zeros x | Many x -> Many.trailing_zeros x
(* ~trailing_zeros~:2 ends here *) (* General implementation:27 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:28]] *)
(* Returns the Hamming distance, i.e. the number of bits differing
* between two bit strings. *)
(* [[file:../bitstring.org::*~hamdist~][~hamdist~:2]] *)
let hamdist a b = match a, b with let hamdist a b = match a, b with
| One a, One b -> One.hamdist a b | One a, One b -> One.hamdist a b
| Many a, Many b -> Many.hamdist a b | Many a, Many b -> Many.hamdist a b
| _ -> invalid_arg "Bitstring.hamdist" | _ -> invalid_arg "Bitstring.hamdist"
(* ~hamdist~:2 ends here *) (* General implementation:28 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:29]] *)
(* Returns the number of bits set to one in the bit string. *)
(* [[file:../bitstring.org::*~popcount~][~popcount~:2]] *)
let popcount = function let popcount = function
| One x -> One.popcount x | One x -> One.popcount x
| Many x -> Many.popcount x | Many x -> Many.popcount x
(* ~popcount~:2 ends here *) (* General implementation:29 ends here *)
(* Converts a bit string into a list of integers indicating the
* positions where the bits are set to ~1~. The first value for the (* #+begin_example
* position is not ~0~ but ~1~.
*
* #+begin_example
* Bitstring.to_list (of_int 5);; * Bitstring.to_list (of_int 5);;
* - : int list = [1; 3] * - : int list = [1; 3]
* #+end_example *) * #+end_example *)
(* [[file:../bitstring.org::*~to_list~][~to_list~:2]] *) (* [[file:../bitstring.org::*General implementation][General implementation:30]] *)
let rec to_list ?(accu=[]) = function let rec to_list ?(accu=[]) = function
| t when (is_zero t) -> List.rev accu | t when (is_zero t) -> List.rev accu
| t -> let newlist = | t -> let newlist =
@ -331,15 +255,11 @@ let rec to_list ?(accu=[]) = function
in in
logand t @@ minus_one t logand t @@ minus_one t
|> (to_list [@tailcall]) ~accu:newlist |> (to_list [@tailcall]) ~accu:newlist
(* ~to_list~:2 ends here *) (* General implementation:30 ends here *)
(* ~permutations m n~ generates the list of all possible ~n~-bit (* #+begin_example
* strings with ~m~ bits set to ~1~.
* Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]].
*
* #+begin_example
* Bitstring.permutations 2 4 * Bitstring.permutations 2 4
* |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; * |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
* - : string list = * - : string list =
@ -352,7 +272,7 @@ let rec to_list ?(accu=[]) = function
* #+end_example *) * #+end_example *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:2]] *) (* [[file:../bitstring.org::*General implementation][General implementation:32]] *)
let permutations m n = let permutations m n =
let rec aux k u rest = let rec aux k u rest =
@ -370,7 +290,7 @@ let permutations m n =
(aux [@tailcall]) (k-1) (logor t' t'') (u :: rest) (aux [@tailcall]) (k-1) (logor t' t'') (u :: rest)
in in
aux (Util.binom n m) (minus_one (shift_left_one n m)) [] aux (Util.binom n m) (minus_one (shift_left_one n m)) []
(* ~permutations~:2 ends here *) (* General implementation:32 ends here *)
(* [[file:../bitstring.org::*Printers][Printers:2]] *) (* [[file:../bitstring.org::*Printers][Printers:2]] *)
let pp ppf = function let pp ppf = function

View File

@ -5,153 +5,38 @@
type t type t
(* Type:1 ends here *) (* Type:1 ends here *)
(* ~of_int~ *) (* General implementation *)
(* [[file:../bitstring.org::*~of_int~][~of_int~:1]] *) (* [[file:../bitstring.org::*General implementation][General implementation:1]] *)
val of_int : int -> t val of_int : int -> t
(* ~of_int~:1 ends here *)
(* ~of_z~ *)
(* [[file:../bitstring.org::*~of_z~][~of_z~:1]] *)
val of_z : Z.t -> t val of_z : Z.t -> t
(* ~of_z~:1 ends here *)
(* ~zero~ *)
(* [[file:../bitstring.org::*~zero~][~zero~:1]] *)
val zero : int -> t val zero : int -> t
(* ~zero~:1 ends here *)
(* ~numbits~ *)
(* [[file:../bitstring.org::*~numbits~][~numbits~:1]] *)
val numbits : t -> int
(* ~numbits~:1 ends here *)
(* ~is_zero~ *)
(* [[file:../bitstring.org::*~is_zero~][~is_zero~:1]] *)
val is_zero : t -> bool val is_zero : t -> bool
(* ~is_zero~:1 ends here *) val numbits : t -> int
(* ~neg~ *)
(* [[file:../bitstring.org::*~neg~][~neg~:1]] *)
val neg : t -> t
(* ~neg~:1 ends here *)
(* ~shift_left~ *)
(* [[file:../bitstring.org::*~shift_left~][~shift_left~:1]] *)
val shift_left : t -> int -> t
(* ~shift_left~:1 ends here *)
(* ~shift_right~ *)
(* [[file:../bitstring.org::*~shift_right~][~shift_right~:1]] *)
val shift_right : t -> int -> t
(* ~shift_right~:1 ends here *)
(* ~shift_left_one~ *)
(* [[file:../bitstring.org::*~shift_left_one~][~shift_left_one~:1]] *)
val shift_left_one : int -> int -> t
(* ~shift_left_one~:1 ends here *)
(* ~testbit~ *)
(* [[file:../bitstring.org::*~testbit~][~testbit~:1]] *)
val testbit : t -> int -> bool val testbit : t -> int -> bool
(* ~testbit~:1 ends here *)
(* ~logor~ *) val neg : t -> t
val shift_left : t -> int -> t
val shift_right : t -> int -> t
val shift_left_one : int -> int -> t
(* [[file:../bitstring.org::*~logor~][~logor~:1]] *)
val logor : t -> t -> t val logor : t -> t -> t
(* ~logor~:1 ends here *)
(* ~logxor~ *)
(* [[file:../bitstring.org::*~logxor~][~logxor~:1]] *)
val logxor : t -> t -> t val logxor : t -> t -> t
(* ~logxor~:1 ends here *)
(* ~logand~ *)
(* [[file:../bitstring.org::*~logand~][~logand~:1]] *)
val logand : t -> t -> t val logand : t -> t -> t
(* ~logand~:1 ends here *)
(* ~lognot~ *)
(* [[file:../bitstring.org::*~lognot~][~lognot~:1]] *)
val lognot : t -> t val lognot : t -> t
(* ~lognot~:1 ends here *)
(* ~minus_one~ *)
(* [[file:../bitstring.org::*~minus_one~][~minus_one~:1]] *)
val minus_one : t -> t
(* ~minus_one~:1 ends here *)
(* ~plus_one~ *)
(* [[file:../bitstring.org::*~plus_one~][~plus_one~:1]] *)
val plus_one : t -> t val plus_one : t -> t
(* ~plus_one~:1 ends here *) val minus_one : t -> t
(* ~trailing_zeros~ *)
(* [[file:../bitstring.org::*~trailing_zeros~][~trailing_zeros~:1]] *)
val trailing_zeros : t -> int
(* ~trailing_zeros~:1 ends here *)
(* ~hamdist~ *)
(* [[file:../bitstring.org::*~hamdist~][~hamdist~:1]] *)
val hamdist : t -> t -> int val hamdist : t -> t -> int
(* ~hamdist~:1 ends here *) val trailing_zeros : t -> int
(* ~popcount~ *)
(* [[file:../bitstring.org::*~popcount~][~popcount~:1]] *)
val popcount : t -> int val popcount : t -> int
(* ~popcount~:1 ends here *)
(* ~to_list~ *)
(* [[file:../bitstring.org::*~to_list~][~to_list~:1]] *)
val to_list : ?accu:(int list) -> t -> int list val to_list : ?accu:(int list) -> t -> int list
(* ~to_list~:1 ends here *)
(* ~permutations~ *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:1]] *)
val permutations : int -> int -> t list val permutations : int -> int -> t list
(* ~permutations~:1 ends here *) (* General implementation:1 ends here *)
(* Printers *) (* Printers *)

View File

@ -1,18 +1,19 @@
(* This type should be used for all charges in the program (electrons, nuclei,...). *)
(* [[file:../charge.org::*Type][Type:2]] *) (* [[file:../charge.org::*Type][Type:2]] *)
type t = float type t = float
(* Type:2 ends here *) (* Type:2 ends here *)
(* [[file:../charge.org::*~of_float~ / ~to_float~][~of_float~ / ~to_float~:2]] *) (* [[file:../charge.org::*Conversions][Conversions:2]] *)
external of_float : float -> t = "%identity" external of_float : float -> t = "%identity"
external to_float : t -> float = "%identity" external to_float : t -> float = "%identity"
(* ~of_float~ / ~to_float~:2 ends here *)
(* [[file:../charge.org::*~of_int~ / ~to_int~][~of_int~ / ~to_int~:2]] *)
let of_int = float_of_int let of_int = float_of_int
let to_int = int_of_float let to_int = int_of_float
(* ~of_int~ / ~to_int~:2 ends here *)
(* [[file:../charge.org::*~of_string~ / ~to_string~][~of_string~ / ~to_string~:2]] *)
let of_string = float_of_string let of_string = float_of_string
let to_string x = let to_string x =
@ -22,7 +23,7 @@ let to_string x =
Printf.sprintf "%f" x Printf.sprintf "%f" x
else else
"0.0" "0.0"
(* ~of_string~ / ~to_string~:2 ends here *) (* Conversions:2 ends here *)
(* [[file:../charge.org::*Simple operations][Simple operations:2]] *) (* [[file:../charge.org::*Simple operations][Simple operations:2]] *)
let gen_op op = let gen_op op =

View File

@ -1,35 +1,23 @@
(* Type (* Type *)
*
* This type should be used for all charges in the program (electrons, nuclei,...). *)
(* [[file:../charge.org::*Type][Type:1]] *) (* [[file:../charge.org::*Type][Type:1]] *)
type t type t
(* Type:1 ends here *) (* Type:1 ends here *)
(* ~of_float~ / ~to_float~ *) (* Conversions *)
(* [[file:../charge.org::*~of_float~ / ~to_float~][~of_float~ / ~to_float~:1]] *) (* [[file:../charge.org::*Conversions][Conversions:1]] *)
val of_float : float -> t val of_float : float -> t
val to_float : t -> float val to_float : t -> float
(* ~of_float~ / ~to_float~:1 ends here *)
(* ~of_int~ / ~to_int~ *)
(* [[file:../charge.org::*~of_int~ / ~to_int~][~of_int~ / ~to_int~:1]] *)
val of_int : int -> t val of_int : int -> t
val to_int : t -> int val to_int : t -> int
(* ~of_int~ / ~to_int~:1 ends here *)
(* ~of_string~ / ~to_string~ *)
(* [[file:../charge.org::*~of_string~ / ~to_string~][~of_string~ / ~to_string~:1]] *)
val of_string: string -> t val of_string: string -> t
val to_string: t -> string val to_string: t -> string
(* ~of_string~ / ~to_string~:1 ends here *) (* Conversions:1 ends here *)
(* Simple operations *) (* Simple operations *)

View File

@ -151,19 +151,15 @@ let output_long max_width x =
(* Returns the list of anonymous arguments *) (* | ~get~ | Returns the argument associated with a long option |
* | ~get_bool~ | True if the ~Optional~ argument is present in the command-line |
* | ~anon_args~ | Returns the list of anonymous arguments | *)
(* [[file:../command_line.org::*~anon_args~][~anon_args~:2]] *)
(* [[file:../command_line.org::*Query functions][Query functions:2]] *)
let anon_args () = !anon_args_ref let anon_args () = !anon_args_ref
(* ~anon_args~:2 ends here *)
(* ~help~ :noexport:
*
* Prints the documentation of the program. *)
(* [[file:../command_line.org::*~help~][~help~:1]] *)
let help () = let help () =
(* Print the header *) (* Print the header *)
@ -229,27 +225,15 @@ let help () =
(* Print footer *) (* Print footer *)
output_text !footer_doc; output_text !footer_doc;
Format.printf "@." Format.printf "@."
(* ~help~:1 ends here *)
(* Returns the argument associated with a long option. *)
(* [[file:../command_line.org::*~get~][~get~:2]] *)
let get x = let get x =
try Some (Hashtbl.find dict x) try Some (Hashtbl.find dict x)
with Not_found -> None with Not_found -> None
(* ~get~:2 ends here *)
(* True if the ~Optional~ argument is present in the command-line *)
(* [[file:../command_line.org::*~get_bool~][~get_bool~:2]] *)
let get_bool x = Hashtbl.mem dict x let get_bool x = Hashtbl.mem dict x
(* ~get_bool~:2 ends here *) (* Query functions:2 ends here *)

View File

@ -28,26 +28,14 @@ val set_footer_doc : string -> unit
val anonymous : long_opt -> optional -> documentation -> description val anonymous : long_opt -> optional -> documentation -> description
(* Mutable attributes:4 ends here *) (* Mutable attributes:4 ends here *)
(* ~anon_args~ *) (* Query functions *)
(* [[file:../command_line.org::*~anon_args~][~anon_args~:1]] *) (* [[file:../command_line.org::*Query functions][Query functions:1]] *)
val anon_args : unit -> string list
(* ~anon_args~:1 ends here *)
(* ~get~ *)
(* [[file:../command_line.org::*~get~][~get~:1]] *)
val get : long_opt -> string option val get : long_opt -> string option
(* ~get~:1 ends here *)
(* ~get_bool~ *)
(* [[file:../command_line.org::*~get_bool~][~get_bool~:1]] *)
val get_bool : long_opt -> bool val get_bool : long_opt -> bool
(* ~get_bool~:1 ends here *) val anon_args : unit -> string list
(* Query functions:1 ends here *)
(* Specification *) (* Specification *)

View File

@ -15,84 +15,69 @@ type t = bohr point
type axis = X | Y | Z type axis = X | Y | Z
(* Type:2 ends here *) (* Type:2 ends here *)
(* [[file:../coordinate.org::*~make~][~make~:2]] *)
(* | ~make~ | Creates a point in atomic units |
* | ~make_angstrom~ | Creates a point in angstrom |
* | ~zero~ | $(0., 0., 0.)$ | *)
(* [[file:../coordinate.org::*Creation][Creation:2]] *)
external make : 'a point -> t = "%identity" external make : 'a point -> t = "%identity"
(* ~make~:2 ends here *)
(* [[file:../coordinate.org::*~make_angstrom~][~make_angstrom~:2]] *)
external make_angstrom : 'a point -> angstrom point = "%identity" external make_angstrom : 'a point -> angstrom point = "%identity"
(* ~make_angstrom~:2 ends here *)
(* [[file:../coordinate.org::*~bohr_to_angstrom~][~bohr_to_angstrom~:2]] *) let zero =
make { x = 0. ; y = 0. ; z = 0. }
(* Creation:2 ends here *)
(* | ~bohr_to_angstrom~ | Converts a point in bohr to angstrom |
* | ~angstrom_to_bohr~ | Converts a point in angstrom to bohr | *)
(* [[file:../coordinate.org::*Conversion][Conversion:2]] *)
let b_to_a b = Constants.a0 *. b let b_to_a b = Constants.a0 *. b
let bohr_to_angstrom { x ; y ; z } = let bohr_to_angstrom { x ; y ; z } =
make { x = b_to_a x ; make { x = b_to_a x ;
y = b_to_a y ; y = b_to_a y ;
z = b_to_a z ; } z = b_to_a z ; }
(* ~bohr_to_angstrom~:2 ends here *)
(* [[file:../coordinate.org::*~angstrom_to_bohr~][~angstrom_to_bohr~:2]] *)
let a_to_b a = Constants.a0_inv *. a let a_to_b a = Constants.a0_inv *. a
let angstrom_to_bohr { x ; y ; z } = let angstrom_to_bohr { x ; y ; z } =
make { x = a_to_b x ; make { x = a_to_b x ;
y = a_to_b y ; y = a_to_b y ;
z = a_to_b z ; } z = a_to_b z ; }
(* ~angstrom_to_bohr~:2 ends here *) (* Conversion:2 ends here *)
(* [[file:../coordinate.org::*~zero~][~zero~:2]] *)
let zero =
make { x = 0. ; y = 0. ; z = 0. }
(* ~zero~:2 ends here *)
(* [[file:../coordinate.org::*~get~][~get~:2]] *)
let get axis { x ; y ; z } =
match axis with
| X -> x
| Y -> y
| Z -> z
(* ~get~:2 ends here *)
(* #+begin_example (* | ~neg~ | Negative of a point |
* | ~get~ | Extracts the projection of the coordinate on an axis |
* | ~dot~ | Dot product |
* | ~norm~ | $\ell{^2}$ norm of the vector |
* | ~¦.~ | Scales the vector by a constant |
* | ~¦+~ | Adds two vectors |
* | ~¦-~ | Subtracts two vectors |
*
* #+begin_example
* Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
* - : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.}
*
* Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;;
* - : float = 2.
*
* Coordinate.( * Coordinate.(
* 2. |. { x=1. ; y=2. ; z=3. } * 2. |. { x=1. ; y=2. ; z=3. }
* ) ;; * ) ;;
* - : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.} * - : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.}
* #+end_example *) *
(* [[file:../coordinate.org::*Scale][Scale:2]] *)
let ( |. ) s { x ; y ; z } =
make { x = s *. x ;
y = s *. y ;
z = s *. z ; }
(* Scale:2 ends here *)
(* #+begin_example
* Coordinate.( * Coordinate.(
* { x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. } * { x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. }
* );; * );;
* - : Coordinate.t = {Qcaml.Common.Coordinate.x = 3.; y = 5.; z = 4.} * - : Coordinate.t = {Qcaml.Common.Coordinate.x = 3.; y = 5.; z = 4.}
* #+end_example *) *
(* [[file:../coordinate.org::*Add][Add:2]] *)
let ( |+ )
{ x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } =
make { x = x1 +. x2 ;
y = y1 +. y2 ;
z = z1 +. z2 ; }
(* Add:2 ends here *)
(* #+begin_example
* Coordinate.( * Coordinate.(
* { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. } * { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. }
* );; * );;
@ -100,45 +85,56 @@ let ( |+ )
* #+end_example *) * #+end_example *)
(* [[file:../coordinate.org::*Subtract][Subtract:2]] *)
(* [[file:../coordinate.org::*Vector operations][Vector operations:2]] *)
let get axis { x ; y ; z } =
match axis with
| X -> x
| Y -> y
| Z -> z
let ( |. ) s { x ; y ; z } =
make { x = s *. x ;
y = s *. y ;
z = s *. z ; }
let ( |+ )
{ x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } =
make { x = x1 +. x2 ;
y = y1 +. y2 ;
z = z1 +. z2 ; }
let ( |- ) let ( |- )
{ x = x1 ; y = y1 ; z = z1 } { x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } = { x = x2 ; y = y2 ; z = z2 } =
make { x = x1 -. x2 ; make { x = x1 -. x2 ;
y = y1 -. y2 ; y = y1 -. y2 ;
z = z1 -. z2 ; } z = z1 -. z2 ; }
(* Subtract:2 ends here *)
(* #+begin_example
* Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
* - : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.}
* #+end_example *)
(* [[file:../coordinate.org::*Negative][Negative:2]] *)
let neg a = -1. |. a let neg a = -1. |. a
(* Negative:2 ends here *)
(* [[file:../coordinate.org::*Dot product][Dot product:2]] *)
let dot let dot
{ x = x1 ; y = y1 ; z = z1 } { x = x1 ; y = y1 ; z = z1 }
{ x = x2 ; y = y2 ; z = z2 } = { x = x2 ; y = y2 ; z = z2 } =
x1 *. x2 +. x1 *. x2 +.
y1 *. y2 +. y1 *. y2 +.
z1 *. z2 z1 *. z2
(* Dot product:2 ends here *)
(* $\ell{^2}$ norm of the vector. *)
(* [[file:../coordinate.org::*Norm][Norm:2]] *)
let norm u = let norm u =
sqrt ( dot u u ) sqrt ( dot u u )
(* Norm:2 ends here *) (* Vector operations:2 ends here *)
(* Coordinates can be printed in bohr or angstrom. *)
(* [[file:../coordinate.org::*Printers][Printers:2]] *) (* [[file:../coordinate.org::*Printers][Printers:2]] *)
open Format open Format

View File

@ -19,110 +19,37 @@ type t = bohr point
type axis = X | Y | Z type axis = X | Y | Z
(* types ends here *) (* types ends here *)
(* ~make~ (* Creation *)
*
* Creates a point in atomic units. *)
(* [[file:../coordinate.org::*~make~][~make~:1]] *) (* [[file:../coordinate.org::*Creation][Creation:1]] *)
val make : 'a point -> t val make : 'a point -> t
(* ~make~:1 ends here *)
(* ~make_angstrom~
*
* Creates a point in angstrom. *)
(* [[file:../coordinate.org::*~make_angstrom~][~make_angstrom~:1]] *)
val make_angstrom : 'a point -> angstrom point val make_angstrom : 'a point -> angstrom point
(* ~make_angstrom~:1 ends here *)
(* ~bohr_to_angstrom~
*
* Converts a point in bohr to angstrom. *)
(* [[file:../coordinate.org::*~bohr_to_angstrom~][~bohr_to_angstrom~:1]] *)
val bohr_to_angstrom : bohr point -> angstrom point
(* ~bohr_to_angstrom~:1 ends here *)
(* ~angstrom_to_bohr~
*
* Converts a point in angstrom to bohr. *)
(* [[file:../coordinate.org::*~angstrom_to_bohr~][~angstrom_to_bohr~:1]] *)
val angstrom_to_bohr : angstrom point -> bohr point
(* ~angstrom_to_bohr~:1 ends here *)
(* ~zero~
*
* ~zero~ = (0., 0., 0.) *)
(* [[file:../coordinate.org::*~zero~][~zero~:1]] *)
val zero : bohr point val zero : bohr point
(* ~zero~:1 ends here *) (* Creation:1 ends here *)
(* ~get~ (* Conversion *)
*
* Extracts the projection of the coordinate on an axis.
*
* #+begin_example
* Coordinate.(get Y { x=1. ; y=2. ; z=3. })
* - float: 2.
* #+end_example *)
(* [[file:../coordinate.org::*~get~][~get~:1]] *) (* [[file:../coordinate.org::*Conversion][Conversion:1]] *)
val get : axis -> bohr point -> float val bohr_to_angstrom : bohr point -> angstrom point
(* ~get~:1 ends here *) val angstrom_to_bohr : angstrom point -> bohr point
(* Conversion:1 ends here *)
(* Scale *) (* Vector operations *)
(* [[file:../coordinate.org::*Scale][Scale:1]] *) (* [[file:../coordinate.org::*Vector operations][Vector operations:1]] *)
val ( |. ) : float -> t -> t
(* Scale:1 ends here *)
(* Add *)
(* [[file:../coordinate.org::*Add][Add:1]] *)
val ( |+ ) : t -> t -> t
(* Add:1 ends here *)
(* Subtract *)
(* [[file:../coordinate.org::*Subtract][Subtract:1]] *)
val ( |- ) : t -> t -> t
(* Subtract:1 ends here *)
(* Negative *)
(* [[file:../coordinate.org::*Negative][Negative:1]] *)
val neg : t -> t val neg : t -> t
(* Negative:1 ends here *) val get : axis -> bohr point -> float
(* Dot product *)
(* [[file:../coordinate.org::*Dot product][Dot product:1]] *)
val dot : t -> t -> float val dot : t -> t -> float
(* Dot product:1 ends here *)
(* Norm *)
(* [[file:../coordinate.org::*Norm][Norm:1]] *)
val norm : t -> float val norm : t -> float
(* Norm:1 ends here *) val ( |. ) : float -> t -> t
val ( |+ ) : t -> t -> t
val ( |- ) : t -> t -> t
(* Vector operations:1 ends here *)
(* Printers (* Printers *)
*
* Coordinates can be printed in bohr or angstrom. *)
(* [[file:../coordinate.org::*Printers][Printers:1]] *) (* [[file:../coordinate.org::*Printers][Printers:1]] *)

View File

@ -1,5 +1,14 @@
(* [[file:../non_negative_float.org::*Type][Type:2]] *)
type t = float type t = float
(* Type:2 ends here *)
(* The ~of_float~ function checks that the float is non-negative.
* The unsafe variant doesn't do this check. *)
(* [[file:../non_negative_float.org::*Conversions][Conversions:2]] *)
let of_float x = let of_float x =
if x < 0. then invalid_arg (__FILE__^": of_float"); if x < 0. then invalid_arg (__FILE__^": of_float");
x x
@ -12,4 +21,4 @@ let to_string x =
let of_string x = let of_string x =
let f = float_of_string x in of_float f let f = float_of_string x in of_float f
(* Conversions:2 ends here *)

View File

@ -1,7 +1,18 @@
(** Floats >= 0. *) (* Type *)
(* [[file:../non_negative_float.org::*Type][Type:1]] *)
type t = private float type t = private float
(* Type:1 ends here *)
(* Conversions *)
(* [[file:../non_negative_float.org::*Conversions][Conversions:1]] *)
val of_float : float -> t val of_float : float -> t
val unsafe_of_float : float -> t val unsafe_of_float : float -> t
val to_float : t -> float val to_float : t -> float
val to_string : t -> string
val of_string : string -> t val of_string : string -> t
val to_string : t -> string
(* Conversions:1 ends here *)

View File

@ -0,0 +1,54 @@
#+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
* Non-negative float
:PROPERTIES:
:header-args: :noweb yes :comments both
:END:
** Type
#+begin_src ocaml :tangle (eval mli)
type t = private float
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
type t = float
#+end_src
** Conversions
#+begin_src ocaml :tangle (eval mli)
val of_float : float -> t
val unsafe_of_float : float -> t
val to_float : t -> float
val of_string : string -> t
val to_string : t -> string
#+end_src
The ~of_float~ function checks that the float is non-negative.
The unsafe variant doesn't do this check.
#+begin_src ocaml :tangle (eval ml) :exports none
let of_float x =
if x < 0. then invalid_arg (__FILE__^": of_float");
x
external to_float : t -> float = "%identity"
external unsafe_of_float : float -> t = "%identity"
let to_string x =
let f = to_float x in string_of_float f
let of_string x =
let f = float_of_string x in of_float f
#+end_src

View File

@ -3,7 +3,8 @@
(* [[file:../bitstring.org::*Tests header][Tests header:1]] *) (* [[file:../bitstring.org::*Tests header][Tests header:1]] *)
open Common.Bitstring open Common.Bitstring
let check msg x = Alcotest.(check bool) msg true x let check_bool = Alcotest.(check bool)
let check msg x = check_bool msg true x
let test_all () = let test_all () =
let x = 8745687 in let x = 8745687 in
let one_x = of_int x in let one_x = of_int x in
@ -11,63 +12,63 @@ let test_all () =
let many_x = of_z z in let many_x = of_z z in
(* Tests header:1 ends here *) (* Tests header:1 ends here *)
(* [[file:../bitstring.org::*~of_int~][~of_int~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:3]] *)
Alcotest.(check bool) "of_x" true (one_x = (of_int x)); check_bool "of_x" true (one_x = (of_int x));
(* ~of_int~:3 ends here *) (* General implementation:3 ends here *)
(* [[file:../bitstring.org::*~of_z~][~of_z~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:5]] *)
Alcotest.(check bool) "of_z" true (one_x = (of_z (Z.of_int x))); check_bool "of_z" true (one_x = (of_z (Z.of_int x)));
(* ~of_z~:3 ends here *) (* General implementation:5 ends here *)
(* [[file:../bitstring.org::*~shift_left~][~shift_left~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:11]] *)
Alcotest.(check bool) "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3);
Alcotest.(check bool) "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3);
Alcotest.(check bool) "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100);
(* ~shift_left~:3 ends here *) (* General implementation:11 ends here *)
(* [[file:../bitstring.org::*~shift_right~][~shift_right~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:13]] *)
Alcotest.(check bool) "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3);
Alcotest.(check bool) "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3);
(* ~shift_right~:3 ends here *) (* General implementation:13 ends here *)
(* [[file:../bitstring.org::*~shift_left_one~][~shift_left_one~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:15]] *)
Alcotest.(check bool) "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3); check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3);
Alcotest.(check bool) "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200); check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200);
(* ~shift_left_one~:3 ends here *) (* General implementation:15 ends here *)
(* [[file:../bitstring.org::*~testbit~][~testbit~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:17]] *)
Alcotest.(check bool) "testbit1" true (testbit (of_int 8) 3); check_bool "testbit1" true (testbit (of_int 8) 3);
Alcotest.(check bool) "testbit2" false (testbit (of_int 8) 2); check_bool "testbit2" false (testbit (of_int 8) 2);
Alcotest.(check bool) "testbit3" false (testbit (of_int 8) 4); check_bool "testbit3" false (testbit (of_int 8) 4);
Alcotest.(check bool) "testbit4" true (testbit (of_z (Z.of_int 8)) 3); check_bool "testbit4" true (testbit (of_z (Z.of_int 8)) 3);
Alcotest.(check bool) "testbit5" false (testbit (of_z (Z.of_int 8)) 2); check_bool "testbit5" false (testbit (of_z (Z.of_int 8)) 2);
Alcotest.(check bool) "testbit6" false (testbit (of_z (Z.of_int 8)) 4); check_bool "testbit6" false (testbit (of_z (Z.of_int 8)) 4);
(* ~testbit~:3 ends here *) (* General implementation:17 ends here *)
(* [[file:../bitstring.org::*~logor~][~logor~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:19]] *)
Alcotest.(check bool) "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2)); check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2));
Alcotest.(check bool) "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2))); check_bool "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2)));
(* ~logor~:3 ends here *) (* General implementation:19 ends here *)
(* [[file:../bitstring.org::*~logxor~][~logxor~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:21]] *)
Alcotest.(check bool) "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2)); check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2));
Alcotest.(check bool) "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2))); check_bool "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2)));
(* ~logxor~:3 ends here *) (* General implementation:21 ends here *)
(* [[file:../bitstring.org::*~logand~][~logand~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:23]] *)
Alcotest.(check bool) "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3)); check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3));
Alcotest.(check bool) "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3))); check_bool "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3)));
(* ~logand~:3 ends here *) (* General implementation:23 ends here *)
(* [[file:../bitstring.org::*~to_list~][~to_list~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:31]] *)
Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
(* ~to_list~:3 ends here *) (* General implementation:31 ends here *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:3]] *) (* [[file:../bitstring.org::*General implementation][General implementation:33]] *)
check "permutations" check "permutations"
(permutations 2 4 = List.map of_int (permutations 2 4 = List.map of_int
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]); [ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
(* ~permutations~:3 ends here *) (* General implementation:33 ends here *)
(* Tests :noexport: *) (* Tests :noexport: *)

View File

@ -69,6 +69,9 @@ with class 'color and highest min-color value."
(advice-add 'face-attribute :override #'my-face-attribute) (advice-add 'face-attribute :override #'my-face-attribute)
(setq org-html-htmlize-output-type 'css) ; default: 'inline-css
(setq org-html-htmlize-font-prefix "org-") ; default: "org-"
(setq ml "ml") (setq ml "ml")
(setq mli "mli") (setq mli "mli")
(setq test-ml "test-ml") (setq test-ml "test-ml")