hilbert 0.0.2700100 → 0.0.2700110
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 +4 -4
- data/README.md +16 -2
- data/bin/hilbert +7 -0
- data/hilbert.gemspec +1 -1
- data/lib/hilbert/api/limit_api.rb +1 -0
- data/lib/hilbert/api/sigma_api.rb +1 -0
- data/lib/hilbert/iq.rb +2 -2
- data/lib/hilbert/lexer/main_lexer.rb +6 -4
- data/lib/hilbert/parser.rb +8 -10
- data/lib/hilbert/version.rb +1 -1
- data/lib/hilbert/world.rb +32 -12
- data/test/interpreter/test_differential.rb +30 -14
- data/test/interpreter/test_function.rb +3 -0
- data/test/interpreter/test_general.rb +10 -2
- data/test/interpreter/test_limit.rb +6 -1
- data/test/interpreter/test_propositional_logic.rb +3 -0
- data/test/interpreter/test_sigma.rb +6 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6c55b9859234a6710c7d633a13a06112ab0a4f
|
4
|
+
data.tar.gz: 2c336de0d9940bb01e151f8fe235d107248540b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
22
|
+
spec.add_dependency 'dydx', '~> 0.2.7000001'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'rake'
|
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
|
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 <
|
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(
|
7
|
-
rule(
|
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(
|
19
|
-
rule(
|
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 }
|
data/lib/hilbert/parser.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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+)/
|
data/lib/hilbert/version.rb
CHANGED
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
|
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
|
14
|
-
@@propositions << logic_form
|
15
|
-
end
|
16
|
-
|
17
|
-
def impl(logic_form, logic_str)
|
14
|
+
def impl(logic_str)
|
18
15
|
# HOTFIX:
|
19
|
-
return
|
20
|
-
str = (!!!!!!!(@@propositions.inject(:*) >=
|
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
|
-
|
20
|
+
eval_rslt(logic_str, 'TRUE')
|
24
21
|
when 'FALSE'
|
25
|
-
|
22
|
+
eval_rslt(logic_str, 'FALSE')
|
26
23
|
else
|
27
|
-
|
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
|
-
'
|
10
|
-
'e
|
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
|
-
'
|
15
|
-
'
|
30
|
+
'cos( x )',
|
31
|
+
'd/dx( sin(x) )'
|
16
32
|
)
|
17
33
|
|
18
34
|
assert_iq_equal(
|
19
|
-
'
|
20
|
-
'
|
35
|
+
'1 / x',
|
36
|
+
'd/dx(log(x))'
|
21
37
|
)
|
22
38
|
|
23
39
|
assert_iq_equal(
|
24
|
-
'
|
25
|
-
'cos(
|
40
|
+
'- sin( x )',
|
41
|
+
'd/dx cos(x)'
|
26
42
|
)
|
27
43
|
|
28
44
|
assert_iq_equal(
|
29
|
-
'
|
30
|
-
'
|
45
|
+
'2x',
|
46
|
+
'd/dx xx'
|
31
47
|
)
|
32
48
|
|
33
49
|
assert_iq_equal(
|
34
|
-
'
|
35
|
-
'
|
50
|
+
'1 / x',
|
51
|
+
'd/dx log(x)'
|
36
52
|
)
|
37
53
|
|
38
54
|
assert_iq_equal(
|
39
|
-
'
|
40
|
-
'
|
55
|
+
'( cos( x ) / x ) + ( log( x )( - sin( x ) ) )',
|
56
|
+
'd/dx log(x) * cos(x)'
|
41
57
|
)
|
42
58
|
end
|
43
59
|
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'
|
10
|
-
assert_iq_equal('
|
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)
|
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.
|
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-
|
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.
|
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.
|
26
|
+
version: 0.2.7000001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|