Class: Rucas::Symbolic::BinaryOpExpr
- Inherits:
-
Struct
- Object
- Struct
- Rucas::Symbolic::BinaryOpExpr
- Includes:
- OpExpr
- Defined in:
- lib/rucas/symbolic.rb,
lib/rucas/rewrite.rb,
lib/rucas/symbolic.rb
Overview
Binary operations.
Direct Known Subclasses
Constant Summary
Constants included from OpExpr
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#op ⇒ Object
Returns the value of attribute op.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
Instance Method Summary collapse
- #children ⇒ Object
- #match(expr, bindings = {}) ⇒ Object
- #to_s ⇒ Object
- #to_s_paren ⇒ Object
- #value ⇒ Object
Methods included from OpExpr
#constant?, #precedence, #rewrite, #with
Methods included from Expr
make, #precedence, #rewrite, #simplify
Instance Attribute Details
#lhs ⇒ Object
Returns the value of attribute lhs
148 149 150 |
# File 'lib/rucas/symbolic.rb', line 148 def lhs @lhs end |
#op ⇒ Object
Returns the value of attribute op
148 149 150 |
# File 'lib/rucas/symbolic.rb', line 148 def op @op end |
#rhs ⇒ Object
Returns the value of attribute rhs
148 149 150 |
# File 'lib/rucas/symbolic.rb', line 148 def rhs @rhs end |
Instance Method Details
#children ⇒ Object
152 |
# File 'lib/rucas/symbolic.rb', line 152 def children; [lhs, rhs] end |
#match(expr, bindings = {}) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/rucas/rewrite.rb', line 127 def match expr, bindings = {} if expr.is_a?(BinaryOpExpr) && self.op == expr.op lb = self.lhs.match(expr.lhs, bindings) rb = self.rhs.match(expr.rhs, lb) if lb return rb if rb end nil end |
#to_s ⇒ Object
159 160 161 162 163 |
# File 'lib/rucas/symbolic.rb', line 159 def to_s inner = self.children.map{|c| c.precedence < self.precedence ? "(#{c})" : c.to_s} "#{inner.join(self.op_string)}" end |
#to_s_paren ⇒ Object
154 155 156 157 |
# File 'lib/rucas/symbolic.rb', line 154 def to_s_paren op_string = " #{self.op} " "(#{self.children.map{|c| c.to_s_paren}.join(op_string)})" end |
#value ⇒ Object
136 137 138 139 140 |
# File 'lib/rucas/rewrite.rb', line 136 def value lv = lhs.value rv = rhs.value eval "(#{lv})#{self.op}(#{rv})" if lv && rv end |