|
fraction Specification SheetComputer Algebra Kit (c) 1993,00 by Comp.Alg.Objects. All Rights Reserved.
FractionInherits from: CAObjectMaturity Index: Relatively immature
Class DescriptionFraction objects consist of a numerator object divided by a denominator object. The numerators and denominators can be arbitrary Computer Algebra Kit objects, but the current implementation has been tested only in the case of total fractions i.e., numerators and denominators are taken as elements of the same set. For example, a fraction of two integers is a rational number; a fraction of two polynomials is a rational function.
Canonical FormThe arithmetical operations on fractions assume that the fractions are in a simplified (canonical) form, and produce, as result, a fraction in canonical form. In the case of the integers, or any ordered, integral domain (see inIntegralDomain and inOrderedSet), the numerator and denominator are kept coprime (common gcd is divided out) and the denominator is kept positive. For example, the fraction minus one, is represented as (-1)/1, and never as 1/(-1). In the case of an unordered, integral domain, such as polynomials over the integers or over a field, the denominator and numerator are also coprime, and the leading unit of the denominator is equal to one (over fields, this means that the denominator is kept monic, see leadingUnit). For example, the fraction minus x is represented over Z mod 3 as (2 x)/1 and not as x/2. Finally, for rational functions with floating-point coefficients, no gcd is computed, but the denominator of the fraction is kept monic.
Method typesCreationIdentityCoercionAdditionMultiplicationMultiplication by Int ValuePrintingMethodstotalFraction:+totalFraction:aNumeratorReturns a new fraction with numerator set to aNumerator and denominator set to the element one for aNumerator.
numerator:denominator:+numerator:aNumeratordenominator:aDenominatorReturns a new fraction with numerator set to aNumerator and denominator set to aDenominator.
copy-copyReturns a new copy of the fraction.
deepCopy-deepCopyReturns a new copy of the fraction; sends deepCopy messages to denominator and numerator.
numerator-numeratorReturns a for a fraction a/b.
denominator-denominatorReturns b for a fraction a/b.
hash- (unsigned)hashReturns a small integer that is the same for fractions that are equal in the sense of isEqual:.
isEqual:- (BOOL)isEqual:bTwo fractions are equal if they are pointer equal, or if their numerators and denominators are equal. If the numerators and denominators are coprime, but not ordered, the method returns YES if numerators and denominators are opposite to each other. If the fraction is not in canonical form, it is verified that the difference of the two fractions is zero.
compare:- (int)compare:bCompares the fractions by comparing the products of numerators and denominators.
asNumerical-asNumericalReturns the numerical value of the fraction. Attempts to divide the numerical value of the numerator and denominator.
asModp:-asModp:(unsigned short)pReturns the value of the fraction modulo p. Attempts to divide the values of the numerator and denominator. If the division fails, the method generates an error message.
asIntegral-asIntegralReturns, if the denominator of the fraction is equal to one, a new reference to the numerator. Otherwise, the method generates an error message.
zero-zeroReturns a new fraction with numerator equal to zero.
isZero- (BOOL)isZeroWhether the numerator of the fraction is equal to zero.
isOpposite:- (BOOL)isOpposite:bTwo fractions are opposite if their numerators are opposite and the denominators are equal. However, if the numerators and denominators are coprime, but not ordered, the method returns YES if the numerators are equal and the denominators are opposite to each other. If the fraction is not in canonical form, it is verified that the sum of the two fractions is zero.
negate-negateReturns a new fraction, the opposite of self by negating the numerator.
double-doubleReturns a new fraction, the double of self by doubling the numerator.
add:-add:bReturns a new fraction, the sum of self and b. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not.
subtract:-subtract:bReturns a new fraction, the difference of self and b. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not.
one-oneReturns a new fraction with numerator equal to one.
isOne- (BOOL)isOneWhether the numerator is equal to the denominator.
isMinusOne- (BOOL)isMinusOneWhether the numerator is the opposite of the denominator.
square-squareReturns a new fraction; squares numerator and denominator.
inverse-inverseReturns the inverse of the fraction; interchanges, in the case of a total fraction, denominator and numerator.
multiply:-multiply:bReturns a new fraction; multiplies the numerators and the denominators together.
divide:-divide:bReturns a new fraction by multiplying the fraction by the inverse of b.
power:-power:(int)nReturns a new fraction; raises numerator and denominator to the n-th power.
intValue:-intValue:(int)intValueCreates a fraction with numerator equal to intValue and denominator one.
intValue- (int)intValueReturns intValue of numerator divided by intValue of denominator.
multiplyIntValue:-multiplyIntValue:(int)intValueReturns a new fraction by multiplying the numerator by intValue.
divideIntValue:-divideIntValue:(int)intValueReturns a new fraction by multiplying the denominator by intValue.
printsLeadingSign- (BOOL)printsLeadingSignWhether the fraction prints a leading minus sign.
printsSum- (BOOL)printsSumWhether the fraction prints as a sum.
printsProduct- (BOOL)printsProductWhether the fraction prints as a product.
printOn:-printOn:(IOD)aFilePrints the fraction to aFile by sending printOn: messages to numerator and denominator.
|