Skip to content

Commit 8cd4c60

Browse files
author
Victor kariuki
committed
Pakeji Hisabati Documentation redo
1 parent b2de172 commit 8cd4c60

File tree

1 file changed

+186
-97
lines changed

1 file changed

+186
-97
lines changed

third_party/math/README.md

Lines changed: 186 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,247 @@
1-
# Math Package
2-
3-
4-
5-
## Explanation
6-
This math package provides a collection of mathematical functions and constants implemented in the Nuru programming language. These functions cover a wide range of mathematical operations, including trigonometric functions, logarithmic functions, and other common mathematical operations. Below is a detailed list of all methods along with their descriptions and examples:
1+
# Pakeji Hisabati (Math Package)
2+
3+
A math package written in pure Nuru by [VictorKariuki](https://github.com/VictorKariuki).
4+
5+
This package provides various mathematical functions and constants implemented in a custom programming language. It includes methods for `trigonometric functions`, `logarithmic functions`, `array operations`, and `utility functions`.
6+
7+
8+
## Usage
9+
To use the `pakeji hisabati` package and its third-party packages, follow the steps below:
10+
11+
1. Copy the `hisabati.nr` file and any required third-party package files into the same directory as your project.
12+
13+
2. Ensure that the third-party package file names end with the `.nr` extension and match the package names. For example, if the package name is `hisabati`, the corresponding file name should be `hisabati.nr`.
14+
15+
3. You can directly import the `hisabati.nr` package and any required third-party packages in your Nuru code using the `ingiza` keyword. For example:
16+
17+
```nuru
18+
tumia "hisabati.nr"
19+
```
20+
Example of usage:
21+
```nuru
22+
andika(hisabati.e())
23+
24+
## What is in
25+
These package covers a wide range of mathematical operations, including `basic arithmetic`, `trigonometry`, `exponential and logarithmic functions`, `rounding and comparison operations`, as well as some `utility and array operations`.
26+
27+
28+
Here's an overview of the available methods and their functionalities:
29+
The methods provided in the `hisabati` package can be classified into different categories based on their functionalities. Here is a classification of the methods:
30+
31+
1. Trigonometric Functions:
32+
- `cos(x)`
33+
- `sin(x)`
34+
- `tan(x)`
35+
- `acos(x)`
36+
- `asin(x)`
37+
- `atan(x)`
38+
39+
2. Hyperbolic Functions:
40+
- `cosh(x)`
41+
- `sinh(x)`
42+
- `tanh(x)`
43+
- `acosh(x)`
44+
- `asinh(x)`
45+
- `atanh(x)`
46+
47+
3. Exponential and Logarithmic Functions:
48+
- `exp(x)`
49+
- `expm1(x)`
50+
- `log(x)`
51+
- `log10(x)`
52+
- `log1p(x)`
53+
54+
4. Other Mathematical Functions:
55+
- `abs(namba)`
56+
- `ceil(x)`
57+
- `floor(x)`
58+
- `sqrt(x)`
59+
- `cbrt(x)`
60+
- `root(x, n)`
61+
- `hypot(values)`
62+
- `factorial(n)`
63+
64+
5. Rounding and Comparison Functions:
65+
- `round(x, method)`
66+
- `max(numbers)`
67+
- `min(numbers)`
68+
69+
6. Utility Functions:
70+
- `sign(x)`
71+
- `isNegative(num)`
72+
- `isInteger(num)`
73+
- `getIntegerPart(num)`
74+
75+
7. Array and List Operations:
76+
- `list(first, last, interval)`
77+
- `reduce(iterator, callback, initialValue)`
78+
79+
80+
### 1. Constants:
81+
- **PI**: Represents the mathematical constant `π`.
82+
- **e**: Represents `Euler's Number`.
83+
- **phi**: Represents the `Golden Ratio`.
84+
- **ln10**: Represents the `natural logarithm of 10`.
85+
- **ln2**: Represents the `natural logarithm of 2`.
86+
- **log10e**: Represents the `base 10 logarithm` of Euler's number `(e)`.
87+
- **log2e**: Represents the `base 2 logarithm` of Euler's number` (e)`.
88+
- **sqrt1_2**: Represents the `square root` of `1/2`.
89+
- **sqrt2**: Represents the `square root` of `2`.
90+
- **sqrt3**: Represents the `square root`of `3`.
91+
- **sqrt5**: Represents the `square root` of `5`.
92+
- **EPSILON**: Represents a small value (2.220446049250313e-16).
93+
94+
### 2. Methods:
795
896
1. **abs(namba)**
997
- Description: Calculates the absolute value of a number.
10-
- Example: `Hisabati.abs(-42)` returns `42`.
98+
- Example: `hisabati.abs(-42)` returns `42`.
1199
12100
2. **acos(x)**
13-
- Description: Calculates the arccosine (inverse cosine) of a number in radians.
14-
- Example: `Hisabati.acos(0.5)` returns the arccosine of 0.5.
101+
- Description: Calculates the arccosine of a number.
102+
- Example: `hisabati.acos(0.5)` returns `1.0471975511965979`.
15103
16104
3. **acosh(x)**
17105
- Description: Calculates the inverse hyperbolic cosine of a number.
18-
- Example: `Hisabati.acosh(2)` returns the inverse hyperbolic cosine of 2.
106+
- Example: `hisabati.acosh(2)` returns `1.3169578969248166`.
19107
20108
4. **arcsin(x)**
21-
- Description: Calculates the arcsine (inverse sine) of a number using a Taylor series.
22-
- Example: `Hisabati.arcsin(0.5)` returns the arcsine of 0.5.
109+
- Description: Calculates the arcsine of a number using the Taylor series.
110+
- Example: `hisabati.arcsin(0.5)` returns `0.5235987755982988`.
23111
24112
5. **arsinh(x)**
25113
- Description: Calculates the inverse hyperbolic sine of a number.
26-
- Example: `Hisabati.arsinh(1)` returns the inverse hyperbolic sine of 1.
114+
- Example: `hisabati.arsinh(2)` returns `1.4436354751788103`.
27115
28116
6. **atan(x)**
29-
- Description: Calculates the arctangent (inverse tangent) of a number in radians using a Taylor series.
30-
- Example: `Hisabati.atan(1)` returns the arctangent of 1.
117+
- Description: Calculates the arctangent of a number using the Taylor series.
118+
- Example: `hisabati.atan(1)` returns `0.7853981633974483`.
31119
32120
7. **atan2(y, x)**
33-
- Description: Calculates the angle in radians between the positive x-axis and the point (x, y).
34-
- Example: `Hisabati.atan2(1, 1)` returns the angle for the point (1, 1).
121+
- Description: Calculates the arctangent of the quotient of its arguments.
122+
- Example: `hisabati.atan2(1, 1)` returns `0.7853981633974483`.
35123
36124
8. **atanh(x)**
37125
- Description: Calculates the inverse hyperbolic tangent of a number.
38-
- Example: `Hisabati.atanh(0.5)` returns the inverse hyperbolic tangent of 0.5.
126+
- Example: `hisabati.atanh(0.5)` returns `0.5493061443340549`.
39127
40128
9. **cbrt(x)**
41129
- Description: Calculates the cube root of a number.
42-
- Example: `Hisabati.cbrt(8)` returns the cube root of 8.
130+
- Example: `hisabati.cbrt(8)` returns `2`.
43131
44-
10. **ceil(x)**
132+
10. **root(x, n)**
133+
- Description: Calculates the nth root of a number using the Newton-Raphson method.
134+
- Example: `hisabati.root(27, 3)` returns `3`.
135+
136+
11. **ceil(x)**
45137
- Description: Rounds up to the smallest integer greater than or equal to a given number.
46-
- Example: `Hisabati.ceil(4.2)` returns `5`.
138+
- Example: `hisabati.ceil(4.3)` returns `5`.
47139
48-
11. **cos(x, terms)**
49-
- Description: Calculates the cosine of a number in radians using a Taylor series.
50-
- Example: `Hisabati.cos(1)` returns the cosine of 1.
140+
12. **cos(x)**
141+
- Description: Calculates the cosine of an angle in radians using the Taylor series.
142+
- Example: `hisabati.cos(0)` returns `1`.
51143
52-
12. **cosh(x)**
144+
13. **cosh(x)**
53145
- Description: Calculates the hyperbolic cosine of a number.
54-
- Example: `Hisabati.cosh(2)` returns the hyperbolic cosine of 2.
146+
- Example: `hisabati.cosh(0)` returns `1`.
55147
56-
13. **exp(x, precision)**
57-
- Description: Calculates the value of the mathematical constant e raised to the power of x using a Taylor series.
58-
- Example: `Hisabati.exp(2)` returns `e^2`.
148+
14. **exp(x)**
149+
- Description: Calculates the value of Euler's number raised to the power of a given number.
150+
- Example: `hisabati.exp(2)` returns `7.38905609893065`.
59151
60-
14. **expm1(x)**
61-
- Description: Calculates the value of e^x - 1 using a Taylor series.
62-
- Example: `Hisabati.expm1(1)` returns `e - 1`.
152+
15. **expm1(x)**
153+
- Description: Calculates Euler's number raised to the power of a number minus 1.
154+
- Example: `hisabati.expm1(1)` returns `1.718281828459045`.
63155
64-
15. **floor(x)**
156+
16. **floor(x)**
65157
- Description: Rounds down to the largest integer less than or equal to a given number.
66-
- Example: `Hisabati.floor(4.9)` returns `4`.
67-
68-
16. **hypot(values)**
69-
- Description: Calculates the Euclidean norm (square root of the sum of squares) of a list of values.
70-
- Example: `Hisabati.hypot([3, 4])` returns `5`, which is the hypotenuse of a right triangle.
71-
72-
17. **log(x)**
73-
- Description: Calculates the natural logarithm of a number using a Taylor series.
74-
- Example: `Hisabati.log(2)` returns the natural logarithm of 2.
158+
- Example: `hisabati.floor(4.7)` returns `4`.
75159
76-
18. **log10(x)**
77-
- Description: Calculates the base 10 logarithm of a number using the natural logarithm.
78-
- Example: `Hisabati.log10(100)` returns `2`.
160+
17. **hypot(values)**
161+
- Description: Calculates the square root of the sum of squares of the given values.
162+
- Example: `hisabati.hypot([3, 4])` returns `5`.
79163
80-
19. **log1p(x)**
81-
- Description: Calculates the natural logarithm of 1 + x using a Taylor series.
82-
- Example: `Hisabati.log1p(0.5)` returns the natural logarithm of 1.5.
164+
18. **log(x)**
165+
- Description: Calculates the natural logarithm of a number.
166+
- Example: `hisabati.log(1)` returns `0`.
83167
84-
20. **log2(x)**
168+
19. **log10(x)**
169+
- Description: Calculates the base 10 logarithm of a number.
170+
- Example: `hisabati.log10(100)` returns `2`.
85171
172+
20. **log1p(x)**
173+
- Description: Calculates the natural logarithm of 1 plus the given number.
174+
- Example: `hisabati.log1p(1)` returns `0.6931471805599453`.
86175
176+
21. **log2(x)**
87177
- Description: Calculates the base 2 logarithm of a number.
88-
- Example: `Hisabati.log2(8)` returns `3`.
178+
- Example: `hisabati.log2(8)` returns `3`.
89179
90-
21. **max(numbers)**
91-
- Description: Returns the largest number from a list of numbers.
92-
- Example: `Hisabati.max([3, 7, 2, 9])` returns `9`.
180+
22. **max(numbers)**
181+
- Description: Finds the maximum value in a list of numbers.
182+
- Example: `hisabati.max([4, 2, 9, 5])` returns `9`.
93183
94-
22. **min(numbers)**
95-
- Description: Returns the smallest number from a list of numbers.
96-
- Example: `Hisabati.min([3, 7, 2, 9])` returns `2`.
184+
23. **min(numbers)**
185+
- Description: Finds the minimum value in a list of numbers.
186+
- Example: `hisabati.min([4, 2, 9, 5])` returns `2`.
97187
98-
23. **round(x, method)**
99-
- Description: Rounds a number to the nearest integer using different rounding methods.
100-
- Example: `Hisabati.round(3.6, "rpi")` rounds to the nearest integer (`4`) using "round half up."
188+
24. **round(x, method)**
189+
- Description: Rounds a number to the nearest integer using the specified method.
190+
- Example: `hisabati.round(4.6, "rpi")` returns `5`.
101191
102-
24. **sign(x)**
103-
- Description: Returns the sign of a number: `1` for positive, `-1` for negative, and `0` for zero.
104-
- Example: `Hisabati.sign(-7)` returns `-1`.
192+
25. **sign(x)**
193+
- Description: Determines the sign of a number.
194+
- Example: `hisabati.sign(-5)` returns `-1`.
105195
106-
25. **sin(x, terms)**
107-
- Description: Calculates the sine of a number in radians using a Taylor series.
108-
- Example: `Hisabati.sin(0.5)` returns the sine of 0.5.
196+
26. **sin(x)**
197+
- Description: Calculates the sine of an angle in radians using the Taylor series.
198+
- Example: `hisabati.sin(0)` returns `0`.
109199
110-
26. **sinh(x)**
200+
27. **sinh(x)**
111201
- Description: Calculates the hyperbolic sine of a number.
112-
- Example: `Hisabati.sinh(1)` returns the hyperbolic sine of 1.
202+
- Example: `hisabati.sinh(0)` returns `0`.
113203
114-
27. **sqrt(x)**
115-
- Description: Calculates the square root of a number using the Newton-Raphson method.
116-
- Example: `Hisabati.sqrt(16)` returns `4`.
204+
28. **sqrt(x)**
205+
- Description: Calculates the square root of a number.
206+
- Example: `hisabati.sqrt(4)` returns `2`.
117207
118-
28. **tangent(x)**
119-
- Description: Calculates the tangent of a number in radians.
120-
- Example: `Hisabati.tangent(1)` returns the tangent of 1.
208+
29. **tan(x)**
209+
- Description: Calculates the tangent of an angle in radians.
210+
- Example: `hisabati.tan(0)` returns `0`.
121211
122-
29. **tanh(x)**
212+
30. **tanh(x)**
123213
- Description: Calculates the hyperbolic tangent of a number.
124-
- Example: `Hisabati.tanh(0.5)` returns the hyperbolic tangent of 0.5.
125-
126-
30. **isNegativeZero(num)**
127-
- Description: Checks if a number is negative zero (0 with a negative sign).
128-
- Example: `Hisabati.isNegativeZero(-0)` returns `true`.
214+
- Example: `hisabati.tanh(0)` returns `0`.
129215
130216
31. **factorial(n)**
131217
- Description: Calculates the factorial of a number.
132-
- Example: `Hisabati.factorial(5)` returns `120`.
133-
134-
32. **pow(base, exponent)**
135-
- Description: Calculates the power of a number.
136-
- Example: `Hisabati.pow(2, 3)` returns `8`.
218+
- Example: `hisabati.factorial(5)` returns `120`.
137219
138-
33. **isNegative(num)**
220+
32. **isNegative(num)**
139221
- Description: Checks if a number is negative.
140-
- Example: `Hisabati.isNegative(-5)` returns `true`.
222+
- Example: `hisabati.isNegative(-5)` returns `true`.
141223
142-
34. **isInteger(num)**
224+
33. **isInteger(num)**
143225
- Description: Checks if a number is an integer.
144-
- Example: `Hisabati.isInteger(42)` returns `true`.
226+
- Example: `hisabati.isInteger(4.5)` returns `false`.
145227
146-
35. **getIntegerPart(num)**
228+
34. **getIntegerPart(num)**
147229
- Description: Gets the integer part of a number.
148-
- Example: `Hisabati.getIntegerPart(5.8)` returns `5`.
230+
- Example: `hisabati.getIntegerPart(4.5)` returns `4`.
231+
232+
35. **list(first, last, interval)**
233+
- Description: Creates a list of numbers with the specified interval between them.
234+
- Example: `hisabati.list(1, 5, 1)` returns `[1, 2, 3, 4]`.
235+
236+
36. **reduce(iterator, callback, initialValue)**
237+
- Description: Reduces the elements of an array to a single value using a specified callback function.
238+
- Example: `hisabati.reduce([1, 2, 3, 4], (accumulator, currentValue) => accumulator + currentValue, 0)` returns `10`.
239+
240+
241+
### Contributing
149242
150-
36. **list(first, last, interval)**
151-
- Description: Creates a list of numbers within a specified range with a given interval.
152-
- Example: `Hisabati.list(0, 10, 2)` returns `[0, 2, 4, 6, 8]`.
243+
Contributions to the `pakeji hisabati` package are welcome. If you have any improvements or bug fixes, feel free to create a pull request.
153244
154-
37. **square(n, i, j)**
155-
- Description: Finds the square root of a number using a method that iteratively narrows down the root.
156-
- Example: `Hisabati.square(16)` returns `4`.
245+
### License
157246
158-
Feel free to use this package for your mathematical calculations and applications.
247+
This package is available under the MIT License. See the [LICENSE](LICENSE) file for more information.

0 commit comments

Comments
 (0)