notation 0.2.1 → 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: '09bbac1adce0c9a99319b9acbf60c52debeba9cc14b7eb7b6bfc6a2b5eb9878b'
4
- data.tar.gz: e6495aece79cbc99129e56884a2a06eb1194d5b28ed498e7fa52441c5f291c46
3
+ metadata.gz: 36a4c918f1fa1b18facae1b46a6ce84f350434f6beeff794d6f759068762f0ac
4
+ data.tar.gz: 8b7fdbb5388cf332e791189fc399f192ea2ea47999eac90ecaf0a87186374480
5
5
  SHA512:
6
- metadata.gz: 935d9d65981d2087654981d7688aaf56a7b06839bce8f0a731a8b1b5c56fe80b6ed1e176872aaf0a398d35b836bd81e02d58ec6e90d63c585abc0a49c8e265ba
7
- data.tar.gz: 4f2d8396ed4db4acdae2b39235559c50f202cb5b3adc4e325f22a618d4b87744fac9ebde228596b60fa54742bcac31a39a11305c108af951bdcc61fb39909565
6
+ metadata.gz: 6d47b34b3651a4652d061b8fdb000440863f4e8c5b8b18808c466eb21ff673565311961a1dbce73f4a156283bf9d626b0a3bb6391a6ca93f861cc9b7fd273187
7
+ data.tar.gz: e0ba3d661748fded3a500f466f46ccc2f1786106926695b3c351435884393d900327aec1b1f832f36193223b6ad77627c909d9cf384dd7dd15544a474ea16734
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,21 @@
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
18
+
1
19
  ## 0.2.1 - 20-Feb-2021
2
20
  * Added metadata to the gemspec.
3
21
 
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md CHANGED
@@ -1,17 +1,43 @@
1
+ [![Ruby](https://github.com/djberg96/notation/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/notation/actions/workflows/ruby.yml)
2
+
1
3
  ## Description
2
4
  Unicode methods for Ruby.
3
5
 
4
6
  ## Installation
5
7
  `gem install notation`
6
8
 
9
+ ## Installing the Trusted Cert
10
+
11
+ `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/notation/main/certs/djberg96_pub.pem)`
12
+
7
13
  ## Synopsis
8
14
  ```ruby
9
15
  require 'notation'
10
-
11
- λ { puts "hello" } # => "Hello"
12
- [1,2,3] # => 6
13
- ∏ [2,3,4] # => 24
14
- √ 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
15
41
  ```
16
42
 
17
43
  ## Author's Notes
@@ -29,6 +55,6 @@ All Rights Reserved
29
55
 
30
56
  ## License
31
57
  Apache-2.0
32
-
58
+
33
59
  ## Author
34
60
  Daniel Berger
data/Rakefile CHANGED
@@ -2,13 +2,13 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
- CLEAN.include("**/*.gem", "**/*.rbc")
5
+ CLEAN.include("**/*.gem", "**/*.rbc", "**/*.lock")
6
6
 
7
7
  namespace :gem do
8
8
  desc 'Build the notation gem'
9
9
  task :create => [:clean] do
10
10
  require 'rubygems/package'
11
- spec = eval(IO.read('notation.gemspec'))
11
+ spec = Gem::Specification.load('notation.gemspec')
12
12
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
13
  Gem::Package.build(spec)
14
14
  end
data/lib/notation.rb CHANGED
@@ -1,10 +1,9 @@
1
- # encoding: utf-8
2
-
3
- # Run with -Ku if using Ruby 1.8.
1
+ # frozen_string_literal: true
4
2
 
3
+ # Extend the core Kernel module
5
4
  module Kernel
6
5
  # Version of the notation library
7
- NOTATION_VERSION = '0.2.1'.freeze
6
+ NOTATION_VERSION = '0.3.0'
8
7
 
9
8
  # Make lambda a true lambda
10
9
  #
@@ -14,21 +13,27 @@ module Kernel
14
13
  alias λ proc
15
14
 
16
15
  # Sigma, i.e. the sum of all elements.
16
+ # Improved to handle arrays and individual arguments
17
17
  #
18
- # Example:
18
+ # Examples:
19
19
  # ∑ [1,2,3] => 6
20
+ # ∑ 1,2,3 => 6
20
21
  #
21
22
  def ∑(*args)
22
- 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 }
23
25
  end
24
26
 
25
27
  # Pi product, i.e. the product of all elements.
28
+ # Improved to handle arrays and individual arguments
26
29
  #
27
- # Example:
30
+ # Examples:
28
31
  # ∏ [2,3,4] => 24
32
+ # ∏ 2,3,4 => 24
29
33
  #
30
34
  def ∏(*args)
31
- 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 }
32
37
  end
33
38
 
34
39
  # Square root
@@ -36,7 +41,126 @@ module Kernel
36
41
  # Example:
37
42
  # √ 49 => 7.0
38
43
  #
39
- def √(root)
40
- 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
41
165
  end
42
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.1'
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'
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
15
  spec.add_development_dependency('rake')
16
+ spec.add_development_dependency('rspec', '~> 3.9')
16
17
 
17
18
  spec.description = <<-EOF
18
19
  The notation library provides unicode symbols that you can use as
@@ -20,11 +21,14 @@ Gem::Specification.new do |spec|
20
21
  EOF
21
22
 
22
23
  spec.metadata = {
23
- 'homepage_uri' => 'https://github.com/djberg96/notation',
24
- 'bug_tracker_uri' => 'https://github.com/djberg96/notation/issues',
25
- 'changelog_uri' => 'https://github.com/djberg96/notation/blob/master/CHANGES.md',
26
- 'documentation_uri' => 'https://github.com/djberg96/notation/wiki',
27
- 'source_code_uri' => 'https://github.com/djberg96/notation',
28
- 'wiki_uri' => 'https://github.com/djberg96/notation/wiki'
24
+ 'homepage_uri' => 'https://github.com/djberg96/notation',
25
+ 'bug_tracker_uri' => 'https://github.com/djberg96/notation/issues',
26
+ 'changelog_uri' => 'https://github.com/djberg96/notation/blob/πρῶτον/CHANGES.md',
27
+ 'documentation_uri' => 'https://github.com/djberg96/notation/wiki',
28
+ 'source_code_uri' => 'https://github.com/djberg96/notation',
29
+ 'wiki_uri' => 'https://github.com/djberg96/notation/wiki',
30
+ 'rubygems_mfa_required' => 'true',
31
+ 'github_repo' => 'https://github.com/djberg96/notation',
32
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
29
33
  }
30
34
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  ################################################################
3
4
  # notation_spec.rb
4
5
  #
@@ -8,28 +9,113 @@
8
9
  require 'rspec'
9
10
  require 'notation'
10
11
 
11
- RSpec.describe "Notation" do
12
- example "version" do
13
- expect(Kernel::NOTATION_VERSION).to eq('0.2.1')
12
+ RSpec.describe 'Notation' do
13
+ example 'version' do
14
+ expect(Kernel::NOTATION_VERSION).to eq('0.3.0')
14
15
  expect(Kernel::NOTATION_VERSION).to be_frozen
15
16
  end
16
17
 
17
- example "sigma" do
18
+ example 'sigma (sum)' do
18
19
  expect(Kernel).to respond_to(:∑)
19
- expect(∑(1,2,3)).to eq(6)
20
+ expect(∑(1, 2, 3)).to eq(6)
21
+ expect(∑([1, 2, 3])).to eq(6)
20
22
  end
21
23
 
22
- example "pi" do
24
+ example 'pi (product)' do
23
25
  expect(Kernel).to respond_to(:∏)
24
- expect(∏(2,3,4)).to eq(24)
26
+ expect(∏(2, 3, 4)).to eq(24)
27
+ expect(∏([2, 3, 4])).to eq(24)
25
28
  end
26
29
 
27
- example "square_root" do
30
+ example 'square_root' do
28
31
  expect(Kernel).to respond_to(:√)
29
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)
30
116
  end
31
117
 
32
- example "lambda" do
118
+ example 'lambda' do
33
119
  expect(λ{ 'hello' }.call).to eq('hello')
34
120
  end
35
121
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2021-02-20 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
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.9'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.9'
54
68
  description: |2
55
69
  The notation library provides unicode symbols that you can use as
56
70
  methods instead of using standard method names.
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - CHANGES.md
77
+ - Gemfile
63
78
  - LICENSE
64
79
  - MANIFEST.md
65
80
  - README.md
@@ -74,10 +89,13 @@ licenses:
74
89
  metadata:
75
90
  homepage_uri: https://github.com/djberg96/notation
76
91
  bug_tracker_uri: https://github.com/djberg96/notation/issues
77
- changelog_uri: https://github.com/djberg96/notation/blob/master/CHANGES.md
92
+ changelog_uri: https://github.com/djberg96/notation/blob/πρῶτον/CHANGES.md
78
93
  documentation_uri: https://github.com/djberg96/notation/wiki
79
94
  source_code_uri: https://github.com/djberg96/notation
80
95
  wiki_uri: https://github.com/djberg96/notation/wiki
96
+ rubygems_mfa_required: 'true'
97
+ github_repo: https://github.com/djberg96/notation
98
+ funding_uri: https://github.com/sponsors/djberg96
81
99
  post_install_message:
82
100
  rdoc_options: []
83
101
  require_paths:
@@ -93,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
111
  - !ruby/object:Gem::Version
94
112
  version: '0'
95
113
  requirements: []
96
- rubygems_version: 3.0.3
114
+ rubygems_version: 3.5.22
97
115
  signing_key:
98
116
  specification_version: 4
99
117
  summary: Unicode symbols that can be used as methods.
metadata.gz.sig CHANGED
Binary file