Example #1
0
        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)
Example #2
0
 def calluser():
     availableOperations = []
     tokenString = ''
     equationTokens = []
     self.resultOut = True
     if name == 'addition':
         if self.solutionType == 'expression':
             self.tokens, availableOperations, tokenString, equationTokens, comments = addition(
                 self.tokens, True)
         else:
             self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = additionEquation(
                 self.lTokens, self.rTokens, True)
     elif name == 'subtraction':
         if self.solutionType == 'expression':
             self.tokens, availableOperations, tokenString, equationTokens, comments = subtraction(
                 self.tokens, True)
         else:
             self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = subtractionEquation(
                 self.lTokens, self.rTokens, True)
     elif name == 'multiplication':
         if self.solutionType == 'expression':
             self.tokens, availableOperations, tokenString, equationTokens, comments = multiplication(
                 self.tokens, True)
         else:
             self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = multiplicationEquation(
                 self.lTokens, self.rTokens, True)
     elif name == 'division':
         if self.solutionType == 'expression':
             self.tokens, availableOperations, tokenString, equationTokens, comments = division(
                 self.tokens, True)
         else:
             self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = divisionEquation(
                 self.lTokens, self.rTokens, True)
     elif name == 'simplify':
         if self.solutionType == 'expression':
             self.tokens, availableOperations, tokenString, equationTokens, comments = simplify(
                 self.tokens)
         else:
             self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = simplifyEquation(
                 self.lTokens, self.rTokens)
     elif name == 'factorize':
         self.tokens, availableOperations, tokenString, equationTokens, comments = factorize(
             self.tokens)
     elif name == 'find roots':
         self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = quadraticRoots(
             self.lTokens, self.rTokens)
     elif name == 'solve':
         lhs, rhs = getLHSandRHS(self.tokens)
         variables = getVariables(lhs, rhs)
         self.wrtVariableButtons(variables, name)
         self.resultOut = False
     elif name == 'integrate':
         lhs, rhs = getLHSandRHS(self.tokens)
         variables = getVariables(lhs, rhs)
         self.wrtVariableButtons(variables, name)
         self.resultOut = False
     elif name == 'differentiate':
         lhs, rhs = getLHSandRHS(self.tokens)
         variables = getVariables(lhs, rhs)
         self.wrtVariableButtons(variables, name)
         self.resultOut = False
     if self.resultOut:
         self.eqToks = equationTokens
         self.output = resultLatex(name, equationTokens, comments)
         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)
Example #3
0
 def clearAll(self):
     self.textedit.clear()
     self.eqToks = [[]]
     self.output = ""
     showSteps(self)
     plot(self)
Example #4
0
        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)
Example #5
0
        def calluser():
            availableOperations = []
            tokenString = ''
            equationTokens = []
            self.resultOut = True
            if not self.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
                """
                if name == 'addition':
                    if self.solutionType == 'expression':
                        self.tokens, availableOperations, tokenString, equationTokens, comments = addition(
                            self.tokens, True)
                    else:
                        self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = additionEquation(
                            self.lTokens, self.rTokens, True)
                elif name == 'subtraction':
                    if self.solutionType == 'expression':
                        self.tokens, availableOperations, tokenString, equationTokens, comments = subtraction(
                            self.tokens, True)
                    else:
                        self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = subtractionEquation(
                            self.lTokens, self.rTokens, True)
                elif name == 'multiplication':
                    if self.solutionType == 'expression':
                        self.tokens, availableOperations, tokenString, equationTokens, comments = multiplication(
                            self.tokens, True)
                    else:
                        self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = multiplicationEquation(
                            self.lTokens, self.rTokens, True)
                elif name == 'division':
                    if self.solutionType == 'expression':
                        self.tokens, availableOperations, tokenString, equationTokens, comments = division(
                            self.tokens, True)
                    else:
                        self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = divisionEquation(
                            self.lTokens, self.rTokens, True)
                elif name == 'simplify':
                    if self.solutionType == 'expression':
                        self.tokens, availableOperations, tokenString, equationTokens, comments = simplify(self.tokens)
                    else:
                        self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = simplifyEquation(self.lTokens, self.rTokens)
                elif name == 'factorize':
                    self.tokens, availableOperations, tokenString, equationTokens, comments = factorize(self.tokens)
                elif name == 'find roots':
                    self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = rootFinder(self.lTokens, self.rTokens)
                elif name == 'solve':
                    if not self.simul:
                        lhs, rhs = getLHSandRHS(self.tokens)
                        variables = getVariables(lhs, rhs)
                    else:
                        variables = getVariableSim(self.tokens)
                    self.wrtVariableButtons(variables, name)
                    self.resultOut = False
                elif name == 'factorial':
                    self.tokens, availableOperations, tokenString, equationTokens, comments = factorial(self.tokens)
                elif name == 'combination':
                    nTokens = self.tokens[0]
                    rTokens = self.tokens[1]
                    self.tokens, _, _, equationTokens, comments = combination(nTokens, rTokens)
                elif name == 'permutation':
                    nTokens = self.tokens[0]
                    rTokens = self.tokens[1]
                    self.tokens, _, _, equationTokens, comments = permutation(nTokens, rTokens)
                elif name == 'integrate':
                    lhs, rhs = getLHSandRHS(self.tokens)
                    variables = getVariables(lhs, rhs)
                    self.wrtVariableButtons(variables, name)
                    self.resultOut = False
                elif name == 'differentiate':
                    lhs, rhs = getLHSandRHS(self.tokens)
                    variables = getVariables(lhs, rhs)
                    self.wrtVariableButtons(variables, name)
                    self.resultOut = False
            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.)
                """
                #   TODO: use latex tools like /amsmath for displaying matrices
                if self.dualOperandMatrix:
                    Matrix1_copy = copy.deepcopy(self.Matrix1)
                    Matrix2_copy = copy.deepcopy(self.Matrix2)
                else:
                    Matrix0_copy = copy.deepcopy(self.Matrix0)
                if name == 'Addition':
                    MatrixResult = addMatrix(self.Matrix1, self.Matrix2)
                elif name == 'Subtraction':
                    MatrixResult = subMatrix(self.Matrix1, self.Matrix2)
                elif name == 'Multiply':
                    MatrixResult = multiplyMatrix(self.Matrix1, self.Matrix2)
                elif name == 'Simplify':
                    MatrixResult = simplifyMatrix(self.Matrix0)
                elif name == 'Trace':
                    sqMatrix = SquareMat()
                    sqMatrix.value = self.Matrix0.value
                    result = sqMatrix.traceMat()
                elif name == 'Determinant':
                    sqMatrix = SquareMat()
                    sqMatrix.value = self.Matrix0.value
                    result = sqMatrix.determinant()
                elif name == 'Inverse':
                    sqMatrix = SquareMat()
                    sqMatrix.value = self.Matrix0.value
                    MatrixResult = SquareMat()
                    MatrixResult = sqMatrix.inverse()
                if name in ['Addition', 'Subtraction', 'Multiply']:
                    self.dualOperandMatrix = True
                else:
                    self.dualOperandMatrix = False
                if name in ['Determinant', 'Trace']:
                    self.nonMatrixResult = True
                else:
                    self.nonMatrixResult = False
            if self.resultOut:
                if not self.matrix:
                    self.eqToks = equationTokens
                    self.output = resultLatex(equationTokens, name, comments, self.solutionType)
                    if (mathError(self.eqToks[-1])):
                        self.output += 'Math Error: LHS not equal to RHS' + '\n'
                    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)
                else:
                    if self.dualOperandMatrix:
                        if not self.scalarOperationsMatrix:
                            self.output = resultMatrixStringLatex(operation=name, operand1=Matrix1_copy, operand2=Matrix2_copy, result=MatrixResult)
                        else:
                            # TODO: Implement Scalar Matrices operations.
                            pass
                            # finalCLIstring = resultMatrix_Latex(operation=name, operand1=scalarTokens_copy, operand2=Matrix2_copy, result=MatrixResult)
                    else:
                        if self.nonMatrixResult:
                            self.output = resultMatrixStringLatex(operation=name, operand1=Matrix0_copy, nonMatrixResult=True, result=result)
                        else:
                            self.output = resultMatrixStringLatex(operation=name, operand1=Matrix0_copy, result=MatrixResult)
                    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)