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.
- 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.
- If z = 0, we output or return the triple (a, 0, 1) where s / t = a + 0 / 1 = a.
- Otherwise, i. e. if z > 0, then we
- find d = GCD(z, t), and
- compute for p = z / d and q = t / d.
- Then we return the triple (a, p, q) where s / t = a + p / q.
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
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"
Next topic: "Digitizing a Natural Number"
Main Objective: "Digitizing a Rational Number"
2 comments:
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.
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.
Post a Comment