notation 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e23661f94f5bf2dfef11e26f2af11c958dfb06fe66d5d8dc5fa4332e71dfb80d
4
- data.tar.gz: 8a2e6bb2508c0b577d4497df812efe9c3ee1934619eb8466db19048b2a7239a2
3
+ metadata.gz: 36a4c918f1fa1b18facae1b46a6ce84f350434f6beeff794d6f759068762f0ac
4
+ data.tar.gz: 8b7fdbb5388cf332e791189fc399f192ea2ea47999eac90ecaf0a87186374480
5
5
  SHA512:
6
- metadata.gz: 2af0f7a4ea3413d9375687cd6bade35197e4db199b82168de9e5098b2542b32671a080186f88ce491158f056c9a6f9d27fa1ec60ff6b603724c0f96cb826d54c
7
- data.tar.gz: e708df538e3b930aff5f316c70773d3d0a1ce90b39548b0f2b4a455859e116a410b419856af93eeb1522b1bb94a2c632945fb055472f1efc9db2ee6415ca26ab
6
+ metadata.gz: 6d47b34b3651a4652d061b8fdb000440863f4e8c5b8b18808c466eb21ff673565311961a1dbce73f4a156283bf9d626b0a3bb6391a6ca93f861cc9b7fd273187
7
+ data.tar.gz: e0ba3d661748fded3a500f466f46ccc2f1786106926695b3c351435884393d900327aec1b1f832f36193223b6ad77627c909d9cf384dd7dd15544a474ea16734
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,6 +1,20 @@
1
- ## 0.2.2 - 22-Jun-2024
2
- * Rubocop config and cleanup.
3
- * Removed some old directives and comments.
1
+ ## 0.3.0 - 17-Jul-2025
2
+ * Major expansion of Unicode mathematical notation methods
3
+ * Improved (sigma) and ∏ (pi) methods to handle both arrays and individual arguments
4
+ * Added ∛ (cube root) method
5
+ * Added ∜ (fourth root) method
6
+ * Added || (absolute value) method
7
+ * Added ∞ (infinity) constant
8
+ * Added ! (factorial) method
9
+ * Added Δ (delta/difference) method
10
+ * Added ≈ (approximately equal) method
11
+ * Added ≠ (not equal) method
12
+ * Added ≤ (less than or equal) method
13
+ * Added ≥ (greater than or equal) method
14
+ * Added ± (plus or minus) method
15
+ * Added ° (degrees to radians) method
16
+ * Added % (percentage) method
17
+ * Enhanced documentation and test coverage
4
18
 
5
19
  ## 0.2.1 - 20-Feb-2021
6
20
  * Added metadata to the gemspec.
data/README.md CHANGED
@@ -13,11 +13,31 @@ Unicode methods for Ruby.
13
13
  ## Synopsis
14
14
  ```ruby
15
15
  require 'notation'
16
-
17
- λ { puts "hello" } # => "Hello"
18
- [1,2,3] # => 6
19
- ∏ [2,3,4] # => 24
20
- √ 49 # => 7.0
16
+
17
+ # Lambda notation
18
+ λ { puts "hello" } # => "Hello"
19
+
20
+ # Mathematical operations
21
+ ∑ [1,2,3] # => 6 (sum)
22
+ ∏ [2,3,4] # => 24 (product)
23
+ √ 49 # => 7.0 (square root)
24
+ ∛ 27 # => 3.0 (cube root)
25
+ ∜ 16 # => 2.0 (fourth root)
26
+ |-5| # => 5 (absolute value)
27
+ ! 5 # => 120 (factorial)
28
+
29
+ # Comparison operations
30
+ ≈ 3.14159, 3.14160, 0.001 # => true (approximately equal)
31
+ ≠ 5, 3 # => true (not equal)
32
+ ≤ 5, 10 # => true (less than or equal)
33
+ ≥ 10, 5 # => true (greater than or equal)
34
+
35
+ # Utility functions
36
+ Δ 10, 7 # => 3 (delta/difference)
37
+ ± 5, 2 # => [3, 7] (plus or minus)
38
+ ° 180 # => 3.14159... (degrees to radians)
39
+ % 50 # => 0.5 (percentage)
40
+ ∞ # => Float::INFINITY
21
41
  ```
22
42
 
23
43
  ## Author's Notes
@@ -30,11 +50,11 @@ The ability to add unicode methods is limited to method names that have
30
50
  no receiver. This is a limitation of the Ruby parser.
31
51
 
32
52
  ## Copyright
33
- (C) 2009-2024 Daniel J. Berger
53
+ (C) 2009-2021 Daniel J. Berger
34
54
  All Rights Reserved
35
55
 
36
56
  ## License
37
57
  Apache-2.0
38
-
58
+
39
59
  ## Author
40
60
  Daniel Berger
data/lib/notation.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Extend the core Kernel module
4
4
  module Kernel
5
5
  # Version of the notation library
6
- NOTATION_VERSION = '0.2.2'
6
+ NOTATION_VERSION = '0.3.0'
7
7
 
8
8
  # Make lambda a true lambda
9
9
  #
@@ -13,21 +13,27 @@ module Kernel
13
13
  alias λ proc
14
14
 
15
15
  # Sigma, i.e. the sum of all elements.
16
+ # Improved to handle arrays and individual arguments
16
17
  #
17
- # Example:
18
+ # Examples:
18
19
  # ∑ [1,2,3] => 6
20
+ # ∑ 1,2,3 => 6
19
21
  #
20
22
  def ∑(*args)
21
- args.inject(0){ |e, m| m + e }
23
+ args = args.first if args.length == 1 && args.first.respond_to?(:each)
24
+ args.inject(0) { |sum, element| sum + element }
22
25
  end
23
26
 
24
27
  # Pi product, i.e. the product of all elements.
28
+ # Improved to handle arrays and individual arguments
25
29
  #
26
- # Example:
30
+ # Examples:
27
31
  # ∏ [2,3,4] => 24
32
+ # ∏ 2,3,4 => 24
28
33
  #
29
34
  def ∏(*args)
30
- args.inject(1){ |e, m| m * e }
35
+ args = args.first if args.length == 1 && args.first.respond_to?(:each)
36
+ args.inject(1) { |product, element| product * element }
31
37
  end
32
38
 
33
39
  # Square root
@@ -35,7 +41,126 @@ module Kernel
35
41
  # Example:
36
42
  # √ 49 => 7.0
37
43
  #
38
- def √(root)
39
- Math.sqrt(root)
44
+ def √(value)
45
+ Math.sqrt(value)
46
+ end
47
+
48
+ # Cube root
49
+ #
50
+ # Example:
51
+ # ∛ 27 => 3.0
52
+ #
53
+ def ∛(value)
54
+ value < 0 ? -((-value) ** (1.0/3)) : value ** (1.0/3)
55
+ end
56
+
57
+ # Fourth root
58
+ #
59
+ # Example:
60
+ # ∜ 16 => 2.0
61
+ #
62
+ def ∜(value)
63
+ value ** (1.0/4)
64
+ end
65
+
66
+ # Absolute value
67
+ #
68
+ # Example:
69
+ # |-5| => 5
70
+ #
71
+ def |(value)
72
+ value.abs
73
+ end
74
+
75
+ # Infinity constant
76
+ #
77
+ # Example:
78
+ # ∞ => Float::INFINITY
79
+ #
80
+ def ∞
81
+ Float::INFINITY
82
+ end
83
+
84
+ # Factorial
85
+ #
86
+ # Example:
87
+ # ! 5 => 120
88
+ #
89
+ def !(n)
90
+ raise ArgumentError, 'Factorial is only defined for non-negative integers' if n < 0
91
+ return 1 if n == 0 || n == 1
92
+ (2..n).inject(1) { |result, i| result * i }
93
+ end
94
+
95
+ # Delta (difference between two values)
96
+ #
97
+ # Example:
98
+ # Δ 10, 7 => 3
99
+ #
100
+ def Δ(a, b)
101
+ (a - b).abs
102
+ end
103
+
104
+ # Approximately equal (within epsilon)
105
+ #
106
+ # Example:
107
+ # ≈ 3.14159, 3.14160, 0.001 => true
108
+ #
109
+ def ≈(a, b, epsilon = 1e-10)
110
+ (a - b).abs < epsilon
111
+ end
112
+
113
+ # Not equal
114
+ #
115
+ # Example:
116
+ # ≠ 5, 3 => true
117
+ #
118
+ def ≠(a, b)
119
+ a != b
120
+ end
121
+
122
+ # Less than or equal
123
+ #
124
+ # Example:
125
+ # ≤ 5, 10 => true
126
+ #
127
+ def ≤(a, b)
128
+ a <= b
129
+ end
130
+
131
+ # Greater than or equal
132
+ #
133
+ # Example:
134
+ # ≥ 10, 5 => true
135
+ #
136
+ def ≥(a, b)
137
+ a >= b
138
+ end
139
+
140
+ # Plus or minus (returns array with both values)
141
+ #
142
+ # Example:
143
+ # ± 5, 2 => [3, 7]
144
+ #
145
+ def ±(value, delta)
146
+ [value - delta, value + delta]
147
+ end
148
+
149
+ # Degrees to radians
150
+ #
151
+ # Example:
152
+ # ° 180 => 3.141592653589793
153
+ #
154
+ def °(degrees)
155
+ degrees * Math::PI / 180
156
+ end
157
+
158
+ # Percentage (divide by 100)
159
+ #
160
+ # Example:
161
+ # % 50 => 0.5
162
+ #
163
+ def %(value)
164
+ value / 100.0
40
165
  end
41
166
  end
data/notation.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'notation'
5
- spec.version = '0.2.2'
5
+ spec.version = '0.3.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.license = 'Apache-2.0'
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  'source_code_uri' => 'https://github.com/djberg96/notation',
29
29
  'wiki_uri' => 'https://github.com/djberg96/notation/wiki',
30
30
  'rubygems_mfa_required' => 'true',
31
- 'github_repo' => 'https://github.com/djberg96/notation'
31
+ 'github_repo' => 'https://github.com/djberg96/notation',
32
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
32
33
  }
33
34
  end
@@ -11,23 +11,108 @@ require 'notation'
11
11
 
12
12
  RSpec.describe 'Notation' do
13
13
  example 'version' do
14
- expect(Kernel::NOTATION_VERSION).to eq('0.2.2')
14
+ expect(Kernel::NOTATION_VERSION).to eq('0.3.0')
15
15
  expect(Kernel::NOTATION_VERSION).to be_frozen
16
16
  end
17
17
 
18
- example 'sigma' do
18
+ example 'sigma (sum)' do
19
19
  expect(Kernel).to respond_to(:∑)
20
20
  expect(∑(1, 2, 3)).to eq(6)
21
+ expect(∑([1, 2, 3])).to eq(6)
21
22
  end
22
23
 
23
- example 'pi' do
24
+ example 'pi (product)' do
24
25
  expect(Kernel).to respond_to(:∏)
25
26
  expect(∏(2, 3, 4)).to eq(24)
27
+ expect(∏([2, 3, 4])).to eq(24)
26
28
  end
27
29
 
28
30
  example 'square_root' do
29
31
  expect(Kernel).to respond_to(:√)
30
32
  expect(√(49)).to eq(7.0)
33
+ expect(√(16)).to eq(4.0)
34
+ end
35
+
36
+ example 'cube_root' do
37
+ expect(Kernel).to respond_to(:∛)
38
+ expect(∛(27)).to eq(3.0)
39
+ expect(∛(-8)).to eq(-2.0)
40
+ end
41
+
42
+ example 'fourth_root' do
43
+ expect(Kernel).to respond_to(:∜)
44
+ expect(∜(16)).to eq(2.0)
45
+ expect(∜(81)).to eq(3.0)
46
+ end
47
+
48
+ example 'absolute_value' do
49
+ expect(Kernel).to respond_to(:|)
50
+ expect(|(-5)).to eq(5)
51
+ expect(|(5)).to eq(5)
52
+ expect(|(0)).to eq(0)
53
+ end
54
+
55
+ example 'infinity' do
56
+ expect(Kernel).to respond_to(:∞)
57
+ expect(∞).to eq(Float::INFINITY)
58
+ end
59
+
60
+ example 'factorial' do
61
+ expect(Kernel).to respond_to(:!)
62
+ expect(!(5)).to eq(120)
63
+ expect(!(0)).to eq(1)
64
+ expect(!(1)).to eq(1)
65
+ expect { !(-1) }.to raise_error(ArgumentError)
66
+ end
67
+
68
+ example 'delta (difference)' do
69
+ expect(Kernel).to respond_to(:Δ)
70
+ expect(Δ(10, 7)).to eq(3)
71
+ expect(Δ(7, 10)).to eq(3)
72
+ end
73
+
74
+ example 'approximately_equal' do
75
+ expect(Kernel).to respond_to(:≈)
76
+ expect(≈(3.14159, 3.14160, 0.001)).to be true
77
+ expect(≈(3.14159, 3.15159, 0.001)).to be false
78
+ end
79
+
80
+ example 'not_equal' do
81
+ expect(Kernel).to respond_to(:≠)
82
+ expect(≠(5, 3)).to be true
83
+ expect(≠(5, 5)).to be false
84
+ end
85
+
86
+ example 'less_than_or_equal' do
87
+ expect(Kernel).to respond_to(:≤)
88
+ expect(≤(5, 10)).to be true
89
+ expect(≤(5, 5)).to be true
90
+ expect(≤(10, 5)).to be false
91
+ end
92
+
93
+ example 'greater_than_or_equal' do
94
+ expect(Kernel).to respond_to(:≥)
95
+ expect(≥(10, 5)).to be true
96
+ expect(≥(5, 5)).to be true
97
+ expect(≥(5, 10)).to be false
98
+ end
99
+
100
+ example 'plus_or_minus' do
101
+ expect(Kernel).to respond_to(:±)
102
+ expect(±(5, 2)).to eq([3, 7])
103
+ expect(±(10, 1)).to eq([9, 11])
104
+ end
105
+
106
+ example 'degrees_to_radians' do
107
+ expect(Kernel).to respond_to(:°)
108
+ expect(°(180)).to be_within(0.0001).of(Math::PI)
109
+ expect(°(90)).to be_within(0.0001).of(Math::PI / 2)
110
+ end
111
+
112
+ example 'percentage' do
113
+ expect(Kernel).to respond_to(:%)
114
+ expect(%(50)).to eq(0.5)
115
+ expect(%(100)).to eq(1.0)
31
116
  end
32
117
 
33
118
  example 'lambda' do
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2024-06-23 00:00:00.000000000 Z
38
+ date: 2025-07-17 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
@@ -95,7 +95,8 @@ metadata:
95
95
  wiki_uri: https://github.com/djberg96/notation/wiki
96
96
  rubygems_mfa_required: 'true'
97
97
  github_repo: https://github.com/djberg96/notation
98
- post_install_message:
98
+ funding_uri: https://github.com/sponsors/djberg96
99
+ post_install_message:
99
100
  rdoc_options: []
100
101
  require_paths:
101
102
  - lib
@@ -110,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 3.4.22
114
- signing_key:
114
+ rubygems_version: 3.5.22
115
+ signing_key:
115
116
  specification_version: 4
116
117
  summary: Unicode symbols that can be used as methods.
117
118
  test_files:
metadata.gz.sig CHANGED
Binary file