hilbert 0.0.2700100 → 0.0.2700110

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: 9a0a3fec8ea8685b98cb92d396c58fb3467b85cf
4
- data.tar.gz: 521413e76c6b6512e462695a6603d697da6b1a60
3
+ metadata.gz: 8b6c55b9859234a6710c7d633a13a06112ab0a4f
4
+ data.tar.gz: 2c336de0d9940bb01e151f8fe235d107248540b9
5
5
  SHA512:
6
- metadata.gz: 490d8872bf5cc5c9efea975fe3d596981080844229024916adaf35bbe607831a2f431b331490a91fd4dff83582ca836ff4ac19870b57713b9392bea46a70b4ee
7
- data.tar.gz: 154c250c7a531e80b939bcc1ed8e382489ff1a9068240ea4118e5da29e7f7c01a071c7228157472e262d63bafc6bd72fac4b83eb29e0bff386b81950f1abd224
6
+ metadata.gz: 4b567ae6c9b84b1ff938035dccf82fa3fae2473264c030ba5691deef2ab004c8c85991f33159da43d0cd6e5301bb89afe43e344262ddc3bfa3b5167a561bda8d
7
+ data.tar.gz: 7eb3fda6ec81613dbdd59dafe0b558ad8deef8fcac1b00dbe3a828e81d3f7ceb574aaba62a5749bc877dabe09a30294529446e79c62b52c5ac2d8d137fbaa56e
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Do you know the one best language in this world?
6
6
 
7
- #### I believe mathematics is absolutely that one.
7
+ #### I believe mathematics(logic) is absolutely that one.
8
8
 
9
9
  ## How can we deal something as great as mathematics in a discrete world?
10
10
 
@@ -26,6 +26,19 @@ The code below is input and output for the Hilbert interpreter
26
26
 
27
27
  (you can try it by `hilbert -i`)
28
28
 
29
+ ### Logic
30
+ ```coffeescript
31
+ P -> Q
32
+ Q -> R
33
+ (P -> R)?
34
+ => TRUE
35
+
36
+ P | Q # P or Q
37
+ ~P # not P
38
+ Q? # Q is TURE?
39
+ => TURE
40
+ ```
41
+
29
42
  ### Differentiate
30
43
 
31
44
  ```
@@ -155,5 +168,6 @@ end
155
168
 
156
169
  ## Contributing
157
170
 
158
- Any PRs or issues are welcome.
171
+ Any PRs or issues are welcome. (Please make to `develop` branch)
172
+
159
173
  You can become a commiter, even if you only commit once.
data/bin/hilbert CHANGED
@@ -11,6 +11,13 @@ require 'hilbert/iq'
11
11
  # TODO: There are vanch of todo ..
12
12
  case ARGV.first
13
13
  when '-i'
14
+ if ARGV[1] == '-zfc'
15
+ Hilbert::Iq.execute('postulate zfc_analysis')
16
+ print %|Hi guys, your postulating zfc_analysis is success. :) \n\n|
17
+ else
18
+ print %|Hi guys,thank you for using Hilbert.\nYou need to execute "postulate zfc_analysis" if you wanna do real analysis.\n\n|
19
+ end
20
+
14
21
  loop do
15
22
  print 'Enjoy! -> '
16
23
  begin
data/hilbert.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'dydx', '~> 0.2.7000000'
22
+ spec.add_dependency 'dydx', '~> 0.2.7000001'
23
23
 
24
24
  spec.add_development_dependency 'bundler'
25
25
  spec.add_development_dependency 'rake'
@@ -14,6 +14,7 @@ module Hilbert
14
14
  temp_cal_f(#{close_to} + Float::EPSILON ** 20)"
15
15
  end
16
16
  when :inter
17
+ Dydx::API.reset!
17
18
  Dydx::API.store_func(eval(var), eval(formula), :tmp)
18
19
  Dydx::API.eval_func(eval(close_to) + Float::EPSILON ** 20, :tmp)
19
20
  else
@@ -5,6 +5,7 @@ module Hilbert
5
5
  case $meta_info.lang
6
6
  # TODO: I know what you want to say.
7
7
  when :ruby
8
+ Dydx::API.reset!
8
9
  "temp_cal_f(#{var}) <= #{formula};
9
10
  (#{from}..#{to}).inject(0) {|sum, i| sum+=temp_cal_f(i) }"
10
11
  else
data/lib/hilbert/iq.rb CHANGED
@@ -30,10 +30,10 @@ module Hilbert
30
30
  when Matrix, Vector, Dydx::Algebra::Formula
31
31
  ruby_obj.to_q
32
32
  when Numeric
33
- # TODO: I know you wanna way..
33
+ # TODO: I know what you wanna say..
34
34
  if ruby_obj > 10000.0 then 'oo'
35
35
  elsif ruby_obj < -10000.0 then '-oo'
36
- elsif ruby_obj.abs < Float::EPSILON then '0.0'
36
+ elsif ruby_obj.abs < 1.0/10**4 then '0.0'
37
37
  else ruby_obj.to_s.equalize!
38
38
  end
39
39
  else
@@ -3,8 +3,9 @@ module Hilbert
3
3
  class MainLexer < Base
4
4
  # TODO: So far so good, but...
5
5
  rule(/postulate zfc_analysis/) { :POST_ZFC }
6
- rule(/#{EVALOGIC}/) { :EVALOGIC }
7
- rule(/#{DEFLOGIC}/) { :DEFLOGIC }
6
+ rule(/paradox\?/) { :P_PARAD }
7
+ rule(/\A.*[A-RT-Z].*\?.*\z/m) { :EVALOGIC }
8
+ rule(/\A.*[A-RT-Z].*\z/m) { :DEFLOGIC }
8
9
  rule(/[ \t\f]/)
9
10
 
10
11
  rule(/(\r|\n)+/) { :NULL }
@@ -15,8 +16,9 @@ module Hilbert
15
16
  def zfc_analysis!
16
17
  clear!
17
18
  rule(/postulate zfc_analysis/) { :POST_ZFC }
18
- rule(/#{EVALOGIC}/) { :EVALOGIC }
19
- rule(/#{DEFLOGIC}/) { :DEFLOGIC }
19
+ rule(/paradox\?/) { :P_PARAD }
20
+ rule(/\A.*[A-RT-Z].*\?.*\z/m) { :EVALOGIC }
21
+ rule(/\A.*[A-RT-Z].*\z/m) { :DEFLOGIC }
20
22
  rule(/(#{FUNCCV})#{ANYSP}#{EQL}#{ANYSP}(#{FORMULA})/) { :DEF_FUNC }
21
23
  rule(/#{INTE_SYM}#{ANYSP}#{LPRN}(#{ANYSTR})#{RPRN}#{LBRCT}(#{ANYSTR})#{RBRCT}/) { :INTEGRAL }
22
24
  rule(/#{DIFF_SYM}(#{VAR}) (#{FORMULA})/) { :DIFFERENTIAL }
@@ -27,20 +27,18 @@ module Hilbert
27
27
  case lexed.token_str
28
28
  when /:(POST_ZFC)(\d+)/
29
29
  Hilbert::Lexer::MainLexer.zfc_analysis!
30
- lexed.parsed!('', $2)
30
+ lexed.parsed!('"success! :)"', $2)
31
+ when /:(P_PARAD)(\d+)/
32
+ lexed.parsed!($world.paradox?, $2)
33
+
31
34
  when /:(DEFLOGIC)(\d+)/
32
- value = lexed.get_value($1)
33
- lexeds = Lexer::WorldLexer.execute(value)
34
- Parser::WorldParser.execute(lexeds)
35
- $world << eval(Parser::WorldParser.parsed_srt)
36
- rslt = %|"Defined: #{value} is TRUE"|
35
+ value = lexed.get_value($1).delete("\n")
36
+ rslt = $world << value
37
37
  lexed.parsed!(rslt, $2)
38
38
 
39
39
  when /:(EVALOGIC)(\d+)/
40
- value = lexed.get_value($1).delete('?')
41
- lexeds = Lexer::WorldLexer.execute(value)
42
- Parser::WorldParser.execute(lexeds)
43
- rslt = $world.impl eval(Parser::WorldParser.parsed_srt), value
40
+ value = lexed.get_value($1).delete("?\n")
41
+ rslt = $world.impl value
44
42
  lexed.parsed!(rslt, $2)
45
43
 
46
44
  when /:(VECTOR)(\d+)/, /:(MATRIX)(\d+)/, /:(TMATRIX)(\d+)/, /:(INTEGRAL)(\d+)/, /:(DEF_FUNC)(\d+)/, /:(DIFFERENTIAL)(\d+)/, /:(LIMIT)(\d+)/, /:(SIGMA)(\d+)/
@@ -1,3 +1,3 @@
1
1
  module Hilbert
2
- VERSION = '0.0.2700100'
2
+ VERSION = '0.0.2700110'
3
3
  end
data/lib/hilbert/world.rb CHANGED
@@ -6,25 +6,22 @@ module Hilbert
6
6
  class Entity
7
7
  @@propositions = []
8
8
  class << self
9
- def tautology
10
- @@propositions
9
+ def <<(logic_str)
10
+ @@propositions << to_rb_obj(logic_str)
11
+ %|"Defined: #{logic_str} is TRUE"|
11
12
  end
12
13
 
13
- def <<(logic_form)
14
- @@propositions << logic_form
15
- end
16
-
17
- def impl(logic_form, logic_str)
14
+ def impl(logic_str)
18
15
  # HOTFIX:
19
- return %|"Evaluate: #{logic_str} is UNDEFINED"| if @@propositions.empty?
20
- str = (!!!!!!!(@@propositions.inject(:*) >= logic_form)).to_s
16
+ return eval_rslt(logic_str, 'UNDEFINED') if @@propositions.empty?
17
+ str = (!!!!!!!(@@propositions.inject(:*) >= to_rb_obj(logic_str))).to_s
21
18
  case str
22
19
  when 'TRUE'
23
- %|"Evaluate: #{logic_str} is TRUE"|
20
+ eval_rslt(logic_str, 'TRUE')
24
21
  when 'FALSE'
25
- %|"Evaluate: #{logic_str} is FALSE"|
22
+ eval_rslt(logic_str, 'FALSE')
26
23
  else
27
- %|"Evaluate: #{logic_str} is UNDEFINED"|
24
+ eval_rslt(logic_str, 'UNDEFINED')
28
25
  end
29
26
  end
30
27
 
@@ -38,6 +35,29 @@ module Hilbert
38
35
  def clear!
39
36
  @@propositions = []
40
37
  end
38
+
39
+ def paradox?
40
+ return %|"FALSE"| if @@propositions.empty?
41
+ str = (!!!!!!!(@@propositions.inject(:*) >= (atom(:P) * ~atom(:P)))).to_s
42
+ case str
43
+ when 'TRUE'
44
+ %|"TRUE"|
45
+ else
46
+ %|"FALSE"|
47
+ end
48
+ end
49
+
50
+ # Internal Utils
51
+ def to_rb_obj(logic_str)
52
+ lexeds = Lexer::WorldLexer.execute(logic_str)
53
+ Parser::WorldParser.execute(lexeds)
54
+ eval Parser::WorldParser.parsed_srt
55
+ end
56
+
57
+ def eval_rslt(logic_str, rslt)
58
+ %|"Evaluate: #{logic_str} is #{rslt}"|
59
+ end
60
+
41
61
  end
42
62
  end
43
63
  end
@@ -1,43 +1,59 @@
1
1
  require 'minitest_helper'
2
2
 
3
3
  class TestDifferential < TestInterpreterBase
4
+
5
+ # TODO: opposite
6
+ def assert_iq_equal(output, input)
7
+ assert_equal(output, Hilbert::Iq.execute(input))
8
+ end
9
+
4
10
  def setup
5
11
  end
6
12
 
7
13
  def test_general
8
14
  assert_iq_equal(
9
- 'd/dx(e ** x)',
10
- 'e ^ x'
15
+ 'e ^ x',
16
+ 'd/dx(e ** x)'
17
+ )
18
+
19
+ assert_iq_equal(
20
+ '2x',
21
+ 'd/dx(x ** 2)'
22
+ )
23
+
24
+ assert_iq_equal(
25
+ '2',
26
+ 'd/dx(x * 2)'
11
27
  )
12
28
 
13
29
  assert_iq_equal(
14
- 'd/dx(x ** 2)',
15
- '2x'
30
+ 'cos( x )',
31
+ 'd/dx( sin(x) )'
16
32
  )
17
33
 
18
34
  assert_iq_equal(
19
- 'd/dx(x * 2)',
20
- '2'
35
+ '1 / x',
36
+ 'd/dx(log(x))'
21
37
  )
22
38
 
23
39
  assert_iq_equal(
24
- 'd/dx( sin(x) )',
25
- 'cos( x )'
40
+ '- sin( x )',
41
+ 'd/dx cos(x)'
26
42
  )
27
43
 
28
44
  assert_iq_equal(
29
- 'd/dx(log( x ))',
30
- '1 / x'
45
+ '2x',
46
+ 'd/dx xx'
31
47
  )
32
48
 
33
49
  assert_iq_equal(
34
- 'd/dx cos(x)',
35
- '- sin( x )'
50
+ '1 / x',
51
+ 'd/dx log(x)'
36
52
  )
37
53
 
38
54
  assert_iq_equal(
39
- 'd/dx xx',
40
- '2x'
55
+ '( cos( x ) / x ) + ( log( x )( - sin( x ) ) )',
56
+ 'd/dx log(x) * cos(x)'
41
57
  )
42
58
  end
43
59
  end
@@ -40,5 +40,8 @@ class TestFunction < TestInterpreterBase
40
40
 
41
41
  assert_def_func('f(x) = log(x)', 'log( x )')
42
42
  assert_cal_func('f(e)', '1.0')
43
+
44
+ assert_def_func('f(x) = cos(x)', 'cos( x )')
45
+ assert_cal_func('f(pi/2.0)', '0.0')
43
46
  end
44
47
  end
@@ -4,9 +4,17 @@ class TestGeneral < TestInterpreterBase
4
4
  def setup
5
5
  end
6
6
 
7
+ # TODO: opposite
8
+ def assert_iq_equal(output, input)
9
+ assert_equal(output, Hilbert::Iq.execute(input))
10
+ end
11
+
7
12
  def test_general
8
13
  assert_iq_equal('2x', '2x')
9
- assert_iq_equal('x + x', '2x')
10
- assert_iq_equal('x * y', 'xy')
14
+ assert_iq_equal('2x', 'x + x')
15
+ # assert_iq_equal('xy', 'xy')
16
+ assert_iq_equal('x ^ y', 'x ^ y')
17
+ assert_iq_equal('2sin( x )', 'sin(x) + sin(x)')
18
+ assert_iq_equal('log( x ) ^ 2', 'log(x) * log(x)')
11
19
  end
12
20
  end
@@ -5,7 +5,7 @@ class TestLimit < TestInterpreterBase
5
5
  end
6
6
 
7
7
  def assert_iq_equal(output, input)
8
- assert_equal(Hilbert::Iq.execute(input), output)
8
+ assert_equal(output, Hilbert::Iq.execute(input))
9
9
  end
10
10
 
11
11
  def test_general
@@ -33,5 +33,10 @@ class TestLimit < TestInterpreterBase
33
33
  '0.0',
34
34
  'lim[x->0] x'
35
35
  )
36
+
37
+ assert_iq_equal(
38
+ 'oo',
39
+ 'lim[x->0] 1/x'
40
+ )
36
41
  end
37
42
  end
@@ -27,8 +27,11 @@ class TestPropositionalLogic < TestInterpreterBase
27
27
  end
28
28
 
29
29
  def test_paradox?
30
+ assert_iq_equal('FALSE', 'paradox?')
30
31
  assert_iq_equal('Defined: A is TRUE', 'A')
32
+ assert_iq_equal('FALSE', 'paradox?')
31
33
  assert_iq_equal('Defined: ~A is TRUE', '~A')
34
+ assert_iq_equal('TRUE', 'paradox?')
32
35
  end
33
36
  # assert_iq_equal('Defined: P(1) is true', "P(1)")
34
37
  # assert_iq_equal('Evaluate: P(1) is true', 'P?(1)')
@@ -12,6 +12,11 @@ class TestSigma < TestInterpreterBase
12
12
  '55.0'
13
13
  )
14
14
 
15
+ assert_iq_equal(
16
+ '∑[i=1, 10] i',
17
+ '55.0'
18
+ )
19
+
15
20
  assert_iq_equal(
16
21
  '∑[x=0, 10] x^2',
17
22
  '385.0'
@@ -21,5 +26,6 @@ class TestSigma < TestInterpreterBase
21
26
  '∑[x=0, 10] x^3',
22
27
  '3025.0'
23
28
  )
29
+
24
30
  end
25
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hilbert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2700100
4
+ version: 0.0.2700110
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-15 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dydx
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.7000000
19
+ version: 0.2.7000001
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.7000000
26
+ version: 0.2.7000001
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement