# Can I implement a constant in such a way that every function of it gets redirected?

Basically, I want to implement split-complex numbers and tessarines.

They can be easily implemented as 2x2 matrices with complex elements.

But I want them to work in general expressions.

So I want a constant J such that ANY function on this constant be redirected into MatrixFunction on matrix $$\left( \begin{array}{cc} 0 & 1 \\ 1 & 0 \\ \end{array} \right)$$ And after calculations the matrices of the form $$\left( \begin{array}{cc} a & b \\ b & a \\ \end{array} \right)$$ converted back to numbers a + b J.

Is it possible? I do not want to re-define operations on J, but want all the operations to be calculated using the matrix form but so that this would be hidden from the user.

• Have you heard of UpValues? For the most part those should work Mar 11, 2021 at 20:55
• @b3m2a1 I already found an answer, see below: mathematica.stackexchange.com/a/241582/651 Mar 11, 2021 at 20:57
• I understand that, but overloading $Pre can be dangerous if you forget about it or if someone else is trying to use your code. UpValues are much kinder/safer in that regard Mar 11, 2021 at 20:58 • @b3m2a1 I do not know how to do similar things with UpValues. If you know, I welcome other answers. Mar 11, 2021 at 21:00 • Note that the result of MatrixFunction[f, {{a, b}, {b, a}}][[1]] . {1, J} shows a way to interpret the result of applying an arbitrary function to a split-complex number. Dec 12, 2021 at 13:38 ## 2 Answers I do not know if the following works for all functions, but it may be a start. We may check every input if it contains J, using $Pre. If not, we proceed as usual. If yes, we replace every functions, containing J as an argument by MatrixFunction acting on this function. Then we evaluate and replace the matrix again by the form: a + b J:

ClearAll[J];
$Pre = If[FreeQ[#, J], #, Module[{tmp}, tmp = Evaluate[# /. f_[x1___, J, x2___] :> MatrixFunction[f[x1, #, x2] &, {{0, 1}, {1, 0}}]]; tmp /. {{a_, b_}, {b_, a_}} -> a + J b]] &;  • When I try Log[J + 5] it gives Log[5]. And Log[I J] gives - Infinity (should be$ij\pi/2$). Mar 11, 2021 at 13:10 • Exp[2J], Exp[2+J] etc also gives wrong results... Mar 11, 2021 at 13:56 • Log[I J] is actuall Log[Times[I,J]] what boils down to Log[MatrixFunction[I #1 &, {{0, 1}, {1, 0}}]] what gives {{-Infinity,..},{..}}, certainly not what to expect. Therefore I think the idea with MatrixFunction is too complicated for the general case. Mar 11, 2021 at 14:51 • I think a better idea would be to implement explicit replacement rules for the symbol J Mar 11, 2021 at 15:20 • Log also should be converted to MatrixFunction. Otherwise it is applied per each element separately. Mar 11, 2021 at 16:24 The following code based on the code by Daniel Huber seems to work: $Pre = If[FreeQ[#, J], #, Module[{tmp},

tmp = Evaluate[MatrixFunction[Function[J, #], {{0, 1}, {1, 0}}]];
tmp /. {{a_, b_}, {b_, a_}} -> a + J b]] &;

Gamma[J + 3]

7/2 + (5 J)/2


P.S. This code is even simpler, but less universal (works with split-complex numbers but not with other hypercomplexes):

\$Pre = (# /. J -> {-1, 1}) /. {x_, y_} -> (x + y)/2 + (J (y - x))/2 &;

• PLeased to hear this. Have fun. Mar 11, 2021 at 20:40