Class: Hilbert::World::Entity
- Inherits:
-
Object
- Object
- Hilbert::World::Entity
- Defined in:
- lib/hilbert/world.rb
Defined Under Namespace
Modules: Messanger
Constant Summary collapse
- @@propositions =
[]
Class Method Summary collapse
- .<<(logic_str) ⇒ Object
- .atom(sym) ⇒ Object
- .clear! ⇒ Object
- .impl(logic_str) ⇒ Object
- .paradox? ⇒ Boolean
-
.to_rb_obj(logic_str) ⇒ Object
Internal Utils.
Class Method Details
.<<(logic_str) ⇒ Object
9 10 11 12 |
# File 'lib/hilbert/world.rb', line 9 def <<(logic_str) @@propositions << to_rb_obj(logic_str) Messanger.define(logic_str) end |
.atom(sym) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/hilbert/world.rb', line 34 def atom(sym) unless sym.to_s == sym.to_s.upcase && sym.to_s.length == 1 raise 'Proposltionla variable should be capital character' end eval "$#{sym} ||= PropositionalLogic::Atom.new(:#{sym})" end |
.clear! ⇒ Object
41 42 43 |
# File 'lib/hilbert/world.rb', line 41 def clear! @@propositions = [] end |
.impl(logic_str) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hilbert/world.rb', line 14 def impl(logic_str) # HOTFIX: we need to .. return Messanger.evaluate(logic_str, 'UNDEFINED') if @@propositions.empty? logic = (@@propositions.inject(:*) >= to_rb_obj(logic_str)) str = logic.dpll!.to_s case str when 'TRUE' then Messanger.evaluate(logic_str, 'TRUE') when 'FALSE' then Messanger.evaluate(logic_str, 'FALSE') else logic = (@@propositions.inject(:*) >= (~to_rb_obj(logic_str))) str = logic.dpll!.to_s case str when 'TRUE' then Messanger.evaluate(logic_str, 'FALSE') when 'FALSE' then Messanger.evaluate(logic_str, 'TRUE') else Messanger.evaluate(logic_str, 'UNDEFINED') end end end |
.paradox? ⇒ Boolean
45 46 47 48 49 50 51 52 |
# File 'lib/hilbert/world.rb', line 45 def paradox? return Messanger.tell_false if @@propositions.empty? case (!!!!!!!(@@propositions.inject(:*) >= (atom(:P) * ~atom(:P)))).to_s when 'TRUE' then Messanger.tell_true else Messanger.tell_false end end |
.to_rb_obj(logic_str) ⇒ Object
Internal Utils
55 56 57 58 59 |
# File 'lib/hilbert/world.rb', line 55 def to_rb_obj(logic_str) lexeds = Lexer::WorldLexer.execute(logic_str) Parser::WorldParser.execute(lexeds) eval Parser::WorldParser.parsed_srt end |