Added bin/tangle.sh

This commit is contained in:
Anthony Scemama 2020-12-28 01:55:03 +01:00
parent d2e7848de2
commit ceca635621
33 changed files with 324 additions and 241 deletions

101
bin/tangle.sh Executable file
View File

@ -0,0 +1,101 @@
#!/bin/bash
# Usage: $0 [DIR]
if [[ -z $1 ]] ; then
echo "Usage: $0 [DIR]"
exit -1
fi
if [[ $(basename $PWD) != "QCaml" ]] ; then
echo "This script needs to be run in the QCaml directory"
exit -1
fi
DIR=${1%/}
cat << EOF > ${PWD}/tmpfile
(package-initialize)
(add-to-list 'package-archives
'("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(setq package-archive-priorities '(("melpa-stable" . 100)
("melpa" . 50)
("gnu" . 10)))
(require 'cl)
(let* ((required-packages
'(dash
htmlize
ess
evil
gnuplot
tuareg
tramp
bibtex-completion
org-ref
org-gnome
org-evil
org-bullets
org-mime
magit
rustic
auctex))
(missing-packages (remove-if #'package-installed-p required-packages)))
(when missing-packages
(message "Missing packages: %s" missing-packages)
(package-refresh-contents)
(dolist (pkg missing-packages)
(package-install pkg)
(message "Package %s has been installed" pkg))))
(setq org-alphabetical-lists t)
(setq org-src-fontify-natively t)
(setq org-src-preserve-indentation t)
(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages
'org-babel-load-languages
'(
(emacs-lisp . t)
(shell . t)
(python . t)
(C . t)
(ocaml . t)
(gnuplot . t)
(latex . t)
(ditaa . t)
(dot . t)
(org . t)
(makefile . t)
))
(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 c (concat lib name ".c"))
(setq test-ml (concat testdir name ".ml"))
(org-babel-tangle)
EOF
cd $DIR
for i in *.org
do
echo "--- $i ----"
emacs --batch ./$i --load=../tmpfile
done
rm ../tmpfile

View File

@ -7,7 +7,7 @@
* quartets, use in the two-electron operators. *)
(* [[file:../angular_momentum.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Type][Type:2]] *)
type t =
| S | P | D | F | G | H | I | J | K | L | M | N | O
| Int of int
@ -49,7 +49,7 @@ open Powers
* #+end_example *)
(* [[file:../angular_momentum.org::*Conversions][Conversions:2]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Conversions][Conversions:2]] *)
let of_char = function
| 's' | 'S' -> S | 'p' | 'P' -> P
| 'd' | 'D' -> D | 'f' | 'F' -> F
@ -118,7 +118,7 @@ let of_int = function
* #+end_example *)
(* [[file:../angular_momentum.org::*Shell functions][Shell functions:2]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Shell functions][Shell functions:2]] *)
let n_functions a =
let a =
to_int a
@ -214,7 +214,7 @@ let zkey_array a =
* #+end_example *)
(* [[file:../angular_momentum.org::*Arithmetic][Arithmetic:2]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Arithmetic][Arithmetic:2]] *)
let ( + ) a b =
of_int ( (to_int a) + (to_int b) )
@ -222,7 +222,7 @@ let ( - ) a b =
of_int ( (to_int a) - (to_int b) )
(* Arithmetic:2 ends here *)
(* [[file:../angular_momentum.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Printers][Printers:2]] *)
let pp_string ppf x =
Format.fprintf ppf "@[%s@]" (to_string x)

View File

@ -2,7 +2,7 @@
*
* #+NAME: types *)
(* [[file:../angular_momentum.org::types][types]] *)
(* [[file:~/QCaml/common/angular_momentum.org::types][types]] *)
type t =
| S | P | D | F | G | H | I | J | K | L | M | N | O
| Int of int
@ -19,7 +19,7 @@ type kind =
(* Conversions *)
(* [[file:../angular_momentum.org::*Conversions][Conversions:1]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Conversions][Conversions:1]] *)
val of_char : char -> t
val to_char : t -> char
@ -32,7 +32,7 @@ val to_string : t -> string
(* Shell functions *)
(* [[file:../angular_momentum.org::*Shell functions][Shell functions:1]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Shell functions][Shell functions:1]] *)
val n_functions : t -> int
val zkey_array : kind -> Zkey.t array
(* Shell functions:1 ends here *)
@ -40,7 +40,7 @@ val zkey_array : kind -> Zkey.t array
(* Arithmetic *)
(* [[file:../angular_momentum.org::*Arithmetic][Arithmetic:1]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Arithmetic][Arithmetic:1]] *)
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
(* Arithmetic:1 ends here *)
@ -50,7 +50,7 @@ val ( - ) : t -> t -> t
* Printers can print as a string (default) or as an integer. *)
(* [[file:../angular_momentum.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/angular_momentum.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
val pp_string : Format.formatter -> t -> unit
val pp_int : Format.formatter -> t -> unit

View File

@ -1,7 +1,7 @@
(* Single-integer implementation :noexport: *)
(* [[file:../bitstring.org::*Single-integer implementation][Single-integer implementation:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Single-integer%20implementation][Single-integer implementation:1]] *)
module One = struct
let of_int x =
@ -43,7 +43,7 @@ end
(* Zarith implementation :noexport: *)
(* [[file:../bitstring.org::*Zarith implementation][Zarith implementation:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Zarith%20implementation][Zarith implementation:1]] *)
module Many = struct
let of_z x = x
@ -73,7 +73,7 @@ module Many = struct
end
(* Zarith implementation:1 ends here *)
(* [[file:../bitstring.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/bitstring.org::*Type][Type:2]] *)
type t =
| One of int
| Many of Z.t
@ -104,65 +104,65 @@ type t =
* | ~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::*General implementation][General implementation:2]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:4]] *)
(* [[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 *)
(* [[file:../bitstring.org::*General implementation][General implementation:6]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:6]] *)
let zero = function
| n when n < 64 -> One (One.zero)
| _ -> Many (Many.zero)
(* General implementation:6 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:7]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:8]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:9]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:10]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:12]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:14]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:16]] *)
(* [[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 *)
(* [[file:../bitstring.org::*General implementation][General implementation:18]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:18]] *)
let logor a b =
match a,b with
| One a, One b -> One (One.logor a b)
@ -170,7 +170,7 @@ let logor a b =
| _ -> invalid_arg "Bitstring.logor"
(* General implementation:18 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:20]] *)
(* [[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)
@ -178,7 +178,7 @@ let logxor a b =
| _ -> invalid_arg "Bitstring.logxor"
(* General implementation:20 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:22]] *)
(* [[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)
@ -186,7 +186,7 @@ let logand a b =
| _ -> invalid_arg "Bitstring.logand"
(* General implementation:22 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:24]] *)
(* [[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)
@ -195,12 +195,12 @@ let lognot = function
(* #+begin_example
(* #+begin_example
* minus_one (of_int 10) = of_int 9
* #+end_example *)
* #+end_example *)
(* [[file:../bitstring.org::*General implementation][General implementation:25]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:25]] *)
let minus_one = function
| One x -> One (One.minus_one x)
| Many x -> Many (Many.minus_one x)
@ -209,30 +209,30 @@ let minus_one = function
(* #+begin_example
(* #+begin_example
* plus_one (of_int 10) = of_int 11
* #+end_example *)
* #+end_example *)
(* [[file:../bitstring.org::*General implementation][General implementation:26]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:27]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:27]] *)
let trailing_zeros = function
| One x -> One.trailing_zeros x
| Many x -> Many.trailing_zeros x
(* General implementation:27 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:28]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:29]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:29]] *)
let popcount = function
| One x -> One.popcount x
| Many x -> Many.popcount x
@ -241,13 +241,13 @@ let popcount = function
(* #+begin_example
(* #+begin_example
* Bitstring.to_list (of_int 5);;
* - : int list = [1; 3]
* #+end_example *)
* #+end_example *)
(* [[file:../bitstring.org::*General implementation][General implementation:30]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:30]] *)
let rec to_list ?(accu=[]) = function
| t when (is_zero t) -> List.rev accu
| t -> let newlist =
@ -259,7 +259,7 @@ let rec to_list ?(accu=[]) = function
(* #+begin_example
(* #+begin_example
* Bitstring.permutations 2 4
* |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
* - : string list =
@ -269,10 +269,10 @@ let rec to_list ?(accu=[]) = function
* "+--+------------------------------------------------------------";
* "-+-+------------------------------------------------------------";
* "--++------------------------------------------------------------"]
* #+end_example *)
* #+end_example *)
(* [[file:../bitstring.org::*General implementation][General implementation:32]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:32]] *)
let permutations m n =
let rec aux k u rest =
@ -292,7 +292,7 @@ let permutations m n =
aux (Util.binom n m) (minus_one (shift_left_one n m)) []
(* General implementation:32 ends here *)
(* [[file:../bitstring.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/bitstring.org::*Printers][Printers:2]] *)
let pp ppf = function
| One x -> One.pp ppf x
| Many x -> Many.pp ppf x

View File

@ -1,14 +1,14 @@
(* Type *)
(* [[file:../bitstring.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Type][Type:1]] *)
type t
(* Type:1 ends here *)
(* General implementation *)
(* [[file:../bitstring.org::*General implementation][General implementation:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:1]] *)
val of_int : int -> t
val of_z : Z.t -> t
val zero : int -> t
@ -41,6 +41,6 @@ val permutations : int -> int -> t list
(* Printers *)
(* [[file:../bitstring.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -3,11 +3,11 @@
(* This type should be used for all charges in the program (electrons, nuclei,...). *)
(* [[file:../charge.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/charge.org::*Type][Type:2]] *)
type t = float
(* Type:2 ends here *)
(* [[file:../charge.org::*Conversions][Conversions:2]] *)
(* [[file:~/QCaml/common/charge.org::*Conversions][Conversions:2]] *)
external of_float : float -> t = "%identity"
external to_float : t -> float = "%identity"
@ -25,7 +25,7 @@ let to_string x =
"0.0"
(* Conversions:2 ends here *)
(* [[file:../charge.org::*Simple operations][Simple operations:2]] *)
(* [[file:~/QCaml/common/charge.org::*Simple%20operations][Simple operations:2]] *)
let gen_op op =
fun a b ->
op (to_float a) (to_float b)
@ -37,7 +37,7 @@ let ( * ) = gen_op ( *. )
let ( / ) = gen_op ( /. )
(* Simple operations:2 ends here *)
(* [[file:../charge.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/charge.org::*Printers][Printers:2]] *)
let pp ppf x =
Format.fprintf ppf "@[+%s@]" (to_string x)
(* Printers:2 ends here *)

View File

@ -1,14 +1,14 @@
(* Type *)
(* [[file:../charge.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/charge.org::*Type][Type:1]] *)
type t
(* Type:1 ends here *)
(* Conversions *)
(* [[file:../charge.org::*Conversions][Conversions:1]] *)
(* [[file:~/QCaml/common/charge.org::*Conversions][Conversions:1]] *)
val of_float : float -> t
val to_float : t -> float
@ -22,7 +22,7 @@ val to_string: t -> string
(* Simple operations *)
(* [[file:../charge.org::*Simple operations][Simple operations:1]] *)
(* [[file:~/QCaml/common/charge.org::*Simple%20operations][Simple operations:1]] *)
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( * ) : t -> float -> t
@ -32,6 +32,6 @@ val ( / ) : t -> float -> t
(* Printers *)
(* [[file:../charge.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/charge.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -11,7 +11,7 @@
* (~git --log[=<n>]~) *)
(* [[file:../command_line.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/command_line.org::*Type][Type:2]] *)
type short_opt = char
type long_opt = string
type optional = Mandatory | Optional
@ -33,7 +33,7 @@ type description = {
* is the long option and the value is a value of type ~description~. *)
(* [[file:../command_line.org::*Mutable attributes][Mutable attributes:1]] *)
(* [[file:~/QCaml/common/command_line.org::*Mutable attributes][Mutable attributes:1]] *)
let header_doc = ref ""
let description_doc = ref ""
let footer_doc = ref ""
@ -48,7 +48,7 @@ let dict = Hashtbl.create 67
* documentation provided by the ~help~ function: *)
(* [[file:../command_line.org::*Mutable attributes][Mutable attributes:3]] *)
(* [[file:~/QCaml/common/command_line.org::*Mutable attributes][Mutable attributes:3]] *)
let set_header_doc s = header_doc := s
let set_description_doc s = description_doc := s
let set_footer_doc s = footer_doc := s
@ -59,7 +59,7 @@ let set_footer_doc s = footer_doc := s
(* Function to create an anonymous argument. *)
(* [[file:../command_line.org::*Mutable attributes][Mutable attributes:5]] *)
(* [[file:~/QCaml/common/command_line.org::*Mutable attributes][Mutable attributes:5]] *)
let anonymous name opt doc =
{ short=' ' ; long=name; opt; doc; arg=Without_arg; }
(* Mutable attributes:5 ends here *)
@ -69,7 +69,7 @@ let anonymous name opt doc =
* Function to print some text such that it fits on the screen *)
(* [[file:../command_line.org::*Text formatting functions][Text formatting functions:1]] *)
(* [[file:~/QCaml/common/command_line.org::*Text formatting functions][Text formatting functions:1]] *)
let output_text t =
Format.printf "@[<v 0>";
begin
@ -101,7 +101,7 @@ let output_text t =
* #+end_example *)
(* [[file:../command_line.org::*Text formatting functions][Text formatting functions:2]] *)
(* [[file:~/QCaml/common/command_line.org::*Text formatting functions][Text formatting functions:2]] *)
let output_short x =
match x.short, x.opt, x.arg with
| ' ', Mandatory, _ -> Format.printf "@[%s@]" x.long
@ -126,7 +126,7 @@ let output_short x =
* #+end_example *)
(* [[file:../command_line.org::*Text formatting functions][Text formatting functions:3]] *)
(* [[file:~/QCaml/common/command_line.org::*Text formatting functions][Text formatting functions:3]] *)
let output_long max_width x =
let arg =
match x.short, x.arg with
@ -157,7 +157,7 @@ let output_long max_width x =
(* [[file:../command_line.org::*Query functions][Query functions:2]] *)
(* [[file:~/QCaml/common/command_line.org::*Query functions][Query functions:2]] *)
let anon_args () = !anon_args_ref
let help () =
@ -241,7 +241,7 @@ let get_bool x = Hashtbl.mem dict x
* ~descrption~ variables. *)
(* [[file:../command_line.org::*Specification][Specification:2]] *)
(* [[file:~/QCaml/common/command_line.org::*Specification][Specification:2]] *)
let set_specs specs_in =
specs := { short = 'h' ;
long = "help" ;

View File

@ -2,7 +2,7 @@
*
* #+NAME:type *)
(* [[file:../command_line.org::type][type]] *)
(* [[file:~/QCaml/common/command_line.org::type][type]] *)
type short_opt = char
type long_opt = string
type optional = Mandatory | Optional
@ -18,20 +18,20 @@ type description = {
}
(* type ends here *)
(* [[file:../command_line.org::*Mutable attributes][Mutable attributes:2]] *)
(* [[file:~/QCaml/common/command_line.org::*Mutable attributes][Mutable attributes:2]] *)
val set_header_doc : string -> unit
val set_description_doc : string -> unit
val set_footer_doc : string -> unit
(* Mutable attributes:2 ends here *)
(* [[file:../command_line.org::*Mutable attributes][Mutable attributes:4]] *)
(* [[file:~/QCaml/common/command_line.org::*Mutable attributes][Mutable attributes:4]] *)
val anonymous : long_opt -> optional -> documentation -> description
(* Mutable attributes:4 ends here *)
(* Query functions *)
(* [[file:../command_line.org::*Query functions][Query functions:1]] *)
(* [[file:~/QCaml/common/command_line.org::*Query functions][Query functions:1]] *)
val get : long_opt -> string option
val get_bool : long_opt -> bool
val anon_args : unit -> string list
@ -40,6 +40,6 @@ val anon_args : unit -> string list
(* Specification *)
(* [[file:../command_line.org::*Specification][Specification:1]] *)
(* [[file:~/QCaml/common/command_line.org::*Specification][Specification:1]] *)
val set_specs : description list -> unit
(* Specification:1 ends here *)

View File

@ -1,16 +1,25 @@
(* [[file:../constants.org::*Constants][Constants:2]] *)
(* Constants:2 ends here *)
(* [[file:../constants.org::*~epsilon~][~epsilon~:2]] *)
(* | ~epsilon~ | Value below which a float is considered null. Default is \epsilon = 2.10^{-15} |
* | ~integrals_cutoff~ | Cutoff value for integrals. Default is \epsilon | *)
(* [[file:~/QCaml/common/constants.org::*Thresholds][Thresholds:2]] *)
let epsilon = 2.e-15
(* ~epsilon~:2 ends here *)
(* [[file:../constants.org::*~integrals_cutoff~][~integrals_cutoff~:2]] *)
let integrals_cutoff = epsilon
(* ~integrals_cutoff~:2 ends here *)
(* Thresholds:2 ends here *)
(* [[file:../constants.org::*Mathematical constants][Mathematical constants:2]] *)
(* | ~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}$ | *)
(* [[file:~/QCaml/common/constants.org::*Mathematical%20constants][Mathematical constants:2]] *)
let pi = acos (-1.)
let two_pi = 2. *. pi
let sq_pi = sqrt pi
@ -19,7 +28,15 @@ let pi_inv = 1. /. pi
let two_over_sq_pi = 2. /. sq_pi
(* Mathematical constants:2 ends here *)
(* [[file:../constants.org::*Physical constants][Physical constants:2]] *)
(* | ~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~ | *)
(* [[file:~/QCaml/common/constants.org::*Physical%20constants][Physical constants:2]] *)
let a0 = 0.529_177_210_67
let a0_inv = 1. /. a0
let ha_to_ev = 27.211_386_02

View File

@ -1,45 +1,15 @@
(* Constants
* :PROPERTIES:
* :header-args: :noweb yes :comments both
* :END:
*
* All constants used in the program. *)
(* Thresholds *)
(* [[file:../constants.org::*Constants][Constants:1]] *)
(* Constants:1 ends here *)
(* ~epsilon~
*
* Value below which a float is considered null. Default is
* \epsilon = 2.10^{-15}. *)
(* [[file:../constants.org::*~epsilon~][~epsilon~:1]] *)
val epsilon : float
(* ~epsilon~:1 ends here *)
(* ~integrals_cutoff~
*
* Cutoff value for integrals. Default is \epsilon . *)
(* [[file:../constants.org::*~integrals_cutoff~][~integrals_cutoff~:1]] *)
(* [[file:~/QCaml/common/constants.org::*Thresholds][Thresholds:1]] *)
val epsilon : float
val integrals_cutoff : float
(* ~integrals_cutoff~:1 ends here *)
(* Thresholds:1 ends here *)
(* 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}$ | *)
(* Mathematical constants *)
(* [[file:../constants.org::*Mathematical constants][Mathematical constants:1]] *)
(* [[file:~/QCaml/common/constants.org::*Mathematical%20constants][Mathematical constants:1]] *)
val pi : float
val two_pi : float
val sq_pi : float
@ -48,15 +18,10 @@ val pi_inv : float
val two_over_sq_pi : float
(* Mathematical constants:1 ends here *)
(* 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~ | *)
(* Physical constants *)
(* [[file:../constants.org::*Physical constants][Physical constants:1]] *)
(* [[file:~/QCaml/common/constants.org::*Physical%20constants][Physical constants:1]] *)
val a0 : float
val a0_inv : float
val ha_to_ev : float

View File

@ -1,4 +1,4 @@
(* [[file:../coordinate.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/coordinate.org::*Type][Type:2]] *)
type bohr
type angstrom
@ -22,7 +22,7 @@ type axis = X | Y | Z
* | ~zero~ | $(0., 0., 0.)$ | *)
(* [[file:../coordinate.org::*Creation][Creation:2]] *)
(* [[file:~/QCaml/common/coordinate.org::*Creation][Creation:2]] *)
external make : 'a point -> t = "%identity"
external make_angstrom : 'a point -> angstrom point = "%identity"
@ -36,7 +36,7 @@ let zero =
* | ~angstrom_to_bohr~ | Converts a point in angstrom to bohr | *)
(* [[file:../coordinate.org::*Conversion][Conversion:2]] *)
(* [[file:~/QCaml/common/coordinate.org::*Conversion][Conversion:2]] *)
let b_to_a b = Constants.a0 *. b
let bohr_to_angstrom { x ; y ; z } =
make { x = b_to_a x ;
@ -86,7 +86,7 @@ let angstrom_to_bohr { x ; y ; z } =
(* [[file:../coordinate.org::*Vector operations][Vector operations:2]] *)
(* [[file:~/QCaml/common/coordinate.org::*Vector operations][Vector operations:2]] *)
let get axis { x ; y ; z } =
match axis with
| X -> x
@ -136,7 +136,7 @@ let norm u =
(* Coordinates can be printed in bohr or angstrom. *)
(* [[file:../coordinate.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/coordinate.org::*Printers][Printers:2]] *)
open Format
let pp ppf c =
fprintf ppf "@[@[%8.4f@] @[%8.4f@] @[%8.4f@]@]" c.x c.y c.z

View File

@ -2,7 +2,7 @@
*
* #+NAME: types *)
(* [[file:../coordinate.org::types][types]] *)
(* [[file:~/QCaml/common/coordinate.org::types][types]] *)
type bohr
type angstrom
@ -22,7 +22,7 @@ type axis = X | Y | Z
(* Creation *)
(* [[file:../coordinate.org::*Creation][Creation:1]] *)
(* [[file:~/QCaml/common/coordinate.org::*Creation][Creation:1]] *)
val make : 'a point -> t
val make_angstrom : 'a point -> angstrom point
val zero : bohr point
@ -31,7 +31,7 @@ val zero : bohr point
(* Conversion *)
(* [[file:../coordinate.org::*Conversion][Conversion:1]] *)
(* [[file:~/QCaml/common/coordinate.org::*Conversion][Conversion:1]] *)
val bohr_to_angstrom : bohr point -> angstrom point
val angstrom_to_bohr : angstrom point -> bohr point
(* Conversion:1 ends here *)
@ -39,7 +39,7 @@ val angstrom_to_bohr : angstrom point -> bohr point
(* Vector operations *)
(* [[file:../coordinate.org::*Vector operations][Vector operations:1]] *)
(* [[file:~/QCaml/common/coordinate.org::*Vector operations][Vector operations:1]] *)
val neg : t -> t
val get : axis -> bohr point -> float
val dot : t -> t -> float
@ -52,7 +52,7 @@ val ( |- ) : t -> t -> t
(* Printers *)
(* [[file:../coordinate.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/coordinate.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
val pp_bohr: Format.formatter -> t -> unit
val pp_angstrom : Format.formatter -> t -> unit

View File

@ -1,4 +1,4 @@
(* [[file:../non_negative_float.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/non_negative_float.org::*Type][Type:2]] *)
type t = float
(* Type:2 ends here *)
@ -8,7 +8,7 @@ type t = float
* The unsafe variant doesn't do this check. *)
(* [[file:../non_negative_float.org::*Conversions][Conversions:2]] *)
(* [[file:~/QCaml/common/non_negative_float.org::*Conversions][Conversions:2]] *)
let of_float x =
if x < 0. then invalid_arg (__FILE__^": of_float");
x

View File

@ -1,14 +1,14 @@
(* Type *)
(* [[file:../non_negative_float.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/non_negative_float.org::*Type][Type:1]] *)
type t = private float
(* Type:1 ends here *)
(* Conversions *)
(* [[file:../non_negative_float.org::*Conversions][Conversions:1]] *)
(* [[file:~/QCaml/common/non_negative_float.org::*Conversions][Conversions:1]] *)
val of_float : float -> t
val unsafe_of_float : float -> t
val to_float : t -> float

View File

@ -3,7 +3,7 @@
(* ~tot~ always contains ~x+y+z~. *)
(* [[file:../powers.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/powers.org::*Type][Type:2]] *)
type t = {
x : int ;
y : int ;
@ -23,7 +23,7 @@ type t = {
* #+end_example *)
(* [[file:../powers.org::*Conversions][Conversions:2]] *)
(* [[file:~/QCaml/common/powers.org::*Conversions][Conversions:2]] *)
let of_int_tuple t =
let result =
match t with
@ -59,7 +59,7 @@ let to_int_tuple { x ; y ; z ; _ } = (x,y,z)
(* [[file:../powers.org::*Operations][Operations:2]] *)
(* [[file:~/QCaml/common/powers.org::*Operations][Operations:2]] *)
let get coord t =
match coord with
| Coordinate.X -> t.x
@ -79,7 +79,7 @@ let decr coord t =
| Coordinate.Z -> let r = t.z-1 in { t with z = r ; tot = t.tot-1 }
(* Operations:2 ends here *)
(* [[file:../powers.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/powers.org::*Printers][Printers:2]] *)
let pp ppf t =
Format.fprintf ppf "@[x^%d + y^%d + z^%d@]" t.x t.y t.z
(* Printers:2 ends here *)

View File

@ -1,7 +1,7 @@
(* Type *)
(* [[file:../powers.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/powers.org::*Type][Type:1]] *)
type t = private {
x : int ;
y : int ;
@ -13,7 +13,7 @@ type t = private {
(* Conversions *)
(* [[file:../powers.org::*Conversions][Conversions:1]] *)
(* [[file:~/QCaml/common/powers.org::*Conversions][Conversions:1]] *)
val of_int_tuple : int * int * int -> t
val to_int_tuple : t -> int * int * int
(* Conversions:1 ends here *)
@ -21,7 +21,7 @@ val to_int_tuple : t -> int * int * int
(* Operations *)
(* [[file:../powers.org::*Operations][Operations:1]] *)
(* [[file:~/QCaml/common/powers.org::*Operations][Operations:1]] *)
val get : Coordinate.axis -> t -> int
val incr : Coordinate.axis -> t -> t
val decr : Coordinate.axis -> t -> t
@ -30,6 +30,6 @@ val decr : Coordinate.axis -> t -> t
(* Printers *)
(* [[file:../powers.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/powers.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -4,7 +4,7 @@
* | ~name~ | ~"QCaml"~ | *)
(* [[file:../qcaml.org::*QCaml][QCaml:2]] *)
(* [[file:~/QCaml/common/qcaml.org::*QCaml][QCaml:2]] *)
let name = "QCaml"
let root =

View File

@ -6,7 +6,7 @@
* QCaml-specific parameters *)
(* [[file:../qcaml.org::*QCaml][QCaml:1]] *)
(* [[file:~/QCaml/common/qcaml.org::*QCaml][QCaml:1]] *)
val root : string
val name : string
(* QCaml:1 ends here *)

View File

@ -1,8 +1,8 @@
(* [[file:../range.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/range.org::*Type][Type:2]] *)
type t = int list
(* Type:2 ends here *)
(* [[file:../range.org::*Conversion][Conversion:2]] *)
(* [[file:~/QCaml/common/range.org::*Conversion][Conversion:2]] *)
let to_int_list r = r
let expand_range r =
@ -43,7 +43,7 @@ let to_string l =
"]"
(* Conversion:2 ends here *)
(* [[file:../range.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/range.org::*Printers][Printers:2]] *)
let pp ppf t =
Format.fprintf ppf "@[%s@]" (to_string t)
(* Printers:2 ends here *)

View File

@ -1,14 +1,14 @@
(* Type *)
(* [[file:../range.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/range.org::*Type][Type:1]] *)
type t
(* Type:1 ends here *)
(* Conversion *)
(* [[file:../range.org::*Conversion][Conversion:1]] *)
(* [[file:~/QCaml/common/range.org::*Conversion][Conversion:1]] *)
val of_string : string -> t
val to_string : t -> string
val to_int_list : t -> int list
@ -17,6 +17,6 @@ val to_int_list : t -> int list
(* Printers *)
(* [[file:../range.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/range.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -5,7 +5,7 @@
* letters as ~Beta~, so the alignment of the code is nicer. *)
(* [[file:../spin.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/spin.org::*Type][Type:2]] *)
type t = (* m_s *)
| Alfa (* {% $m_s = +1/2$ %} *)
| Beta (* {% $m_s = -1/2$ %} *)
@ -16,7 +16,7 @@ type t = (* m_s *)
(* Returns the opposite spin *)
(* [[file:../spin.org::*Functions][Functions:2]] *)
(* [[file:~/QCaml/common/spin.org::*Functions][Functions:2]] *)
let other = function
| Alfa -> Beta
| Beta -> Alfa
@ -26,7 +26,7 @@ let to_string = function
| Beta -> "Beta "
(* Functions:2 ends here *)
(* [[file:../spin.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/spin.org::*Printers][Printers:2]] *)
let pp ppf t =
Format.fprintf ppf "@[%s@]" (to_string t)
(* Printers:2 ends here *)

View File

@ -1,20 +1,20 @@
(* Type *)
(* [[file:../spin.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/spin.org::*Type][Type:1]] *)
type t = Alfa | Beta
(* Type:1 ends here *)
(* Functions *)
(* [[file:../spin.org::*Functions][Functions:1]] *)
(* [[file:~/QCaml/common/spin.org::*Functions][Functions:1]] *)
val other : t -> t
(* Functions:1 ends here *)
(* Printers *)
(* [[file:../spin.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/spin.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -8,7 +8,7 @@
/* | ~leadz~ | ~bsf~ instruction | */
/* [[file:../util.org::*External C functions][External C functions:1]] */
/* [[file:~/QCaml/common/util.org::*External%20C%20functions][External C functions:1]] */
#include <math.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
@ -17,7 +17,7 @@
/* Erf */
/* [[file:../util.org::*Erf][Erf:1]] */
/* [[file:~/QCaml/common/util.org::*Erf][Erf:1]] */
CAMLprim value erf_float_bytecode(value x) {
return copy_double(erf(Double_val(x)));
}
@ -30,7 +30,7 @@ CAMLprim double erf_float(double x) {
/* Erfc */
/* [[file:../util.org::*Erfc][Erfc:1]] */
/* [[file:~/QCaml/common/util.org::*Erfc][Erfc:1]] */
CAMLprim value erfc_float_bytecode(value x) {
return copy_double(erfc(Double_val(x)));
}
@ -43,7 +43,7 @@ CAMLprim double erfc_float(double x) {
/* Gamma */
/* [[file:../util.org::*Gamma][Gamma:1]] */
/* [[file:~/QCaml/common/util.org::*Gamma][Gamma:1]] */
CAMLprim value gamma_float_bytecode(value x) {
return copy_double(tgamma(Double_val(x)));
}
@ -57,7 +57,7 @@ CAMLprim double gamma_float(double x) {
/* Popcnt */
/* [[file:../util.org::*Popcnt][Popcnt:1]] */
/* [[file:~/QCaml/common/util.org::*Popcnt][Popcnt:1]] */
CAMLprim int32_t popcnt(int64_t i) {
return __builtin_popcountll (i);
}
@ -71,7 +71,7 @@ CAMLprim value popcnt_bytecode(value i) {
/* Trailz */
/* [[file:../util.org::*Trailz][Trailz:1]] */
/* [[file:~/QCaml/common/util.org::*Trailz][Trailz:1]] */
CAMLprim int32_t trailz(int64_t i) {
return __builtin_ctzll (i);
}
@ -85,7 +85,7 @@ CAMLprim value trailz_bytecode(value i) {
/* Leadz */
/* [[file:../util.org::*Leadz][Leadz:1]] */
/* [[file:~/QCaml/common/util.org::*Leadz][Leadz:1]] */
CAMLprim int32_t leadz(int64_t i) {
return __builtin_clzll(i);
}

View File

@ -1,30 +1,30 @@
(* [[file:../util.org::*Erf][Erf:3]] *)
(* [[file:~/QCaml/common/util.org::*Erf][Erf:3]] *)
external erf_float : float -> float = "erf_float_bytecode" "erf_float" [@@unboxed] [@@noalloc]
(* Erf:3 ends here *)
(* [[file:../util.org::*Erfc][Erfc:3]] *)
(* [[file:~/QCaml/common/util.org::*Erfc][Erfc:3]] *)
external erfc_float : float -> float = "erfc_float_bytecode" "erfc_float" [@@unboxed] [@@noalloc]
(* Erfc:3 ends here *)
(* [[file:../util.org::*Gamma][Gamma:3]] *)
(* [[file:~/QCaml/common/util.org::*Gamma][Gamma:3]] *)
external gamma_float : float -> float = "gamma_float_bytecode" "gamma_float" [@@unboxed] [@@noalloc]
(* Gamma:3 ends here *)
(* [[file:../util.org::*Popcnt][Popcnt:3]] *)
(* [[file:~/QCaml/common/util.org::*Popcnt][Popcnt:3]] *)
external popcnt : int64 -> int32 = "popcnt_bytecode" "popcnt"
[@@unboxed] [@@noalloc]
let popcnt i = (popcnt [@inlined] ) i |> Int32.to_int
(* Popcnt:3 ends here *)
(* [[file:../util.org::*Trailz][Trailz:3]] *)
(* [[file:~/QCaml/common/util.org::*Trailz][Trailz:3]] *)
external trailz : int64 -> int32 = "trailz_bytecode" "trailz" "int"
[@@unboxed] [@@noalloc]
let trailz i = trailz i |> Int32.to_int
(* Trailz:3 ends here *)
(* [[file:../util.org::*Leadz][Leadz:3]] *)
(* [[file:~/QCaml/common/util.org::*Leadz][Leadz:3]] *)
external leadz : int64 -> int32 = "leadz_bytecode" "leadz" "int"
[@@unboxed] [@@noalloc]
@ -43,7 +43,7 @@ let leadz i = leadz i |> Int32.to_int
* | ~of_some~ | Extracts the value of an option | *)
(* [[file:../util.org::*General functions][General functions:2]] *)
(* [[file:~/QCaml/common/util.org::*General%20functions][General functions:2]] *)
let memo_float_of_int =
Array.init 64 float_of_int
@ -149,7 +149,7 @@ let of_some = function
(* [[file:../util.org::*Functions related to the Boys function][Functions related to the Boys function:2]] *)
(* [[file:~/QCaml/common/util.org::*Functions%20related%20to%20the%20Boys%20function][Functions related to the Boys function:2]] *)
let incomplete_gamma ~alpha x =
assert (alpha >= 0.);
assert (x >= 0.);
@ -211,7 +211,7 @@ let incomplete_gamma ~alpha x =
* - $F_m(t) = \frac{ 2t\, F_{m+1}(t) + e^{-t} }{2m+1}$ *)
(* [[file:../util.org::*Functions related to the Boys function][Functions related to the Boys function:4]] *)
(* [[file:~/QCaml/common/util.org::*Functions%20related%20to%20the%20Boys%20function][Functions related to the Boys function:4]] *)
let boys_function ~maxm t =
assert (t >= 0.);
match maxm with
@ -257,7 +257,7 @@ let boys_function ~maxm t =
* | ~list_pack~ | ~list_pack n l~ Creates a list of ~n~-elements lists | *)
(* [[file:../util.org::*List functions][List functions:2]] *)
(* [[file:~/QCaml/common/util.org::*List%20functions][List functions:2]] *)
let list_some l =
List.filter (function None -> false | _ -> true) l
|> List.rev_map (function Some x -> x | _ -> assert false)
@ -295,7 +295,7 @@ let list_pack n l =
* | ~array_product~ | Returns the product of all the elements of the array | *)
(* [[file:../util.org::*Array functions][Array functions:2]] *)
(* [[file:~/QCaml/common/util.org::*Array%20functions][Array functions:2]] *)
let array_range first last =
if last < first then [| |] else
Array.init (last-first+1) (fun i -> i+first)
@ -316,7 +316,7 @@ let array_product a =
* | ~stream_fold~ | Apply a fold to the elements of the stream | *)
(* [[file:../util.org::*Stream functions][Stream functions:2]] *)
(* [[file:~/QCaml/common/util.org::*Stream%20functions][Stream functions:2]] *)
let stream_range first last =
Stream.from (fun i ->
let result = i+first in
@ -382,7 +382,7 @@ let stream_fold f init stream =
* #+end_example *)
(* [[file:../util.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/util.org::*Printers][Printers:2]] *)
let pp_float_array ppf a =
Format.fprintf ppf "@[<2>[@ ";
Array.iter (fun f -> Format.fprintf ppf "@[%10f@]@ " f) a;

View File

@ -1,31 +1,31 @@
(* [[file:../util.org::*Erf][Erf:2]] *)
(* [[file:~/QCaml/common/util.org::*Erf][Erf:2]] *)
external erf_float : float -> float = "erf_float_bytecode" "erf_float" [@@unboxed] [@@noalloc]
(* Erf:2 ends here *)
(* [[file:../util.org::*Erfc][Erfc:2]] *)
(* [[file:~/QCaml/common/util.org::*Erfc][Erfc:2]] *)
external erfc_float : float -> float = "erfc_float_bytecode" "erfc_float" [@@unboxed] [@@noalloc]
(* Erfc:2 ends here *)
(* [[file:../util.org::*Gamma][Gamma:2]] *)
(* [[file:~/QCaml/common/util.org::*Gamma][Gamma:2]] *)
external gamma_float : float -> float = "gamma_float_bytecode" "gamma_float" [@@unboxed] [@@noalloc]
(* Gamma:2 ends here *)
(* [[file:../util.org::*Popcnt][Popcnt:2]] *)
(* [[file:~/QCaml/common/util.org::*Popcnt][Popcnt:2]] *)
val popcnt : int64 -> int
(* Popcnt:2 ends here *)
(* [[file:../util.org::*Trailz][Trailz:2]] *)
(* [[file:~/QCaml/common/util.org::*Trailz][Trailz:2]] *)
val trailz : int64 -> int
(* Trailz:2 ends here *)
(* [[file:../util.org::*Leadz][Leadz:2]] *)
(* [[file:~/QCaml/common/util.org::*Leadz][Leadz:2]] *)
val leadz : int64 -> int
(* Leadz:2 ends here *)
(* General functions *)
(* [[file:../util.org::*General functions][General functions:1]] *)
(* [[file:~/QCaml/common/util.org::*General%20functions][General functions:1]] *)
val fact : int -> float
(* @raise Invalid_argument for negative arguments or arguments >100. *)
val binom : int -> int -> int
@ -42,19 +42,19 @@ val of_some : 'a option -> 'a
(* Functions related to the Boys function *)
(* [[file:../util.org::*Functions related to the Boys function][Functions related to the Boys function:1]] *)
(* [[file:~/QCaml/common/util.org::*Functions%20related%20to%20the%20Boys%20function][Functions related to the Boys function:1]] *)
val incomplete_gamma : alpha:float -> float -> float
(* @raise Failure when the calculation doesn't converge. *)
(* Functions related to the Boys function:1 ends here *)
(* [[file:../util.org::*Functions related to the Boys function][Functions related to the Boys function:3]] *)
(* [[file:~/QCaml/common/util.org::*Functions%20related%20to%20the%20Boys%20function][Functions related to the Boys function:3]] *)
val boys_function : maxm:int -> float -> float array
(* Functions related to the Boys function:3 ends here *)
(* List functions *)
(* [[file:../util.org::*List functions][List functions:1]] *)
(* [[file:~/QCaml/common/util.org::*List%20functions][List functions:1]] *)
val list_some : 'a option list -> 'a list
val list_range : int -> int -> int list
val list_pack : int -> 'a list -> 'a list list
@ -63,7 +63,7 @@ val list_pack : int -> 'a list -> 'a list list
(* Array functions *)
(* [[file:../util.org::*Array functions][Array functions:1]] *)
(* [[file:~/QCaml/common/util.org::*Array%20functions][Array functions:1]] *)
val array_range : int -> int -> int array
val array_sum : float array -> float
val array_product : float array -> float
@ -72,7 +72,7 @@ val array_product : float array -> float
(* Stream functions *)
(* [[file:../util.org::*Stream functions][Stream functions:1]] *)
(* [[file:~/QCaml/common/util.org::*Stream%20functions][Stream functions:1]] *)
val stream_range : int -> int -> int Stream.t
val stream_to_list : 'a Stream.t -> 'a list
val stream_fold : ('a -> 'b -> 'a) -> 'a -> 'b Stream.t -> 'a
@ -81,7 +81,7 @@ val stream_fold : ('a -> 'b -> 'a) -> 'a -> 'b Stream.t -> 'a
(* Printers *)
(* [[file:../util.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/util.org::*Printers][Printers:1]] *)
val pp_float_array_size : Format.formatter -> float array -> unit
val pp_float_array : Format.formatter -> float array -> unit
val pp_float_2darray_size : Format.formatter -> float array array -> unit

View File

@ -1,4 +1,4 @@
(* [[file:../zkey.org::*Types][Types:2]] *)
(* [[file:~/QCaml/common/zkey.org::*Types][Types:2]] *)
type t =
{
mutable left : int;
@ -18,19 +18,19 @@ type kind =
(* | ~of_powers_three | Create from a ~Powers.t~ |
* | ~of_powers_six | Create from two ~Powers.t~ |
* | ~of_powers_nine | Create from three ~Powers.t~ |
* | ~of_powers_twelve | Create from four ~Powers.t~ |
* | ~of_powers | Create using the ~kind~ type |
* | ~of_int_array | Convert from an ~int~ array |
* | ~of_int_four | Create from four ~ints~ |
* | ~to_int_array | Convert to an ~int~ array |
* | ~to_powers | Convert to an ~Powers.t~ array |
* | ~to_string | Pretty printing | *)
(* | ~of_powers_three~ | Create from a ~Powers.t~ |
* | ~of_powers_six~ | Create from two ~Powers.t~ |
* | ~of_powers_nine~ | Create from three ~Powers.t~ |
* | ~of_powers_twelve~ | Create from four ~Powers.t~ |
* | ~of_powers~ | Create using the ~kind~ type |
* | ~of_int_array~ | Convert from an ~int~ array |
* | ~of_int_four~ | Create from four ~ints~ |
* | ~to_int_array~ | Convert to an ~int~ array |
* | ~to_powers~ | Convert to an ~Powers.t~ array |
* | ~to_string~ | Pretty printing | *)
(* [[file:../zkey.org::*Conversions][Conversions:2]] *)
(* [[file:~/QCaml/common/zkey.org::*Conversions][Conversions:2]] *)
(** Creates a Zkey. *)
let make ~kind right =
{ left = 0 ; right ; kind }
@ -232,7 +232,7 @@ let to_powers { left ; right ; kind } =
* | ~compare~ | Comparison function, used for sorting | *)
(* [[file:../zkey.org::*Functions for hash tables][Functions for hash tables:2]] *)
(* [[file:~/QCaml/common/zkey.org::*Functions%20for%20hash%20tables][Functions for hash tables:2]] *)
let hash = Hashtbl.hash
let equal
@ -261,7 +261,7 @@ let to_string { left ; right ; kind } =
) ^ " >"
(* Functions for hash tables:2 ends here *)
(* [[file:../zkey.org::*Printers][Printers:2]] *)
(* [[file:~/QCaml/common/zkey.org::*Printers][Printers:2]] *)
let pp ppf t =
Format.fprintf ppf "@[%s@]" (to_string t)
(* Printers:2 ends here *)

View File

@ -1,7 +1,7 @@
(* Types *)
(* [[file:../zkey.org::*Types][Types:1]] *)
(* [[file:~/QCaml/common/zkey.org::*Types][Types:1]] *)
type t
type kind =
@ -15,7 +15,7 @@ type kind =
(* Conversions *)
(* [[file:../zkey.org::*Conversions][Conversions:1]] *)
(* [[file:~/QCaml/common/zkey.org::*Conversions][Conversions:1]] *)
val of_powers_three : Powers.t -> t
val of_powers_six : Powers.t -> Powers.t -> t
val of_powers_nine : Powers.t -> Powers.t -> Powers.t -> t
@ -31,7 +31,7 @@ val to_string : t -> string
(* Functions for hash tables *)
(* [[file:../zkey.org::*Functions for hash tables][Functions for hash tables:1]] *)
(* [[file:~/QCaml/common/zkey.org::*Functions%20for%20hash%20tables][Functions for hash tables:1]] *)
val hash : t -> int
val equal : t -> t -> bool
val compare : t -> t -> int
@ -40,6 +40,6 @@ val compare : t -> t -> int
(* Printers *)
(* [[file:../zkey.org::*Printers][Printers:1]] *)
(* [[file:~/QCaml/common/zkey.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -1,4 +1,4 @@
(* [[file:../zmap.org::*Type][Type:2]] *)
(* [[file:~/QCaml/common/zmap.org::*Type][Type:2]] *)
module Zmap = Hashtbl.Make(Zkey)
include Zmap
(* Type:2 ends here *)

View File

@ -1,6 +1,6 @@
(* Type *)
(* [[file:../zmap.org::*Type][Type:1]] *)
(* [[file:~/QCaml/common/zmap.org::*Type][Type:1]] *)
include module type of Hashtbl.Make(Zkey)
(* Type:1 ends here *)

View File

@ -1,7 +1,7 @@
(* Tests header :noexport: *)
(* [[file:../bitstring.org::*Tests header][Tests header:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Tests%20header][Tests header:1]] *)
open Common.Bitstring
let check_bool = Alcotest.(check bool)
let check msg x = check_bool msg true x
@ -12,31 +12,31 @@ let test_all () =
let many_x = of_z z in
(* Tests header:1 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:3]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:3]] *)
check_bool "of_x" true (one_x = (of_int x));
(* General implementation:3 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:5]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:11]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:13]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:15]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:15]] *)
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:../bitstring.org::*General implementation][General implementation:17]] *)
(* [[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);
@ -45,26 +45,26 @@ 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 *)
(* [[file:../bitstring.org::*General implementation][General implementation:19]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:19]] *)
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:../bitstring.org::*General implementation][General implementation:21]] *)
(* [[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:../bitstring.org::*General implementation][General implementation:23]] *)
(* [[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 *)
(* [[file:../bitstring.org::*General implementation][General implementation:31]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:31]] *)
check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
(* General implementation:31 ends here *)
(* [[file:../bitstring.org::*General implementation][General implementation:33]] *)
(* [[file:~/QCaml/common/bitstring.org::*General%20implementation][General implementation:33]] *)
check "permutations"
(permutations 2 4 = List.map of_int
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
@ -73,7 +73,7 @@ check "permutations"
(* Tests :noexport: *)
(* [[file:../bitstring.org::*Tests][Tests:1]] *)
(* [[file:~/QCaml/common/bitstring.org::*Tests][Tests:1]] *)
()
let tests = [

View File

@ -1,7 +1,7 @@
(* Test header :noexport: *)
(* [[file:../util.org::*Test header][Test header:1]] *)
(* [[file:~/QCaml/common/util.org::*Test%20header][Test header:1]] *)
open Common.Util
open Alcotest
(* Test header:1 ends here *)
@ -9,7 +9,7 @@ open Alcotest
(* Test *)
(* [[file:../util.org::*Test][Test:1]] *)
(* [[file:~/QCaml/common/util.org::*Test][Test:1]] *)
let test_external () =
check (float 1.e-15) "erf" 0.842700792949715 (erf_float 1.0);
check (float 1.e-15) "erf" 0.112462916018285 (erf_float 0.1);
@ -35,7 +35,7 @@ let test_external () =
()
(* Test:1 ends here *)
(* [[file:../util.org::*General functions][General functions:3]] *)
(* [[file:~/QCaml/common/util.org::*General%20functions][General functions:3]] *)
let test_general () =
check int "of_some_of_int_fast" 1 (of_some (Some 1)) ;
check int "binom" 35 (binom 7 4);
@ -46,7 +46,7 @@ let test_general () =
()
(* General functions:3 ends here *)
(* [[file:../util.org::*Functions related to the Boys function][Functions related to the Boys function:5]] *)
(* [[file:~/QCaml/common/util.org::*Functions%20related%20to%20the%20Boys%20function][Functions related to the Boys function:5]] *)
let test_boys () =
check (float 1.e-15) "incomplete_gamma" 0.0 (incomplete_gamma ~alpha:0.5 0.);
check (float 1.e-15) "incomplete_gamma" 1.114707979049507 (incomplete_gamma ~alpha:0.5 0.4);
@ -63,7 +63,7 @@ let test_boys () =
()
(* Functions related to the Boys function:5 ends here *)
(* [[file:../util.org::*List functions][List functions:3]] *)
(* [[file:~/QCaml/common/util.org::*List%20functions][List functions:3]] *)
let test_list () =
check bool "list_range" true ([ 2; 3; 4 ] = list_range 2 4);
check bool "list_some" true ([ 2; 3; 4 ] =
@ -74,7 +74,7 @@ let test_list () =
()
(* List functions:3 ends here *)
(* [[file:../util.org::*Array functions][Array functions:3]] *)
(* [[file:~/QCaml/common/util.org::*Array%20functions][Array functions:3]] *)
let test_array () =
check bool "array_range" true ([| 2; 3; 4 |] = array_range 2 4);
check (float 1.e-15) "array_sum" 9. (array_sum [| 2.; 3.; 4. |]);
@ -85,7 +85,7 @@ let test_array () =
(* Test footer :noexport: *)
(* [[file:../util.org::*Test footer][Test footer:1]] *)
(* [[file:~/QCaml/common/util.org::*Test%20footer][Test footer:1]] *)
let tests = [
"External", `Quick, test_external;
"General" , `Quick, test_general;

View File

@ -85,16 +85,16 @@ val to_powers : t -> kind
val to_string : t -> string
#+end_src
| ~of_powers_three | Create from a ~Powers.t~ |
| ~of_powers_six | Create from two ~Powers.t~ |
| ~of_powers_nine | Create from three ~Powers.t~ |
| ~of_powers_twelve | Create from four ~Powers.t~ |
| ~of_powers | Create using the ~kind~ type |
| ~of_int_array | Convert from an ~int~ array |
| ~of_int_four | Create from four ~ints~ |
| ~to_int_array | Convert to an ~int~ array |
| ~to_powers | Convert to an ~Powers.t~ array |
| ~to_string | Pretty printing |
| ~of_powers_three~ | Create from a ~Powers.t~ |
| ~of_powers_six~ | Create from two ~Powers.t~ |
| ~of_powers_nine~ | Create from three ~Powers.t~ |
| ~of_powers_twelve~ | Create from four ~Powers.t~ |
| ~of_powers~ | Create using the ~kind~ type |
| ~of_int_array~ | Convert from an ~int~ array |
| ~of_int_four~ | Create from four ~ints~ |
| ~to_int_array~ | Convert to an ~int~ array |
| ~to_powers~ | Convert to an ~Powers.t~ array |
| ~to_string~ | Pretty printing |
#+begin_src ocaml :tangle (eval ml) :exports none
(** Creates a Zkey. *)