In cosmology, it is common to work with both a normal time variable t and a “conformal” time variable τ, which is defined such that dt = a(t) dτ. In other words, d/dτ = a(t) d/dt.

I have a bunch of expressions in conformal time that I want to convert to cosmic time. Right now, I am applying a bunch of explicit rules like this:

expressions /. {
    f[τ] -> f[t],
    f'[τ] -> a[t] f'[t],
    f''[τ] -> a[t] a'[t] f'[t] + a[t]^2 f''[t],
    g[τ] -> g[t],
    g'[τ] -> a[t] g'[t],
    g''[τ] -> a[t] a'[t] g'[t] + a[t]^2 g''[t],

Is there a simpler approach that (a) doesn't require me to perform the chain rule myself to work out the higher derivatives, and (b) doesn't require me to list separate rules for f, g, and all the other relevant symbols?


I think the best way to do this is to use Derivative:

rules = {func_[τ] /; MemberQ[{f, g, h}, func] :> func[t],
         Derivative[n_][func_][τ] /; MemberQ[{f, g, h}, func] :> D[func[t[τ]], {τ, n}], 
         Derivative[n_][t][τ] :> D[a[t[τ]], {τ, n - 1}]}

The first rule is needed to replace functions of τ with functions of t. The next two rules tells Mathematica to take derivatives of the specific functions f[τ], g[τ] and h[τ].

The result will contain a bunch of f[t[τ]] and g[t[τ] etc. So apply a finishing rule to remove the explicit dependence of t on τ:

finishingRule = {Derivative[n_][f_][t[τ]] :> Derivative[n][f][t], 
                 f_[t[τ]] :> f[t]}

Let's try it out:

 f[τ] + r[τ] - f'[τ] + g''[τ] //. rules /. finishingRule

f[t] + r[τ] − a[t] f'[t] + a[t] a'[t] g'[t] + a[t]^2 g''[t]

  • $\begingroup$ Thank you. I see you have set up the rule to match any function of τ except t, which is probably what I want. But is there any way to explicitly match a specific list of functions {f, g, h} instead? $\endgroup$ – thecommexokid Dec 15 '14 at 20:11
  • $\begingroup$ And more importantly, this solution nicely replaces f'[τ] or f''[τ] but does not make the necessary replacement to f[τ]. $\endgroup$ – thecommexokid Dec 15 '14 at 20:25
  • 1
    $\begingroup$ @thecommexokid I have modified the rules so that f[τ] correctly gets replaced to f[t], and changed the condition so that it looks only for {f, g, h}. $\endgroup$ – QuantumDot Dec 15 '14 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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