@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Context; |
4 | 4 | |
5 | -use Samsara\Fermat\Context\Base\BaseContext; |
|
6 | -use Samsara\Fermat\Numbers; |
|
7 | -use Samsara\Fermat\Provider\BCProvider; |
|
8 | -use Samsara\Fermat\Provider\GaussianProvider; |
|
5 | +use Samsara\Fermat\Context\Base\BaseContext; |
|
6 | +use Samsara\Fermat\Numbers; |
|
7 | +use Samsara\Fermat\Provider\BCProvider; |
|
8 | +use Samsara\Fermat\Provider\GaussianProvider; |
|
9 | 9 | use Samsara\Fermat\Values\Base\NumberInterface; |
10 | 10 | |
11 | 11 | /** |
@@ -85,6 +85,9 @@ |
||
85 | 85 | return $this->PDFByValue($value); |
86 | 86 | } |
87 | 87 | |
88 | + /** |
|
89 | + * @param NumberInterface $value |
|
90 | + */ |
|
88 | 91 | public function PDFByValue($value) |
89 | 92 | { |
90 | 93 | $value = Numbers::makeOrDont($this->numberType, $value); |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Context; |
4 | 4 | |
5 | -use RandomLib\Factory; |
|
6 | -use Samsara\Fermat\Context\Base\BaseContext; |
|
7 | -use Samsara\Fermat\Context\Base\ContextInterface; |
|
8 | -use Samsara\Fermat\Numbers; |
|
9 | -use Samsara\Fermat\Provider\BCProvider; |
|
10 | -use Samsara\Fermat\Values\ImmutableNumber; |
|
5 | +use RandomLib\Factory; |
|
6 | +use Samsara\Fermat\Context\Base\BaseContext; |
|
7 | +use Samsara\Fermat\Context\Base\ContextInterface; |
|
8 | +use Samsara\Fermat\Numbers; |
|
9 | +use Samsara\Fermat\Provider\BCProvider; |
|
10 | +use Samsara\Fermat\Values\ImmutableNumber; |
|
11 | 11 | use Samsara\Fermat\Values\Base\NumberInterface; |
12 | 12 | |
13 | 13 | class UniformContext extends BaseContext implements ContextInterface |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Provider\Stats\Distribution; |
4 | 4 | |
5 | -use Samsara\Fermat\Numbers; |
|
6 | -use Samsara\Fermat\Provider\Stats\Stats; |
|
5 | +use Samsara\Fermat\Numbers; |
|
6 | +use Samsara\Fermat\Provider\Stats\Stats; |
|
7 | 7 | use Samsara\Fermat\Values\Base\NumberInterface; |
8 | 8 | |
9 | 9 | class Normal |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | ->multiply($e->pow($eExponent)) |
33 | 33 | ->multiply(SeriesProvider::maclaurinSeries( |
34 | 34 | $x, |
35 | - function ($n) { |
|
35 | + function($n) { |
|
36 | 36 | return Numbers::makeOne(); |
37 | 37 | }, |
38 | - function ($n) { |
|
38 | + function($n) { |
|
39 | 39 | return SequenceProvider::nthOddNumber($n); |
40 | 40 | }, |
41 | - function ($n) { |
|
41 | + function($n) { |
|
42 | 42 | return SequenceProvider::nthOddNumber($n)->doubleFactorial(); |
43 | 43 | } |
44 | 44 | )) |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | $answer = $answer->multiply( |
69 | 69 | SeriesProvider::maclaurinSeries( |
70 | 70 | $x, |
71 | - function ($n) { |
|
71 | + function($n) { |
|
72 | 72 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
73 | 73 | |
74 | 74 | return $negOne->pow($n); |
75 | 75 | }, |
76 | - function ($n) { |
|
76 | + function($n) { |
|
77 | 77 | return SequenceProvider::nthOddNumber($n); |
78 | 78 | }, |
79 | - function ($n) { |
|
79 | + function($n) { |
|
80 | 80 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
81 | 81 | |
82 | 82 | return $n->factorial()->multiply(SequenceProvider::nthOddNumber($n)); |
@@ -88,6 +88,9 @@ |
||
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | + /** |
|
92 | + * @param NumberInterface $p |
|
93 | + */ |
|
91 | 94 | public static function inverseNormalCDF($p, $precision = 10) |
92 | 95 | { |
93 | 96 | $pi = Numbers::makePi(); |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Provider\Stats\Distribution; |
4 | 4 | |
5 | -use RandomLib\Factory; |
|
6 | -use Samsara\Fermat\Numbers; |
|
7 | -use Samsara\Fermat\Provider\Stats\Distribution\Base\DistributionInterface; |
|
5 | +use RandomLib\Factory; |
|
6 | +use Samsara\Fermat\Numbers; |
|
7 | +use Samsara\Fermat\Provider\Stats\Distribution\Base\DistributionInterface; |
|
8 | 8 | use Samsara\Fermat\Values\Base\NumberInterface; |
9 | 9 | |
10 | 10 | class Poisson implements DistributionInterface |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $cumulative = Numbers::makeZero(); |
34 | 34 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
35 | 35 | |
36 | - for ($i = 0;$x->greaterThanOrEqualTo($i);$i++) { |
|
36 | + for ($i = 0; $x->greaterThanOrEqualTo($i); $i++) { |
|
37 | 37 | $cumulative = $cumulative->add($this->pmf($i)); |
38 | 38 | } |
39 | 39 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $cumulative = Numbers::makeZero(); |
64 | 64 | |
65 | - for (;$larger->isGreaterThanOrEqualTo($smaller);$smaller->add(1)) { |
|
65 | + for (;$larger->isGreaterThanOrEqualTo($smaller); $smaller->add(1)) { |
|
66 | 66 | $cumulative = $cumulative->add($this->pmf($smaller)); |
67 | 67 | } |
68 | 68 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | while ($p->isLessThan($L)) { |
98 | 98 | $k = $k->add(1); |
99 | - $u = $randFactory->getMediumStrengthGenerator()->generateInt() / PHP_INT_MAX; |
|
99 | + $u = $randFactory->getMediumStrengthGenerator()->generateInt()/PHP_INT_MAX; |
|
100 | 100 | $p = $p->multiply($u); |
101 | 101 | } |
102 | 102 |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Values; |
4 | 4 | |
5 | -use Samsara\Fermat\Numbers; |
|
6 | -use Samsara\Fermat\Types\Number; |
|
7 | -use Samsara\Fermat\Types\Base\DecimalInterface; |
|
5 | +use Samsara\Fermat\Numbers; |
|
6 | +use Samsara\Fermat\Types\Number; |
|
7 | +use Samsara\Fermat\Types\Base\DecimalInterface; |
|
8 | 8 | use Samsara\Fermat\Types\Base\NumberInterface; |
9 | 9 | |
10 | 10 | class ImmutableNumber extends Number implements NumberInterface, DecimalInterface |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Values; |
4 | 4 | |
5 | -use Samsara\Fermat\Types\Number; |
|
6 | -use Samsara\Fermat\Types\Base\DecimalInterface; |
|
7 | -use Samsara\Fermat\Types\Base\NumberInterface; |
|
5 | +use Samsara\Fermat\Types\Number; |
|
6 | +use Samsara\Fermat\Types\Base\DecimalInterface; |
|
7 | +use Samsara\Fermat\Types\Base\NumberInterface; |
|
8 | 8 | use Samsara\Fermat\Numbers; |
9 | 9 | |
10 | 10 | class MutableNumber extends Number implements NumberInterface, DecimalInterface |
@@ -2,11 +2,11 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat; |
4 | 4 | |
5 | -use Samsara\Exceptions\UsageError\IntegrityConstraint; |
|
6 | -use Samsara\Fermat\Values\ImmutableFraction; |
|
7 | -use Samsara\Fermat\Values\ImmutableNumber; |
|
8 | -use Samsara\Fermat\Values\MutableFraction; |
|
9 | -use Samsara\Fermat\Values\MutableNumber; |
|
5 | +use Samsara\Exceptions\UsageError\IntegrityConstraint; |
|
6 | +use Samsara\Fermat\Values\ImmutableFraction; |
|
7 | +use Samsara\Fermat\Values\ImmutableNumber; |
|
8 | +use Samsara\Fermat\Values\MutableFraction; |
|
9 | +use Samsara\Fermat\Values\MutableNumber; |
|
10 | 10 | use Samsara\Fermat\Types\Base\NumberInterface; |
11 | 11 | |
12 | 12 | class Numbers |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Types; |
4 | 4 | |
5 | -use Ds\Hashable; |
|
6 | -use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState; |
|
7 | -use Samsara\Fermat\Numbers; |
|
8 | -use Samsara\Fermat\Provider\BCProvider; |
|
9 | -use Riimu\Kit\BaseConversion\BaseConverter; |
|
10 | -use Samsara\Fermat\Provider\SequenceProvider; |
|
11 | -use Samsara\Fermat\Provider\SeriesProvider; |
|
5 | +use Ds\Hashable; |
|
6 | +use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState; |
|
7 | +use Samsara\Fermat\Numbers; |
|
8 | +use Samsara\Fermat\Provider\BCProvider; |
|
9 | +use Riimu\Kit\BaseConversion\BaseConverter; |
|
10 | +use Samsara\Fermat\Provider\SequenceProvider; |
|
11 | +use Samsara\Fermat\Provider\SeriesProvider; |
|
12 | 12 | use Samsara\Fermat\Types\Base\NumberInterface; |
13 | 13 | |
14 | 14 | abstract class Number implements Hashable |
@@ -22,6 +22,9 @@ discard block |
||
22 | 22 | |
23 | 23 | protected $base; |
24 | 24 | |
25 | + /** |
|
26 | + * @param integer $precision |
|
27 | + */ |
|
25 | 28 | public function __construct($value, $precision = null, $base = 10) |
26 | 29 | { |
27 | 30 | $this->base = $base; |
@@ -49,6 +52,9 @@ discard block |
||
49 | 52 | return $this->precision; |
50 | 53 | } |
51 | 54 | |
55 | + /** |
|
56 | + * @param NumberInterface $num |
|
57 | + */ |
|
52 | 58 | public function add($num) |
53 | 59 | { |
54 | 60 | $num = Numbers::makeOrDont($this, $num, $this->getPrecision()); |
@@ -98,7 +104,7 @@ discard block |
||
98 | 104 | * Note about precision: it uses the smaller of the two precisions (significant figures). |
99 | 105 | * |
100 | 106 | * @param $num |
101 | - * @return mixed |
|
107 | + * @return NumberInterface |
|
102 | 108 | */ |
103 | 109 | public function divide($num) |
104 | 110 | { |
@@ -509,6 +515,9 @@ discard block |
||
509 | 515 | } |
510 | 516 | } |
511 | 517 | |
518 | + /** |
|
519 | + * @param integer $value |
|
520 | + */ |
|
512 | 521 | public function isGreaterThan($value): bool |
513 | 522 | { |
514 | 523 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -541,6 +550,9 @@ discard block |
||
541 | 550 | } |
542 | 551 | } |
543 | 552 | |
553 | + /** |
|
554 | + * @param integer $value |
|
555 | + */ |
|
544 | 556 | public function isLessThanOrEqualTo($value): bool |
545 | 557 | { |
546 | 558 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct($value, $precision = null, $base = 10) |
26 | 26 | { |
27 | 27 | $this->base = $base; |
28 | - $this->value = (string)$value; |
|
28 | + $this->value = (string) $value; |
|
29 | 29 | |
30 | 30 | if (!is_null($precision)) { |
31 | 31 | $this->precision = $precision; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $curVal = $this->getValue(); |
136 | 136 | $calcVal = Numbers::make(Numbers::IMMUTABLE, 1); |
137 | 137 | |
138 | - for ($i = 1;$i <= $curVal;$i++) { |
|
138 | + for ($i = 1; $i <= $curVal; $i++) { |
|
139 | 139 | $calcVal = $calcVal->multiply($i); |
140 | 140 | } |
141 | 141 | |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | |
152 | 152 | if ($val->modulo(2)->isEqual(1)) { |
153 | 153 | $m = Numbers::make(Numbers::IMMUTABLE, $val->add(1)->divide(2)); |
154 | - $term = function ($n) { |
|
154 | + $term = function($n) { |
|
155 | 155 | return Numbers::make(Numbers::IMMUTABLE, 2)->multiply($n); |
156 | 156 | }; |
157 | 157 | } else { |
158 | 158 | $m = Numbers::make(Numbers::IMMUTABLE, $val->divide(2)); |
159 | - $term = function ($n) { |
|
159 | + $term = function($n) { |
|
160 | 160 | return Numbers::make(Numbers::IMMUTABLE, 2)->multiply($n)->subtract(1); |
161 | 161 | }; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $newVal = Numbers::makeOne(); |
165 | 165 | |
166 | - for ($i = 1;$m->isGreaterThanOrEqualTo($i);$i++) { |
|
166 | + for ($i = 1; $m->isGreaterThanOrEqualTo($i); $i++) { |
|
167 | 167 | $newVal = $newVal->multiply($term($i)); |
168 | 168 | } |
169 | 169 | |
@@ -228,15 +228,15 @@ discard block |
||
228 | 228 | return $this->setValue( |
229 | 229 | SeriesProvider::maclaurinSeries( |
230 | 230 | Numbers::make(Numbers::IMMUTABLE, $value), |
231 | - function ($n) { |
|
231 | + function($n) { |
|
232 | 232 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
233 | 233 | |
234 | 234 | return $negOne->pow($n); |
235 | 235 | }, |
236 | - function ($n) { |
|
236 | + function($n) { |
|
237 | 237 | return SequenceProvider::nthOddNumber($n); |
238 | 238 | }, |
239 | - function ($n) { |
|
239 | + function($n) { |
|
240 | 240 | return SequenceProvider::nthOddNumber($n)->factorial(); |
241 | 241 | }, |
242 | 242 | 0, |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | return $this->setValue( |
275 | 275 | SeriesProvider::maclaurinSeries( |
276 | 276 | Numbers::make(Numbers::IMMUTABLE, $value), |
277 | - function ($n) { |
|
277 | + function($n) { |
|
278 | 278 | return SequenceProvider::nthPowerNegativeOne($n); |
279 | 279 | }, |
280 | - function ($n) { |
|
280 | + function($n) { |
|
281 | 281 | return SequenceProvider::nthEvenNumber($n); |
282 | 282 | }, |
283 | - function ($n) { |
|
283 | + function($n) { |
|
284 | 284 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
285 | 285 | }, |
286 | 286 | 0, |
@@ -314,18 +314,18 @@ discard block |
||
314 | 314 | return $this->setValue( |
315 | 315 | SeriesProvider::maclaurinSeries( |
316 | 316 | Numbers::make(Numbers::IMMUTABLE, $value), |
317 | - function ($n) { |
|
317 | + function($n) { |
|
318 | 318 | $four = Numbers::make(Numbers::IMMUTABLE, 4); |
319 | 319 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
320 | 320 | |
321 | 321 | return SequenceProvider::nthBernoulliNumber($n->multiply(2)->getValue(), -4)->pow($n)->multiply(Numbers::makeOne()->subtract($four->pow($n))); |
322 | 322 | }, |
323 | - function ($n) { |
|
323 | + function($n) { |
|
324 | 324 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
325 | 325 | |
326 | 326 | return $n->multiply(2)->subtract(1); |
327 | 327 | }, |
328 | - function ($n) { |
|
328 | + function($n) { |
|
329 | 329 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
330 | 330 | }, |
331 | 331 | 1, |