Sha256: 7e762e9d65af01e73af509d0c418b6a2819ad0fe3f7b8865f943f2ddd51f28c7

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

class Predicate
  module Expr
    include Factory

    OP_NEGATIONS = {
      :eq  => :neq,
      :neq => :eq,
      :lt  => :gte,
      :lte => :gt,
      :gt  => :lte,
      :gte => :lt
    }

    def tautology?
      false
    end

    def contradiction?
      false
    end

    def literal?
      sexpr_type == :literal
    end

    def identifier?
      sexpr_type == :identifier
    end

    def !
      sexpr([:not, self])
    end

    def dyadic_priority
      0
    end

    def &(other)
      return other if other.contradiction?
      return self  if other.tautology?
      return other & self if other.dyadic_priority > self.dyadic_priority
      sexpr([:and, self, other])
    end

    def |(other)
      return other if other.tautology?
      return self  if other.contradiction?
      sexpr([:or, self, other])
    end

    def and_split(attr_list)
      # If we have no reference to attr_list, then we are P2, else we are P1
      (free_variables & attr_list).empty? ? [ tautology, self ] : [ self, tautology ]
    end

    def attr_split
      # if I have only one variable reference, then I can return
      # myself mapped to that variable...
      if (vars = free_variables).size == 1
        { vars.first => self }
      else
        # I must still map myself to nil to meet the conjunction
        # specification
        { nil => self }
      end
    end

    def rename(renaming)
      Renamer.call(self, :renaming => renaming)
    end

    def qualify(qualifier)
      Qualifier.new(qualifier).call(self)
    end

    def constant_variables
      []
    end

    def constants
      {}
    end

    def to_s(scope = nil)
      ToS.call(self, scope: scope)
    end
    alias :inspect :to_s

    def sexpr(arg)
      Factory.sexpr(arg)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
predicate-2.0.1 lib/predicate/nodes/expr.rb
predicate-2.0.0 lib/predicate/nodes/expr.rb