diff --git a/common.py b/common.py index 722f8bd..cd77460 100644 --- a/common.py +++ b/common.py @@ -47,6 +47,7 @@ def _str(self, node, depth=0) -> str: (r'rref', 'OPR'), (r'solve', 'OPR'), (r'eval', 'OPR'), + (r'ls', 'OPR'), (r'[a-zA-Z_]+', 'IDT'), (r'=', 'EQL'), (r'\+', 'ADD'), diff --git a/tests.py b/tests.py index 4843270..4a4c882 100644 --- a/tests.py +++ b/tests.py @@ -116,7 +116,7 @@ def runTest(self): self.assertTrue(sympy.Matrix(evaluate('identity({})'.format(r_dim), False)).equals(sympy.Identity(r_dim))) - for _ in range(1): + for _ in range(5): print(_) mat = [[more_zeroes(random.randint(0, 100)) for _ in range(r_dim)] for _ in range(r_dim)] diff --git a/vartypes.py b/vartypes.py index 1ba2996..04831e8 100644 --- a/vartypes.py +++ b/vartypes.py @@ -52,6 +52,12 @@ def identity(self): def solve(self, other): raise EvaluationException('Operation not defined for ' + self.type) + def eval(self, other): + raise EvaluationException('Operation not defined for ' + self.type) + + def ls(self, other): + raise EvaluationException('Operation not defined for ' + self.type) + class VariableValue(Value): def __init__(self, data): @@ -188,16 +194,13 @@ def trans(self): return MatrixValue(list(map(list, zip(*self.value)))) def cof(self): - # TODO: self code is pretty ugly. - cofactor_matrix = [] - mat = self.value - for row in range(len(mat)): + for row in range(len(self.value)): cofactor_matrix.append([]) - for col in range(len(mat[row])): - minor = copy.deepcopy(mat) + for col in range(len(self.value[row])): + minor = copy.deepcopy(self.value) del minor[row] for r in minor: @@ -234,6 +237,9 @@ def trnsform(self): def solve(self, other): return DynamicVectorValue(MatrixTransformer(copy.deepcopy(self.value)).rref(other.value[0])[2]) + def ls(self, other): + return (self.trans().mul(self)).inv().mul(self.trans()).mul(other) + class MatrixRowValue(Value): def __init__(self, data):