dydx 0.1.412 → 0.1.41421

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05be03d422e433fa724050ae6c77c6de2044005d
4
- data.tar.gz: 5a8ef94f9d271d9383ac3308c0f77acec91c6864
3
+ metadata.gz: 220e4986b77c2c86709b2fdd5c237c4bfdd14e7a
4
+ data.tar.gz: fdf1336073d4c594af4ff01b1818d86790ee821d
5
5
  SHA512:
6
- metadata.gz: 9c2d8881754f7ee43700223926c2a249d91c3431bcc49ce9886c8c2991e5c58694a83626d5d1947c97c822208159d487343d8a85e353448ad7843177446757a7
7
- data.tar.gz: 4a89a20e3810e52c23c97d88dd915e2a54263374e3f1a9b8a52ca444f9f1e3b219e63d1367be693a3787bf4f10f6e69f86baf6e9bc97ab1d2f2c7c5b46590760
6
+ metadata.gz: d0378ecf27babc0f72147e1c580d113aef606c4c75ce061df0bba1a98279615c6491900b7a9078f03cba499cd814c4574ab25b15fa572f17c0e41f64398074db
7
+ data.tar.gz: 43e1aeee044edb2b3e23fbe4c1f4e541d07c3584bc30d73a76283705b49029c24961cbad68e50d9328bfd479ab6c509a5201eca1ab737934535555991d9396d7
@@ -31,6 +31,7 @@ module Dydx
31
31
 
32
32
  # TODO: Cylomatic complexity for differentiate is too high. [7/6]
33
33
  def differentiate(sym = :x)
34
+
34
35
  case @operator
35
36
  when :+ then f.d(sym) + g.d(sym)
36
37
  when :* then (f.d(sym) * g) + (f * g.d(sym))
@@ -38,8 +39,12 @@ module Dydx
38
39
  # TODO:
39
40
  if g.num?
40
41
  f.d(sym) * g * (f ** (g - 1))
41
- elsif f == sym
42
- g * (f ** (g - 1))
42
+ elsif (f == sym) && (
43
+ g.num? || (
44
+ g.is_a?(Symbol) && g != sym
45
+ )
46
+ )
47
+ g * f ** (g - 1)
43
48
  elsif f == e
44
49
  g.d(sym) * self
45
50
  else
@@ -50,12 +55,14 @@ module Dydx
50
55
  alias_method :d, :differentiate
51
56
 
52
57
  def to_s
53
- if formula?(:*) && (f.minus1? || g.minus1?)
58
+ str = if formula?(:*) && (f.minus1? || g.minus1?)
54
59
  "( - #{g} )"
55
60
  elsif g.inverse?(operator)
56
61
  "( #{f} #{operator.inv} #{g.x} )"
57
62
  elsif f.inverse?(operator)
58
63
  "( #{g} #{operator.inv} #{f.x} )"
64
+ elsif f.negative?
65
+ "( #{g} - #{f.n.abs} )"
59
66
  elsif formula?(:*) && !rationals.empty?
60
67
  terms = [f, g]
61
68
  terms.delete(rationals.first)
@@ -36,6 +36,10 @@ module Dydx
36
36
  [-1, -1.0].include?(self) || (is_a?(Num) && n.minus1?)
37
37
  end
38
38
 
39
+ def negative?
40
+ num? && self < 0
41
+ end
42
+
39
43
  def distributive?(ope1, ope2)
40
44
  [ope1.super, ope1.inv_super].include?(ope2)
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = '0.1.412'
2
+ VERSION = '0.1.41421'
3
3
  end
@@ -13,14 +13,16 @@ describe Dydx::Delta do
13
13
 
14
14
  it 'ex1' do
15
15
  $y = x ** n
16
- expect(dy/dx).to eq( n * ( x ** ( n - 1 ) ) )
17
- expect(d/dx($y)).to eq( n * ( x ** ( n - 1 ) ) )
16
+ expect(d/dx($y)).to eq( n * ( x ** ( n - 1 ) ))
18
17
  end
19
18
 
20
19
  it 'ex2' do
21
20
  $y = x ** (x * 2)
22
- expect(dy/dx).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
23
- expect(d/dx($y)).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
21
+ expect(
22
+ eval((d/dx($y)).to_s)
23
+ ).to eq(
24
+ ( ( x ** ( 2 * x ) ) * ( 2 * ( 1 + log( x ) ) ) )
25
+ )
24
26
  end
25
27
 
26
28
  it 'ex3' do
@@ -32,4 +34,14 @@ describe Dydx::Delta do
32
34
  $y = 2 * (e ** (2 * z))
33
35
  expect(dy/dz).to eq(4 * ( e ** ( 2 * z ) ))
34
36
  end
37
+
38
+ it 'ex5' do
39
+ $y = 2 ** x
40
+ expect(dy/dx).to eq(( 2 ** x ) * log( 2 ))
41
+ end
42
+
43
+ it 'ex6' do
44
+ $y = x ** x
45
+ expect(dy/dx).to eq(x ** x * (log(x) + 1))
46
+ end
35
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dydx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.412
4
+ version: 0.1.41421
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler