Last active
August 29, 2015 14:09
-
-
Save gogotanaka/f7f6b107f7792c23fc9d to your computer and use it in GitHub Desktop.
世界で一番ピュアな論理型プログラミング言語Hilbert(ヒルベルト)をRubyで作った. ref: http://qiita.com/gogotanaka/items/97ae187156541c8eaa9d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A # 命題Aが真である事の宣言 | |
A -> B # 命題A->Bが真である事の宣言 | |
B? # Aが真かつA-BならばBは真 | |
#=> TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 三段ロンポー | |
P -> Q | |
Q -> R | |
P -> R ? | |
=> TRUE | |
P | Q # PまたはQ | |
~P # Pではない | |
Q? # ではQである | |
=> TRUE | |
A? | |
=> UNDEFINED | |
~A | |
A? | |
=>FALSE | |
A -> B # AならばBである | |
B -> A ? # BならばAとは限らない | |
=> UNDEFINED | |
B -> A # BならばAである | |
A <-> B ? # AとBは同値である | |
# 標準の公理系をインポートすれば実数解析なども扱える | |
postulate zfc_analysis | |
d/dx x^2 | |
=> 2x | |
d/dx e^x | |
=> e^x | |
S(sin(x)dx)[0..pi] | |
=> 2 | |
lim[x->oo] 1/x | |
=> 0 | |
∑[i=1, 10] i | |
=> 55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f(x, y) = x + y | |
f(2, 2) | |
=> 4 | |
g(x) = x ** 2 | |
g(2) | |
=> 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install hilbert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo "gem 'hilbert'" >> ~/.Gemfile; bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ hilbert -i | |
Enjoy! -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ hilbert -i -zfc | |
Enjoy! -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ hilbert -r foo.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ hilbert -rb foo.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ hilbert -py foo.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IsHuman(gogotanaka) # gogotanakaは人間である | |
A[x] IsHuman(x) -> WillDie(x) # 全ての人間は死ぬ | |
WillDie(gogotanaka)? # gogotanakaは死ぬのか? | |
#=>true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gogotanaka <- HUMAN # gogotanakaは人間である. | |
A[h<-HUMAN] WillDie(h) # 全ての人間は死ぬ | |
WillDie(gogotanaka)? # gogotanakaは死ぬのか? | |
#=>true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Axiom tanaka | |
A | |
A->B | |
end | |
postulate tanaka #公理系の仮定(事実モジュールのインポート) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A # Aは真 | |
A->B # AならばBも真 | |
B? # Bも真 | |
#=> true | |
A->B | |
B->C | |
(A->C)? | |
#=> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A # Aは真である | |
~A # Aは偽でもある | |
paradox? | |
=> TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d/dx(cos(x)) | |
=> ( - sin( x ) ) | |
d/dx(log(x)) | |
=> ( 1 / x ) | |
d/dy(y ** 2) | |
=> ( 2 * y ) | |
d/dz(e ** z) | |
=> ( e ** z ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S(log(x)dx)[0..1] | |
=> - oo | |
S( sin(x)dx )[0..pi] | |
=> 2.0 | |
S( cos(x)dx )[0..pi] | |
=> 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1 2 3; 4 5 6) | |
=> (1 2 3; 4 5 6) | |
(1 2 3; 4 5 6) + (1 2 3; 4 5 6) | |
=> (2 4 6; 8 10 12) | |
(1 2 3; 4 5 6) * (1 2 3) | |
=> (14 32) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment