# Implementing a function that exhibits linearity

I am trying to define a function $$\mathbb{E}_t$$ such that $$\mathbb{E}_{t}[f[x_{s}]] = f[x_{s}]$$ if s<=t, and $$\mathbb{E}_{t}[f[x_{s}]] = \mathbb{E}_{t}[f[x_{s}]]$$ if s>t. $$\mathbb{E}_{t}$$ is linear such that $$\mathbb{E}_{t}[x_{s}+y_{r}]=\mathbb{E}_{t}[x_{s}]+\mathbb{E}_{t}[y_{r}]$$ and $$\mathbb{E}_{t}[x_{s}*y_{r}]=\mathbb{E}_{t}[x_{s}]*\mathbb{E}_{t}[y_{r}]$$

I tried (f:->x in this definition)

$$\mathbb{E}_{t\_}[x_{s\_}] := If[Refine[t>s,Elment[\{t,s\},Reals]],x_{s},HoldForm[\mathbb{E}_{t}[x_{s}] ]]$$ and $$\mathbb{E}_{t\_}[x\_+y\_]:=\mathbb{E}_{t}[x]+\mathbb{E}_{t}[y]$$ and $$\mathbb{E}_{t}[x\_*y\_]:=\mathbb{E}_{t}[x]*\mathbb{E}_{t}[y]$$

It works for the simple cases. However, it gives

$$\mathbb{E}_{t}[x_{t}^{2}]=\mathbb{E}_{t}[x_{t}^{2}]$$

$$\mathbb{E}_{t}[x_{t}^{2}]=x_{t}^{2}$$.
I suspect the reason is because the head of x*y is not the same as x^2. Is there an easier way to define such a function? I hope $$\mathbb{E}_{t}$$ will work for a more general function f. I used HoldForm so that I do not get an infinite loop.
• Your rule is too ambiguous to work for any f, consider a definition with additional arguments, $\mathbb{E}_{t\_}[expr\_,x\_,s\_]$ for example. – swish Jan 5 at 1:54