11
$\begingroup$

How are Mod and Quotient defined for three real/complex arguments? I wasn't able to find the definition.

My main surprise so far when investigating their behavior is a discontinuity between real and complex arguments. For real x, Mod[x,1,0] gives a result between 0 and 1. As soon as one adds a small imaginary part, the result's real part is now between -1/2 and 1/2.

Plot[Re[Mod[x, 1, 0]], {x, -1, 1}]

Plot of Mod[x,1,0] for real x

Plot[Re[Mod[x+.001I, 1, 0]], {x, -1, 1}]    (* or (x-.001I) *)

Plot of Re@Mod[x+.001I,1,0] for real x

$\endgroup$
10
$\begingroup$

I can't find any confirmations in the documentation, but through numerical and visual checks I think when at least one input to Mod is not real, we have

enter image description here

This definition doesn't equal the definition one would think to have over the reals, so my guess is a piecewise definition is used to modify the function over the real line.

Testing

mod[z_, n_, d_] := z - n (Round[Re[(z - d)/n]] + I Round[Im[(z - d)/n]])

Numerical check

rand = RandomComplex[{-10-10I, 10+10I}, {1000, 3}];

(mod @@@ rand) == (Mod @@@ rand)
True

Visual check

Plot the argument in the complex plane of mod and Mod:

With[{z = x + I y, n = 1 + I/2, d = 0.1 + 0.2 I},
  DensityPlot[
    Arg[#[z, n, d]], 
    {x, -Re[n], Re[n]}, {y, -Re[n], Re[n]}, 
    ColorFunction -> Hue, 
    Exclusions -> None, 
    PlotPoints -> 100
  ] & /@ {mod, Mod}
]

enter image description here

Plot the absolute value of both in the complex plane:

With[{z = x + I y, n = 1 + I/2, d = 0.1 + 0.2 I},
  Plot3D[
    Abs[#[z, n, d]], 
    {x, -Re[n], Re[n]}, {y, -Re[n], Re[n]}, 
    Exclusions -> None, 
    PlotPoints -> 100
  ] & /@ {mod, Mod}
]

enter image description here

$\endgroup$
  • $\begingroup$ Isn't it supposed to be Floor[] and not Round[]? $\endgroup$ – J. M. is in limbo May 5 '16 at 13:43
  • $\begingroup$ I thought so too but for d == 0, Round has cuts as a box centered at z == 0 rather than having cuts on the real line like Floor would leave. So maybe that's why it's chosen? $\endgroup$ – Chip Hurst May 5 '16 at 13:46

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.