Recursive approach for computing $(a,b) \mapsto a^b$

82 Views Asked by At

As a programming exercise I was asked to implement a recursive approach for computing $a^b$ given two real $a,b \in \mathbb R, a>0$.

I assume this task has a typo, as a recursive approach makes sense when $b \in \mathbb Z$. But I am still wondering, is there some kind of recursive (not too terribly inefficient) method for approximating $a^b$ if $b$ is not an integer?

1

There are 1 best solutions below

6
On

I here assume that $b>0$.

$ f(a,b) = \begin{cases} a*f(a,b-1), & \text{if $b$ > 1} \\ a^b, & \text{else} \end{cases} $