0
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ Have you heard of UpValues? For the most part those should work $\endgroup$
    – b3m2a1
    Mar 11, 2021 at 20:55
  • $\begingroup$ @b3m2a1 I already found an answer, see below: mathematica.stackexchange.com/a/241582/651 $\endgroup$
    – Anixx
    Mar 11, 2021 at 20:57
  • $\begingroup$ 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 $\endgroup$
    – b3m2a1
    Mar 11, 2021 at 20:58
  • $\begingroup$ @b3m2a1 I do not know how to do similar things with UpValues. If you know, I welcome other answers. $\endgroup$
    – Anixx
    Mar 11, 2021 at 21:00
  • $\begingroup$ 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. $\endgroup$ Dec 12, 2021 at 13:38

2 Answers 2

1
$\begingroup$

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]] &;
$\endgroup$
17
  • $\begingroup$ When I try Log[J + 5] it gives Log[5]. And Log[I J] gives - Infinity (should be $ij\pi/2$). $\endgroup$
    – Anixx
    Mar 11, 2021 at 13:10
  • $\begingroup$ Exp[2J], Exp[2+J] etc also gives wrong results... $\endgroup$
    – Anixx
    Mar 11, 2021 at 13:56
  • $\begingroup$ 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. $\endgroup$ Mar 11, 2021 at 14:51
  • $\begingroup$ I think a better idea would be to implement explicit replacement rules for the symbol J $\endgroup$ Mar 11, 2021 at 15:20
  • $\begingroup$ Log also should be converted to MatrixFunction. Otherwise it is applied per each element separately. $\endgroup$
    – Anixx
    Mar 11, 2021 at 16:24
0
$\begingroup$

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 &;
$\endgroup$
1
  • $\begingroup$ PLeased to hear this. Have fun. $\endgroup$ Mar 11, 2021 at 20:40

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.