polynomials 0.1.4 → 0.1.5

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/Rakefile CHANGED
@@ -17,14 +17,10 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "polynomials"
18
18
  gem.homepage = "http://github.com/mkorfmann/polynomials"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{Polyomial calculations library}
20
+ gem.summary = %Q{parsing and computing data on polynomials}
21
21
  gem.description = %Q{
22
- * Parses polynomials
23
- * Provides useful methods on top of the Polynomial class, like:
24
- ** Polynomial#local_extremums
25
- ** Polynomial#nulls
26
- ** Polynomial#curvature_behaviour
27
- * Implements root's finding formulas for quadratic, cubic and quartic functions
22
+ This is a gem dedicated to parsing, manipulating and finding roots,extrema and inflection points of polynomials.
23
+ It can solve polynomial equations with a degree up to 4 by implementing formulas for solving quadratic, cubic and quartic functions.
28
24
  }
29
25
  gem.email = "manu@korfmann.info"
30
26
  gem.authors = ["Manuel Korfmann"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/lib/polynomials.rb CHANGED
@@ -3,7 +3,7 @@ require_relative 'term'
3
3
  require_relative 'core_ext/math'
4
4
  class Polynomial
5
5
  MinMaxMapping = { 1.0 => :max, -1.0 => :min }
6
- AfterExtremumsCurvatureMapping = { max: :right, min: :left }
6
+ AfterextremaCurvatureMapping = { max: :right, min: :left }
7
7
  NegPosMinMaxExtremumMapping = {[1.0,-1.0] => :max,[-1.0,1.0] => :min}
8
8
 
9
9
  attr_accessor :terms
@@ -62,17 +62,17 @@ class Polynomial
62
62
  end
63
63
  end
64
64
 
65
- def local_extremums
65
+ def local_extrema
66
66
  derivative = self.derivative
67
67
  max_min_extremum = Hash.new { |hash,key| hash[key] = Set.new }
68
68
  unless derivative.degree == 0
69
- possible_extremums = derivative.roots.sort
69
+ possible_extrema = derivative.roots.sort
70
70
 
71
- samples = ([possible_extremums.first - 1] + possible_extremums.sort + [possible_extremums.last + 1]).each_cons(2).map do |before,after|
71
+ samples = ([possible_extrema.first - 1] + possible_extrema.sort + [possible_extrema.last + 1]).each_cons(2).map do |before,after|
72
72
  (before + after)/2
73
73
  end
74
74
 
75
- possible_extremums.zip(samples.each_cons(2)).each do |pe,(after,before)|
75
+ possible_extrema.zip(samples.each_cons(2)).each do |pe,(after,before)|
76
76
  yafter = derivative.calculate(after)
77
77
  ybefore = derivative.calculate(before)
78
78
  kind_of_extremum = NegPosMinMaxExtremumMapping[[yafter/yafter.abs,ybefore/ybefore.abs]]
@@ -86,10 +86,10 @@ class Polynomial
86
86
  if degree < 2
87
87
  return {}
88
88
  else
89
- extremums = self.derivative.extremums
89
+ extrema = self.derivative.extrema
90
90
  curvature_behaviour = Hash.new {|h,k|h[k]=Set.new}
91
- extremums.values.inject(&:|).sort.each_cons(2) do |start_point,end_point|
92
- curvature_behaviour[AfterExtremumsCurvatureMapping[extremums.find { |k,v| v.include?(start_point) }.first]] << Range.new(start_point,end_point)
91
+ extrema.values.inject(&:|).sort.each_cons(2) do |start_point,end_point|
92
+ curvature_behaviour[AfterextremaCurvatureMapping[extrema.find { |k,v| v.include?(start_point) }.first]] << Range.new(start_point,end_point)
93
93
  end
94
94
  end
95
95
  return curvature_behaviour
@@ -110,13 +110,13 @@ class Polynomial
110
110
  self.terms.delete_if(&delete_zeros) == other.terms.delete_if(&delete_zeros)
111
111
  end
112
112
 
113
- def extremums
114
- extremums = local_extremums
113
+ def extrema
114
+ extrema = local_extrema
115
115
  a = self.terms[self.degree].coefficient
116
116
  max_or_min = (self.degree.even? ? [1,1] : [-1,1]).map { |n| (n * a)/a.abs }
117
- extremums[MinMaxMapping[max_or_min.first]] << -1.0/0
118
- extremums[MinMaxMapping[max_or_min.last]] << 1.0/0
119
- return extremums
117
+ extrema[MinMaxMapping[max_or_min.first]] << -1.0/0
118
+ extrema[MinMaxMapping[max_or_min.last]] << 1.0/0
119
+ return extrema
120
120
  end
121
121
 
122
122
  private
data/polynomials.gemspec CHANGED
@@ -5,18 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{polynomials}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Manuel Korfmann"]
12
12
  s.date = %q{2011-05-13}
13
13
  s.description = %q{
14
- * Parses polynomials
15
- * Provides useful methods on top of the Polynomial class, like:
16
- ** Polynomial#local_extremums
17
- ** Polynomial#nulls
18
- ** Polynomial#curvature_behaviour
19
- * Implements root's finding formulas for quadratic, cubic and quartic functions
14
+ This is a gem dedicated to parsing, manipulating and finding roots,extrema and inflection points of polynomials.
15
+ It can solve polynomial equations with a degree up to 4 by implementing formulas for solving quadratic, cubic and quartic functions.
20
16
  }
21
17
  s.email = %q{manu@korfmann.info}
22
18
  s.extra_rdoc_files = [
@@ -45,7 +41,7 @@ Gem::Specification.new do |s|
45
41
  s.licenses = ["MIT"]
46
42
  s.require_paths = ["lib"]
47
43
  s.rubygems_version = %q{1.3.7}
48
- s.summary = %q{Polyomial calculations library}
44
+ s.summary = %q{parsing and computing data on polynomials}
49
45
 
50
46
  if s.respond_to? :specification_version then
51
47
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -38,16 +38,16 @@ class TestPolynomial < MiniTest::Unit::TestCase
38
38
  assert_equal 5,Polynomial.parse('3x^5 - 5 x + 3').degree
39
39
  end
40
40
 
41
- def test_extremums
41
+ def test_extrema
42
42
  polynomial = Polynomial.parse('3x^2 + 2x + 1')
43
- assert_equal({ min: Set[-2.0/6.0] }, polynomial.local_extremums)
43
+ assert_equal({ min: Set[-2.0/6.0] }, polynomial.local_extrema)
44
44
  polynomial = Polynomial.parse('5x^3 - 5x^2 + 2x - 2')
45
45
  end
46
46
 
47
- def test_extremums_with_slope_of_derivative_equal_to_zero
47
+ def test_extrema_with_slope_of_derivative_equal_to_zero
48
48
  polynomial = Polynomial.parse('1x^4')
49
- assert_equal({ min: Set[0.0] }, polynomial.local_extremums)
50
- assert_equal({ max: Set[1.0/0, -1.0/0], min: Set[0.0]}, polynomial.extremums)
49
+ assert_equal({ min: Set[0.0] }, polynomial.local_extrema)
50
+ assert_equal({ max: Set[1.0/0, -1.0/0], min: Set[0.0]}, polynomial.extrema)
51
51
  end
52
52
 
53
53
  def test_no_inflection_points
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Manuel Korfmann
@@ -87,9 +87,8 @@ dependencies:
87
87
  prerelease: false
88
88
  version_requirements: *id005
89
89
  description: "\n\
90
- * Parses polynomials\n\
91
- * Provides useful methods on top of the Polynomial class, like:\n ** Polynomial#local_extremums\n ** Polynomial#nulls\n ** Polynomial#curvature_behaviour\n\
92
- * Implements root's finding formulas for quadratic, cubic and quartic functions\n "
90
+ This is a gem dedicated to parsing, manipulating and finding roots,extrema and inflection points of polynomials.\n\
91
+ It can solve polynomial equations with a degree up to 4 by implementing formulas for solving quadratic, cubic and quartic functions.\n "
93
92
  email: manu@korfmann.info
94
93
  executables: []
95
94
 
@@ -129,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
128
  requirements:
130
129
  - - ">="
131
130
  - !ruby/object:Gem::Version
132
- hash: -100517783123906074
131
+ hash: -856232510255966388
133
132
  segments:
134
133
  - 0
135
134
  version: "0"
@@ -147,6 +146,6 @@ rubyforge_project:
147
146
  rubygems_version: 1.3.7
148
147
  signing_key:
149
148
  specification_version: 3
150
- summary: Polyomial calculations library
149
+ summary: parsing and computing data on polynomials
151
150
  test_files: []
152
151