Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

(* I a *)


(* -a *)


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

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

share|improve this question
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
up vote 2 down vote accepted

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


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:

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


-I a
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.