3

Consider two irreducible fractions:

$r_1 = \frac{p_1}{q_1}$

$r_2 = \frac{p_2}{q_2}$

with $r_1 \ge 0$ and $r_2 \ge 0$.

How the modulo $\%$ is defined over rational numbers (I think that is $r_3$ such that $r_1 = r_2 \times n + r_3$ with $n$ a positive integer but I am not sure of that), and how to compute the numerator $p_3$ and the denominator $q_3$ from $p_1, q_1, p_2, q_2$ and using only the following operations on integers: $+, -, \times, /, \%, \text{gcd}(), \text{lcm}()$ ?

Vincent
  • 1,425
  • It is that the result of division $c$ and remainder $r$ satiate $q \in \mathbb{Z}$, $a = n \times c + r$, where $|r| < |n|$. http://lmgtfy.com/?q=modulo – cygorx Dec 29 '13 at 04:21
  • 1
    From my standpoint, this seems unusual and unorthodox enough that I’d recommend that the individual writer make her/his own definitions. Do you have a use for this? – Lubin Dec 29 '13 at 04:31
  • See here for gcd and lcm on rationals. @Lubin too – Bill Dubuque Dec 29 '13 at 04:35
  • @BillDubuque, I say, Ah, but gdc and lcm are purely multiplicative gadgets, living in the free $\mathbb Z$-module with basis the primes. No addition involved whatsoever. – Lubin Dec 29 '13 at 04:40
  • @Lubin, I have found working with rationals modulo an integer useful when solving linear congruences. – user44197 Dec 29 '13 at 04:41
  • @user44197 Yes, one can use fractions in modular arithmetic, as long as the denominator is coprime to the modulus (I do that in many of my posts here). But that is different than extending divisibility theory to fractions. – Bill Dubuque Dec 29 '13 at 04:50
  • @user44197, yes, but I think that OP is interested in working modulo integral multiples of a nonintegral rational. I still think that anyone wishing to do so must do his own work of making the definition and notation explicit. – Lubin Dec 29 '13 at 21:27

1 Answers1

2

If you don't impose any condition on $n$ then clearly $$r_3 = r_1 - n r_2$$ is a solution as $n$ goes over all the integers. If you want the one that minimizes $r_3$ then choose $$ n = \left\lfloor \frac{r_1}{r_2}\right\rfloor$$ If you want the smallest $r_3$ in magnitude then round the ratio instead of flooring it, i.e $$ n = \left\lfloor \frac{r_1}{r_2} + \frac{1}{2}\right\rfloor$$

If you program in C/C++ and similar programming language, the code would be

n = (p1 * q2)/(p2*q1); // Using floor
n = (p1 * q2 + ((p2*q1) >> 1)/(p2*q1); // Using rounding
user44197
  • 9,730