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;
}
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;
}
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;
}
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());
}
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);
}
Aggregations