Fast simulation of new coins from old

Let S⊂(0,1). Given a known function f:S→(0,1), we consider the problem of using independent tosses of a coin with probability of heads p (where p∈S is unknown) to simulate a coin with probability of heads f(p). We prove that if S is a closed interval and f is real analytic on S, then f has a fast simulation on S (the number of p-coin tosses needed has exponential tails). Conversely, if a function f has a fast simulation on an open set, then it is real analytic on that set.