# Modulus (Modulo?) of TWO fractions. on
I have two fractions I want to find the "MOD" between them. Is the answer another fraction?

I chose: Since integer mod is sort of the opposite of integer division. I found the mod of the first fractions numerator and denominator and arbitrarily assigned it as the numerator of the new fraction The same for the second fraction and assigned to the denominator of the new fraction.

Both fractions have already been through euclid's algorithm and are in GCD form.

I have seen many trying to explain it in the terms of ax + by = d or something like that. What are the variables as they relate to the fractions. Is this even the correct direction?
Comment
Watch Question

Do more with EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
It may be my shortcoming, but I don't ever recall modulo being discussed in terms of fractions.  Nonetheless, it seems that the same principle should apply as with integers.  If you want to know a MOD b, and the remainder is the MOD.

If they are in GCD form, it seems that the MOD should be the MOD of the numerators, then divided by the denominator.  That is:

(a/x) MOD (b/x) = (a MOD b)/x

Keep in mind that this is my take on the matter,withouto a proper reference to back it up.
Fixer of Problems
Most Valuable Expert 2014
Commented:
I agree with @CompProbSolv.  As long as you handle it as integer fractions with a GCD, it could work.  The Wikipedia article http://en.wikipedia.org/wiki/Modulo_operation points out that anything other than positive integers may not be predictable in some computer languages.
Most Valuable Expert 2014
Top Expert 2015

Commented:
z mod y      = z-y*floor(z/y)
(a/b) mod (c/d) = (a/b) - (c/d)*floor((a/b) / (c/d))
A Mod B is classically defined for integers. If you are wishing it for non standard arguments then the question you ask yourself.

What am I using this number for?
How does my extended definition fulfill that function?
Is the definition  consistent with that for integer arguments?

In short there is no one way of defining this number.
Most Valuable Expert 2014
Top Expert 2015

Commented:
see Section 3.4, of "Concrete Mathematics," by Graham, Knuth, and Patashnik.
..the definition is cast in stone?  ( or concrete? :)
Most Valuable Expert 2014
Top Expert 2015

Commented:
there is no one way of defining
A Mod B even for integers, especially when you consider computer implementations, but I would argue that the most sensible definition is the one espoused by Graham, Knuth, and Patashnik.
Fixer of Problems
Most Valuable Expert 2014

Commented:
From http://www.php.net/manual/en/language.operators.arithmetic.php
Operands of modulus are converted to integers (by stripping the decimal part) before processing.

And from http://msdn.microsoft.com/en-us/library/basszbdt%28v=vs.84%29.aspx
If number1 or number2 are floating point numbers, they are first rounded to integers.

At least in Firefox, javascript will accept entries with decimal fractions.

Commented:
I think I see the problem. When I say GCD I actually mean "normalized" part of which uses euclid's. So 2/4 becomes 1/2. I can still have 2 "normalized: fractions that I need to MOD.

1/2 MOD 1/3 if I apply the formula you have shown requires 3 and 2 to be equal which they are not. But if I take 2 * 3 = 6 (regardless if it is lcf (lcd)) then 3 * 1 = 3 so I now have 3/6 and then take 2 * 1 = 2/6 NOW I can use (3 MOD 2)/6 1/6 is the fraction? I then normalize the new fraction and that's my answer. So formula wise:

a/x MOD b/y  = c/z
z = x * y
a = y * a
b = x * b
c = a mod b
normalize ( c , z )

That sound right?
Most Valuable Expert 2014
Top Expert 2015
Commented:
a/x MOD b/y  = a/x - (b/y)*floor( (a/x)/(b/y) )
=  a/x - (b/y)*floor((y*a)/(x*b))
= ((y*a)/(x*y) - (x*b)/(x*y)*floor((y*a)/(x*b))
= (y*a - x*b*floor((y*a)/(x*b)))/(x*y)
= (y*a MOD x*b) / (x*y)

so, yes.
Ozo's last comment hits the mark.

One can consider a MOD operation as choosing a member of a field. In a MOD b, b is a number of elements, ie: the field, and we start with the first field member and count "a" elements going around in a ring, thus picking out on element in b.

In the case of fractions, b/y has to represent a field of elements. Since a/x is going to be the maximum value for the counter, the question arises as to what is the value of one element. That must be 1/xy, since xy is a number which both x and y divide. Thus again one counts a elements in the field b/y of elements of value 1/xy in a ring.

Commented:
And.... to simplify ozo's comment when the fractions are in GCD form:
since x=y, (a/x) MOD (b/x) = (a MOD b)/x

Commented:
Ozo,

I appreciate how succint this is:  (y*a MOD x*b) / (x*y) but for order of operations * and
MOD (%) are on the same order should it be  (y*a) MOD( x*b) / (x*y) ?
Most Valuable Expert 2014
Top Expert 2015

Commented:
in C++, yes

Do more with 