(* Random Permutation *) let rp n = let ra = Array.init n (fun j -> j) and ans = Array.make n 0 in for i = 0 to n-1 do let f = Random.int (n-i) in ans.(i) <- ra.(f); ra.(f) <- ra.(n-i-1) done; ans;; (* Generalized Cross Product *) exception Ragged let cross a = let n = Array.length a in (for i = 0 to n-1 do if Array.length a.(i) <> n+1 then raise Ragged done; let x = Linear.trans a in let d = Array.init n (fun j -> x.(j+1)) and b = Array.make (n+1) 0. and s = ref 1. in for i = 0 to n do b.(i) <- !s *. Linear.determ d; if i [] | [a] -> [[a]] | a::b::c -> (if less a b then [a; b] else [b; a])::(fp c) in let rec mrg a b = match (a, b) with | (c, []) -> a | ([], c) -> b | (c::d, e::f) -> if less c e then c::(mrg d b) else e::(mrg f a) in let rec lmrg llst = match llst with [] -> [] | [a] -> [a] | a::b::c -> (mrg a b)::(lmrg c) in let rec rlm lx = match lx with | [] -> [] | [a] -> a | a::b::c -> rlm (lmrg lx) in rlm (fp lst);;