Traditional division of integers with remainder in Wolfram

As is well known, division of integers with remainder can be defined in different ways. The definition in Wolfram and the definition in theoretical mathematics are different. How to express traditional division with remainder in Wolfram? Here is a variant solution:

quotient[m_, n_] := (m - Mod[m, Abs[n]])/n
remainder[m_, n_] := Mod[m, Abs[n]]

Is there anything more elegant?

Thank you! I knew Wolfram had thought of everything.

Have you tried the function QuotientRemainder ?

In[6]:= QuotientRemainder[14, 5]
Out[6]= {2, 4}

A closer look revealed that the functions Quotient[m,n,0], Mod[m,n,0] and QuotientRemainder do not compute the traditional quotient and remainder.

An alternative definition of traditional quotient and remainder via the Floor function could be as follows:

**remainder[m_, n_] := m - Abs[n] Floor[m/Abs[n]];
quotient[m_, n_] := Sign[n] Floor[m/Abs[n]]**

Could you clarify what you find wrong, or non-traditional, with the QuotientRemainder results below

I think you could define your preference like this:

altQuotientRemainder[m_, n_?Negative] := -QuotientRemainder[-m, n];
altQuotientRemainder[m_, n_] := QuotientRemainder[m, n]

In the traditional definition of dividing integers with a remainder, the remainder cannot be negative. This is neither right nor wrong. It is a different definition.

The residuals in your definition may be negative. It shouldn’t be.

Did you actually test it? If you provide an example where the implementation I suggested differs from the implementation you provided, then I can work on a better implementation.

Okay, I understand that this is just a matter of conventions. Just out of curiosity: Do you have any reference to support that positive remainders is the common and established convention?

altQuotientRemainder[m, n] /. {m → 17, n → -5}
{-4, -3}

It should be {-3, 2}

PS
This is weird

altQuotientRemainder[17, -5]
{-3, 2}

Any number theory textbook (not for programmers) defines the traditional division of integers with remainder. For example, Burton, Elementary number theory (2011). This is necessary to determine modulo equivalence. The number of remainders when dividing by n, must be |n|. So it’s strange to me that Wolfram didn’t provide this function.

Restrict inputs to integers. That avoids inadvertent misuse as a symbolic function.

One can use Mod to get a remainder between 0 and n-1. Or a different set of contiguous residue classes if so desired.

As for definitions of quotient and remainder, there are conventions. It isn’t one-size-fits-all.

Well, yeah, you ran the function on symbols which then resolved to the built in QuotientRemainder. Why would you use ReplaceAll like that? But if that’s the way you want to use it, then you can add constraints on the arguments.

Daniel Lichtblau already mentioned that! Thanks! Here’s what you can do Sasha:

altQuotientRemainder[m_Integer, n_Integer?Negative] := -QuotientRemainder[-m, n];
altQuotientRemainder[m_Integer, n_Integer] := QuotientRemainder[m, n]

altQuotientRemainder[m, n] /. {m -> 17, n -> -5}
(* {-3, 2} *)

Also, I should probably clarify that I’m not saying this implementation is “right” in any sense. Either of your other implementations is just fine as far as I’m concerned. You asked for alternatives, and since QuotientRemainder is already built in and gives you almost everything you want, using it seemed like a reasonable alternative.