wmfarmer% ocaml Objective Caml version 3.08.0 # let seq_lim s epsilon max_n = let abs x = if x >= 0. then x else (-. x) in let first = ref (s 0) in let second = ref (s 1) in let n = ref 1 in while (abs (!first -. !second) >= epsilon) && !n < max_n do first := !second ; second := s (!n + 1) ; n := !n + 1 done ; (!second, !n) ;; val seq_lim : (int -> float) -> float -> int -> float * int = # seq_lim (function x -> 1.) 0.001 1000 ;; - : float * int = (1., 1) # seq_lim (function x -> float_of_int x) 0.001 1000 ;; - : float * int = (1000., 1000) # seq_lim (function x -> 1. +. (1. /. (float_of_int x))) 0.001 1000 ;; - : float * int = (1.03030303030303028, 33) # seq_lim (function x -> 1. +. (1. /. (float_of_int x))) 0.000000001 10000000 ;; - : float * int = (1.00003162155325076, 31624) # seq_lim (function x -> 1. +. (1. /. (float_of_int x))) 0.000000000000001 10000000 ;; - : float * int = (1.0000001, 10000000) #