Class: Hilbert::World::Entity
- Inherits:
-
Object
- Object
- Hilbert::World::Entity
- Defined in:
- lib/hilbert/world.rb
Constant Summary collapse
- @@propositions =
[]
Class Method Summary collapse
- .<<(logic_str) ⇒ Object
- .atom(sym) ⇒ Object
- .clear! ⇒ Object
- .eval_rslt(logic_str, rslt) ⇒ 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) %|"Defined: #{logic_str} is TRUE"| end |
.atom(sym) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/hilbert/world.rb', line 38 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
45 46 47 |
# File 'lib/hilbert/world.rb', line 45 def clear! @@propositions = [] end |
.eval_rslt(logic_str, rslt) ⇒ Object
67 68 69 |
# File 'lib/hilbert/world.rb', line 67 def eval_rslt(logic_str, rslt) %|"Evaluate: #{logic_str} is #{rslt}"| end |
.impl(logic_str) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hilbert/world.rb', line 14 def impl(logic_str) # HOTFIX: we need to .. return eval_rslt(logic_str, 'UNDEFINED') if @@propositions.empty? logic = (@@propositions.inject(:*) >= to_rb_obj(logic_str)) str = logic.dpll!.to_s case str when 'TRUE' eval_rslt(logic_str, 'TRUE') when 'FALSE' eval_rslt(logic_str, 'FALSE') else logic = (@@propositions.inject(:*) >= (~to_rb_obj(logic_str))) str = logic.dpll!.to_s case str when 'TRUE' eval_rslt(logic_str, 'FALSE') when 'FALSE' eval_rslt(logic_str, 'TRUE') else eval_rslt(logic_str, 'UNDEFINED') end end end |
.paradox? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hilbert/world.rb', line 49 def paradox? return %|"FALSE"| if @@propositions.empty? str = (!!!!!!!(@@propositions.inject(:*) >= (atom(:P) * ~atom(:P)))).to_s case str when 'TRUE' %|"TRUE"| else %|"FALSE"| end end |
.to_rb_obj(logic_str) ⇒ Object
Internal Utils
61 62 63 64 65 |
# File 'lib/hilbert/world.rb', line 61 def to_rb_obj(logic_str) lexeds = Lexer::WorldLexer.execute(logic_str) Parser::WorldParser.execute(lexeds) eval Parser::WorldParser.parsed_srt end |