-
Notifications
You must be signed in to change notification settings - Fork 0
Avmath root
The avmath.__init__.py
file provides basic math features.
It can be used importing:
# pip install avmath
import avmath
Avmath includes the following constants:
Constant name | accessible name in module | accurate post comma decimal digits digits | Implemented in version | Last change |
---|---|---|---|---|
Pi (π) | avmath.pi | 21 | v1.0.0 | v3.0.0 |
Euler`s number (e) | avmath.e | 21 | v1.0.0 | v3.0.0 |
Golden ratio (φ) | avmath.phi | 21 | v3.0.0 | v3.0.0 |
Euler-Mascheroni constant (γ) | avmath.gamma | 21 | v3.0.0 | v3.0.0 |
Two digit prime numbers | avmath.two_digit_primes | - | v3.0.0 | v3.0.0 |
Constant name | Default value | usage | Implemented in version | Last change |
---|---|---|---|---|
avmath._TAYLOR_DIFFERENCE | 1e-16 | Loops of functions using Taylor-series calculate until the difference of the values is less equal this value | v3.0.0 | v3.0.0 |
avmath._MAX_CALCULATION_TIME | 5 | Some loops may need a long time for calculation. These loops may not calculate longer as this time (in seconds) | v3.0.0 | v3.0.0 |
avmath.REAL | typing.Union[int, float, 'Fraction'] | Real numbers for type hints | v3.0.0 | v3.0.0 |
avmath.scope | dictionary that contains all functions for REALs and Fraction | scope for analysis.Function | v2.0.0 | v3.1.1 |
Implemented in v3.0.0 | Last change v3.0.0
Avmath's fractions are used to bypass the float inaccuracies.
Attribute | Usage | Implemented in version | Last Change |
---|---|---|---|
self.a |
numerator | v3.0.0 | v3.0.0 |
self.b |
denominator | v3.0.0 | v3.0.0 |
All methods simulate an immutable type.
Implemented in v3.0.0 | Last change v3.1.0
Initialises Fraction with given numerator and denominator. Can contain float values too.
A fraction can be initialised by giving numerator and denominator as parameters to the constructor.
import avmath
my_fraction = avmath.Fraction(3, 7)
Now the fraction is initialised and is ready to be used. It is not automatically reduced and never reduced to int.
Implemented in v3.0.0 | Last change v3.0.0
Returns string representation of Fraction
. Gets always
printed in reduced shape.
import avmath
a = avmath.Fraction(2, 4)
b = avmath.Fraction(6, 3)
print(a)
print(b)
gives the output
1/2
2
Implemented in v3.0.0 | Last change v3.0.0
Returns negative fraction.
Implemented in v3.0.0 | Last change v3.0.0
Returns whether Fraction is equal to given REAL.
Implemented in v3.0.0 | Last change v3.0.0
Returns whether Fraction is less than given REAL.
Implemented in v3.0.0 | Last change v3.0.0
Returns whether Fraction is greater than given REAL.
Implemented in v3.0.0 | Last change v3.1.0
Adds a Fraction with a REAL. Return value is always a Fraction.
Implemented in v3.0.0 | Last change v3.1.0
Subtracts a REAL from a Fraction. Returns always Fractions.
Implemented in v3.0.0 | Last change v3.0.0
Multiplies a Fraction with a REAL.
Implemented in v3.0.0 | Last change v3.1.0
Divides a Fraction by a REAL.
Implemented in v3.0.0 | Last change v3.0.0
Power operation for Fraction and REAL. If power
=-1;
switches numerator and denominator.
Implemented in v3.0.0 | Last change v3.0.0
Power operation with Fraction as exponent.
Implemented in v3.0.0 | Last change v3.0.0
Modulo operation for Fraction and REAL.
Implemented in v3.0.0 | Last change v3.0.0
Returns integer representation of Fraction.
Implemented in v3.0.0 | Last change v3.0.0
Returns float representation of Fraction.
Implemented in v3.1.0 | Last change v3.1.0
Returns float representation of Fraction.
Implemented in v3.0.0 | Last change v3.0.0
Returns absolute of the Fraction.
Implemented in v3.0.0 | Last change v3.0.0
Returns reduced fraction.
Implemented in v3.0.0 | Last change v3.0.0
Returns whether the numerator and denominator are integers or integer-like.
Implemented in: v3.0.0 | Last change: v3.0.0
This function returns True if the integer x
is a prime number.
The method checks, whether the integer less than the square root of
the argument is divisible by any number.
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning True if the integer x
is an even number. Used by avmath.fac
.
Implemented in: v3.0.0 | Last change: v3.0.0
Function returning the greatest common divisor of two integers x
and y
.
Implemented in: v3.0.0 | Last change: v3.0.0
Function that returns the least common multiply of two integers x
and y
.
Implemented in: v3.0.0 | Last change: v3.0.0
Function that returns the signum of a number. For values <0 returns -1 for 0 returns 0 and for values >0 returns 1
Implemented in: v1.0.0 | Last change: v3.0.0
Function returning the faculty x! of a number.
Parameters for opt
:
-
'double'
: Returns double faculty [^1]
[^1]: Double faculty is an operation that factorizes all odd numbers less equal the value if the value is odd and all even numbers less equal the value if it is even
Implemented in: v1.0.0 | Last change: v3.0.0
Function that returns the natural logarithm of a number using
Taylor-series. Takes
only not negative values. Function is recommended to use for values
between 1e-300
and. 1e300
x domain | precise post comma decimal places |
---|---|
1e-300 to 1e300
|
12 |
1e-3 to 1e3
|
14 |
Implemented in: v1.0.0 | Last change: v1.0.0
Function that returns the logarithm of any base of a number. Returns only ln(x) / ln(base) and in this way is dependent to the natural logarithm.
Implemented in: v1.0.0 | Last change: v3.0.0
Sine function using Taylor -series. The function is recommended to use in the domain between -100'000 and 100'000 because of inaccuracies of the modulo operator that increase with the value.
x-domain | precise post comma decimal places |
---|---|
-1e4 to 1e4
|
12 |
-1e5 to 1e5
|
10 |
-1e6 to 1e6
|
9-10 |
Implemented in: v1.0.0 | Last change: v3.0.0
Function returning the cosine of a number using Taylor -series. Shares modulo problem with sine and is also recommended between -100'000 and 100'000.
x-domain | precise post comma decimal places |
---|---|
-1e4 to 1e4
|
12 |
-1e5 to 1e5
|
10 |
-1e6 to 1e6
|
9-10 |
Implemented in: v1.0.0 | Last change: v3.0.0
Function returning the tangent of a number calculating
sin(x) / cos(x)
. Shares modulo problem with sine and cosine
and is also inaccurate when approaching the asymptotes.
x-domain | precise post comma decimal places |
---|---|
-1e4 to 1e4 (normal case) |
12 |
-1e5 to 1e5 (normal case) |
10 |
-1e6 to 1e6 (normal case) |
9-10 |
1e-3 difference to asymptote |
10 |
1e-3 difference to asymptote |
7 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning the arc sine of a number -1 < x < 1 using
Taylor-series.
Calculation time increases when approaching |1|. Function may be stopped
by _MAX_CALCULATION_TIME
. Values of -1 and 1 are manually set.
Difference of x-value to abs(1)
|
precise post comma decimal places |
---|---|
0.1 to 0.9
|
15 |
0.01 to 0.1
|
13 |
0.001 to 0.01
|
4 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning the arc cosine of a number -1 < x < 1 using
arccos(x) = π / 2 - arcsin(x). Due to the usage of arcsin(x)
,
the accuracy stays the same.
Difference of x-value to abs(1)
|
precise post comma decimal places |
---|---|
0.1 to 0.9
|
15 |
0.01 to 0.1
|
13 |
0.001 to 0.01
|
4 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function that returns the arc tangent of a number using two Taylor-series. Calculation time increases when approaching |1|.
absolute of x-domain | precise post comma decimal places |
---|---|
0 to 0.9
|
14-15 |
at least 0.01 difference to 1 | 13-14 |
at least 0.001 difference to 1 | 13 |
1 |
6 |
Implemented in: v2.0.0 | Last change: v3.1.1
Function returning the hyperbolic sine of a number using Taylor-series. Does only work for x values |x| < 710 then throws ArgumentError.
x-domain | precise decimal places |
---|---|
-710 to 710
|
14-15 |
Implemented in: v2.0.0 | Last change: v3.1.1
Function returning the hyperbolic cosine of a number using Taylor-series. Does only work for x values |x| < 710 then throws ArgumentError.
x-domain | precise decimal places |
---|---|
-710 to 710
|
14-15 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning the hyperbolic tangent of a number using sinh(x) / cosh(x). When surpassing x-value 20, returns 1.0
x-domain | precise post comma decimal places |
---|---|
-20 to 20
|
14-15 |
abs(x) > 20 |
(returns 1.0) |
Implemented in: v2.0.0 | Last change: v3.0.0
Function that returns the inverse hyperbolic sine (Areasinus hyperbolicus)
of a number using Arsinh(x) = sgn(x) ln(|x| + sqrt(x² + 1)). Values
must lie between -1e150
and 1e150
else cause OverflowError.
x-domain | precise post comma decimal places |
---|---|
-1e150 to 1e150
|
13-14 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning the inverse hyperbolic cosine (Areacosinus hyperbolicus)
of a number x >= 1 using Arcosh(x) = ln(x + sqrt(x² - 1)). Values must lie
between -1e150
and 1e150
else cause OverflowError.
x-domain | precise post comma decimal places |
---|---|
-1e150 to 1e150
|
13-14 |
Implemented in: v2.0.0 | Last change: v3.0.0
Function returning the inverse hyperbolic tangent (Areatangens hyperbolicus) of a number -1 < x < 1. Therefore, uses Artanh(x) = 0.5 ln((1 + x) / (1 - x)).
x-domain | precise post comma decimal places |
---|---|
entire domain | 12-14 |
Implemented in: v3.0.0 | Last change: v3.0.0
Checks whether all items of the iterable object are of the given types.