def quickSimplify(workspace): """Dynamic simplifier for simplifying expression as it is being typed Arguments: workspace {QtWidgets.QWidget} -- main layout Returns: qSolution/log {string} -- quick solution or error log enableInteraction {bool} -- if False disables 'visma'(interaction) button """ # FIXME: Crashes for some cases. Find and fix. logger.setLogName('qsolver') logger.setLevel(0) qSolution = "" strIn = workspace.textedit.toPlainText() cleanInput = removeSpaces(strIn) if ';' in cleanInput: return "", True, True terms = getTerms(cleanInput) normalizedTerms = normalize(terms) symTokens = tokenizeSymbols(normalizedTerms) normalizedTerms, symTokens = removeUnary(normalizedTerms, symTokens) if checkEquation(normalizedTerms, symTokens) is True and strIn != "": if symTokens and symTokens[-1] is not False: tokens = getToken(normalizedTerms, symTokens) tokens = tokens.tokens lhs, rhs = getLHSandRHS(tokens) _, solutionType = checkTypes(lhs, rhs) lhs, rhs = getLHSandRHS(tokens) if solutionType == 'expression': _, _, _, equationTokens, _ = simplify(tokens) qSolution = r'$ ' + '= \ ' else: _, _, _, _, equationTokens, _ = simplifyEquation(lhs, rhs) qSolution = r'$ ' + '\Rightarrow \ ' qSolution += tokensToLatex(equationTokens[-1]) + ' $' # workspace.eqToks = equationTokens # plot(workspace) return qSolution, True, False elif symTokens: log = "Invalid Expression" workspace.logBox.append(logger.error(log)) return log, False, _ else: log = "" workspace.logBox.append(logger.error(log)) return log, False, _ else: log = "" if strIn != "": _, log = checkEquation(normalizedTerms, symTokens) workspace.logBox.append(logger.error(log)) return log, False, _
def quickTest(inp, operation, wrtVar=None): lhs, rhs = getLHSandRHS(tokenizer(inp)) _, inpType = checkTypes(lhs, rhs) if inpType == "equation": if wrtVar is not None: _, _, _, token_string, _, _ = operation(lhs, rhs, wrtVar) else: _, _, _, token_string, _, _ = operation(lhs, rhs) elif inpType == "expression": if wrtVar is not None: _, _, token_string, _, _ = operation(lhs, wrtVar) else: _, _, token_string, _, _ = operation(lhs) output = removeSpaces(token_string) return output
def calluser(): availableOperations = [] tokenString = '' equationTokens = [] if varName == 'back': self.input = str(self.textedit.toPlainText()) self.tokens = tokenizer(self.input) # print(self.tokens) lhs, rhs = getLHSandRHS(self.tokens) operations, self.solutionType = checkTypes(lhs, rhs) self.refreshButtons(operations) else: if operation == 'solve': self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = solveFor( self.lTokens, self.rTokens, varName) elif operation == 'integrate': self.lTokens, availableOperations, tokenString, equationTokens, comments = integrate( self.lTokens, varName) elif operation == 'differentiate': self.lTokens, availableOperations, tokenString, equationTokens, comments = differentiate( self.lTokens, varName) self.eqToks = equationTokens self.output = resultLatex(operation, equationTokens, comments, varName) if len(availableOperations) == 0: self.clearButtons() else: self.refreshButtons(availableOperations) if self.mode == 'normal': self.textedit.setText(tokenString) elif self.mode == 'interaction': cursor = self.textedit.textCursor() cursor.insertText(tokenString) if self.showStepByStep is True: showSteps(self) if self.showPlotter is True: plot(self)
def quickSimplify(workspace): """Dynamic simplifier for simplifying expression as it is being typed Arguments: workspace {QtWidgets.QWidget} -- main layout Returns: qSolution/log {string} -- quick solution or error log """ # FIXME: Crashes for some cases. Find and fix. qSolution = "" input = workspace.textedit.toPlainText() cleanInput = removeSpaces(input) terms = getTerms(cleanInput) normalizedTerms = normalize(terms) symTokens = tokenizeSymbols(normalizedTerms) terms, symTokens = removeUnary(normalizedTerms, symTokens) if checkEquation(normalizedTerms, symTokens) is True and input != "": if symTokens[-1] is not False: tokens = getToken(normalizedTerms, symTokens) tokens = tokens.tokens lhs, rhs = getLHSandRHS(tokens) _, solutionType = checkTypes(lhs, rhs) if solutionType == 'expression': _, _, _, equationTokens, _ = simplify(tokens) qSolution = r'$ ' + '= \ ' else: _, _, _, _, equationTokens, _ = simplifyEquation(lhs, rhs) qSolution = r'$ ' + '\Rightarrow \ ' qSolution += tokensToLatex(equationTokens[-1]) + ' $' # workspace.eqToks = equationTokens # plot(workspace) return qSolution else: log = "Invalid Expression" return log else: log = "" if input != "": _, log = checkEquation(normalizedTerms, symTokens) return log
def quickTest(inp, operation, wrtVar=None): if operation.__name__ not in ['ArithemeticMean', 'Mode', 'Median']: if (inp.count(';') == 2): afterSplit = inp.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] token_string, _, _ = operation(tokens[0], tokens[1], tokens[2], wrtVar) return removeSpaces(token_string) elif (inp.count(';') == 1): afterSplit = inp.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] tokens = [tokenizer(eqStr1), tokenizer(eqStr2)] _, _, token_string, _, _ = operation(tokens[0], tokens[1]) return removeSpaces(token_string) else: lhs, rhs = getLHSandRHS(tokenizer(inp)) _, inpType = checkTypes(lhs, rhs) if inpType == "equation": if wrtVar is not None: _, _, _, token_string, _, _ = operation(lhs, rhs, wrtVar) else: _, _, _, token_string, _, _ = operation(lhs, rhs) elif inpType == "expression": if wrtVar is not None: _, _, token_string, _, _ = operation(lhs, wrtVar) else: _, _, token_string, _, _ = operation(lhs) else: sampleSpaceObject = sampleSpace(inp) token_string, _, _ = operation(sampleSpaceObject) output = removeSpaces(token_string) return output
def interactionMode(self): self.enableQSolver = False showQSolve(self, self.enableQSolver) cursor = self.textedit.textCursor() interactionText = cursor.selectedText() if str(interactionText) == '': self.mode = 'normal' self.input = str(self.textedit.toPlainText()) else: self.input = str(interactionText) self.mode = 'interaction' showbuttons = True if len(self.input) == 0: self.input = '0' QMessageBox.information( self, "Message", "No input is given. please enter some expression.") showbuttons = False self.tokens = tokenizer(self.input) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) if isinstance(operations, list) and showbuttons: opButtons = [] if len(operations) > 0: if len(operations) == 1: if operations[0] not in [ 'integrate', 'differentiate', 'find roots', 'factorize' ]: opButtons = ['simplify'] else: opButtons = ['simplify'] for operation in operations: if operation == '+': opButtons.append("addition") elif operation == '-': opButtons.append("subtraction") elif operation == '*': opButtons.append("multiplication") elif operation == '/': opButtons.append("division") else: opButtons.append(operation) if self.buttonSet: for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) else: self.bottomButton.setParent(None) self.solutionWidget = QWidget() for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) self.solutionWidget.setLayout(self.solutionOptionsBox) self.buttonSplitter.addWidget(self.solutionWidget) self.buttonSet = True
def commandExec(command): operation = command.split('(', 1)[0] inputEquation = command.split('(', 1)[1][:-1] if ',' in inputEquation: varName = inputEquation.split(',')[1] inputEquation = inputEquation.split(',')[0] lhs = [] rhs = [] solutionType = '' lTokens = [] rTokens = [] equationTokens = [] comments = [] tokens = tokenizer(inputEquation) lhs, rhs = getLHSandRHS(tokens) lTokens = lhs rTokens = rhs _, solutionType = checkTypes(lhs, rhs) if operation == 'simplify': if solutionType == 'expression': tokens, _, _, equationTokens, comments = simplify(tokens) else: lTokens, rTokens, _, _, equationTokens, comments = simplifyEquation( lTokens, rTokens) elif operation == 'addition': if solutionType == 'expression': tokens, _, _, equationTokens, comments = addition(tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = additionEquation( lTokens, rTokens, True) elif operation == 'subtraction': if solutionType == 'expression': tokens, _, _, equationTokens, comments = subtraction(tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = subtractionEquation( lTokens, rTokens, True) elif operation == 'multiplication': if solutionType == 'expression': tokens, _, _, equationTokens, comments = multiplication( tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = multiplicationEquation( lTokens, rTokens, True) elif operation == 'division': if solutionType == 'expression': tokens, _, _, equationTokens, comments = division(tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = divisionEquation( lTokens, rTokens, True) elif operation == 'simplify': if solutionType == 'expression': tokens, _, _, equationTokens, comments = simplify(tokens) else: lTokens, rTokens, _, _, equationTokens, comments = simplifyEquation( lTokens, rTokens) elif operation == 'factorize': tokens, _, _, equationTokens, comments = factorize(tokens) elif operation == 'find-roots': lTokens, rTokens, _, _, equationTokens, comments = quadraticRoots( lTokens, rTokens) elif operation == 'solve': lhs, rhs = getLHSandRHS(tokens) lTokens, rTokens, _, _, equationTokens, comments = solveFor( lTokens, rTokens, varName) elif operation == 'integrate': lhs, rhs = getLHSandRHS(tokens) lTokens, _, _, equationTokens, comments = integrate(lTokens, varName) elif operation == 'differentiate': lhs, rhs = getLHSandRHS(tokens) lTokens, _, _, equationTokens, comments = differentiate( lTokens, varName) printOnCLI(equationTokens, operation, comments)
def calluser(): availableOperations = [] tokenString = '' equationTokens = [] self.input = str(self.textedit.toPlainText()) if varName == 'back': if self.input[0:4] == 'mat_': self.input = self.input[4:] self.input = self.input[0:-1] self.input = self.input[1:] if ';' in self.input: self.simul = True if (self.input.count(';') == 2): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] elif (self.input.count(';') == 1): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = '' if self.simul: self.tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] else: self.tokens = tokenizer(self.input) # DBP: print(self.tokens) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) self.refreshButtons(operations) else: if operation == 'solve': if not self.simul: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = solveFor(self.lTokens, self.rTokens, varName) else: tokenString, equationTokens, comments = simulSolver(self.tokens[0], self.tokens[1], self.tokens[2], varName) elif operation == 'integrate': self.lTokens, availableOperations, tokenString, equationTokens, comments = integrate(self.lTokens, varName) elif operation == 'differentiate': self.lTokens, availableOperations, tokenString, equationTokens, comments = differentiate(self.lTokens, varName) self.eqToks = equationTokens renderQuickSol(self, tokenString, self.showQSolver) self.output = resultLatex(equationTokens, operation, comments, self.solutionType, self.simul, varName) if len(availableOperations) == 0: self.clearButtons() else: self.refreshButtons(availableOperations) if self.mode == 'normal': self.textedit.setText(tokenString) elif self.mode == 'interaction': cursor = self.textedit.textCursor() cursor.insertText(tokenString) if self.showStepByStep is True: showSteps(self) if self.showPlotter is True: plot(self)
def interactionMode(self): if not self.matrix: self.enableQSolver = False renderQuickSol(self, self.qSol, self.enableQSolver) cursor = self.textedit.textCursor() interactionText = cursor.selectedText() if str(interactionText) == '': self.mode = 'normal' self.input = str(self.textedit.toPlainText()) else: self.input = str(interactionText) self.mode = 'interaction' showbuttons = True if len(self.input) == 0: return self.warning("No input given!") self.simul = False self.combi = False self.matrix = False self.dualOperandMatrix = False self.scalarOperationsMatrix = False self.nonMatrixResult = False if self.input[0:4] == 'mat_': self.input = self.input[4:] self.input = self.input[0:-1] self.input = self.input[1:] self.matrix = True if not self.matrix: if ';' in self.input: self.simul = True if (self.input.count(';') == 2): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] elif (self.input.count(';') == 1): self.combi = True afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = '' if self.simul: self.tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] self.addEquation() operations = ['solve'] if self.combi: operations.extend(['combination', 'permutation']) self.solutionType = 'equation' else: self.tokens = tokenizer(self.input) # DBP: print(self.tokens) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) if isinstance(operations, list) and showbuttons: opButtons = [] if len(operations) > 0: if len(operations) == 1: if (operations[0] not in ['integrate', 'differentiate', 'find roots', 'factorize']) and (not self.simul): opButtons = ['simplify'] else: opButtons = ['simplify'] for operation in operations: if operation == '+': opButtons.append("addition") elif operation == '-': opButtons.append("subtraction") elif operation == '*': opButtons.append("multiplication") elif operation == '/': opButtons.append("division") else: opButtons.append(operation) else: if ',' in self.input: self.dualOperandMatrix = True [inputEquation1, inputEquation2] = self.input.split(', ') if '[' in inputEquation1: inputEquation1 = inputEquation1[1:][:-1] inputEquation1 = inputEquation1.split('; ') matrixOperand1 = [] for row in inputEquation1: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand1.append(row1) self.Matrix1 = Matrix() self.Matrix1.value = matrixOperand1 inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) self.Matrix2 = Matrix() self.Matrix2.value = matrixOperand2 else: self.scalarOperationsMatrix = True inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) self.Matrix2 = Matrix() self.Matrix2.value = matrixOperand2 else: self.dualOperandMatrix = False inputEquation = self.input[:-2] inputEquation = inputEquation[:-1][1:] inputEquation = inputEquation.split('; ') matrixOperand = [] for row in inputEquation: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand.append(row1) self.Matrix0 = Matrix() self.Matrix0.value = matrixOperand opButtons = [] if ',' in self.input: opButtons.extend(['Addition', 'Subtraction', 'Multiply']) else: opButtons.extend(['Determinant', 'Trace', 'Inverse']) if self.buttonSet: for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) else: self.bottomButton.setParent(None) self.solutionWidget = QWidget() for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) self.solutionWidget.setLayout(self.solutionOptionsBox) self.buttonSplitter.addWidget(self.solutionWidget) self.buttonSet = True
def commandExec(command): operation = command.split('(', 1)[0] inputEquation = command.split('(', 1)[1][:-1] matrix = False # True when matrices operations are present in the code. if operation[0:4] == 'mat_': matrix = True if not matrix: """ This part handles the cases when VisMa is NOT dealing with matrices. Boolean flags used in code below: simul -- {True} when VisMa is dealing with simultaneous equations & {False} in all other cases """ varName = None if ',' in inputEquation: varName = inputEquation.split(',')[1] varName = "".join(varName.split()) inputEquation = inputEquation.split(',')[0] simul = False # True when simultaneous equation is present if (inputEquation.count(';') == 2) and (operation == 'solve'): simul = True afterSplit = inputEquation.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] lhs = [] rhs = [] solutionType = '' lTokens = [] rTokens = [] equationTokens = [] comments = [] if simul: tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] else: tokens = tokenizer(inputEquation) if '=' in inputEquation: lhs, rhs = getLHSandRHS(tokens) lTokens = lhs rTokens = rhs _, solutionType = checkTypes(lhs, rhs) else: solutionType = 'expression' lhs, rhs = getLHSandRHS(tokens) lTokens = lhs rTokens = rhs if operation == 'plot': app = QApplication(sys.argv) App(tokens) sys.exit(app.exec_()) elif operation == 'simplify': if solutionType == 'expression': tokens, _, _, equationTokens, comments = simplify(tokens) else: lTokens, rTokens, _, _, equationTokens, comments = simplifyEquation( lTokens, rTokens) elif operation == 'addition': if solutionType == 'expression': tokens, _, _, equationTokens, comments = addition(tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = additionEquation( lTokens, rTokens, True) elif operation == 'subtraction': if solutionType == 'expression': tokens, _, _, equationTokens, comments = subtraction( tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = subtractionEquation( lTokens, rTokens, True) elif operation == 'multiplication': if solutionType == 'expression': tokens, _, _, equationTokens, comments = multiplication( tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = multiplicationEquation( lTokens, rTokens, True) elif operation == 'division': if solutionType == 'expression': tokens, _, _, equationTokens, comments = division(tokens, True) else: lTokens, rTokens, _, _, equationTokens, comments = divisionEquation( lTokens, rTokens, True) elif operation == 'factorize': tokens, _, _, equationTokens, comments = factorize(tokens) elif operation == 'find-roots': lTokens, rTokens, _, _, equationTokens, comments = rootFinder( lTokens, rTokens) elif operation == 'solve': if simul: if varName is not None: _, equationTokens, comments = simulSolver( tokens[0], tokens[1], tokens[2], varName) else: _, equationTokens, comments = simulSolver( tokens[0], tokens[1], tokens[2]) solutionType = equationTokens else: lhs, rhs = getLHSandRHS(tokens) lTokens, rTokens, _, _, equationTokens, comments = solveFor( lTokens, rTokens, varName) elif operation == 'factorial': tokens, _, _, equationTokens, comments = factorial(tokens) elif operation == 'combination': n = tokenizer(inputEquation) r = tokenizer(varName) tokens, _, _, equationTokens, comments = combination(n, r) elif operation == 'permutation': n = tokenizer(inputEquation) r = tokenizer(varName) tokens, _, _, equationTokens, comments = permutation(n, r) elif operation == 'integrate': lhs, rhs = getLHSandRHS(tokens) lTokens, _, _, equationTokens, comments = integrate( lTokens, varName) elif operation == 'differentiate': lhs, rhs = getLHSandRHS(tokens) lTokens, _, _, equationTokens, comments = differentiate( lTokens, varName) if operation != 'plot': # FIXME: when either plotting window or GUI window is opened from CLI and after it is closed entire CLI exits, it would be better if it is avoided final_string = resultStringCLI(equationTokens, operation, comments, solutionType, simul) print(final_string) else: """ This part handles the cases when VisMa is dealing with matrices. Boolean flags used in code below: dualOperand -- {True} when the matrix operations require two operands (used in operations like addition, subtraction etc) nonMatrixResult -- {True} when the result after performing operations on the Matrix is not a Matrix (in operations like Determinant, Trace etc.) scalarOperations -- {True} when one of the operand in a scalar (used in operations like Scalar Addition, Scalar Subtraction etc.) """ operation = operation[4:] dualOperand = False nonMatrixResult = False scalarOperations = False if ', ' in inputEquation: dualOperand = True [inputEquation1, inputEquation2] = inputEquation.split(', ') if '[' in inputEquation1: inputEquation1 = inputEquation1[1:][:-1] inputEquation1 = inputEquation1.split('; ') matrixOperand1 = [] for row in inputEquation1: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand1.append(row1) Matrix1 = Matrix() Matrix1.value = matrixOperand1 inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) Matrix2 = Matrix() Matrix2.value = matrixOperand2 Matrix1_copy = copy.deepcopy(Matrix1) Matrix2_copy = copy.deepcopy(Matrix2) else: scalarOperations = True scalar = inputEquation1 scalarTokens = scalar # scalarTokens = tokenizer(scalar) inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) Matrix2 = Matrix() Matrix2.value = matrixOperand2 scalarTokens_copy = copy.deepcopy(scalarTokens) Matrix2_copy = copy.deepcopy(Matrix2) else: inputEquation = inputEquation[1:][:-1] inputEquation = inputEquation.split('; ') matrixOperand = [] for row in inputEquation: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand.append(row1) Matrix0 = Matrix() Matrix0.value = matrixOperand Matrix0_copy = copy.deepcopy(Matrix0) if operation == 'simplify': MatrixResult = simplifyMatrix(Matrix0) elif operation == 'add': MatrixResult = addMatrix(Matrix1, Matrix2) elif operation == 'sub': MatrixResult = subMatrix(Matrix1, Matrix2) elif operation == 'mult': MatrixResult = multiplyMatrix(Matrix1, Matrix2) elif operation == 'determinant': nonMatrixResult = True sqMatrix = SquareMat() sqMatrix.value = Matrix0.value result = sqMatrix.determinant() elif operation == 'trace': nonMatrixResult = True sqMatrix = SquareMat() sqMatrix.value = Matrix0.value result = sqMatrix.traceMat() elif operation == 'inverse': sqMatrix = SquareMat() sqMatrix.value = Matrix0.value MatrixResult = SquareMat() MatrixResult = sqMatrix.inverse() finalCLIstring = '' if dualOperand: if not scalarOperations: finalCLIstring = resultMatrixString(operation=operation, operand1=Matrix1_copy, operand2=Matrix2_copy, result=MatrixResult) else: finalCLIstring = resultMatrixString(operation=operation, operand1=scalarTokens_copy, operand2=Matrix2_copy, result=MatrixResult) else: if nonMatrixResult: finalCLIstring = resultMatrixString(operation=operation, operand1=Matrix0_copy, nonMatrixResult=True, result=result) else: finalCLIstring = resultMatrixString(operation=operation, operand1=Matrix0_copy, result=MatrixResult) print(finalCLIstring)