Skip to content

cogpunk/math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cogpunk Math

Cogpunk Math is a set of mathematical utilities for general use

Build Status Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating Apache License, Version 2.0 Cogpunk Math

Building from source

The build requires a Java 11 JDK (or higher) and uses Maven

mvn install

Adding as a dependency

<dependency>
	<groupId>com.cogpunk</groupId>
	<artifactId>cogpunk-math</artifactId>
	<version>1.0.4</version>
</dependency>

License

Code is under the Apache Licence v2.

Example

Determine the probability profile of adding 3 six-sided dice together

// Create a profile for a 6-sided dice

Fraction prob = new Fraction(1, 6);

Map<Integer, Fraction> map = new TreeMap<Integer, Fraction>();

for (int n = 1; n <= 6; n++) {
	map.put(n, prob);
}

ComparableEventProbabilityProfileImpl<Integer, Fraction> dice 
	= new ComparableEventProbabilityProfileImpl<Integer, Fraction>(
		map, new FractionOperator());

// Determine the probabilities of all possible results of adding the dice values together 
// using the EventProbabilityProfileAdditionAggregationStrategy

EventProbabilityProfileAggregator<Integer, Integer, Fraction> aggregator 
	= new EventProbabilityProfileAggregator<Integer, Integer, Fraction>(
		new EventProbabilityProfileAdditionAggregationStrategy<Integer>(
			new IntegerOperator()), new FractionOperator(), dice, dice, dice);

// Print out the results to the console

System.out.println(aggregator);