from ..expression_core import *
from .combiners import *


class Relation(Combiner):
	def compute(self):
		computed_children = []
		for child in self.children:
			try: child = child.compute()
			except: pass
			computed_children.append(child)
		return all([self.eval_op(computed_children[i], computed_children[i+1]) for i in range(len(self.children)-1)])


class Equation(Relation):
	symbol = '='
	symbol_glyph_length = 1
	eval_op = staticmethod(lambda x, y: x == y)

class LessThan(Relation):
	symbol = '<'
	symbol_glyph_length = 1
	eval_op = staticmethod(lambda x, y: x < y)

class GreaterThan(Relation):
	symbol = '>'
	symbol_glyph_length = 1
	eval_op = staticmethod(lambda x, y: x > y)

class LessThanOrEqualTo(Relation):
	symbol = '\\leq'
	symbol_glyph_length = 1
	eval_op = staticmethod(lambda x, y: x <= y)

class GreaterThanOrEqualTo(Relation):
	symbol = '\\geq'
	symbol_glyph_length = 1
	eval_op = staticmethod(lambda x, y: x >= y)
