From dfadaf14c1f64bf7eaf4e019154662c51f99c759 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 26 Dec 2020 01:54:39 +0100 Subject: [PATCH] permtutations -> permutations --- common/bitstring.org | 12 ++++++------ common/lib/bitstring.ml | 6 +++--- common/lib/bitstring.mli | 12 ++++++------ common/test/bitstring.ml | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/bitstring.org b/common/bitstring.org index 47a12e7..2dee502 100644 --- a/common/bitstring.org +++ b/common/bitstring.org @@ -485,14 +485,14 @@ let rec to_list ?(accu=[]) = function Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); #+end_src -*** ~permtutations~ +*** ~permutations~ - ~permtutations m n~ generates the list of all possible ~n~-bit + ~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 -Bitstring.permtutations 2 4 |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; +Bitstring.permutations 2 4 |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; - : string list = ["++--------------------------------------------------------------"; @@ -504,11 +504,11 @@ Bitstring.permtutations 2 4 #+end_example #+begin_src ocaml :tangle (org-entry-get nil "mli" t) -val permtutations : int -> int -> t list +val permutations : int -> int -> t list #+end_src #+begin_src ocaml :tangle (org-entry-get nil "ml" t) -let permtutations m n = +let permutations m n = let rec aux k u rest = if k=1 then @@ -529,7 +529,7 @@ let permtutations m n = #+begin_src ocaml :tangle (org-entry-get nil "test-ml" t) check "permutations" - (permtutations 2 4 = List.map of_int + (permutations 2 4 = List.map of_int [ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]); #+end_src diff --git a/common/lib/bitstring.ml b/common/lib/bitstring.ml index 1491eea..40720b6 100644 --- a/common/lib/bitstring.ml +++ b/common/lib/bitstring.ml @@ -208,8 +208,8 @@ let rec to_list ?(accu=[]) = function |> (to_list [@tailcall]) ~accu:newlist (* ~to_list~:2 ends here *) -(* [[file:../bitstring.org::*~permtutations~][~permtutations~:2]] *) -let permtutations m n = +(* [[file:../bitstring.org::*~permutations~][~permutations~:2]] *) +let permutations m n = let rec aux k u rest = if k=1 then @@ -226,7 +226,7 @@ let permtutations m n = (aux [@tailcall]) (k-1) (logor t' t'') (u :: rest) in aux (Util.binom n m) (minus_one (shift_left_one n m)) [] -(* ~permtutations~:2 ends here *) +(* ~permutations~:2 ends here *) (* [[file:../bitstring.org::*Printers][Printers:2]] *) let pp ppf = function diff --git a/common/lib/bitstring.mli b/common/lib/bitstring.mli index af80e56..f4f238d 100644 --- a/common/lib/bitstring.mli +++ b/common/lib/bitstring.mli @@ -211,14 +211,14 @@ val popcount : t -> int val to_list : ?accu:(int list) -> t -> int list (* ~to_list~:1 ends here *) -(* ~permtutations~ +(* ~permutations~ * - * ~permtutations m n~ generates the list of all possible ~n~-bit + * ~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 - * Bitstring.permtutations 2 4 |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; + * Bitstring.permutations 2 4 * |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;; * - : string list = * ["++--------------------------------------------------------------"; @@ -230,9 +230,9 @@ val to_list : ?accu:(int list) -> t -> int list * #+end_example *) -(* [[file:../bitstring.org::*~permtutations~][~permtutations~:1]] *) -val permtutations : int -> int -> t list -(* ~permtutations~:1 ends here *) +(* [[file:../bitstring.org::*~permutations~][~permutations~:1]] *) +val permutations : int -> int -> t list +(* ~permutations~:1 ends here *) (* Printers * diff --git a/common/test/bitstring.ml b/common/test/bitstring.ml index 76d59d1..f2d70b0 100644 --- a/common/test/bitstring.ml +++ b/common/test/bitstring.ml @@ -63,11 +63,11 @@ let test_all () = Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45))); (* ~to_list~:3 ends here *) -(* [[file:../bitstring.org::*~permtutations~][~permtutations~:3]] *) +(* [[file:../bitstring.org::*~permutations~][~permutations~:3]] *) check "permutations" - (permtutations 2 4 = List.map of_int + (permutations 2 4 = List.map of_int [ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]); -(* ~permtutations~:3 ends here *) +(* ~permutations~:3 ends here *) (* Tests *)