Sha256: 7045e6506ffef917f576faac101b464e1c846d364ad005586b1498d87e2b40ec

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'hilbert/world/base'
require 'hilbert/world/propositional_logic'

module Hilbert
  module World
    class Entity
      @@propositions = []
      class << self
        def <<(logic_str)
          @@propositions << to_rb_obj(logic_str)
          %|"Defined: #{logic_str} is TRUE"|
        end

        def impl(logic_str)
          # HOTFIX:
          return eval_rslt(logic_str, 'UNDEFINED') if @@propositions.empty?
          str = (!!!!!!!(@@propositions.inject(:*) >= to_rb_obj(logic_str))).to_s
          case str
          when 'TRUE'
            eval_rslt(logic_str, 'TRUE')
          when 'FALSE'
            eval_rslt(logic_str, 'FALSE')
          else
            eval_rslt(logic_str, 'UNDEFINED')
          end
        end

        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

        def clear!
          @@propositions = []
        end

        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

        # Internal Utils
        def to_rb_obj(logic_str)
          lexeds = Lexer::WorldLexer.execute(logic_str)
          Parser::WorldParser.execute(lexeds)
          eval Parser::WorldParser.parsed_srt
        end

        def eval_rslt(logic_str, rslt)
          %|"Evaluate: #{logic_str} is #{rslt}"|
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hilbert-0.0.2700110 lib/hilbert/world.rb