Exponentiation operator: Difference between revisions

Content added Content deleted
Line 665: Line 665:
pow [ ] ( @ ) [ 1; 2 ] 10;; (* [1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2] *)
pow [ ] ( @ ) [ 1; 2 ] 10;; (* [1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2] *)


(* more unusual *)
(* Thue-Morse sequence *)
Array.init 200 (fun n -> (1 - pow 1 ( - ) 0 n)/2);;
Array.init 32 (fun n -> (1 - pow 1 ( - ) 0 n) lsr 1);;


(* [|0; 1; 1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0;
(*
[|0; 1; 1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 1; 0; 0;
1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1; 0; 0; 1|]
1; 1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1;
1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1;
0; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0;
1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1;
0; 0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0;
0; 1; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1; 0; 0; 1; 1; 0; 0; 1; 0; 1; 1;
0; 1; 0; 0; 1; 0; 1; 1; 0; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 1; 0; 1; 0; 0; 1|]


See http://en.wikipedia.org/wiki/Thue-Morse_sequence
See http://en.wikipedia.org/wiki/Thue-Morse_sequence
*)
*)</lang>

</lang>


See also [[Matrix-exponentiation_operator#OCaml]] for a matrix usage.
See also [[Matrix-exponentiation_operator#OCaml]] for a matrix usage.