From aa40a995b2991a9e40d6af8f4253471c563718d2 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 29 Dec 2020 01:08:37 +0100 Subject: [PATCH] Cleaned examples --- bin/tangle.sh | 6 +- common/angular_momentum.org | 17 ++-- common/bitstring.org | 171 +++++++++++++++++---------------- common/coordinate.org | 8 +- common/lib/angular_momentum.ml | 17 ++-- common/lib/bitstring.ml | 119 +++++++++++------------ common/lib/coordinate.ml | 8 +- common/lib/powers.ml | 6 +- common/powers.org | 6 +- common/test/bitstring.ml | 100 +++++++++++++------ particles/lib/element.ml | 8 +- particles/lib/element.mli | 8 +- top/install_printers.org | 1 + top/lib/install_printers.ml | 1 + 14 files changed, 255 insertions(+), 221 deletions(-) diff --git a/bin/tangle.sh b/bin/tangle.sh index 312d752..35bd020 100755 --- a/bin/tangle.sh +++ b/bin/tangle.sh @@ -14,7 +14,7 @@ fi DIR=${1%/} -cat << EOF > ${PWD}/tmpfile +cat << EOF > ${PWD}/tmpfile_$DIR (package-initialize) (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")) @@ -92,10 +92,10 @@ cd $DIR for i in *.org do echo "--- $i ----" - emacs --batch ./$i --load=../tmpfile + emacs --batch ./$i --load=../tmpfile_$DIR done -rm ../tmpfile +rm ../tmpfile_$DIR diff --git a/common/angular_momentum.org b/common/angular_momentum.org index 6dc2f79..2d35ed1 100644 --- a/common/angular_momentum.org +++ b/common/angular_momentum.org @@ -66,13 +66,13 @@ val to_string : t -> string #+begin_example Angular_momentum.of_char 'p';; -- : Angular_momentum.t = Qcaml.Common.Angular_momentum.P +- : Angular_momentum.t = P Angular_momentum.(to_char P);; - : char = 'P' Angular_momentum.of_int 2;; -- : Angular_momentum.t = Qcaml.Common.Angular_momentum.D +- : Angular_momentum.t = D Angular_momentum.(to_int D);; - : int = 2 @@ -147,11 +147,10 @@ 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} |] - +- : Zkey.t array = +[|< 01125899906842624 | 1, 0, 0, 0, 0, 0 >; + < 01099511627776 | 0, 1, 0, 0, 0, 0 >; + < 01073741824 | 0, 0, 1, 0, 0, 0 >|] #+end_example #+begin_src ocaml :tangle (eval ml) :exports none @@ -248,10 +247,10 @@ val ( - ) : t -> t -> t #+begin_example Angular_momentum.(D + P);; -- : Angular_momentum.t = Qcaml.Common.Angular_momentum.F +- : Angular_momentum.t = F Angular_momentum.(F - P);; -- : Angular_momentum.t = Qcaml.Common.Angular_momentum.D +- : Angular_momentum.t = D #+end_example #+begin_src ocaml :tangle (eval ml) :exports none diff --git a/common/bitstring.org b/common/bitstring.org index 7f02cff..91ef5fb 100644 --- a/common/bitstring.org +++ b/common/bitstring.org @@ -176,95 +176,89 @@ val permutations : int -> int -> t list #+begin_src ocaml :tangle (eval ml) :exports none let of_int x = One (One.of_int x) - #+end_src - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "of_x" true (one_x = (of_int x)); - #+end_src - - - #+begin_src ocaml :tangle (eval ml) :exports none let of_z x = if Z.numbits x < 64 then One (Z.to_int x) else Many (Many.of_z x) #+end_src #+begin_src ocaml :tangle (eval test-ml) :exports none +check_bool "of_x" true (one_x = (of_int x)); check_bool "of_z" true (one_x = (of_z (Z.of_int x))); #+end_src - + #+begin_example +Bitstring.of_int 15;; +- : Bitstring.t = +++++------------------------------------------------------------ + #+end_example + #+begin_src ocaml :tangle (eval ml) :exports none let zero = function | n when n < 64 -> One (One.zero) | _ -> Many (Many.zero) - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let numbits = function | One x -> One.numbits x | Many x -> Many.numbits x - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let is_zero = function | One x -> One.is_zero x | Many x -> Many.is_zero x - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let neg = function | One x -> One (One.neg x) | Many x -> Many (Many.neg x) - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let shift_left x i = match x with | One x -> One (One.shift_left x i) | Many x -> Many (Many.shift_left x i) - #+end_src - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); -check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); -check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let shift_right x i = match x with | One x -> One (One.shift_right x i) | Many x -> Many (Many.shift_right x i) - #+end_src - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); -check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); - #+end_src - - - #+begin_src ocaml :tangle (eval ml) :exports none let shift_left_one = function | n when n < 64 -> fun i -> One (One.shift_left_one i) | _ -> fun i -> Many (Many.shift_left_one i) - #+end_src - - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3); -check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200); - #+end_src - - - #+begin_src ocaml :tangle (eval ml) :exports none let testbit = function | One x -> One.testbit x | Many x -> Many.testbit x #+end_src + #+begin_example +Bitstring.(shift_left (of_int 15) 2);; +- : Bitstring.t = +--++++---------------------------------------------------------- + +Bitstring.(shift_right (of_int 15) 2);; +- : Bitstring.t = +++-------------------------------------------------------------- + +Bitstring.shift_left_one 32 4;; +- : Bitstring.t = +----+----------------------------------------------------------- + +Bitstring.(testbit (of_int 15) 3);; +- : bool = true + +Bitstring.(testbit (of_int 15) 4);; +- : bool = false + #+end_example + #+begin_src ocaml :tangle (eval test-ml) :exports none +check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); +check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); +check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); +check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); +check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); +check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3); +check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200); check_bool "testbit1" true (testbit (of_int 8) 3); check_bool "testbit2" false (testbit (of_int 8) 2); check_bool "testbit3" false (testbit (of_int 8) 4); @@ -280,44 +274,22 @@ let logor a b = | One a, One b -> One (One.logor a b) | Many a, Many b -> Many (Many.logor a b) | _ -> invalid_arg "Bitstring.logor" - #+end_src - - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (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 - #+begin_src ocaml :tangle (eval ml) :exports none let logxor a b = match a,b with | One a, One b -> One (One.logxor a b) | Many a, Many b -> Many (Many.logxor a b) | _ -> invalid_arg "Bitstring.logxor" - #+end_src - - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (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 - #+begin_src ocaml :tangle (eval ml) :exports none let logand a b = match a,b with | One a, One b -> One (One.logand a b) | Many a, Many b -> Many (Many.logand a b) | _ -> invalid_arg "Bitstring.logand" - #+end_src - #+begin_src ocaml :tangle (eval test-ml) :exports none -check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (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 - - - #+begin_src ocaml :tangle (eval ml) :exports none let lognot = function | One x -> One (One.lognot x) | Many x -> Many (Many.lognot x) @@ -325,42 +297,65 @@ let lognot = function #+begin_example -minus_one (of_int 10) = of_int 9 +Bitstring.(logor (of_int 15) (of_int 73));; +- : Bitstring.t = +++++--+--------------------------------------------------------- + +Bitstring.(logand (of_int 15) (of_int 10));; +- : Bitstring.t = +-+-+------------------------------------------------------------ + +Bitstring.(logxor (of_int 15) (of_int 73));; +- : Bitstring.t = +-++---+--------------------------------------------------------- #+end_example + + #+begin_src ocaml :tangle (eval test-ml) :exports none +check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (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))); +check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (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))); +check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (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 + + #+begin_src ocaml :tangle (eval ml) :exports none let minus_one = function | One x -> One (One.minus_one x) | Many x -> Many (Many.minus_one x) - #+end_src - #+begin_example -plus_one (of_int 10) = of_int 11 - #+end_example - #+begin_src ocaml :tangle (eval ml) :exports none let plus_one = function | One x -> One (One.plus_one x) | Many x -> Many (Many.plus_one x) #+end_src + #+begin_example +Bitstring.(plus_one (of_int 15));; +- : Bitstring.t = +----+----------------------------------------------------------- + +Bitstring.(minus_one (of_int 15));; +- : Bitstring.t = +-+++------------------------------------------------------------ + #+end_example + + #+begin_src ocaml :tangle (eval ml) :exports none let trailing_zeros = function | One x -> One.trailing_zeros x | Many x -> Many.trailing_zeros x - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let hamdist a b = match a, b with | One a, One b -> One.hamdist a b | Many a, Many b -> Many.hamdist a b | _ -> invalid_arg "Bitstring.hamdist" - #+end_src - #+begin_src ocaml :tangle (eval ml) :exports none let popcount = function | One x -> One.popcount x | Many x -> Many.popcount x @@ -368,8 +363,14 @@ let popcount = function #+begin_example -Bitstring.to_list (of_int 5);; -- : int list = [1; 3] +Bitstring.(trailing_zeros (of_int 12));; +- : int = 2 + +Bitstring.(hamdist (of_int 15) (of_int 73));; +- : int = 3 + +Bitstring.(popcount (of_int 15));; +- : int = 4 #+end_example #+begin_src ocaml :tangle (eval ml) :exports none @@ -387,15 +388,8 @@ check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); #+end_src #+begin_example -Bitstring.permutations 2 4 -|> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; -- : string list = -["++--------------------------------------------------------------"; - "+-+-------------------------------------------------------------"; - "-++-------------------------------------------------------------"; - "+--+------------------------------------------------------------"; - "-+-+------------------------------------------------------------"; - "--++------------------------------------------------------------"] +Bitstring.(to_list (of_int 45));; +- : int list = [1; 3; 4; 6] #+end_example #+begin_src ocaml :tangle (eval ml) :exports none @@ -418,6 +412,17 @@ let permutations m n = aux (Util.binom n m) (minus_one (shift_left_one n m)) [] #+end_src + #+begin_example + Bitstring.permutations 2 4;; +- : Bitstring.t list = +[++--------------------------------------------------------------; + +-+-------------------------------------------------------------; + -++-------------------------------------------------------------; + +--+------------------------------------------------------------; + -+-+------------------------------------------------------------; + --++------------------------------------------------------------] + #+end_example + #+begin_src ocaml :tangle (eval test-ml) :exports none check "permutations" (permutations 2 4 = List.map of_int diff --git a/common/coordinate.org b/common/coordinate.org index 5b5445f..06c372f 100644 --- a/common/coordinate.org +++ b/common/coordinate.org @@ -111,7 +111,7 @@ val ( |- ) : t -> t -> t #+begin_example Coordinate.neg { x=1. ; y=2. ; z=3. } ;; -- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.} +- : Coordinate.t = -1.0000 -2.0000 -3.0000 Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;; - : float = 2. @@ -119,17 +119,17 @@ Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;; Coordinate.( 2. |. { x=1. ; y=2. ; z=3. } ) ;; -- : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.} +- : Coordinate.t = 2.0000 4.0000 6.0000 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.t = 3.0000 5.0000 4.0000 Coordinate.( { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. } );; -- : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -1.; z = 2.} +- : Coordinate.t = -1.0000 -1.0000 2.0000 #+end_example diff --git a/common/lib/angular_momentum.ml b/common/lib/angular_momentum.ml index 44ca23c..57bcfa4 100644 --- a/common/lib/angular_momentum.ml +++ b/common/lib/angular_momentum.ml @@ -33,13 +33,13 @@ open Powers * * #+begin_example * Angular_momentum.of_char 'p';; - * - : Angular_momentum.t = Qcaml.Common.Angular_momentum.P + * - : Angular_momentum.t = P * * Angular_momentum.(to_char P);; * - : char = 'P' * * Angular_momentum.of_int 2;; - * - : Angular_momentum.t = Qcaml.Common.Angular_momentum.D + * - : Angular_momentum.t = D * * Angular_momentum.(to_int D);; * - : int = 2 @@ -110,11 +110,10 @@ let of_int = function * - : 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} |] - * + * - : Zkey.t array = + * [|< 01125899906842624 | 1, 0, 0, 0, 0, 0 >; + * < 01099511627776 | 0, 1, 0, 0, 0, 0 >; + * < 01073741824 | 0, 0, 1, 0, 0, 0 >|] * #+end_example *) @@ -207,10 +206,10 @@ let zkey_array a = (* #+begin_example * Angular_momentum.(D + P);; - * - : Angular_momentum.t = Qcaml.Common.Angular_momentum.F + * - : Angular_momentum.t = F * * Angular_momentum.(F - P);; - * - : Angular_momentum.t = Qcaml.Common.Angular_momentum.D + * - : Angular_momentum.t = D * #+end_example *) diff --git a/common/lib/bitstring.ml b/common/lib/bitstring.ml index 7e8e48c..1a8c553 100644 --- a/common/lib/bitstring.ml +++ b/common/lib/bitstring.ml @@ -107,147 +107,145 @@ type t = (* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:2]] *) let of_int x = One (One.of_int x) -(* General implementation:2 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:4]] *) let of_z x = if Z.numbits x < 64 then One (Z.to_int x) else Many (Many.of_z x) -(* General implementation:4 ends here *) +(* General implementation:2 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:6]] *) + + +(* #+begin_example + * Bitstring.of_int 15;; + * - : Bitstring.t = + * ++++------------------------------------------------------------ + * #+end_example *) + + +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:4]] *) let zero = function | n when n < 64 -> One (One.zero) | _ -> Many (Many.zero) -(* General implementation:6 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:7]] *) + let numbits = function | One x -> One.numbits x | Many x -> Many.numbits x -(* General implementation:7 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:8]] *) + let is_zero = function | One x -> One.is_zero x | Many x -> Many.is_zero x -(* General implementation:8 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:9]] *) + let neg = function | One x -> One (One.neg x) | Many x -> Many (Many.neg x) -(* General implementation:9 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:10]] *) + let shift_left x i = match x with | One x -> One (One.shift_left x i) | Many x -> Many (Many.shift_left x i) -(* General implementation:10 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:12]] *) + let shift_right x i = match x with | One x -> One (One.shift_right x i) | Many x -> Many (Many.shift_right x i) -(* General implementation:12 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:14]] *) let shift_left_one = function | n when n < 64 -> fun i -> One (One.shift_left_one i) | _ -> fun i -> Many (Many.shift_left_one i) -(* General implementation:14 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:16]] *) let testbit = function | One x -> One.testbit x | Many x -> Many.testbit x -(* General implementation:16 ends here *) +(* General implementation:4 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:18]] *) +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:6]] *) let logor a b = match a,b with | One a, One b -> One (One.logor a b) | Many a, Many b -> Many (Many.logor a b) | _ -> invalid_arg "Bitstring.logor" -(* General implementation:18 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:20]] *) + let logxor a b = match a,b with | One a, One b -> One (One.logxor a b) | Many a, Many b -> Many (Many.logxor a b) | _ -> invalid_arg "Bitstring.logxor" -(* General implementation:20 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:22]] *) + let logand a b = match a,b with | One a, One b -> One (One.logand a b) | Many a, Many b -> Many (Many.logand a b) | _ -> invalid_arg "Bitstring.logand" -(* General implementation:22 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:24]] *) + let lognot = function | One x -> One (One.lognot x) | Many x -> Many (Many.lognot x) -(* General implementation:24 ends here *) +(* General implementation:6 ends here *) - - - -(* #+begin_example - * minus_one (of_int 10) = of_int 9 - * #+end_example *) - - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:25]] *) +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:8]] *) let minus_one = function | One x -> One (One.minus_one x) | Many x -> Many (Many.minus_one x) -(* General implementation:25 ends here *) + + +let plus_one = function + | One x -> One (One.plus_one x) + | Many x -> Many (Many.plus_one x) +(* General implementation:8 ends here *) (* #+begin_example - * plus_one (of_int 10) = of_int 11 + * Bitstring.(plus_one (of_int 15));; + * - : Bitstring.t = + * ----+----------------------------------------------------------- + * + * Bitstring.(minus_one (of_int 15));; + * - : Bitstring.t = + * -+++------------------------------------------------------------ * #+end_example *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:26]] *) -let plus_one = function - | One x -> One (One.plus_one x) - | Many x -> Many (Many.plus_one x) -(* General implementation:26 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:27]] *) + +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:9]] *) let trailing_zeros = function | One x -> One.trailing_zeros x | Many x -> Many.trailing_zeros x -(* General implementation:27 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:28]] *) + let hamdist a b = match a, b with | One a, One b -> One.hamdist a b | Many a, Many b -> Many.hamdist a b | _ -> invalid_arg "Bitstring.hamdist" -(* General implementation:28 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:29]] *) + let popcount = function | One x -> One.popcount x | Many x -> Many.popcount x -(* General implementation:29 ends here *) +(* General implementation:9 ends here *) (* #+begin_example - * Bitstring.to_list (of_int 5);; - * - : int list = [1; 3] + * Bitstring.(trailing_zeros (of_int 12));; + * - : int = 2 + * + * Bitstring.(hamdist (of_int 15) (of_int 73));; + * - : int = 3 + * + * Bitstring.(popcount (of_int 15));; + * - : int = 4 * #+end_example *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:30]] *) +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:10]] *) let rec to_list ?(accu=[]) = function | t when (is_zero t) -> List.rev accu | t -> let newlist = @@ -255,24 +253,17 @@ let rec to_list ?(accu=[]) = function in logand t @@ minus_one t |> (to_list [@tailcall]) ~accu:newlist -(* General implementation:30 ends here *) +(* General implementation:10 ends here *) (* #+begin_example - * Bitstring.permutations 2 4 - * |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; - * - : string list = - * ["++--------------------------------------------------------------"; - * "+-+-------------------------------------------------------------"; - * "-++-------------------------------------------------------------"; - * "+--+------------------------------------------------------------"; - * "-+-+------------------------------------------------------------"; - * "--++------------------------------------------------------------"] + * Bitstring.(to_list (of_int 45));; + * - : int list = [1; 3; 4; 6] * #+end_example *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:32]] *) +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:12]] *) let permutations m n = let rec aux k u rest = @@ -290,7 +281,7 @@ let permutations m n = (aux [@tailcall]) (k-1) (logor t' t'') (u :: rest) in aux (Util.binom n m) (minus_one (shift_left_one n m)) [] -(* General implementation:32 ends here *) +(* General implementation:12 ends here *) (* [[file:~/QCaml/common/bitstring.org::*Printers][Printers:2]] *) let pp ppf = function diff --git a/common/lib/coordinate.ml b/common/lib/coordinate.ml index ed1e932..af56d2d 100644 --- a/common/lib/coordinate.ml +++ b/common/lib/coordinate.ml @@ -63,7 +63,7 @@ let angstrom_to_bohr { x ; y ; z } = * * #+begin_example * Coordinate.neg { x=1. ; y=2. ; z=3. } ;; - * - : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -2.; z = -3.} + * - : Coordinate.t = -1.0000 -2.0000 -3.0000 * * Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;; * - : float = 2. @@ -71,17 +71,17 @@ let angstrom_to_bohr { x ; y ; z } = * Coordinate.( * 2. |. { x=1. ; y=2. ; z=3. } * ) ;; - * - : Coordinate.t = {Qcaml.Common.Coordinate.x = 2.; y = 4.; z = 6.} + * - : Coordinate.t = 2.0000 4.0000 6.0000 * * 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.t = 3.0000 5.0000 4.0000 * * Coordinate.( * { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. } * );; - * - : Coordinate.t = {Qcaml.Common.Coordinate.x = -1.; y = -1.; z = 2.} + * - : Coordinate.t = -1.0000 -1.0000 2.0000 * #+end_example *) diff --git a/common/lib/powers.ml b/common/lib/powers.ml index e1fa127..94983bf 100644 --- a/common/lib/powers.ml +++ b/common/lib/powers.ml @@ -16,7 +16,7 @@ type t = { (* #+begin_example * Powers.of_int_tuple (2,3,1);; - * - : Powers.t = {Qcaml.Common.Powers.x = 2; y = 3; z = 1; tot = 6} + * - : Powers.t = x^2 + y^3 + z^1 * * Powers.(to_int_tuple (of_int_tuple (2,3,1)));; * - : int * int * int = (2, 3, 1) @@ -51,10 +51,10 @@ let to_int_tuple { x ; y ; z ; _ } = (x,y,z) * - : int = 3 * * Powers.incr Coordinate.Y (Powers.of_int_tuple (2,3,1));; - * - : Powers.t = {Qcaml.Common.Powers.x = 2; y = 4; z = 1; tot = 7} + * - : Powers.t = x^2 + y^4 + z^1 * * Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));; - * - : Powers.t = {Qcaml.Common.Powers.x = 2; y = 2; z = 1; tot = 5} + * - : Powers.t = x^2 + y^2 + z^1 * #+end_example *) diff --git a/common/powers.org b/common/powers.org index 5319330..9366b63 100644 --- a/common/powers.org +++ b/common/powers.org @@ -47,7 +47,7 @@ val to_int_tuple : t -> int * int * int #+begin_example Powers.of_int_tuple (2,3,1);; -- : Powers.t = {Qcaml.Common.Powers.x = 2; y = 3; z = 1; tot = 6} +- : Powers.t = x^2 + y^3 + z^1 Powers.(to_int_tuple (of_int_tuple (2,3,1)));; - : int * int * int = (2, 3, 1) @@ -87,10 +87,10 @@ 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 = {Qcaml.Common.Powers.x = 2; y = 4; z = 1; tot = 7} +- : Powers.t = x^2 + y^4 + z^1 Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));; -- : Powers.t = {Qcaml.Common.Powers.x = 2; y = 2; z = 1; tot = 5} +- : Powers.t = x^2 + y^2 + z^1 #+end_example diff --git a/common/test/bitstring.ml b/common/test/bitstring.ml index 6ae7765..906d3d6 100644 --- a/common/test/bitstring.ml +++ b/common/test/bitstring.ml @@ -14,61 +14,99 @@ let test_all () = (* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:3]] *) check_bool "of_x" true (one_x = (of_int x)); +check_bool "of_z" true (one_x = (of_z (Z.of_int x))); (* General implementation:3 ends here *) + + +(* #+begin_example + * Bitstring.(shift_left (of_int 15) 2);; + * - : Bitstring.t = + * --++++---------------------------------------------------------- + * + * Bitstring.(shift_right (of_int 15) 2);; + * - : Bitstring.t = + * ++-------------------------------------------------------------- + * + * Bitstring.shift_left_one 32 4;; + * - : Bitstring.t = + * ----+----------------------------------------------------------- + * + * Bitstring.(testbit (of_int 15) 3);; + * - : bool = true + * + * Bitstring.(testbit (of_int 15) 4);; + * - : bool = false + * #+end_example *) + + (* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:5]] *) -check_bool "of_z" true (one_x = (of_z (Z.of_int x))); -(* General implementation:5 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:11]] *) -check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); -check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); -check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); -(* General implementation:11 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:13]] *) -check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); -check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); -(* General implementation:13 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:15]] *) +check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3); +check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3); +check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100); +check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3); +check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3); check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3); check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200); -(* General implementation:15 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:17]] *) check_bool "testbit1" true (testbit (of_int 8) 3); check_bool "testbit2" false (testbit (of_int 8) 2); check_bool "testbit3" false (testbit (of_int 8) 4); check_bool "testbit4" true (testbit (of_z (Z.of_int 8)) 3); check_bool "testbit5" false (testbit (of_z (Z.of_int 8)) 2); check_bool "testbit6" false (testbit (of_z (Z.of_int 8)) 4); -(* General implementation:17 ends here *) +(* General implementation:5 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:19]] *) + + + +(* #+begin_example + * Bitstring.(logor (of_int 15) (of_int 73));; + * - : Bitstring.t = + * ++++--+--------------------------------------------------------- + * + * Bitstring.(logand (of_int 15) (of_int 10));; + * - : Bitstring.t = + * -+-+------------------------------------------------------------ + * + * Bitstring.(logxor (of_int 15) (of_int 73));; + * - : Bitstring.t = + * -++---+--------------------------------------------------------- + * #+end_example *) + + + +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:7]] *) check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (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))); -(* General implementation:19 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:21]] *) check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (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))); -(* General implementation:21 ends here *) - -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:23]] *) check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (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))); -(* General implementation:23 ends here *) +(* General implementation:7 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:31]] *) +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:11]] *) check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); -(* General implementation:31 ends here *) +(* General implementation:11 ends here *) -(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:33]] *) + + +(* #+begin_example + * Bitstring.permutations 2 4;; + * - : Bitstring.t list = + * [++--------------------------------------------------------------; + * +-+-------------------------------------------------------------; + * -++-------------------------------------------------------------; + * +--+------------------------------------------------------------; + * -+-+------------------------------------------------------------; + * --++------------------------------------------------------------] + * #+end_example *) + + +(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:13]] *) check "permutations" (permutations 2 4 = List.map of_int [ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]); -(* General implementation:33 ends here *) +(* General implementation:13 ends here *) (* Tests :noexport: *) diff --git a/particles/lib/element.ml b/particles/lib/element.ml index cfdc2ff..b163d24 100644 --- a/particles/lib/element.ml +++ b/particles/lib/element.ml @@ -1,4 +1,4 @@ -(* [[file:../element.org::*Type][Type:2]] *) +(* [[file:~/QCaml/particles/element.org::*Type][Type:2]] *) type t = |X |H |He @@ -41,7 +41,7 @@ open Common * #+end_example *) -(* [[file:../element.org::*Conversion][Conversion:2]] *) +(* [[file:~/QCaml/particles/element.org::*Conversion][Conversion:2]] *) let of_string x = match (String.capitalize_ascii (String.lowercase_ascii x)) with | "X" | "Dummy" -> X | "H" | "Hydrogen" -> H @@ -165,7 +165,7 @@ let of_charge c = * | ~large_core~ | Number of electrons in the large core model (all except the outermost shell) | *) -(* [[file:../element.org::*Database information][Database information:2]] *) +(* [[file:~/QCaml/particles/element.org::*Database information][Database information:2]] *) let covalent_radius x = let result = function | X -> 0. | H -> 0.37 | He -> 0.70 | Li -> 1.23 @@ -266,7 +266,7 @@ let small_core t = |> loop (* Database information:2 ends here *) -(* [[file:../element.org::*Printers][Printers:2]] *) +(* [[file:~/QCaml/particles/element.org::*Printers][Printers:2]] *) let pp ppf t = Format.fprintf ppf "@[%s@]" (to_string t) diff --git a/particles/lib/element.mli b/particles/lib/element.mli index d916e4f..60dc08f 100644 --- a/particles/lib/element.mli +++ b/particles/lib/element.mli @@ -2,7 +2,7 @@ * * #+NAME: types *) -(* [[file:../element.org::types][types]] *) +(* [[file:~/QCaml/particles/element.org::types][types]] *) type t = |X |H |He @@ -20,7 +20,7 @@ open Common (* Conversion *) -(* [[file:../element.org::*Conversion][Conversion:1]] *) +(* [[file:~/QCaml/particles/element.org::*Conversion][Conversion:1]] *) val of_string : string -> t val to_string : t -> string val to_long_string : t -> string @@ -35,7 +35,7 @@ val of_charge : Charge.t -> t (* Database information *) -(* [[file:../element.org::*Database information][Database information:1]] *) +(* [[file:~/QCaml/particles/element.org::*Database information][Database information:1]] *) val covalent_radius : t -> Non_negative_float.t val vdw_radius : t -> Non_negative_float.t val mass : t -> Mass.t @@ -46,7 +46,7 @@ val large_core : t -> int (* Printers *) -(* [[file:../element.org::*Printers][Printers:1]] *) +(* [[file:~/QCaml/particles/element.org::*Printers][Printers:1]] *) val pp : Format.formatter -> t -> unit val pp_long : Format.formatter -> t -> unit (* Printers:1 ends here *) diff --git a/top/install_printers.org b/top/install_printers.org index e3c5ea5..7b9b2af 100644 --- a/top/install_printers.org +++ b/top/install_printers.org @@ -52,6 +52,7 @@ let rec install_printers = function eval_exn cmd && install_printers printers let () = + eval_exn "#require \"lacaml.top\";;"; if not (install_printers printers) then Format.eprintf "Problem installing QCaml-printers@." diff --git a/top/lib/install_printers.ml b/top/lib/install_printers.ml index 06ebc29..7edd6bb 100644 --- a/top/lib/install_printers.ml +++ b/top/lib/install_printers.ml @@ -27,6 +27,7 @@ let rec install_printers = function eval_exn cmd && install_printers printers let () = + eval_exn "#require \"lacaml.top\";;"; if not (install_printers printers) then Format.eprintf "Problem installing QCaml-printers@." (* Intall printers:2 ends here *)