rem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

rem

Charles E. Suprin
Hello,

This is a simple question.  rem in octave claims to not do imaginary
numbers.  It commnets that the matlab one is a bunch of hooey.
However the complex nature is used in the unwrap function.  Has anyone
implemented a matlab compatible rem function.

Charles Suprin
---
... My name is Ozymandias, king of kings.
Look on my works, ye Mighty, and despair. ...
                        "Ozymandias"
                        P.B. Shelly


Reply | Threaded
Open this post in threaded view
|

rem

John W. Eaton-6
On 19-Nov-1997, Charles E. Suprin <[hidden email]> wrote:

| This is a simple question.  rem in octave claims to not do imaginary
| numbers.  It commnets that the matlab one is a bunch of hooey.
| However the complex nature is used in the unwrap function.  Has anyone
| implemented a matlab compatible rem function.

What is rem supposed to do for complex numbers?  Can someone point me
to a textbook definition?

Matlab 4.2 provides what I think are some strange results:

  >> rem (1,i)
  ans =
     NaN

  >> rem (i, 1)
  ans =
       0

  >> rem (i, 2)
  ans =
       0

  >> rem (55+37i, 3+4i)
  ans =
       1


Note that these results are not the same as x - fix(x./y).*y (what the
help text suggests is used for computing rem(x,y) and which I don't
think would be correct for complex numbers anyway).  Instead, it
appears that Matlab's rem function is discarding the imaginary parts
of its arguments.  If that's the result you want, why not simply code
it explicitly?

Thanks,

jwe


Reply | Threaded
Open this post in threaded view
|

RE: rem

Ted.Harding
On 21-Nov-97 John W. Eaton wrote:
> On 19-Nov-1997, Charles E. Suprin <[hidden email]> wrote:
>| This is a simple question.  rem in octave claims to not do imaginary
>| numbers.  It commnets that the matlab one is a bunch of hooey.
>| However the complex nature is used in the unwrap function.  Has anyone
>| implemented a matlab compatible rem function.
>
> What is rem supposed to do for complex numbers?  Can someone point me
> to a textbook definition?

I don't know of one. I doubt there's a meaningful one that treats real and
complex parts on the same footing and is closely analgous to the case for
reals. If anyone knows better it would be interesting to hear of it.

For example, if you use the "fix" definition (rounding each of real &
imaginary towards 0), then

A:   (2 + 3*i) = (2 + 0*i)*(1 + 1*i) + (0 + 1*i)

so   rem(2 + 3*i, 1 + 1*i) = (0 + 1*i)

But you can also write

B:   (2 + 3*i) = (2 + 1*i)*(1 + 1*i) + (1 + 0*i)

and (independently of "fix" considerations) why prefer (A) to (B)?

There are various ways to approach the concept of remainder for reals. One
is

      y = m*k + r    [ r == rem(y.k) ] where m = integer_part(y/k)

where 0 <= |r| < |k| and r has the same sign as y. This is the same as the
"fix" definition, for reals.

Another is

      y = m*k + r    [ r == rem(y,k) ] where m = floor(y/k)

and in this case 0 <= r < |k|.

If you think of generalising these to the complex numbers, then the fact
that the complex numbers are not ordered removes the determinism of the
reals.

For instance, in the above example, if you choose to carry over the
definition of m then both "fix" and "floor" give case (A). Again, a
condition 0 <= |r| < |k| gives you either (A) or (B). Further, a condition
that m is the number (with integer real & imag parts) of largest complex
modulus such that y = m*k + r with the condition 0 <= |r| < |k| gives case
(B) rather than (A). You cannot have anything like "r has the same sign as
k" for complex numbers.

So I guess what definition you choose for "rem" in the complex case depends
on what properties you want it to have, and there's nothing that strikes me
as so uniquely desirable that it fixes an obvious choice for the definition.

Maybe if you can think of a genuine use for "rem" in the complex case then
you already have a reason (whatever it is) for choosing a particular
definition. But is this unique?

What do others think?

Ted.

--------------------------------------------------------------------
E-Mail: Ted Harding <[hidden email]>
Date: 22-Nov-97                                       Time: 01:34:52
--------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: rem

Raymond E. Rogers-2
The Gaussian integers comprise an Euclidean ring; meaning that, the
remainder exists and they have unique factorization.   This requires
using
u x u* as the norm.  If they are appropriate I could generate an
algorithm.
        I haven't done the complete analysis to see if they meet Ted's
concerns.  I will if there is interest.

Enjoy
Ray



Ted Harding wrote:
>
...snip..snip
> I don't know of one. I doubt there's a meaningful one that treats real and
> complex parts on the same footing and is closely analgous to the case for
> reals. If anyone knows better it would be interesting to hear of it.
>
..snip...snip
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: Ted Harding <[hidden email]>
> Date: 22-Nov-97                                       Time: 01:34:52
> --------------------------------------------------------------------