1. Yaron Minsky
  2. train-tracks-and-permutations

Commits

Yaron Minsky  committed c4882bb

small tweaks

  • Participants
  • Parent commits 8743cf2
  • Branches default

Comments (0)

Files changed (4)

File ocaml/build_all.sh

View file
  • Ignore whitespace
 corebuild \
     -cflag -g -j 4 \
     -pkg core_extended,async \
-    permutation.cmo experiments.byte
+    permutation.cmo experiments.native

File ocaml/experiments.ml

View file
  • Ignore whitespace
 open Permutation.Infix
 module P = Permutation
 
-let count times f =
+let succ_ratio times f =
   let rec loop ~times count =
     if times = 0 then count
     else loop ~times:(times - 1)
            (if f () then count + 1 else count)
   in
-  loop ~times 0
+  loop ~times 0 // times
 
-let count1 n m =
-  count m (fun () ->
+let ratio1 n m =
+  succ_ratio m (fun () ->
     let scramble = P.rand n in
-    P.is_cycle (scramble <<< P.rot1 n <<< P.inverse scramble)
+    P.is_cycle (scramble ++ P.rot1 n ++ P.inverse scramble)
   )
 
-let count2 n m =
+let ratio2 n m =
   let scramble = P.rand n in
-  let cyc = scramble <<< P.rot1 n <<< P.inverse scramble in
+  let cyc = scramble ++ P.rot1 n ++ P.inverse scramble in
   let scramble2 = P.rand n in
-  let cyc2 = scramble2 <<< P.rot1 n <<< P.inverse scramble2 in
-  count m (fun () ->
+  let cyc2 = scramble2 ++ P.rot1 n ++ P.inverse scramble2 in
+  succ_ratio m (fun () ->
     let inv = P.involution n in
-    P.is_cycle (inv <<< cyc)
-    && P.is_cycle (inv <<< cyc2)
+    P.is_cycle (inv ++ cyc)
+    && P.is_cycle (inv ++ cyc2)
   )
 
-let count1r n m =
+let ratio1r n m =
   let scramble = P.rand n in
-  count m (fun () -> P.is_cycle (P.involution n <<< scramble))
+  succ_ratio m (fun () -> P.is_cycle (P.involution n ++ scramble))
 
 
 (* Experiment 1 *)
 
-type exp1 = { n: int;
-              c1: decimal;
-              c2: decimal;
-              c1_sq: decimal;
+type exp1 = { n: int
+            ; r1: decimal
+            ; r2: decimal
+            ; r1_sq: decimal
             }
 with sexp
 
 let exp1 m =
   printf "Cycle counting experiment: M=%d\n" m;
   List.iter (List.range 100 120 ~stride:4) ~f:(fun n ->
-    let c1 = count1 n m in
-    let c2 = count2 n m in
-    let sq x = x *. x in
-    { n
-    ; c1 = c1 // m
-    ; c2 = c2 // m
-    ; c1_sq = sq (c1 // m)
-    }
+    let r1 = ratio1 n m in
+    let r2 = ratio2 n m in
+    let r1_sq = r1 *. r1 in
+    { n; r1; r2; r1_sq }
     |> sexp_of_exp1 |> Sexp.to_string_hum |> print_endline
   )
 

File ocaml/permutation.ml

View file
  • Ignore whitespace
   Array.concat [left;right]
 
 module Infix = struct
-  let (<<<) = compose
+  let (++) = compose
 end
 
 include Pretty_printer.Register (struct

File ocaml/permutation.mli

View file
  • Ignore whitespace
 
 module Infix : sig
   (** compose *)
-  val (<<<) : t -> t -> t
+  val (++) : t -> t -> t
 end
+