Sunday, September 2, 2012

THE RATIONAL NUMBER AS THE SUM OF AN INTEGER AND A PROPER FRACTION

An algorithm is a finite procedure to calculate a function.

We state an algorithm that converts a given rational number into an integer or as the sum of an integer and a proper fraction.

Given a rational number s / t. if t < 0,  we consider -s / -t as the given rational number. Hence, without loss of generality, we assume that t is positive.

  1. By the Division Algorithm, we find the unique integer a and z which is the quotient and the remainder when s is divided by t.
  2. If z = 0, we output or return the triple (a, 0, 1) where s / t  = a + 0 / 1 = a.
  3. Otherwise, i. e. if z > 0, then we 
    1. find d = GCD(z, t), and
    2. compute for p = z / d and q = t / d.
    3. Then we return the triple (a, p, q) where s / t  = a + p / q.
We write a Python implementation for this algorithm. Python is an open-source programming language which can be obtained from www.python.org. We are using the version Python 2.7 for our implementation.

First, let us consider the Python implementation for the GCD of two integers a and b.

#################################################################
def GCD(a , b):
    a , b = abs(a), abs(b)      ## consider a and b as non-negative integers


    if  b = 0:
        return  a

   else:

        return GCD(b, a % b)

 ################################################################

We call the function to express a given rational number as an integer or as the sum of an integer and a proper fraction as "normalize". Thus, we have the following Python implementation.

#################################################################
def normalize(s, t):
    a, z = divmod(s,t)  ## find the quotient a and remainder z

    if z == 0:
        return (a, 0, 1)

    else:
        d = GCD(z , t)
        p, q = z / d, t / d 
        return (a, p, q)
#################################################################

by Felix P. Muga II
Associate Professor, Mathematics Department, Ateneo de Manila University
Senior Fellow, Center for People Empowerment in Governance
Chair, Mathematical Sciences Division, National Research Council of the Philippines

The Mathematics of Kits
Previous Topic: "The Rational Number as the Sum of an Integer and a Proper Fraction";
Next topic: "Digitizing a Natural Number"
Main Objective: "Digitizing a Rational Number"

2 comments:

rational expressions definition said...

I am here to discuss about a simple topic in mathematics that is rational expression,Rational expressions is known as an expression that is the ratio of two polynomials.It is called as rational because one number is divided by the other that is like a ratio.

Unknown said...

Yes. A rational function is a ratio of two polynomial functions. A rational expression is a ratio of two polynomial expressions. A rational number is a ratio of two integers. In all of these cases the denominator is not zero. Note that any integer can be expressed as a polynomial in x where x is an integer.