power: Iterated functions; functional powers

powR Documentation

Iterated functions; functional powers

Description

Given a function f\colon X\longrightarrow X, we define

f^0 = \mathrm{id_X}

f^{n+1} = f\circ f^n=f^n\circ f,\qquad n\geqslant 0

This gives us f^{n+m}=f^n\circ f^m and \left(f^m\right)^n=f^{mn}, which motivates the notation. For example, \sin^3=\sin\circ\sin\circ\sin, so \sin^3(x)=\sin(\sin(\sin x)).

The operator is well-defined due to the power associativity of function composition.

Usage

pow(x, n)

Arguments

x

Object of class vf

n

Non-negative integer

Value

Returns an object of class vf

Note

There are possibly more efficient methods requiring fewer compositions, e.g. pow(f,9) (which would require 8 function compositions) could be evaluated by pow(pow(f,3),3) (which requires only four). But I am not sure that this would actually be any faster, and I have not got round to thinking about it yet.

Also, package idiom for the caret “^” is reserved for arithmetic exponentiation [so, for example, (f^3)(x) == f(x)*f(x)*f(x)]. I believe this is sub-optimal but was unable to overload the caret to implement functional iteration.

Author(s)

Robin K. S. Hankin

Examples


pow(Sin,5)
Sin^5

f <- as.vf(function(x){x^2+1})

pow(f + Sin,4)
pow(f + Sin,4)(2)

vfunc documentation built on Aug. 8, 2025, 6:20 p.m.