Skip to content

Instantly share code, notes, and snippets.

@gogotanaka
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gogotanaka/f7f6b107f7792c23fc9d to your computer and use it in GitHub Desktop.
Save gogotanaka/f7f6b107f7792c23fc9d to your computer and use it in GitHub Desktop.
世界で一番ピュアな論理型プログラミング言語Hilbert(ヒルベルト)をRubyで作った. ref: http://qiita.com/gogotanaka/items/97ae187156541c8eaa9d
A # 命題Aが真である事の宣言
A -> B # 命題A->Bが真である事の宣言
B? # Aが真かつA-BならばBは真
#=> TRUE
# 三段ロンポー
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
f(x, y) = x + y
f(2, 2)
=> 4
g(x) = x ** 2
g(2)
=> 4
$ gem install hilbert
$ echo "gem 'hilbert'" >> ~/.Gemfile; bundle install
$ hilbert -i
Enjoy! ->
$ hilbert -i -zfc
Enjoy! ->
$ hilbert -r foo.hr
$ hilbert -rb foo.hr
$ hilbert -py foo.hr
IsHuman(gogotanaka) # gogotanakaは人間である
A[x] IsHuman(x) -> WillDie(x) # 全ての人間は死ぬ
WillDie(gogotanaka)? # gogotanakaは死ぬのか?
#=>true
gogotanaka <- HUMAN # gogotanakaは人間である.
A[h<-HUMAN] WillDie(h) # 全ての人間は死ぬ
WillDie(gogotanaka)? # gogotanakaは死ぬのか?
#=>true
Axiom tanaka
A
A->B
end
postulate tanaka #公理系の仮定(事実モジュールのインポート)
A # Aは真
A->B # AならばBも真
B? # Bも真
#=> true
A->B
B->C
(A->C)?
#=> true
A # Aは真である
~A # Aは偽でもある
paradox?
=> TRUE
d/dx(cos(x))
=> ( - sin( x ) )
d/dx(log(x))
=> ( 1 / x )
d/dy(y ** 2)
=> ( 2 * y )
d/dz(e ** z)
=> ( e ** z )
S(log(x)dx)[0..1]
=> - oo
S( sin(x)dx )[0..pi]
=> 2.0
S( cos(x)dx )[0..pi]
=> 0.0
(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