Function doesn't finish



If T[n] is the number of calls to simp-%sin required to simplify
sin(sin(...(x) ..)) (n sine functions), experimentally, I find
that

   T[n] = 3 T[n-1] - n + 2.

This makes T[n] = 3^n / 4 + n /2 - 1/3. Several option variables
modify simplification of the trigonometric functions.  Thus
the trig simplification functions have to mostly ignore the simp flag,
because these functions can't tell if the option variables have changed
since the expression was last simplified.  I don't know if this accounts
for all
the slowness we see in simplifying n-fold compositions of trig functions.
The multiplier of 3 in T[n] = 3 T[n-1] - n + 2 seems too big.

One more item:  Passing the name of a function to a function is
risky. Consider:

(%i1) nest(f,x,n) := if n = 0 then x else nest(f, f(x), n-1);
(%o1) nest(f,x,n):=if n=0 then x else nest(f,f(x),n-1)

(%i2) nest(f,x,3);
(%o2) f(f(f(x)))    <--- OK

(%i3) nest(x,f,3);  <--- hangs

Maxima encountered a Lisp error:
 Console interrupt.
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.

New version:

(%i4) nest(f,x,n) := if n = 0 then x else nest(f, funmake(f,[x]), n-1);
(%o4) nest(f,x,n):=if n=0 then x else nest(f,funmake(f,[x]),n-1)
(%i5) nest(x,f,3);
(%o5) x(x(x(f)))   <--- OK

I'll allow somebody else to explain this.

Barton