implement strict equality operator for subclasses of Expression
This commit is contained in:
@@ -50,6 +50,12 @@ module RubyAlgebra
|
||||
def op_assoc_type
|
||||
:left
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
return false if other.type != type
|
||||
lhs == other.lhs && rhs == other.rhs
|
||||
end
|
||||
|
||||
def diff(v)
|
||||
Addition.new(@lhs.diff(v), @rhs.diff(v))
|
||||
end
|
||||
@@ -116,6 +122,11 @@ module RubyAlgebra
|
||||
:left
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
return false if other.type != type
|
||||
lhs == other.lhs && rhs == other.rhs
|
||||
end
|
||||
|
||||
def diff(v)
|
||||
u_prime = @lhs.diff(v)
|
||||
v_prime = @rhs.diff(v)
|
||||
@@ -179,6 +190,11 @@ module RubyAlgebra
|
||||
:right
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
return false if other.type != type
|
||||
base == other.base && exponent == other.exponent
|
||||
end
|
||||
|
||||
def diff(v)
|
||||
unless @exponent.is_a?(Constant)
|
||||
raise NotImplementedError, "Дифференцирование степени с неконстантным показателем не реализовано"
|
||||
@@ -215,6 +231,12 @@ module RubyAlgebra
|
||||
def op_assoc_type
|
||||
nil
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
return false if other.type != type
|
||||
value == other.value
|
||||
end
|
||||
|
||||
def diff(v)
|
||||
Constant.new(0)
|
||||
end
|
||||
@@ -248,6 +270,11 @@ module RubyAlgebra
|
||||
@is_single_letter
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
return false if other.type != type
|
||||
symbol == other.symbol
|
||||
end
|
||||
|
||||
def diff(v)
|
||||
@symbol == v ? Constant.new(1) : Constant.new(0)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user