Class RationalField
- java.lang.Object
-
- com.singularsys.extensions.field.implementations.AbstractComparativeField
-
- com.singularsys.extensions.field.implementations.GenericField<E>
-
- com.singularsys.extensions.field.implementations.GenericPowerField<Rational>
-
- com.singularsys.extensions.field.implementations.RationalField
-
- All Implemented Interfaces:
FieldI
,IntegerConvertor
,java.io.Serializable
public class RationalField extends GenericPowerField<Rational>
A field which works with unlimited precision rational numbers, represented as the quotient of two BigIntegers.Note if using Rational numbers with the
PrintVisitor
a special ruleRationalDivisionPrintRule
is needed to ensure divisions are correctly printed. This can be added withjep.getPrintVisitor().addSpecialRule(jep.getOperatorTable().getDivide(), new RationalDivisionPrintRule());
- See Also:
RationalNumberFactory
,Rational
, Serialized Form
-
-
Field Summary
-
Fields inherited from class com.singularsys.extensions.field.implementations.GenericPowerField
one, zero
-
-
Constructor Summary
Constructors Constructor Description RationalField()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Rational
addG(Rational l, Rational r)
Adds two elements of type E.Rational
cast(java.lang.Object l)
Convert the input to type E.java.lang.Integer
cmpG(Rational l, Rational r)
Compare two objects of the same type.Rational
convertFromInt(java.lang.Integer l)
Attempt to convert argument from an integerjava.lang.Integer
convertToIntE(Rational r)
If possible convert the argument to an Integer to enable integral powers.Rational
divG(Rational l, Rational r)
Divides two elements of type E.Rational
getOne()
Get the multiplicative identity for this field.Rational
getZero()
Get the additive identity for this fieldRational
modG(Rational l, Rational r)
Modulus of two elements of type E.Rational
mulG(Rational l, Rational r)
Multiplies two elements of type E.Rational
negG(Rational l)
Negates an elements of type E.Rational
powNonInt(Rational l, Rational r)
Power only implemented for integral powers.Rational
subG(Rational l, Rational r)
Subtracts two elements of type E.-
Methods inherited from class com.singularsys.extensions.field.implementations.GenericPowerField
powG, powI
-
Methods inherited from class com.singularsys.extensions.field.implementations.GenericField
add, and, cmp, convertToInt, div, mod, mul, neg, not, or, pow, sub
-
-
-
-
Method Detail
-
cast
public Rational cast(java.lang.Object l)
Description copied from class:GenericField
Convert the input to type E.- Specified by:
cast
in classGenericField<Rational>
- Returns:
- l if l is a Rational, null otherwise
-
addG
public Rational addG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Adds two elements of type E.- Specified by:
addG
in classGenericField<Rational>
- Parameters:
l
- lhs argumentr
- rhs argument- Returns:
- the sum
- Throws:
EvaluationException
- on error
-
cmpG
public java.lang.Integer cmpG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Compare two objects of the same type.- Specified by:
cmpG
in classGenericField<Rational>
- Parameters:
l
- left argumentr
- right argument- Returns:
- -1, 0, 1 or null
- Throws:
EvaluationException
-
divG
public Rational divG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Divides two elements of type E.- Specified by:
divG
in classGenericField<Rational>
- Parameters:
l
- numeratorr
- denominator- Returns:
- the division
- Throws:
EvaluationException
- on error
-
modG
public Rational modG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Modulus of two elements of type E.- Specified by:
modG
in classGenericField<Rational>
- Parameters:
l
- lhs argumentr
- rhs argument- Returns:
- the modulus
- Throws:
EvaluationException
- on error
-
mulG
public Rational mulG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Multiplies two elements of type E.- Specified by:
mulG
in classGenericField<Rational>
- Parameters:
l
- lhs argumentr
- rhs argument- Returns:
- the product
- Throws:
EvaluationException
- on error
-
negG
public Rational negG(Rational l) throws EvaluationException
Description copied from class:GenericField
Negates an elements of type E.- Specified by:
negG
in classGenericField<Rational>
- Parameters:
l
- the argument- Returns:
- the negation
- Throws:
EvaluationException
- on error
-
powNonInt
public Rational powNonInt(Rational l, Rational r) throws EvaluationException
Power only implemented for integral powers.- Specified by:
powNonInt
in classGenericPowerField<Rational>
- Returns:
- Throws:
EvaluationException
-
subG
public Rational subG(Rational l, Rational r) throws EvaluationException
Description copied from class:GenericField
Subtracts two elements of type E.- Specified by:
subG
in classGenericField<Rational>
- Parameters:
l
- lhs argumentr
- rhs argument- Returns:
- the difference
- Throws:
EvaluationException
- on error
-
convertFromInt
public Rational convertFromInt(java.lang.Integer l) throws EvaluationException
Description copied from interface:IntegerConvertor
Attempt to convert argument from an integer- Specified by:
convertFromInt
in interfaceIntegerConvertor
- Specified by:
convertFromInt
in classGenericField<Rational>
- Parameters:
l
- value to convert- Returns:
- corresponding value in this field or null if it cannot be converted
- Throws:
EvaluationException
- probably never
-
getOne
public Rational getOne()
Description copied from interface:FieldI
Get the multiplicative identity for this field.- Specified by:
getOne
in interfaceFieldI
- Specified by:
getOne
in classGenericField<Rational>
- Returns:
- object representing one or null if undefined for this field
-
getZero
public Rational getZero()
Description copied from interface:FieldI
Get the additive identity for this field- Specified by:
getZero
in interfaceFieldI
- Specified by:
getZero
in classGenericField<Rational>
- Returns:
- object representing zero or null if undefined for this field
-
convertToIntE
public java.lang.Integer convertToIntE(Rational r) throws EvaluationException
Description copied from class:GenericField
If possible convert the argument to an Integer to enable integral powers. If the argument cannot be converted null should be returned and thepowG(E,E)
method will be called.- Specified by:
convertToIntE
in classGenericField<Rational>
- Parameters:
r
- argument to convert.- Returns:
- an integer or null if argument cannot be converted
- Throws:
EvaluationException
-
-