use of org.matheclipse.core.builtin.Combinatoric.Subsets.KSubsetsList in project symja_android_library by axkr.
the class BigIntegerSym method divisors.
/**
* Return the divisors of this integer number.
*
* <pre>
* divisors(24) ==> {1,2,3,4,6,8,12,24}
* </pre>
*/
@Override
public IAST divisors() {
if (isOne() || isMinusOne()) {
return F.List(F.C1);
}
Set<IInteger> set = new TreeSet<IInteger>();
final IAST primeFactorsList = factorize(F.List());
int len = primeFactorsList.size() - 1;
// build the k-subsets from the primeFactorsList
for (int k = 1; k < len; k++) {
final KSubsetsList iter = Subsets.createKSubsets(primeFactorsList, k, F.List(), 1);
for (IAST subset : iter) {
if (subset == null) {
break;
}
// create the product of all integers in the k-subset
IInteger factor = F.C1;
for (int j = 1; j < subset.size(); j++) {
factor = factor.multiply((IInteger) subset.get(j));
}
// add this divisor to the set collection
set.add(factor);
}
}
// build the final divisors list from the tree set
final IAST resultList = List(F.C1);
for (IInteger entry : set) {
resultList.append(entry);
}
resultList.append(this);
return resultList;
}
use of org.matheclipse.core.builtin.Combinatoric.Subsets.KSubsetsList in project symja_android_library by axkr.
the class IntegerSym method divisors.
/**
* Return the divisors of this integer number.
*
* <pre>
* divisors(24) ==> {1,2,3,4,6,8,12,24}
* </pre>
*/
@Override
public IAST divisors() {
if (isOne() || isMinusOne()) {
return F.List(F.C1);
}
Set<IInteger> set = new TreeSet<IInteger>();
final IAST primeFactorsList = factorize(F.List());
int len = primeFactorsList.size() - 1;
// build the k-subsets from the primeFactorsList
for (int k = 1; k < len; k++) {
final KSubsetsList iter = Subsets.createKSubsets(primeFactorsList, k, F.List(), 1);
for (IAST subset : iter) {
if (subset == null) {
break;
}
// create the product of all integers in the k-subset
IInteger factor = F.C1;
for (int j = 1; j < subset.size(); j++) {
factor = factor.multiply((IInteger) subset.get(j));
}
// add this divisor to the set collection
set.add(factor);
}
}
// build the final divisors list from the tree set
final IAST resultList = F.ListAlloc(set.size() + 1);
resultList.append(F.C1);
for (IInteger entry : set) {
resultList.append(entry);
}
resultList.append(this);
return resultList;
}
Aggregations