symbols 0.0.1
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.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +16 -0
- data/README.md +125 -0
- data/Rakefile +11 -0
- data/lib/math/comparison.rb +15 -0
- data/lib/math/constants.rb +11 -0
- data/lib/math/frac.rb +18 -0
- data/lib/math/logarithm.rb +12 -0
- data/lib/math/mod.rb +6 -0
- data/lib/math/numeric.rb +14 -0
- data/lib/math/numeric_pair.rb +52 -0
- data/lib/math/plus_minus.rb +28 -0
- data/lib/math/power.rb +8 -0
- data/lib/math/root.rb +16 -0
- data/lib/ruby/lambda.rb +4 -0
- data/lib/set/number_set.rb +22 -0
- data/lib/set/set.rb +41 -0
- data/lib/symbols.rb +14 -0
- data/symbols.gemspec +16 -0
- data/test/math/comparison_test.rb +27 -0
- data/test/math/constants_test.rb +44 -0
- data/test/math/frac_test.rb +22 -0
- data/test/math/logarithm_test.rb +15 -0
- data/test/math/mod_test.rb +9 -0
- data/test/math/numeric_pair_test.rb +75 -0
- data/test/math/numeric_test.rb +16 -0
- data/test/math/plus_minus_test.rb +18 -0
- data/test/math/power_test.rb +11 -0
- data/test/math/root_test.rb +27 -0
- data/test/ruby/lambda_test.rb +11 -0
- data/test/set/number_set_test.rb +40 -0
- data/test/set/set_test.rb +77 -0
- data/test/test_helper.rb +2 -0
- metadata +117 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# symbols
|
2
|
+
|
3
|
+
This small library defines constants, aliases and some originial math functionality for a lot of UTF-8 symbols and combinations thereof.
|
4
|
+
|
5
|
+
Warning: This gem pollutes the Kernel module and extends built-in classes. If you don't like that, don't use it.
|
6
|
+
|
7
|
+
## install
|
8
|
+
|
9
|
+
There seems to be a problem with RDoc, ri and UTF-8 characters. So install the gem manually without documentation like this
|
10
|
+
|
11
|
+
gem install symbols --no-rdoc --no-ri
|
12
|
+
|
13
|
+
## example
|
14
|
+
|
15
|
+
Here are some examples (See the tests for more examples):
|
16
|
+
|
17
|
+
### constants
|
18
|
+
|
19
|
+
e, i, π, ∞, etc. are all defined.
|
20
|
+
|
21
|
+
e**(i*π)+1
|
22
|
+
|
23
|
+
### fractions
|
24
|
+
|
25
|
+
Most common fractions are defined, for example:
|
26
|
+
|
27
|
+
⅛, ⅕, ¼, ⅓, ½, ¾, ⅚ and ⅞
|
28
|
+
|
29
|
+
### comparison
|
30
|
+
|
31
|
+
Short cuts for comparison operators
|
32
|
+
|
33
|
+
3.≤ 4
|
34
|
+
4.≥ 3
|
35
|
+
5.≠ 10
|
36
|
+
ϵ.≈ 0.0
|
37
|
+
|
38
|
+
### logarithm
|
39
|
+
|
40
|
+
For any number _n_ between 1 and 10, a log_n_ function is defined, with _n_ as subscript:
|
41
|
+
|
42
|
+
log₂(64)
|
43
|
+
log₁₀(10)
|
44
|
+
|
45
|
+
### plus-minus
|
46
|
+
|
47
|
+
The plus-minus and minus-plus operators are defined. With them, you can calculate e.g. the quadratic formula like this:
|
48
|
+
|
49
|
+
(-b.±(√(b.²-4*a*c)))/2*a
|
50
|
+
|
51
|
+
### power
|
52
|
+
|
53
|
+
For any number _n_ between 0 and 9, there is a function n defined on Numeric, where _n_ is a superscript, that calculates the _n_th power of the caller.
|
54
|
+
|
55
|
+
4 == 2.²
|
56
|
+
16 == 2.⁴
|
57
|
+
|
58
|
+
### root
|
59
|
+
|
60
|
+
There is a root function:
|
61
|
+
|
62
|
+
√(4) == 2
|
63
|
+
|
64
|
+
For common roots, constants are defined:
|
65
|
+
|
66
|
+
√2
|
67
|
+
√3
|
68
|
+
√5
|
69
|
+
|
70
|
+
Also, for any number _n_ between 1 and 9, there is a function defined that calculates the _n_th root:
|
71
|
+
|
72
|
+
³√(8)
|
73
|
+
⁴√(16)
|
74
|
+
⁵√(32)
|
75
|
+
|
76
|
+
### sets
|
77
|
+
|
78
|
+
Common set operators are defined:
|
79
|
+
|
80
|
+
[1,2,3].⊆([1,2,3,4,5])
|
81
|
+
[1,2,3].⊂([1,2,3,4,5])
|
82
|
+
[1,2,3,4,5].⊇([1,2,3,4,5])
|
83
|
+
[1,2,3,4,5].⊃([1,2,3])
|
84
|
+
[1,2].∪([5,6])
|
85
|
+
[1,2,5].∩([2,5,6])
|
86
|
+
[1,2,5].∖([2,5,6])
|
87
|
+
|
88
|
+
"Element of" and "Not element of" are defined on Object. They work for classes, containers and anything that responds to "include?":
|
89
|
+
|
90
|
+
4.∈([4,5,6])
|
91
|
+
"foo".∈(["foo", "bar", "baz"])
|
92
|
+
4.∈(1..10)
|
93
|
+
5.∉(1..3)
|
94
|
+
5.0.∉(Fixnum)
|
95
|
+
3.∉(String)
|
96
|
+
|
97
|
+
### number sets
|
98
|
+
|
99
|
+
The following sets are defined (Warning: These are not just capital letters; they are the double-struck capital letters you know from math lessons):
|
100
|
+
|
101
|
+
ℤ - Integers
|
102
|
+
ℕ - Positive integers
|
103
|
+
ℚ - Rational numbers
|
104
|
+
ℝ - Floats
|
105
|
+
ℂ - Complex
|
106
|
+
𝔹 - Booleans
|
107
|
+
|
108
|
+
Use them in combination with the "Element of" function:
|
109
|
+
|
110
|
+
20.∈(ℕ)
|
111
|
+
-1.∈(ℤ)
|
112
|
+
Rational(4,5).∈(ℚ)
|
113
|
+
π.∈(ℝ)
|
114
|
+
i.∈(ℂ)
|
115
|
+
false.∈(𝔹)
|
116
|
+
|
117
|
+
### ruby
|
118
|
+
|
119
|
+
The lambda function got the short cut λ:
|
120
|
+
|
121
|
+
λ { |x| x ** 2 }
|
122
|
+
|
123
|
+
# fork
|
124
|
+
|
125
|
+
Feel free to fork and submit pull requests!
|
data/Rakefile
ADDED
data/lib/math/frac.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Kernel
|
3
|
+
const_def :⅛ => 0.125,
|
4
|
+
:⅙ => 1.0/6.0,
|
5
|
+
:⅕ => 0.2,
|
6
|
+
:¼ => 0.25,
|
7
|
+
:⅓ => 1.0/3.0,
|
8
|
+
:⅜ => 0.375,
|
9
|
+
:⅖ => 0.4,
|
10
|
+
:½ => 0.5,
|
11
|
+
:⅗ => 0.6,
|
12
|
+
:⅝ => 0.625,
|
13
|
+
:⅔ => 2.0/3.0,
|
14
|
+
:¾ => 0.75,
|
15
|
+
:⅘ => 0.8,
|
16
|
+
:⅚ => 5.0/6.0,
|
17
|
+
:⅞ => 0.875
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Kernel
|
3
|
+
[:₁, :₂, :₃, :₄, :₅, :₆, :₇, :₈, :₉, :₁₀].each_with_index do |name, index|
|
4
|
+
define_method "log#{name}" do |val|
|
5
|
+
Math.log(val) / Math.log(index + 1)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def ln(val)
|
10
|
+
Math.log(val) / Math.log(e)
|
11
|
+
end
|
12
|
+
end
|
data/lib/math/mod.rb
ADDED
data/lib/math/numeric.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
class NumericPair
|
3
|
+
attr_accessor :first, :second
|
4
|
+
|
5
|
+
def initialize(first, second)
|
6
|
+
@first, @second = first, second
|
7
|
+
end
|
8
|
+
|
9
|
+
def ±(other)
|
10
|
+
if other.is_a?(NumericPair)
|
11
|
+
NumericPair.new(first + other.first, second - other.second)
|
12
|
+
else
|
13
|
+
NumericPair.new(first + other, second - other)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def ∓(other)
|
18
|
+
if other.is_a?(NumericPair)
|
19
|
+
NumericPair.new(first - other.first, second + other.second)
|
20
|
+
else
|
21
|
+
NumericPair.new(first - other, second + other)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method, *args)
|
26
|
+
if first.respond_to?(method) && second.respond_to?(method)
|
27
|
+
NumericPair.new(first.send(method, *args), second.send(method, *args))
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_a
|
34
|
+
[first, second]
|
35
|
+
end
|
36
|
+
|
37
|
+
def sort
|
38
|
+
NumericPair.new(*to_a.sort)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_range
|
42
|
+
first..second
|
43
|
+
end
|
44
|
+
|
45
|
+
def ==(other)
|
46
|
+
first == other.first && second == other.second
|
47
|
+
end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
to_a.inspect
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
class Numeric
|
3
|
+
def ±(other = nil)
|
4
|
+
if other
|
5
|
+
NumericPair.new(self + other, self - other)
|
6
|
+
else
|
7
|
+
NumericPair.new(self, -self)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def ∓(other = nil)
|
12
|
+
if other
|
13
|
+
NumericPair.new(self - other, self + other)
|
14
|
+
else
|
15
|
+
NumericPair.new(-self, self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Kernel
|
21
|
+
def ±(numeric)
|
22
|
+
numeric.±
|
23
|
+
end
|
24
|
+
|
25
|
+
def ∓(numeric)
|
26
|
+
numeric.∓
|
27
|
+
end
|
28
|
+
end
|
data/lib/math/power.rb
ADDED
data/lib/math/root.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Kernel
|
3
|
+
def √(val)
|
4
|
+
Math.sqrt(val)
|
5
|
+
end
|
6
|
+
|
7
|
+
const_def :√2 => √(2),
|
8
|
+
:√3 => √(3),
|
9
|
+
:√5 => √(5)
|
10
|
+
|
11
|
+
[:¹, :², :³, :⁴, :⁵, :⁶, :⁷, :⁸, :⁹].each_with_index do |name, index|
|
12
|
+
define_method "#{name}√" do |val|
|
13
|
+
val ** (1.0 / (index + 1).to_f)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ruby/lambda.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'complex'
|
3
|
+
require 'rational'
|
4
|
+
|
5
|
+
class NumberSet
|
6
|
+
def initialize(&block)
|
7
|
+
@block = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def include?(value)
|
11
|
+
@block.call(value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Kernel
|
16
|
+
const_def :ℤ => Fixnum,
|
17
|
+
:ℕ => NumberSet.new { |val| val.∈(ℤ) && val > 0 },
|
18
|
+
:ℚ => NumberSet.new { |val| val.∈(ℤ) || val.∈(Rational) },
|
19
|
+
:ℝ => NumberSet.new { |val| val.∈(ℚ) || val.∈(Float) },
|
20
|
+
:ℂ => NumberSet.new { |val| val.∈(ℝ) || val.∈(Complex) },
|
21
|
+
:𝔹 => [true, false]
|
22
|
+
end
|
data/lib/set/set.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Enumerable
|
3
|
+
alias ∀ all?
|
4
|
+
alias ∃ find
|
5
|
+
end
|
6
|
+
|
7
|
+
class Array
|
8
|
+
def ⊆(other)
|
9
|
+
∀ { |val| val.∈ other }
|
10
|
+
end
|
11
|
+
|
12
|
+
def ⊂(other)
|
13
|
+
⊆(other) && self.≠(other)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ⊇(other)
|
17
|
+
other.⊆(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ⊃(other)
|
21
|
+
other.⊂(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
alias ∪ |
|
25
|
+
alias ∩ &
|
26
|
+
alias ∖ -
|
27
|
+
end
|
28
|
+
|
29
|
+
class Object
|
30
|
+
def ∈(container)
|
31
|
+
if container.is_a?(Class)
|
32
|
+
self.is_a?(container)
|
33
|
+
else
|
34
|
+
container.include?(self)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def ∉(container)
|
39
|
+
!∈(container)
|
40
|
+
end
|
41
|
+
end
|
data/lib/symbols.rb
ADDED
data/symbols.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = "symbols"
|
4
|
+
s.version = "0.0.1"
|
5
|
+
s.authors = ["Thomas Kadauke"]
|
6
|
+
s.email = ["thomas.kadauke@googlemail.com"]
|
7
|
+
s.homepage = "https://github.com/tkadauke/symbols"
|
8
|
+
s.summary = "Defines UTF-8 symbols for common math concepts"
|
9
|
+
s.description = "Defines UTF-8 symbols for common math concepts"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split($\)
|
12
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
|
15
|
+
s.add_development_dependency 'rake'
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class ComparisonTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_lower_equal_operator
|
6
|
+
assert 3.≤ 4
|
7
|
+
assert 2.5.≤ 4
|
8
|
+
assert 5.≤ 5
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_define_greater_equal_operator
|
12
|
+
assert 4.≥ 3
|
13
|
+
assert 4.≥ 2.5
|
14
|
+
assert 5.≥ 5
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_define_inequality_operator
|
18
|
+
assert 5.≠ 10
|
19
|
+
assert 2.0.≠ 4
|
20
|
+
assert !(4.≠ 4)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_define_approximate_equality_operator
|
24
|
+
assert 3.≈(3)
|
25
|
+
assert ϵ.≈(0.0)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class ConstantsTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_pi
|
6
|
+
assert respond_to?(:π)
|
7
|
+
assert_equal Math::PI, π
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_define_tau
|
11
|
+
assert respond_to?(:τ)
|
12
|
+
assert_equal 2*π, τ
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_define_e
|
16
|
+
assert respond_to?(:e)
|
17
|
+
assert_equal Math::E, e
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_define_i
|
21
|
+
assert respond_to?(:i)
|
22
|
+
assert_equal Complex::I, i
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_define_epsilon
|
26
|
+
assert respond_to?(:ϵ)
|
27
|
+
assert_equal Float::EPSILON, ϵ
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_define_infinity
|
31
|
+
assert respond_to?(:∞)
|
32
|
+
assert -∞ < ∞
|
33
|
+
assert ∞ > -∞
|
34
|
+
assert ∞ == ∞
|
35
|
+
assert ∞ <= ∞
|
36
|
+
assert ∞ >= ∞
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_allow_nice_euler_formula
|
40
|
+
v = e**(i*π)+1
|
41
|
+
assert v.real == 0
|
42
|
+
assert v.imag.≈ 0
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class FracTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_fractions
|
6
|
+
assert ⅛ == 0.125
|
7
|
+
assert ⅙ == 1.0/6.0
|
8
|
+
assert ⅕ == 0.2
|
9
|
+
assert ¼ == 0.25
|
10
|
+
assert ⅓ == 1.0/3.0
|
11
|
+
assert ⅜ == 0.375
|
12
|
+
assert ⅖ == 0.4
|
13
|
+
assert ½ == 0.5
|
14
|
+
assert ⅗ == 0.6
|
15
|
+
assert ⅝ == 0.625
|
16
|
+
assert ⅔ == 2.0/3.0
|
17
|
+
assert ¾ == 0.75
|
18
|
+
assert ⅘ == 0.8
|
19
|
+
assert ⅚ == 5.0/6.0
|
20
|
+
assert ⅞ == 0.875
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class LogarithmTest < Test::Unit::TestCase
|
5
|
+
def test_should_calculate_logarithms
|
6
|
+
assert_equal 2, log₂(4)
|
7
|
+
assert_equal 6, log₂(64)
|
8
|
+
assert_equal 1, log₁₀(10)
|
9
|
+
assert_equal 2, log₁₀(100)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_calculate_ln
|
13
|
+
assert_equal 1, ln(e)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class NumericPairTest < Test::Unit::TestCase
|
5
|
+
def test_should_initialize
|
6
|
+
pair = NumericPair.new(1, 2)
|
7
|
+
assert_equal [1, 2], pair.to_a
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_initialize_from_plus_minus
|
11
|
+
pair = 5.±(2)
|
12
|
+
assert_equal [7, 3], pair.to_a
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_initialize_from_minus_plus
|
16
|
+
pair = 5.∓(2)
|
17
|
+
assert_equal [3, 7], pair.to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_allow_chain_of_plus_minus_with_number
|
21
|
+
pair = 5.±(2).±(1)
|
22
|
+
assert_equal [8, 2], pair.to_a
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_allow_chain_of_plus_minus_with_pair
|
26
|
+
pair = 5.±(2).±(1.±(1))
|
27
|
+
assert_equal [9, 3], pair.to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_allow_chain_of_minus_plus_with_number
|
31
|
+
pair = 5.±(2).∓(1)
|
32
|
+
assert_equal [6, 4], pair.to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_allow_chain_of_minus_plus_with_pair
|
36
|
+
pair = 5.±(2).∓(1.±(1))
|
37
|
+
assert_equal [5, 3], pair.to_a
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_allow_numeric_operators
|
41
|
+
assert_equal [6, 4], (3.±(1) + 2).to_a
|
42
|
+
assert_equal [2, 0], (3.±(1) - 2).to_a
|
43
|
+
assert_equal [2, 1], (3.±(1) / 2).to_a
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_convert_to_range
|
47
|
+
assert_equal (2..4), 3.∓(1).to_range
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_inspect
|
51
|
+
assert_equal '[4, 2]', 3.±(1).inspect
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_sort
|
55
|
+
assert_equal [2, 3], NumericPair.new(2, 3).sort.to_a
|
56
|
+
assert_equal [-2, 4], NumericPair.new(4, -2).sort.to_a
|
57
|
+
assert_equal 4.±(2).sort, 4.∓(2).sort
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_test_for_equality
|
61
|
+
assert NumericPair.new(2, 3) == NumericPair.new(2, 3)
|
62
|
+
assert !(NumericPair.new(2, 3) == NumericPair.new(3, 4))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_test_for_inequality
|
66
|
+
assert !(NumericPair.new(2, 3) != NumericPair.new(2, 3))
|
67
|
+
assert NumericPair.new(2, 3) != NumericPair.new(3, 4)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_solve_quadratic_formula
|
71
|
+
a = 1; b = 0; c = -4
|
72
|
+
pair = (-b.±(√(b.²-4*a*c)))/2*a
|
73
|
+
assert_equal [-2, 2], pair.to_a
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class NumericTest < Test::Unit::TestCase
|
5
|
+
def test_should_multiply_with_x_operator
|
6
|
+
assert_equal 15, 3.×(5)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_calculate_promille
|
10
|
+
assert_equal 0.001, 1.‰
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_calculate_pro_ten_thousand
|
14
|
+
assert_equal 0.0001, 1.‱
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class PlusMinusTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_unary_plus_minus_operator
|
6
|
+
assert_equal [3, -3], 3.±.to_a
|
7
|
+
assert_equal [∞, -∞], ∞.±.to_a
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_define_binary_plus_minus_operator
|
11
|
+
assert_equal [8, 2], 5.±(3).to_a
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_define_plus_minus_prefix
|
15
|
+
assert_equal [3, -3], ±(3).to_a
|
16
|
+
assert_equal [∞, -∞], ±(∞).to_a
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class PowerTest < Test::Unit::TestCase
|
5
|
+
def test_should_calculate_powers
|
6
|
+
assert_equal 1, 2.⁰
|
7
|
+
assert_equal 4, 2.²
|
8
|
+
assert_equal 16, 2.⁴
|
9
|
+
assert_equal 64, 2.⁶
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class RootTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_sqrt_2
|
6
|
+
assert_equal √(2), √2
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_define_sqrt_3
|
10
|
+
assert_equal √(3), √3
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_define_sqrt_5
|
14
|
+
assert_equal √(5), √5
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_define_square_root
|
18
|
+
assert_equal 2, √(4)
|
19
|
+
assert_equal Math.sqrt(5), √(5)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_calculate_roots
|
23
|
+
assert_equal 2, ³√(8)
|
24
|
+
assert_equal 2, ⁴√(16)
|
25
|
+
assert_equal 2, ⁵√(32)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class NumberSetTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_natural_number_set
|
6
|
+
assert ! -1.∈(ℕ)
|
7
|
+
assert 20.∈(ℕ)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_define_integer_number_set
|
11
|
+
assert 20.∈(ℤ)
|
12
|
+
assert -1.∈(ℤ)
|
13
|
+
assert ! 10.5.∈(ℤ)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_define_integer_number_set
|
17
|
+
assert Rational(4,5).∈(ℚ)
|
18
|
+
assert 20.∈(ℚ)
|
19
|
+
assert ! 10.5.∈(ℚ)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_define_real_number_set
|
23
|
+
assert π.∈(ℝ)
|
24
|
+
assert √2.∈(ℝ)
|
25
|
+
assert 20.5.∈(ℝ)
|
26
|
+
assert Rational(4,5).∈(ℝ)
|
27
|
+
assert -1.∈(ℝ)
|
28
|
+
assert ! i.∈(ℝ)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_define_complex_number_set
|
32
|
+
assert √2.∈(ℂ)
|
33
|
+
assert i.∈(ℂ)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_define_boolean_number_set
|
37
|
+
assert true.∈(𝔹)
|
38
|
+
assert false.∈(𝔹)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
3
|
+
|
4
|
+
class SetTest < Test::Unit::TestCase
|
5
|
+
def test_should_define_for_all
|
6
|
+
assert [1,2,3].∀ { |x| x < 10 }
|
7
|
+
assert ! [1,2,3].∀ { |x| x > 10 }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_define_exist
|
11
|
+
assert [1,2,3].∃ { |x| x % 2 == 0 }
|
12
|
+
assert ! [1,2,3].∃ { |x| x % 14 == 0 }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_define_subset
|
16
|
+
assert [1,2,3].⊆([1,2,3,4,5])
|
17
|
+
assert [1,2,3].⊆([1,2,3])
|
18
|
+
assert ! [1,2,4].⊆([1,2,3])
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_define_proper_subset
|
22
|
+
assert [1,2,3].⊂([1,2,3,4,5])
|
23
|
+
assert ! [1,2,3].⊂([1,2,3])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_define_superset
|
27
|
+
assert [1,2,3,4,5].⊇([1,2,3,4,5])
|
28
|
+
assert [1,2,3].⊇([1,2,3])
|
29
|
+
assert ! [1,2,3].⊇([1,2,4])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_define_proper_superset
|
33
|
+
assert [1,2,3,4,5].⊃([1,2,3])
|
34
|
+
assert ! [1,2,3].⊃([1,2,3])
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_define_union
|
38
|
+
assert_equal [1,2,5,6], [1,2].∪([5,6])
|
39
|
+
assert_equal [1,2,5,6], [1,2,5].∪([2,5,6])
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_define_intersection
|
43
|
+
assert_equal [], [1,2].∩([5,6])
|
44
|
+
assert_equal [2,5], [1,2,5].∩([2,5,6])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_define_difference
|
48
|
+
assert_equal [1], [1,2,5].∖([2,5,6])
|
49
|
+
assert_equal [1,2,5], [1,2,5].∖([4,9,10])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_return_if_element_is_in_container
|
53
|
+
assert 4.∈([4,5,6])
|
54
|
+
assert "foo".∈(["foo", "bar", "baz"])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_return_if_element_is_in_range
|
58
|
+
assert 4.∈(1..10)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_return_if_element_is_in_number_set
|
62
|
+
set = NumberSet.new { |x| x % 2 == 0 }
|
63
|
+
assert 4.∈(set)
|
64
|
+
assert ! 5.∈(set)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_return_if_element_is_of_type
|
68
|
+
assert 4.∈(Fixnum)
|
69
|
+
assert "foo".∈(String)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_define_not_element
|
73
|
+
assert 5.∉(1..3)
|
74
|
+
assert 5.0.∉(Fixnum)
|
75
|
+
assert 3.∉(String)
|
76
|
+
end
|
77
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: symbols
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Kadauke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-12-10 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Defines UTF-8 symbols for common math concepts
|
27
|
+
email:
|
28
|
+
- thomas.kadauke@googlemail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/math/comparison.rb
|
42
|
+
- lib/math/constants.rb
|
43
|
+
- lib/math/frac.rb
|
44
|
+
- lib/math/logarithm.rb
|
45
|
+
- lib/math/mod.rb
|
46
|
+
- lib/math/numeric.rb
|
47
|
+
- lib/math/numeric_pair.rb
|
48
|
+
- lib/math/plus_minus.rb
|
49
|
+
- lib/math/power.rb
|
50
|
+
- lib/math/root.rb
|
51
|
+
- lib/ruby/lambda.rb
|
52
|
+
- lib/set/number_set.rb
|
53
|
+
- lib/set/set.rb
|
54
|
+
- lib/symbols.rb
|
55
|
+
- symbols.gemspec
|
56
|
+
- test/math/comparison_test.rb
|
57
|
+
- test/math/constants_test.rb
|
58
|
+
- test/math/frac_test.rb
|
59
|
+
- test/math/logarithm_test.rb
|
60
|
+
- test/math/mod_test.rb
|
61
|
+
- test/math/numeric_pair_test.rb
|
62
|
+
- test/math/numeric_test.rb
|
63
|
+
- test/math/plus_minus_test.rb
|
64
|
+
- test/math/power_test.rb
|
65
|
+
- test/math/root_test.rb
|
66
|
+
- test/ruby/lambda_test.rb
|
67
|
+
- test/set/number_set_test.rb
|
68
|
+
- test/set/set_test.rb
|
69
|
+
- test/test_helper.rb
|
70
|
+
homepage: https://github.com/tkadauke/symbols
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 1290685105589525560
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 1290685105589525560
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.17
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Defines UTF-8 symbols for common math concepts
|
103
|
+
test_files:
|
104
|
+
- test/math/comparison_test.rb
|
105
|
+
- test/math/constants_test.rb
|
106
|
+
- test/math/frac_test.rb
|
107
|
+
- test/math/logarithm_test.rb
|
108
|
+
- test/math/mod_test.rb
|
109
|
+
- test/math/numeric_pair_test.rb
|
110
|
+
- test/math/numeric_test.rb
|
111
|
+
- test/math/plus_minus_test.rb
|
112
|
+
- test/math/power_test.rb
|
113
|
+
- test/math/root_test.rb
|
114
|
+
- test/ruby/lambda_test.rb
|
115
|
+
- test/set/number_set_test.rb
|
116
|
+
- test/set/set_test.rb
|
117
|
+
- test/test_helper.rb
|