# Delay operator and Apply used when for applying function of a function

I define my own function like that:

DelayL1t[(q_: 1) a_[t_]] := q Apply[a, {t - L1[t]/c}]
DelayL2t[(q_: 1) a_[t_]] := q Apply[a, {t - L2[t]/c}]


if I just do :

DelayL1t[p2[t]]


I get

p2[t - L1[t]/c]


that is correct, but if I do:

DelayL2t[DelayL1t[p2[t]]]


I get

p2[t - L1[t]/c - L2[t - L1[t]/c]/c]


while I was expecting to obtain:

p2[t - L1[t - L2[t]/c]/c - L2[t]/c]


Does anyone know what I am doing wrong? p2[t - L2[t - L2p[t]/c]/c - L2p[t]/c -L3[t - L2[t - L2p[t]/c]/c - L2p[t]/c]/c]

I would like to do a series expansion around L_[i,k]/c or L_[i,k]*L[k,i]/c^2 in order to get rid off all the terms where an arm depends on another arms..I was able to do that manually [ I attached my code] does anyone know how to built a function that does it ? It would be nice to have a sort of operator which does series expansion around certain terms! thanks in advance!

so once I got the correct time delayed :

p2[t - L2[t - L2p[t]/c]/c - L2p[t]/c -
L3[t - L2[t - L2p[t]/c]/c - L2p[t]/c]/c]


I did the expansion around L2p[t]/c:

ExpandAll[p2[t - (Normal[Series[L2[t - L2p[t]/c] /.L2p[t]/c ->
λL2p[t]/c, {λ, 0,1}]] /. λ -> 1)/c
- L2p[t]/c - L3[t - (Normal[Series[L2[t - L2p[t]/c] /.L2p[t]/c ->
λ L2p[t]/c, {λ, 0, 1}]] /. λ -> 1)/c - L2p[t]/c]/c]]


and I got:

     p2[t - L2[t]/c - L2p[t]/c -L3[t - L2[t]/c - L2p[t]/c
+ (L2p[t] Derivative[L2][t])/c^2]/c +
(L2p[t] Derivative[L2][t])/c^2]


then I did the expansion around

 {L2[t]/c -> λ L2[t]/c,
L2p[t]/c -> λ L2p[t]/c, (L2p[t] Derivative[L2][t])/
c^2 -> λ (L2p[t] Derivative[L2][t])/c^2}


that is:

    ExpandAll[p2[t - L2[t]/c - L2p[t]/c -
1/c(Normal[Series[L3[t - L2[t]/c - L2p[t]/c
+ (L2p[t] Derivative[L2][t])/c^2]/.{L2[t]/c -> λ L2[t]/c, L2p[t]/c ->
λ L2p[t]/c, (L2p[t] Derivative[L2][t])/c^2 ->
λ(L2p[t] Derivative[L2][t])/c^2}, {λ, 0, 1}]]
/.λ -> 1 ) +(L2p[t] Derivative[L2][t])/c^2]] /. 1/c^3 -> 0


and I get:

  p2[t - L2[t]/c - L2p[t]/c - L3[t]/c
+ (L2p[t] Derivative[L2][t])/c^2
+ (L2[t] Derivative[L3][t])/c^2 +
(L2p[t] Derivative[L3][t])/c^2]


I did the final expansion around

{(L2p[t] Derivative[L2][t])/
c^2 -> λ (L2p[t] Derivative[L2][t])/c^2, (
L2[t] Derivative[L3][t])/
c^2 -> λ (L2[t] Derivative[L3][t])/c^2, (
L2p[t] Derivative[L3][t])/
c^2 -> λ (L2p[t] Derivative[L3][t])/c^2}:

ExpandAll[
Normal[Series[
p2[t - L2[t]/c - L2p[t]/c - L3[t]/c + (
L2p[t] Derivative[L2][t])/c^2 + (
L2[t] Derivative[L3][t])/c^2 + (
L2p[t] Derivative[L3][t])/c^2] /. {(
L2p[t] Derivative[L2][t])/
c^2 -> λ (L2p[t] Derivative[L2][t])/c^2, (
L2[t] Derivative[L3][t])/
c^2 -> λ (L2[t] Derivative[L3][t])/c^2, (
L2p[t] Derivative[L3][t])/
c^2 -> λ (L2p[t] Derivative[L3][t])/
c^2}, {λ, 0, 1}]] /. λ -> 1 /. 1/c^3 -> 0]


and finally I got an expression where all the arm-length terms (L2[t],L3[t] and L2p[t]) do not depends anymore on other arms:

p2[t - L2[t]/c - L2p[t]/c - L3[t]/c] + (
L2p[t] Derivative[L2][t] Derivative[p2][
t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + (
L2[t] Derivative[L3][t] Derivative[p2][
t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + (
L2p[t] Derivative[L3][t] Derivative[p2][
t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2


Hey you are right! since it is difficult to explain my intention I upload an immages that show what i need to do! as you can see you where able to help me with the time delay..i was wondering if you are able to do a function that does the series expansion how it is shown.

thank you very much for your kindness  • You get what you expect if you flip the two function applications, i.e. DelayL1t[DelayL2t[p2[t]]]. Why do you expect this in your case? As far as I can tell, everything works as expected. Aug 1, 2018 at 22:07
• hey lukas first of all thanks! But follow me: if I do DelayL1t[p2[t]] and I get p2[t - L1[t]/c] that is totally correct, when I apply another delay of L2[t]/c to my results : DelayL2t[DelayL1t[p2[t]]] I should have that all the things that were depending on time should be delated by L2[t]/c p2[t-L2[t]/c- L1[t-L2[t]/c]/c] ,instead it flips the index and the delays cannot commute!! I need before to do the delay of L1[t] and that delay has to be delayed again by L2[t]. Aug 2, 2018 at 7:27
• @Martina your edited code is very compact and contains expressions which may or may not be interpreted as misstyped input or something else altogether; eg in the second code block there is \[Lambda]L2p[t]/c which I assume should be \[Lambda] L2p[t]/c but I don't know for sure or what L_[i,k]*L[k,i] is supposed to stand for; also in you original code there was no L3 term; I included such a term in my answer to show that it could be extended to such uses if needed; please provide a clear instance of your problem as contained as possible eg if the L3 term is superfluous don't use it Aug 13, 2018 at 19:37
• OK! I put an immage on my answer to help you understand! after having done the time delay I need to do a taylor expansion around Lk[t]/c for Lj[t-Lk[t]/c]/c and then (1/c [Lk[t]+Lj[t]] + 1/c^2 dot[Lj[t]] Lk[t] for f(t-1/c (Lk[t]+Lj[t])+1/c^2 dot[Lj[t]] Lk[t] ) in order to get the last results.... the only different from the picture is that for me Lk[t] ,Lj[t] depends on time even if in the picture they don't Aug 13, 2018 at 20:07
• @Martina I cannot reproduce anything off of a screen-grab (eg the first line of code is wrong; delayBy does not work like that; additionally, in order to get the first approximation described in the excerpt you amended your question with, you should use delaybyApprox not delayBy ); please don't use screen-shots unless absolutely necessary; please identify which function-with what input-did not produce the desired output and what that desired output was, in the first place. Aug 15, 2018 at 11:58

DelayL2t[(q_: 1) a_[t_]] := q Apply[a, {t - L2[t]/c}]


the pattern t_ stands not for time but to the whole argument of the input expression. For example, consider the following code:

ClearAll[f];
f[a_[t_]] := {a, t};
f[p2[t - L1[t]/c]]
(*Returns {p2, t - L1[t]/c}*)


Therefore, when

DelayL2t[p2[t - L1[t]/c]]


is evaluated, the kernel takes the whole construct t - L1[t]/c and substitutes it for t in rhs of your definition

q Apply[a, {t - L2[t]/c}]


leading to the result you obtained. If you want to define a function that will delay symbol t rather than the argument as a whole, then you should use ReplaceAll:

ClearAll[delayBy];
delayBy[expr_, l_] := expr /. t -> t - l[t]/c;
delayBy[delayBy[p2[t], l1], l2]
(*Returns p2[t - l1[t - l2[t]/c]/c - l2[t]/c]*)

• thank you so much! Do you know how to do a series expansion around L[t]/c to get rid off expr like: p2[t - L2[t - L2p[t]/c]/c - L2p[t]/c - L3[t - L2[t - L2p[t]/c]/c - L2p[t]/c]/c], I did : p2[t - (Normal[Series[L2[t - L2p[t]/c] /. L2p[t]/c -> [Lambda] L2p[t]/c, {[Lambda], 0, 1}]] /. [Lambda] -> 1)/c - L2p[t]/c - L3[t - (Normal[Series[L2[t -L2p[t]/c] /. L2p[t]/c -> [Lambda] L2p[t]/c, {[Lambda], 0, 1}]] /. [Lambda] -> 1)/c - L2p[t]/c]/c]] Aug 13, 2018 at 8:10
• and I get: p2[t - L2[t]/c - L2p[t]/c -L3[t - L2[t]/c - L2p[t]/c + (L2p[t] Derivative[L2][t])/c^2]/c + (L2p[t] Derivative[L2][t])/c^2] with another expansion I get: p2[t - L2[t]/c - L2p[t]/c - 1/c (Normal[Series[L3[t - L2[t]/c - L2p[t]/c + (L2p[t] Derivative[L2][t])/c^2] /.{L2[t]/c -> [Lambda] L2[t]/c, L2p[t]/c -> [Lambda] L2p[t]/c, (L2p[t] Derivative[L2][t])/c^2 -> [Lambda] (L2p[t] Derivative[L2][t])/c^2}, {[Lambda], 0, 1}]] /. [Lambda] -> 1 ) + (L2p[t] Derivative[L2][t])/c^2] /.1/c^3 -> 0 Aug 13, 2018 at 8:12
• and I get: p2[t - L2[t]/c - L2p[t]/c - L3[t]/c + (L2p[t] Derivative[L2][t])/c^2 + (L2[t] Derivative[L3][t])/c^2 + (L2p[t] Derivative[L3][t])/c^2], Aug 13, 2018 at 8:14
• then I do another expansion: Normal[Series[p2[t - L2[t]/c - L2p[t]/c - L3[t]/c + (L2p[t] Derivative[L2][t])/c^2 +(L2[t] Derivative[L3][t])/c^2 + ( L2p[t] Derivative[L3][t])/c^2] /. {( L2p[t] Derivative[L2][t])/c^2 -> [Lambda] (L2p[t] Derivative[L2][t])/c^2, ( L2[t] Derivative[L3][t])/c^2 -> [Lambda] (L2[t] Derivative[L3][t])/c^2, (L2p[t] Derivative[L3][t])/c^2 -> [Lambda] (L2p[t] Derivative[L3][t])/c^2}, {[Lambda], 0, 1}]] /.[Lambda] -> 1 /.1/c^3 -> 0] Aug 13, 2018 at 8:16
• and this is the final results: p2[t - L2[t]/c - L2p[t]/c - L3[t]/c] + (L2p[t] Derivative[L2][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + (L2[t] Derivative[L3][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + ( L2p[t] Derivative[L3][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 Aug 13, 2018 at 8:20

I am not sure I understand how your implementation of 'delaying' something works but in order to achieve your desired output you can use the following delayBy function.

It receives as input a function (expression) to delay and a list of functions that will be used in the implementation of sequential delay of the supplied function (eg providing {L1[t],L2[t]} as an argument will delay the function first by using L1 and subsequently by using L2 on the delayed expression from the former iteration). There are also additional input parameters with default values informed by the details in the question

(* main function *)
auxDelayBy[func_, byfuncs_, var_, q_, const_] := Fold[
With[{h = Head[#1], args = Apply[List, #1], df = #2},
q Apply[h, (args /. var -> var - df/const)]] &, func, byfuncs]

(* interface function - this is what the user calls *)
delayBy[func_, byfuncs_, var_: t, q_: 1, const_: c] := Which[
ListQ[byfuncs] && Length[byfuncs] > 1, auxDelayBy[func, byfuncs, var, q, const],
True, auxDelayBy[func, {byfuncs}, var, q, const]]


Evaluating delayBy[p2[t], L1[t]] returns

p2[t - L1[t]/c]


while evaluating delayBy[p2[t], {L1[t], L2[t]}] returns

p2[t - L1[t - L2[t]/c]/c - L2[t]/c]


Now, assuming that evaluating something like delayBy[p2[t], {L1[t], L2[t], L3[t]}] is desirable and it makes sense in the context of the question delayBy can accomodate such a request with the following output:

p2[t - L1[t - L2[t - L3[t]/c]/c - L3[t]/c]/c - L2[t - L3[t]/c]/c - L3[t]/c]


(below this line is the answer to the extended question)

The code below reproduces the results for the first Taylor approximation; the second approximation is relatively trivial and is left for future implementations.

I will provide a code block that is similar but not identical to the previous implementation:

delayByApprox[func_, funcs_, var_: t, const_: c, mult_: 1] :=
Module[{rabbit, thread, counter = 0, x = Last[funcs][var], y = Last[Most[funcs]], rl},

(* used to implement the cancelation feature - see notes *)
rl = -y[var - x/const]/const - x/const -> 0;

rabbit[f_, df_, v_, c_, q_] := q f[v - thread[df[v]/c, counter++]];

(* provides the required Taylor expansion *)

(* fold *)
Fold[
rabbit[Head[#1], #2, Apply[Sequence][#1], c, mult] &,
func[var], Reverse[funcs]] //. rl
]


Similarly to the previous implementation, evaluating delayByApprox[p2, {L1, L2, L3}]

will return

p2[t + (L2[t] Derivative[L1][t - L2[t]/c])/c^2]


and (to the extent it makes sense) evaluating delayByApprox[p2, {L1, L2, L3}] returns

p2[t - L1[t + (L3[t] Derivative[L2][t - L3[t]/c])/c^2]/c + (L3[t] Derivative[L2][t - L3[t]/c])/c^2 - (L3[t] Derivative[L1][t + (L3[t] Derivative[L2][t - L3[t]/c])/c^2] (-(1/c) + (2 Derivative[L2][t - L3[t]/c])/c^2 - (L3[t] (L2^\[Prime]\[Prime])[t - L3[t]/c])/c^3))/c]


I hope that helps!

• thank you so much! Do you know how to do a series expansion around L[t]/c to get rid off expr like: p2[t - L2[t - L2p[t]/c]/c - L2p[t]/c - L3[t - L2[t - L2p[t]/c]/c - L2p[t]/c]/c], I did : p2[t - (Normal[Series[L2[t - L2p[t]/c] /. L2p[t]/c -> [Lambda] L2p[t]/c, {[Lambda], 0, 1}]] /. [Lambda] -> 1)/c - L2p[t]/c - L3[t - (Normal[Series[L2[t -L2p[t]/c] /. L2p[t]/c -> [Lambda] L2p[t]/c, {[Lambda], 0, 1}]] /. [Lambda] -> 1)/c - L2p[t]/c]/c]] Aug 13, 2018 at 8:33
• and I get: p2[t - L2[t]/c - L2p[t]/c -L3[t - L2[t]/c - L2p[t]/c + (L2p[t] Derivative[L2][t])/c^2]/c + (L2p[t] Derivative[L2][t])/c^2] with another expansion I get: p2[t - L2[t]/c - L2p[t]/c - 1/c (Normal[Series[L3[t - L2[t]/c - L2p[t]/c + (L2p[t] Derivative[L2][t])/c^2] /.{L2[t]/c -> [Lambda] L2[t]/c, L2p[t]/c -> [Lambda] L2p[t]/c, (L2p[t] Derivative[L2][t])/c^2 -> [Lambda] (L2p[t] Derivative[L2][t])/c^2}, {[Lambda], 0, 1}]] /. [Lambda] -> 1 ) + (L2p[t] Derivative[L2][t])/c^2] /.1/c^3 -> 0 Aug 13, 2018 at 8:33
• and I get: p2[t - L2[t]/c - L2p[t]/c - L3[t]/c + (L2p[t] Derivative[L2][t])/c^2 + (L2[t] Derivative[L3][t])/c^2 + (L2p[t] Derivative[L3][t])/c^2], Aug 13, 2018 at 8:33
• then I do another expansion: Normal[Series[p2[t - L2[t]/c - L2p[t]/c - L3[t]/c + (L2p[t] Derivative[L2][t])/c^2 +(L2[t] Derivative[L3][t])/c^2 + ( L2p[t] Derivative[L3][t])/c^2] /. {( L2p[t] Derivative[L2][t])/c^2 -> [Lambda] (L2p[t] Derivative[L2][t])/c^2, ( L2[t] Derivative[L3][t])/c^2 -> [Lambda] (L2[t] Derivative[L3][t])/c^2, (L2p[t] Derivative[L3][t])/c^2 -> [Lambda] (L2p[t] Derivative[L3][t])/c^2}, {[Lambda], 0, 1}]] /.[Lambda] -> 1 /.1/c^3 -> 0] Aug 13, 2018 at 8:33
• and this is the final results: p2[t - L2[t]/c - L2p[t]/c - L3[t]/c] + (L2p[t] Derivative[L2][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + (L2[t] Derivative[L3][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 + ( L2p[t] Derivative[L3][t] Derivative[p2][t - L2[t]/c - L2p[t]/c - L3[t]/c])/c^2 Aug 13, 2018 at 8:34