How can I represent this automorphism of Q(i,a)?

Let $a$ represent some real irrational number. I am trying to perform computations with an automorphism $f:\mathbb{Q}(i,a)\to\mathbb{Q}(i,a)$ which fixes $\mathbb{Q}(i)$ pointwise and maps $a$ to $i a$.

What's the best way to represent $f$?

My approach below didn't work, since f@f performs a replacement on the symbol f:

f[x_] := x /. a -> I a
f[a]

(* I a *)

f@f[a]

(* -a *)

(f@f)[a]

(* I a (* Not the same as f@f[a] ?! *) *)


What's the best way to define f so that this does not happen?

-
Look at result of f@f. MM is doing exactly what you ask it to. – ciao Apr 21 '14 at 21:00
Thanks, I see now. How can I represent my automorphism f? – tba Apr 21 '14 at 21:04
What is $\mathbb Q(i,a)$? – celtschk Apr 21 '14 at 22:00
The smallest field containing the rationals, i, and a. We can think of an element of $\mathbb{Q}(i,a)$ as a complex polynomial in a. – tba Apr 21 '14 at 23:47

You can define f to operate on f however you would like:

ClearAll[f]

f@f := f@f@# &;

f[x_] := x /. a -> I a

{f[a], f@f[a], (f@f)[a]}

{I a, -a, -a}


However if you expect this to extend to e.g. (f@f@f)[a] you may want something like:

ClearAll[f]
f[f] = Superscript[f, 2];
f[Superscript[f, n_]] := Superscript[f, n + 1]
Superscript[f, n_][x_] := Nest[f, x, n]
f[x_] := x /. a -> I a


Now:

(f@f@f)[a]

-I a

-
One can also use \[CircleDot] = Composition for example. – Kuba Jul 9 '14 at 7:10
@Kuba I'm afraid I don't understand what you're implying; could you give an example? Also, at least in v7, \[CircleDot] = Composition is not valid syntax, but I assume you meant CircleDot = Composition. – Mr.Wizard Jul 9 '14 at 7:32
Oh, yes, I don't know why I've written this :) ofc CircleDot :) – Kuba Jul 9 '14 at 7:34