ChebyRuby 0.1.0 → 0.1.2

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
  SHA1:
3
- metadata.gz: 3252d81142e31e2eb4e1f6f9375505e82ab92351
4
- data.tar.gz: c24e5191aff126747b837a13e5a8fc9bb0dbf79e
3
+ metadata.gz: bcc33ce7c3a803a3612eca3dbb20a83a520a32fe
4
+ data.tar.gz: 593ee57abfe76a5b961919632da5ea9b449d5a9b
5
5
  SHA512:
6
- metadata.gz: 5919c55140a5632c3defee1f22c1459ef524d6351e4f54b1aa8598bf2ba5fbb7262bb1f7cf1febe3a0db1168bbfda9b59e482d7412e410cd4b35972910ed7791
7
- data.tar.gz: e57d75af7a75e6421707b8cd6226368c12fb6cabc642fff624b831738712ed7f44ab653c90fe877c2b74b2f275224429240258bba6c85ec24fa2d452003e2b92
6
+ metadata.gz: 7b4d24ae70a0cd5cd1073b1cecc2d0ea59a450bbec62dc89461b24086c794f8920efe6236e7e7a5b77a86400ab890d6086f78054ab79b784dfd353b797fe1ff0
7
+ data.tar.gz: 0f0c4781e443cb21bf210262e349111f70d35a992c7e07008f0d07338a0f710da658ac6e91403e415b7d11c16f3b938082512c7c95e115e355d688c077059f39
@@ -0,0 +1,27 @@
1
+ # ChebyRuby
2
+ [![Gem Version](https://badge.fury.io/rb/ChebyRuby.svg)](https://badge.fury.io/rb/ChebyRuby)
3
+
4
+ ## Name
5
+ The name is an homage to one of my favorite mathematicians: [Pafnuty Lvovich
6
+ Chebyshev](https://en.wikipedia.org/wiki/Pafnuty_Chebyshev). The Chebyshev polynomial is such an
7
+ important concept in mathematics and I am eternally grateful for his discovery of that.
8
+ Additionally, shortening his name to the nickname _Cheby_ works really well with Ruby.
9
+
10
+ ## Description
11
+ This is a gem that is designed to aid with numerical analysis and scientific computing in Ruby. As
12
+ of now it has relatively rudimentary numeric integration and differentiation methods heavily
13
+ inspired by the Apache Commons[Math] project. The end goal is for this to be a substantive numerical
14
+ analysis suite for Ruby.
15
+
16
+ ## Contributing
17
+ Contributors are more than welcome. The style rules I abide by are:
18
+ - 2 spaces for indentation
19
+ - 80 character max column size
20
+ - Single quote unless a double quote is necessary
21
+ - Yard style commenting
22
+ - Use `Class::X` to refer to a constant and `Class.x` to refer to a class
23
+ method.
24
+
25
+ ## License
26
+
27
+ This work is under the MIT License. (Eli Sadoff 2016)
@@ -1,8 +1,8 @@
1
- class ChebyRuby
2
-
3
- end
4
-
5
1
  require 'chebyruby/romberg_integration'
6
2
  require 'chebyruby/simpsons_integration'
7
3
  require 'chebyruby/integration'
8
4
  require 'chebyruby/univariate_function'
5
+
6
+ # This is an empty module for the project.
7
+ module Chebyruby
8
+ end
@@ -1,18 +1,48 @@
1
- # require_relative 'univariate_function'
1
+ require_relative 'univariate_function'
2
2
 
3
+ # This is a class for generic expressions.
4
+ # Whereas univariate functions are analogous to named functions
5
+ # this is more similar to a lambda. Additionally, this is more
6
+ # in the field of CAS instead of numerical analysis. Note:
7
+ # This is not at all stable or well tested and exists to try out
8
+ # but do not at all rely on this class.
9
+ #
10
+ # @attr left [Object] the left side of the expression (on a binary operator)
11
+ # @attr op [Operator] the binary operator
12
+ # @attr right [Object] the right side of the expression
3
13
  class Expression
4
14
  attr_accessor :left, :op, :right
5
15
 
16
+ # The constructor for the class Expression
17
+ #
18
+ # @param [Object] left the left side of the expression
19
+ # @param [Operator] op the binary operator
20
+ # @param [Object] right the right side of the expression
6
21
  def initialize(left, op, right)
7
22
  @left = left
8
23
  @op = op
9
24
  @right = right
10
25
  end
11
26
 
27
+ # The method missing method for expressions. Using some
28
+ # swanky tricks, a non-extant method on an expression is turned
29
+ # into a binary operator using a symbol and creates a new expression
30
+ # with the left expression being nested into a unit. Thus the expressions
31
+ # are by default left associative.
32
+ #
33
+ # @param [Object] method the method that is missing
34
+ # @param [Object[]] args the args that are passed to the missing method
35
+ # @return a new expression
12
36
  def method_missing(method, *args)
13
37
  Expression.new(self, method, Variable.new(args[0]))
14
38
  end
15
39
 
40
+ # This method returns a flattened list of the variables within an
41
+ # expression. For example, the expression
42
+ # <code>((x + y) + z) + a</code>
43
+ # will have a vars of [x, y, z, a]
44
+ #
45
+ # @return an array of the variables
16
46
  def vars
17
47
  a = []
18
48
  nested?[:left] ? a << left.vars : a << left.x
@@ -20,11 +50,18 @@ class Expression
20
50
  (a.flatten rescue a).select{|i| String === i}.uniq
21
51
  end
22
52
 
53
+ # This method returns a hash describing if the right
54
+ # and/or left sides of an expression are nested.
55
+ #
56
+ # @return a boolean hash with keys [:right, :left]
23
57
  def nested?
24
58
  {:right => (Expression === right),
25
59
  :left => (Expression === left)}
26
60
  end
27
61
 
62
+ # This method returns a string version of an expression.
63
+ #
64
+ # @return a string version of an expression
28
65
  def to_s
29
66
  if nested?[:left]
30
67
  s = "#{left.to_s} #{op}"
@@ -38,6 +75,9 @@ class Expression
38
75
  end
39
76
  end
40
77
 
78
+ # This turns the anonymous expression into a function
79
+ #
80
+ # @return a function of the expression.
41
81
  def to_func
42
82
  if a.vars.size == 1
43
83
  blk = ->(intvar) {eval(to_s.gsub(vars[0],'intvar'))}
@@ -27,7 +27,7 @@ class ChebyRuby::FiniteDifferencing
27
27
 
28
28
  # This does forward finite differencing.
29
29
  # The formula being used is:
30
- # <pre> Sum[(-1)^i * Binom(n i) * f(x + (n-i) * h), {i, 0, n}]/(h^n) </pre>
30
+ # <pre> Sum[(-1)^i * Binom(n i) * f(x + (n-i) * h), (i, 0, n)]/(h^n) </pre>
31
31
  #
32
32
  # @param [Numeric] x the value at which to find the derivative
33
33
  # @param [Numeric] h the value to use for the differencing (generally
@@ -44,7 +44,7 @@ class ChebyRuby::FiniteDifferencing
44
44
 
45
45
  # This does backward finite differencing.
46
46
  # The formula being used is:
47
- # <pre> Sum[(-1)^i * Binom(n i) * f(x - i*h), {i, 0, n}]/(h^n) </pre>
47
+ # <pre> Sum[(-1)^i * Binom(n i) * f(x - i*h), (i, 0, n)]/(h^n) </pre>
48
48
  #
49
49
  # @param [Numeric] x the value at which to find the derivative
50
50
  # @param [Numeric] h the value to use for the differencing (generally
@@ -61,7 +61,7 @@ class ChebyRuby::FiniteDifferencing
61
61
 
62
62
  # This does central finite differencing.
63
63
  # The formula being used is:
64
- # <pre> Sum[(-1)^i * Binom(n i) * f(x + (n/2-i) * h), {i, 0, n}]/(h^n) </pre>
64
+ # <pre> Sum[(-1)^i * Binom(n i) * f(x + (n/2-i) * h), (i, 0, n)]/(h^n) </pre>
65
65
  #
66
66
  # @param [Numeric] x the value at which to find the derivative
67
67
  # @param [Numeric] h the value to use for the differencing (generally
@@ -87,4 +87,4 @@ class ChebyRuby::FiniteDifferencing
87
87
  (n + 1 - i)/i.to_f
88
88
  end.inject(:*) || 1
89
89
  end
90
- end
90
+ end
@@ -1,17 +1,35 @@
1
1
  require_relative 'expression'
2
2
 
3
+ # This is the class for a variable in an expression. It is part of the
4
+ # CAS side-project in ChebyRuby.
5
+ #
6
+ # @attr x [String] the variable name
7
+ # @attr neg [Boolean] the negation status of the variable
3
8
  class Variable
4
9
  attr_accessor :x, :neg
5
10
 
6
- def initialize(x)
11
+ # This is the constructor for the variable class
12
+ #
13
+ # @param [String] x the variable name to initialize
14
+ # @param [Boolean] neg the negation status of the variable
15
+ def initialize(x, neg = false)
7
16
  @x = x
8
17
  @neg = false
9
18
  end
10
19
 
20
+ # This variadic method missing works with Expression's method missing
21
+ # to construct and expression from variables.
22
+ #
23
+ # @param [Object] method the method that is missing
24
+ # @param [Object[]] args the args that are passed to the missing method
25
+ # @return a new expression
11
26
  def method_missing(method, *args)
12
27
  Expression.new(self, method, Variable.new(args[0]))
13
28
  end
14
29
 
30
+ # This method will turn a variadic variable into an array
31
+ #
32
+ # @return an array of the variable
15
33
  def to_a
16
34
  if x.class == Array
17
35
  x
@@ -20,22 +38,39 @@ class Variable
20
38
  end
21
39
  end
22
40
 
41
+ # This is an overriding of the unary negation operation that allows for
42
+ # negation of a variable as simply as -x.
43
+ #
44
+ # @return a negated form of the current variable
23
45
  def -@
24
- @neg = true
46
+ Variable.new(@x, !@neg)
25
47
  end
26
48
 
49
+ # This turns the current array variable into an enumerator
50
+ #
51
+ # @return an enumerated form of the array variable
27
52
  def to_enum
28
53
  Array.new(to_ary).to_enum
29
54
  end
30
55
 
56
+ # A nil returning function for the purposes of expression building
57
+ #
58
+ # @return nil
31
59
  def right
32
60
  nil
33
61
  end
34
62
 
63
+ # A basic to_s function
64
+ #
65
+ # @return a string
35
66
  def to_s
36
67
  "#{x}"
37
68
  end
38
69
 
70
+ # Returns a parseable version of the variable/expression for
71
+ # computer system modification.
72
+ #
73
+ # @return parseable form
39
74
  def parseable
40
75
  to_enum.map do |i|
41
76
  if Array === i
@@ -51,13 +86,17 @@ class Variable
51
86
  alias to_ary to_a
52
87
  end
53
88
 
89
+ # Open class array
54
90
  class Array
91
+ # Public help for Variable#parseable
55
92
  def parseable
56
93
  Variable.new(self).parseable
57
94
  end
58
95
  end
59
96
 
97
+ # Open class Symbol
60
98
  class Symbol
99
+ # Public help for Variable#parseable
61
100
  def parseable
62
101
  self
63
102
  end
metadata CHANGED
@@ -1,21 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ChebyRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Sadoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-15 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A gem for numerical analysis and scientific computing.
13
+ description: |
14
+ This is a gem that is mainly for numerical analysis and especially
15
+ for applications of numerical analysis with regards to univariate
16
+ calculus. The future of this gem might entail expansion towards the
17
+ world of matrix analysis and multivariate calculus, but the primary
18
+ goal for the time being is univariate numerical calculus.
14
19
  email: snood1205@gmail.com
15
20
  executables: []
16
21
  extensions: []
17
- extra_rdoc_files: []
22
+ extra_rdoc_files:
23
+ - README.md
18
24
  files:
25
+ - README.md
19
26
  - Rakefile
20
27
  - bin/chebyruby
21
28
  - lib/chebyruby.rb
@@ -34,14 +41,18 @@ licenses:
34
41
  - MIT
35
42
  metadata: {}
36
43
  post_install_message:
37
- rdoc_options: []
44
+ rdoc_options:
45
+ - "-t"
46
+ - chebyruby RDocs
47
+ - "-m"
48
+ - README.md
38
49
  require_paths:
39
50
  - lib
40
51
  required_ruby_version: !ruby/object:Gem::Requirement
41
52
  requirements:
42
53
  - - ">="
43
54
  - !ruby/object:Gem::Version
44
- version: '0'
55
+ version: 1.9.3
45
56
  required_rubygems_version: !ruby/object:Gem::Requirement
46
57
  requirements:
47
58
  - - ">="
@@ -52,8 +63,7 @@ rubyforge_project:
52
63
  rubygems_version: 2.6.6
53
64
  signing_key:
54
65
  specification_version: 4
55
- summary: A gem for numerical analysis and scientific computing.This is a pre-release
56
- so beware.
66
+ summary: A gem for numerical analysis and scientific computing.
57
67
  test_files:
58
68
  - test/test_function.rb
59
69
  - test/test_integration.rb