jordanrl / fermat Goto Github PK
View Code? Open in Web Editor NEWA library providing math and statistics operations for numbers of arbitrary size.
License: GNU General Public License v2.0
A library providing math and statistics operations for numbers of arbitrary size.
License: GNU General Public License v2.0
There is currently a CartesianCoordinate class, however it is fairly unintegrated with other parts of the library. Additionally, a PolarCoordinate class in needed to complete #14 as it is the easiest way to implement things such as pow().
This will involve formalizing the CoordinateInterface, making an abstract Coordinate class, creating the new PolarCoordinate class, and correctly utilizing the existing classes to allow for smooth transition between other classes in the library and coordinates.
Related to #15 it would be nice to somehow uncap the precision of the trig operations. In order for this to happen there needs to be a way of getting several constants, namely e and pi, to "arbitrary" precision. I'm currently exploring the best way to implement this.
I think precision to 100 digits hits the vast majority of cases, so it might be okay to keep the constants for most cases and call a generator of some kind in the special cases where greater precision is required.
Add comments for all methods for /Types/Number.php class
Requires Algebra Expressions to be at v1.0 (due to the polynomial foil function being utilized in the multiply() implementation)
I thought that maybe it'd be nice if complex numbers are supported including their operations.
I've created this issue mainly because I wanted to check if it's actually something @JordanRL wants in this project. If so, I think I can get started on a PR.
The exceptions in Fermat already provide/contain the information needed for spatie/ignition. Providing integration with the solution aspect of spatie/ignition should be fairly simple.
There are some areas of the documentation that still do not exist, even though the associated code is tested and considered stable. This documentation needs to be created and deployed so that it is available for developers to reference.
This might be something that is most relevant to some of the modules. Affected modules might include:
Currently, both ImmutableVector
and MutableVector
implement the VectorInterface
, but don't implement any of its methods nor are declared abstract. Either remove the classes altogether, mark them as abstract
, create the methods from VectorInterface
or remove implements VectorInterface
from the signatures.
Allow options for printing and exporting in more formats:
The GammaFunction returns an incorrect value for $z, because $x isn't altered each loop. This should cause it to loop infinitely.
Similar blocks of code found in 2 locations. Consider refactoring.
Create a matrix type that can handle how matrix math is done.
Providing the DocBlock comments for all items allows the documentation generated by Roster to be more complete and helpful, particularly where the descriptions or examples are given.
The php-decimal/ext-decimal library implements a better C version of the string/arbitrary precision math than ext-bcmath, and can replace some of the core parts of Type\Number.
Add a type for number collections that allows for working on groups of numbers together. Operations:
Arithmetic operations are really only limited by the BCMath library in precision, so with the proper redesign a few method signatures, this could easily be increased to the 2^32-1 digits that BCMath supports.
The main reason I shied away from doing this for the initial release is that the trig functions can really only be accurate to the number of decimal places that the constants are available at. However, it is probably more of an edge case to need trig functions to > 100 digits than it is to need arithmetic operations to > 100 digits.
Now that the minimum version of PHP for the project has been set at 8.0, it makes sense to update all of the interfaces, classes, and methods to utilize the proper union types.
The same process would need to be done for each of the modules individually (which would also increment their minor version since public signatures change).
Matrix
has 32 functions (exceeds 20 allowed). Consider refactoring.
The Scrutinizer report for the current codebase has several methods with a high CRAP score. These methods need to be refactored to be simplified, or they need to be more well tested.
NumberCollection
has 31 functions (exceeds 20 allowed). Consider refactoring.
Create a calculus provider that can, at the very least, compute the integral over a range (both definite and indefinite) given that the integrand is provided.
Currently the inverse trig functions average around 50 operations per second, and the normal trig functions around 600-700. Current performance: (NOTE: the numerical values depend on the system and are only relevant in comparison to future numbers generated on my development box.)
Function | Ops/Sec | Equivalent md5() Hashes |
---|---|---|
sin() | 657 | 12590 |
cos() | 745 | 11079 |
tan() | 208 | 39622 |
sec() | 703 | 11744 |
csc() | 618 | 13353 |
cot() | 160 | 51400 |
----- | --- | ---- |
arcsin() | 45.3 | 182144 |
arccos() | 42.6 | 193546 |
arctan() | 36.5 | 226051 |
arcsec() | 54.2 | 152068 |
arccsc() | 58.6 | 140874 |
arccot() | 33.8 | 244096 |
Current bottlenecks are primarily:
This issue was discovered by me while attempting to write some unit tests (those for statistics distributions). So, good argument for decent test coverage. This means that about half the purpose of the library has been non-functional since v1.0
The native calculation mode has been available since v1.1.0, however it only controls the behavior of arithmetical operations. None of the trigonometry or exponential methods take advantage of this setting currently, and these are some of the heaviest functions within the entire library.
Though their would eventually see benefit from the mode setting, once the operation had been reduced to a series of multiply, divide, add, and subtract operations, this is fundamentally unnecessary if the program has indicated it is alright with accepting the limitations of int and floats in PHP. The purpose of this setting is to allow a program to use this library as a common fluent interface for math itself, instead of arbitrary precision.
Related (and depending) on #18, update the sequence provider to be able to return sequences as number collections in the case that the developer needs to operate on the whole range in the sequence.
To start with, it should handle 1-dimensional functions of these types:
Should be able to:
Currently there is stuff that slips through, and the processes that I have in place are not very organized. This results in changes being made without corresponding tickets, or extremely lazy PR's that don't probably explain or track what is being merged and why.
By adopting some workflows that actually formalize all of this, it makes it easier for the changelog to be accurate, it encourages me to properly ticket and document what is being updated, and most importantly it makes it easier for others to contribute changes if anyone ever wishes to do so.
Add comments for all methods for /Types/Cartesian.php class
Is your feature request related to a problem? Please describe.
In combinatorics, derangements for a set of a given size can be given using the subfactorial method. This method appears in other places, including some probability distributions.
Describe the solution you'd like
The implementation is fairly straightforward:
function subfactorial($n) {
return floor( factorial($n)/$e + 0.5 ); // For $n > 0
}
Describe alternatives you've considered
This function is fairly simple, and so could easily be implemented by consumers of the library, but it seems an easy candidate for an implementation
The current base conversion library is a bit overkill for what this library needs, and it also presents some problems when it comes to keeping the library up to date with current versions of PHP.
To solve this, add a small BaseConversionProvider
.
BaseConversionProvider
getValue()
calls inside calculations to explicitly call NumberBase::Ten
to avoid calculation errors when an object's base is not 10.Despite the fact that Fermat was originally conceived of as an arbitrary precision expansion to the bcmath library (originally only because there was no way to do logs or trigonometry in bcmath), the PHP landscape has changed.
The ext-stats extension no longer exists for any supported versions of PHP, meaning that there aren't any decently complete stats options in PHP. Additionally, some of the other features such as a fraction type, matrix math, complex & imaginary numbers, and base conversion are not at all dependent on precision.
Thus, there is a real use for Fermat as nothing but a more complete math library that only worries about precision to the extent that other functions in PHP do.
In these cases, where the developer using the library wants the features of Fermat without the precision, a native implementation that is unconcerned with losing precision during arithmetic would likely be at least an order of magnitude faster.
To support this use case, there should be an option or supported development pattern that uses only native PHP functions to perform all math operations.
Similar to the calculation modes, it might be useful to create a run-time configuration for rounding modes to affect the behavior of the round()
and roundToScale()
methods.
Possible Rounding Modes Include:
Add comments for all methods of /Types/Vector.php class
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.