当前位置: 首页>>代码示例>>Java>>正文


Java BigIntegerMath类代码示例

本文整理汇总了Java中com.google.common.math.BigIntegerMath的典型用法代码示例。如果您正苦于以下问题:Java BigIntegerMath类的具体用法?Java BigIntegerMath怎么用?Java BigIntegerMath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BigIntegerMath类属于com.google.common.math包,在下文中一共展示了BigIntegerMath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ValueIterator

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
public ValueIterator(UniformDistributionRNG uniRng, GaussianDistributionRNG gaussRng, int meanBundleSize,
                     double stdDeviation, int iterations) {
    this.uniRng = uniRng;
    this.gaussRng = gaussRng;

    this.meanBundleSize = meanBundleSize;
    this.stdDeviation = stdDeviation;
    this.remainingIterations = iterations;

    numberOfGoods = SizeBasedUniqueRandomXOR.this.goods.size();
    remainingBundles = new ArrayList<>(numberOfGoods - 1);
    while (remainingBundles.size() < numberOfGoods - 1)
        remainingBundles.add(BigInteger.ZERO);

    // TODO To fasten things up, use the symmetry properties of binomial coefficient (symmetric pyramid of
    // values), saving half of calculations.
    for (int bundleSize = 1; bundleSize <= numberOfGoods; bundleSize++) {
        generatedBundleNumbers.put(bundleSize, new TreeSet<>(new BigIntegerComparator()));
        BigInteger numberOfBundles = BigIntegerMath.binomial(numberOfGoods, bundleSize);
        remainingBundles.add(bundleSize - 1, numberOfBundles);
    }

}
 
开发者ID:spectrumauctions,项目名称:sats-core,代码行数:24,代码来源:SizeBasedUniqueRandomXOR.java

示例2: recBinaryString

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
private static StringBuilder recBinaryString(BigInteger sizeBasedIndex, int n, int k) {

        if (n == 0) {
            return new StringBuilder();
        }
        if (k == 0) {
            return new StringBuilder("0").append(recBinaryString(sizeBasedIndex, n - 1, 0));
        }

        // Compute share starting with a one
        BigInteger bin = BigIntegerMath.binomial(n, k);
        BigInteger biggestOneStarterIndex = bin.multiply(BigInteger.valueOf(k)).divide(BigInteger.valueOf(n));

        if (sizeBasedIndex.compareTo(biggestOneStarterIndex) <= 0) {
            return new StringBuilder("1").append(recBinaryString(sizeBasedIndex, n - 1, k - 1));
        } else {
            BigInteger newIndex = sizeBasedIndex.subtract(biggestOneStarterIndex);
            if (n == k) {
                logger.warn("Problem!!!" + newIndex.toString() + " " + n + " " + k);
            }
            return new StringBuilder("0").append(recBinaryString(newIndex, n - 1, k));
        }
    }
 
开发者ID:spectrumauctions,项目名称:sats-core,代码行数:24,代码来源:SizeOrderedXOR.java

示例3: generateBellNumber

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
/**
 * Generates the Bell Number of the given index, where B(1) is 1. This is recursive.
 * 
 * @param index
 * @return
 */
public static BigInteger generateBellNumber(int index) {
	if (index < BELLB_14.length) {
		return BigInteger.valueOf(BELLB_14[index]);
	}
	if (index > 1) {
		BigInteger sum = BigInteger.ZERO;
		for (int i = 0; i < index; i++) {
			BigInteger prevBellNum = generateBellNumber(i);
			BigInteger binomialCoeff = BigIntegerMath.binomial(index - 1, i);
			sum = sum.add(binomialCoeff.multiply(prevBellNum));
		}
		return sum;
	}
	return BigInteger.ONE;
}
 
开发者ID:axkr,项目名称:symja_android_library,代码行数:22,代码来源:NumberTheory.java

示例4: bernoulliNumber

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
/**
 * Compute the Bernoulli number of the first kind.
 * 
 * @param n
 * @return
 */
public static IFraction bernoulliNumber(int n) {
	if (n == 0) {
		return AbstractFractionSym.ONE;
	} else if (n == 1) {
		return AbstractFractionSym.valueOf(-1, 2);
	} else if (n % 2 != 0) {
		return AbstractFractionSym.ZERO;
	}
	IFraction[] bernoulli = new IFraction[n + 1];
	bernoulli[0] = AbstractFractionSym.ONE;
	bernoulli[1] = AbstractFractionSym.valueOf(-1, 2);// new
														// BigFraction(-1,
														// 2);
	for (int k = 2; k <= n; k++) {
		bernoulli[k] = AbstractFractionSym.ZERO;
		for (int i = 0; i < k; i++) {
			if (!bernoulli[i].isZero()) {
				IFraction bin = AbstractFractionSym.valueOf(BigIntegerMath.binomial(k + 1, k + 1 - i));
				bernoulli[k] = bernoulli[k].sub(bin.mul(bernoulli[i]));
			}
		}
		bernoulli[k] = bernoulli[k].div(AbstractFractionSym.valueOf(k + 1));
	}
	return bernoulli[n];
}
 
开发者ID:axkr,项目名称:symja_android_library,代码行数:32,代码来源:NumberTheory.java

示例5: set

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
/**
 * Compute a coefficient in the internal table.
 * 
 * @param a
 *            list of integers
 * @param n
 *            the zero-based index of the coefficient. n=0 for the E_0 term.
 */
protected void set(ArrayList<IInteger> a, final int n) {
	while (n >= a.size()) {
		IInteger val = F.C0;
		boolean sigPos = true;
		int thisn = a.size();
		for (int i = thisn - 1; i > 0; i--) {
			IInteger f = a.get(i);
			f = f.multiply(AbstractIntegerSym.valueOf(BigIntegerMath.binomial(2 * thisn, 2 * i)));
			if (sigPos)
				val = val.add(f);
			else
				val = val.subtract(f);
			sigPos = !sigPos;
		}
		if (thisn % 2 == 0)
			val = val.subtract(F.C1);
		else
			val = val.add(F.C1);
		a.add(val);
	}
}
 
开发者ID:axkr,项目名称:symja_android_library,代码行数:30,代码来源:NumberTheory.java

示例6: bundleSize

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
private static SizeStarter bundleSize(BigInteger index, int n) {
    BigInteger sum = BigInteger.ZERO;
    BigInteger previousSum = null;
    int size = 0;
    while (sum.compareTo(index) < 0) {
        size++;
        if (size > n) {
            throw new RuntimeException("Index to big for available number of items: index=" + index.toString());
        }
        BigInteger thisSizeBundles = BigIntegerMath.binomial(n, size);
        previousSum = sum;
        sum = sum.add(thisSizeBundles);
    }
    return new SizeStarter(size, previousSum);
}
 
开发者ID:spectrumauctions,项目名称:sats-core,代码行数:16,代码来源:SizeOrderedXOR.java

示例7: factorial

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int factorial(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += BigIntegerMath.factorial(factorials[j]).intValue();
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathBenchmark.java

示例8: binomial

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int binomial(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & 0xffff;
    tmp += BigIntegerMath.binomial(factorials[j], binomials[j]).intValue();
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathBenchmark.java

示例9: log2

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int log2(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += BigIntegerMath.log2(positive[j], mode);
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathRoundingBenchmark.java

示例10: log10

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int log10(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += BigIntegerMath.log10(positive[j], mode);
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathRoundingBenchmark.java

示例11: sqrt

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int sqrt(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += BigIntegerMath.sqrt(positive[j], mode).intValue();
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathRoundingBenchmark.java

示例12: divide

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@Benchmark int divide(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += BigIntegerMath.divide(nonzero1[j], nonzero2[j], mode).intValue();
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:BigIntegerMathRoundingBenchmark.java

示例13: build

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Context build(final Context<Object> context) {
	System.out.println("Running builder");
	context.setId("prisonersdilemma");

	final GameAdministrator gameAdministrator = new GameAdministrator();
	context.add(gameAdministrator);

	final Parameters params = RunEnvironment.getInstance().getParameters();
	final int playerCount = (Integer) params.getValue("player_count");
	if (playerCount % 2 != 0)
		throw new CsfRuntimeException(
				"The CSF only supports an even number of players for now.");
	final int numberOfRounds = (Integer) params.getValue("number_of_rounds");

	assert (playerCount % 2 == 0); // Only even numbers supported

	for (int i = 0; i < playerCount; i++) {
		final Player player = new Player(gameAdministrator);
		player.setPlayerNumber(i);
		context.add(player);
	}

	// Calculate the number of combinations
	final BigInteger nFact = BigIntegerMath.factorial(playerCount);
	final BigInteger nMinusRfact = BigIntegerMath.factorial(playerCount - 2);
	final BigInteger rFact = BigIntegerMath.factorial(2);
	final Number denominator = LongMath.multiply(nMinusRfact, rFact);
	final Number numCombinations = LongMath.divide(nFact, denominator);
	final int numbCombinationsInt = numCombinations.intValue();

	RunEnvironment.getInstance().endAt(numbCombinationsInt * numberOfRounds);

	return context;
}
 
开发者ID:OpenSimulationSystems,项目名称:CABSF_Java,代码行数:36,代码来源:PrisonersDilemmaBuilder.java

示例14: binomial

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
public static IInteger binomial(final IInteger n, final IInteger k) {
	// k>n : by definition --> 0
	if (k.isNegative() || k.compareTo(n) > 0) {
		return F.C0;
	}
	if (k.isZero() || k.equals(n)) {
		return F.C1;
	}

	int ni = n.toIntDefault(-1);
	if (ni >= 0) {
		int ki = k.toIntDefault(-1);
		if (ki >= 0) {
			if (ki > ni) {
				return F.C0;
			}
			return AbstractIntegerSym.valueOf(BigIntegerMath.binomial(ni, ki));
		}
	}

	IInteger bin = F.C1;
	IInteger i = F.C1;

	while (!(i.compareTo(k) > 0)) {
		bin = bin.multiply(n.subtract(i).add(F.C1)).div(i);
		i = i.add(F.C1);
	}
	return bin;
}
 
开发者ID:axkr,项目名称:symja_android_library,代码行数:30,代码来源:NumberTheory.java

示例15: sqrt

import com.google.common.math.BigIntegerMath; //导入依赖的package包/类
/**
 * Returns the integer square root of this integer.
 * 
 * @return <code>k<code> such as <code>k^2 <= this < (k + 1)^2</code>. If this integer is negative or it's
 *         impossible to find a square root return <code>F.Sqrt(this)</code>.
 */
public IExpr sqrt() {
	try {
		return valueOf(BigIntegerMath.sqrt(fBigIntValue, RoundingMode.UNNECESSARY));
	} catch (RuntimeException ex) {
		return F.Sqrt(this);
	}
}
 
开发者ID:axkr,项目名称:symja_android_library,代码行数:14,代码来源:BigIntegerSym.java


注:本文中的com.google.common.math.BigIntegerMath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。