Search in sources :

Example 36 with IInteger

use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.

the class AbstractIntegerSym method primitiveRoots.

/**
	 * The primitive roots of this integer number
	 * 
	 * @return the primitive roots
	 * @throws ArithmeticException
	 */
@Override
public IInteger[] primitiveRoots() throws ArithmeticException {
    IInteger phi = eulerPhi();
    int size = phi.eulerPhi().toInt();
    if (size <= 0) {
        return null;
    }
    IAST ast = phi.factorInteger();
    IInteger[] d = new IInteger[ast.size() - 1];
    IAST element;
    for (int i = 1; i < ast.size(); i++) {
        element = (IAST) ast.get(i);
        IInteger q = (IInteger) element.arg1();
        d[i - 1] = phi.quotient(q);
    }
    int k = 0;
    IInteger n = this;
    IInteger m = AbstractIntegerSym.valueOf(1);
    IInteger[] resultArray = new IInteger[size];
    boolean b;
    while (m.compareTo(n) < 0) {
        b = m.gcd(n).compareTo(AbstractIntegerSym.valueOf(1)) == 0;
        for (int i = 0; i < d.length; i++) {
            b = b && m.modPow(d[i], n).compareTo(AbstractIntegerSym.valueOf(1)) > 0;
        }
        if (b) {
            resultArray[k++] = m;
        }
        m = m.add(AbstractIntegerSym.valueOf(1));
    }
    if (resultArray[0] == null) {
        return new IInteger[0];
    }
    return resultArray;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IAST(org.matheclipse.core.interfaces.IAST)

Example 37 with IInteger

use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.

the class AbstractIntegerSym method jacobiSymbolG.

@Override
public IInteger jacobiSymbolG(IInteger b) {
    IInteger i1 = mod(F.C4);
    if (i1.isOne()) {
        return F.C1;
    }
    IInteger i2 = b.mod(F.C4);
    if (i2.isOne()) {
        return F.C1;
    }
    return F.CN1;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger)

Example 38 with IInteger

use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.

the class AbstractIntegerSym method lcm.

/**
	 * Returns the least common multiple of this large integer and the one specified.
	 * 
	 */
@Override
public IInteger lcm(final IInteger that) {
    if (this.isZero() || that.isZero()) {
        return F.C0;
    }
    IInteger a = abs();
    IInteger b = that.abs();
    IInteger gcd = a.gcd(b);
    IInteger lcm = a.multiply(b).div(gcd);
    return lcm;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger)

Example 39 with IInteger

use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.

the class BigFractionSym method add.

@Override
public IRational add(IRational parm1) {
    if (parm1.isZero()) {
        return this;
    }
    if (parm1 instanceof IFraction) {
        return add((IFraction) parm1);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().add(toBigDenominator().multiply(p1.toBigNumerator()));
    return valueOf(newnum, toBigDenominator());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Example 40 with IInteger

use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.

the class BigIntegerSym method add.

@Override
public IRational add(IRational parm1) {
    if (parm1.isZero()) {
        return this;
    }
    if (parm1 instanceof IFraction) {
        return ((IFraction) parm1).add(this);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().add(p1.toBigNumerator());
    return valueOf(newnum);
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Aggregations

IInteger (org.matheclipse.core.interfaces.IInteger)59 IAST (org.matheclipse.core.interfaces.IAST)34 IExpr (org.matheclipse.core.interfaces.IExpr)29 ISymbol (org.matheclipse.core.interfaces.ISymbol)18 IFraction (org.matheclipse.core.interfaces.IFraction)16 BigInteger (java.math.BigInteger)11 INum (org.matheclipse.core.interfaces.INum)10 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)6 ExpVector (edu.jas.poly.ExpVector)5 INumber (org.matheclipse.core.interfaces.INumber)4 ModLong (edu.jas.arith.ModLong)3 GenPolynomial (edu.jas.poly.GenPolynomial)3 Num (org.matheclipse.core.expression.Num)3 IRational (org.matheclipse.core.interfaces.IRational)3 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)3 TreeSet (java.util.TreeSet)2 BigFraction (org.hipparchus.fraction.BigFraction)2 KSubsetsList (org.matheclipse.core.builtin.Combinatoric.Subsets.KSubsetsList)2