@@ -11,46 +11,44 @@ The library supports both targets: Erlang and JavaScript.
11
11
12
12
``` gleam
13
13
import gleam/float
14
- import gleam/iterator
15
- import gleam/option.{Some}
16
- import gleam_community/maths/arithmetics
17
- import gleam_community/maths/combinatorics.{WithoutRepetitions}
18
- import gleam_community/maths/elementary
19
- import gleam_community/maths/piecewise
20
- import gleam_community/maths/predicates
14
+ import gleam/yielder
15
+ import gleam_community/maths
21
16
import gleeunit/should
22
17
23
18
pub fn example() {
24
19
// Evaluate the sine function
25
- let result = elementary .sin(elementary .pi())
20
+ let result = maths .sin(maths .pi())
26
21
27
22
// Set the relative and absolute tolerance
28
- let assert Ok(absolute_tol) = elementary .power(10.0, -6.0)
23
+ let assert Ok(absolute_tol) = float .power(10.0, -6.0)
29
24
let relative_tol = 0.0
30
25
31
26
// Check that the value is very close to 0.0
32
27
// That is, if 'result' is within +/- 10^(-6)
33
- predicates .is_close(result, 0.0, relative_tol, absolute_tol)
28
+ maths .is_close(result, 0.0, relative_tol, absolute_tol)
34
29
|> should.be_true()
35
30
36
31
// Find the greatest common divisor
37
- arithmetics .gcd(54, 24)
32
+ maths .gcd(54, 24)
38
33
|> should.equal(6)
39
34
40
35
// Find the minimum and maximum of a list
41
- piecewise .extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
36
+ maths .extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
42
37
|> should.equal(Ok(#(3.0, 50.0)))
43
38
44
39
// Determine if a number is fractional
45
- predicates .is_fractional(0.3333)
40
+ maths .is_fractional(0.3333)
46
41
|> should.equal(True)
47
42
48
43
// Generate all k = 2 combinations of [1, 2, 3]
49
- let assert Ok(combinations) =
50
- combinatorics.list_combination([1, 2, 3], 2, Some(WithoutRepetitions))
44
+ let assert Ok(combinations) = maths.list_combination([1, 2, 3], 2)
51
45
combinations
52
- |> iterator .to_list()
46
+ |> yielder .to_list()
53
47
|> should.equal([[1, 2], [1, 3], [2, 3]])
48
+
49
+ // Compute the Cosine Similarity between two (orthogonal) vectors
50
+ maths.cosine_similarity([#(-1.0, 1.0), #(1.0, 1.0), #(0.0, -1.0)])
51
+ |> should.equal(Ok(0.0))
54
52
}
55
53
56
54
```
0 commit comments