Skip to content

Commit

Permalink
Merge 7be838e into 3532df2
Browse files Browse the repository at this point in the history
  • Loading branch information
notimeforcaution committed Aug 20, 2019
2 parents 3532df2 + 7be838e commit 11c353d
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 6 deletions.
38 changes: 35 additions & 3 deletions visma/discreteMaths/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
from visma.functions.constant import Constant
from visma.io.tokenize import tokenizer

# TODO: Test cases.
# TODO: Implement GUI/CLI.


def logicalAND(token1, token2):
# TODO: Comments, animations & test cases.
"""Implements Bitwise AND
Arguments:
token1 -- {list} -- List of tokens of a constant number
token2 -- {list} -- List of tokens of a constant number
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

comments = []
animations = []
token1, _, _, _, _ = simplify(token1)
Expand All @@ -30,7 +43,17 @@ def logicalAND(token1, token2):


def logicalOR(token1, token2):
# TODO: Comments, animations & test cases.
"""Implements Bitwise OR
Arguments:
token1 -- {list} -- List of tokens of a constant number
token2 -- {list} -- List of tokens of a constant number
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

comments = []
animations = []
token1, _, _, _, _ = simplify(token1)
Expand All @@ -56,7 +79,16 @@ def logicalOR(token1, token2):


def logicalNOT(token1):
# TODO: Test cases.
"""Implements Bitwise NOT
Arguments:
token1 -- {list} -- List of tokens of a constant number
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

comments = []
animations = []
token1, _, _, _, _ = simplify(token1)
Expand Down
12 changes: 12 additions & 0 deletions visma/discreteMaths/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@


def simpleProbability(sampleSpace, requiredEvent=None):
"""Implements simple probability
Arguments:
sampleSpace -- {visma.discreteMaths.statistics.ArithemeticMean}
requiredEvent -- {Event whose probability is to be calculated}
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

animations = []
comments = []
events = []
Expand Down
36 changes: 36 additions & 0 deletions visma/discreteMaths/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
from visma.io.parser import tokensToString
from visma.functions.constant import Constant

# TODO: Implement this module in GUI/CLI


class sampleSpace(object):
"""Class used to represent sample space of a data.
"""
values = []
size = 0

Expand All @@ -16,6 +20,16 @@ def __init__(self, values):


def ArithemeticMean(sampleSpace):
"""Implements arithemetic mean
Arguments:
sampleSpace -- {visma.discreteMaths.statistics.ArithemeticMean}
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""
animations = []
comments = []
if sampleSpace.values is not []:
Expand All @@ -40,6 +54,17 @@ def ArithemeticMean(sampleSpace):


def Mode(sampleSpace):
"""Implements Mode
Arguments:
sampleSpace -- {visma.discreteMaths.statistics.ArithemeticMean}
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

animations = []
comments = []
token_string = ''
Expand All @@ -56,6 +81,17 @@ def Mode(sampleSpace):


def Median(sampleSpace):
"""Implements Median
Arguments:
sampleSpace -- {visma.discreteMaths.statistics.ArithemeticMean}
Returns:
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

animations = []
comments = []
token_string = ''
Expand Down
5 changes: 3 additions & 2 deletions visma/gui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, parent, tokens):
def commandExec(command):
operation = command.split('(', 1)[0]
inputEquation = command.split('(', 1)[1][:-1]
matrix = False
matrix = False # True when matrices operations are present in the code.
if operation[0:4] == 'mat_':
matrix = True

Expand All @@ -65,7 +65,7 @@ def commandExec(command):
varName = "".join(varName.split())
inputEquation = inputEquation.split(',')[0]

simul = False
simul = False # True when simultaneous equation is present
if (inputEquation.count(';') == 2) and (operation == 'solve'):
simul = True
afterSplit = inputEquation.split(';')
Expand Down Expand Up @@ -155,6 +155,7 @@ def commandExec(command):
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:
Expand Down
3 changes: 2 additions & 1 deletion visma/gui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ def calluser():
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)
Expand Down Expand Up @@ -828,7 +829,7 @@ def calluser():
if not self.scalarOperationsMatrix:
self.output = resultMatrixStringLatex(operation=name, operand1=Matrix1_copy, operand2=Matrix2_copy, result=MatrixResult)
else:
# TODO: Scalar Matrix Operation
# TODO: Implement Scalar Matrices operations.
pass
# finalCLIstring = resultMatrix_Latex(operation=name, operand1=scalarTokens_copy, operand2=Matrix2_copy, result=MatrixResult)
else:
Expand Down
80 changes: 80 additions & 0 deletions visma/simplify/addsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@


def addition(tokens, direct=False):
"""Function deals with addition related operations (driver function in addition module)
Arguments:
tokens {list} -- list of tokens
direct {bool} -- True when we are only concerned about multiplications terms in the input
Returns:
tokens {list} -- list of tokens
availableOperations {list} -- list of operations which can be performed on a equation token
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

animation = [copy.deepcopy(tokens)]
variables = []
Expand All @@ -37,6 +50,21 @@ def addition(tokens, direct=False):


def additionEquation(lToks, rToks, direct=False):
"""Function deals with multiplication related operations FOR EQUATIONS (driver function in multiplication module)
Arguments:
rtoks {list} -- list of right tokens
ltoks {list} -- list of left tokens
direct {bool} -- True when we are only concerned about multiplications terms in the input
Returns:
rtoks {list} -- list of right tokens
ltoks {list} -- list of left tokens
availableOperations {list} -- list of operations which can be performed on a equation token
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

lTokens = copy.deepcopy(lToks)
rTokens = copy.deepcopy(rToks)
Expand Down Expand Up @@ -146,6 +174,18 @@ def additionEquation(lToks, rToks, direct=False):


def expressionAddition(variables, tokens):
"""Function deals with addition related operations of two terms (called from driver function)
Arguments:
variables {list} -- list of LevelVariables
tokens {list} -- list of tokens
Returns:
variables {list} -- list of LevelVariables
tokens {list} -- list of tokens
removeScopes {list} -- indices of those tokens (/terms) which are removed as two terms in the equations get multiplied
comments {list} -- list of comments in equation solving process
"""

removeScopes = []
change = []
Expand Down Expand Up @@ -522,6 +562,19 @@ def equationAddition(lVariables, lTokens, rVariables, rTokens):


def subtraction(tokens, direct=False):
"""Function deals with subtraction related operations (driver function in subtraction module)
Arguments:
tokens {list} -- list of tokens
direct {bool} -- True when we are only concerned about multiplications terms in the input
Returns:
tokens {list} -- list of tokens
availableOperations {list} -- list of operations which can be performed on a equation token
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

animation = [copy.deepcopy(tokens)]
comments = []
Expand All @@ -544,6 +597,21 @@ def subtraction(tokens, direct=False):


def subtractionEquation(lToks, rToks, direct=False):
"""Function deals with multiplication related operations FOR EQUATIONS (driver function in multiplication module)
Arguments:
rtoks {list} -- list of right tokens
ltoks {list} -- list of left tokens
direct {bool} -- True when we are only concerned about multiplications terms in the input
Returns:
rtoks {list} -- list of right tokens
ltoks {list} -- list of left tokens
availableOperations {list} -- list of operations which can be performed on a equation token
token_string {string} -- final result stored in a string
animation {list} -- list of equation solving process
comments {list} -- list of comments in equation solving process
"""

lTokens = copy.deepcopy(lToks)
rTokens = copy.deepcopy(rToks)
Expand Down Expand Up @@ -655,6 +723,18 @@ def subtractionEquation(lToks, rToks, direct=False):


def expressionSubtraction(variables, tokens):
"""Function deals with multiplication related operations of two terms (called from driver function)
Arguments:
variables {list} -- list of LevelVariables
tokens {list} -- list of tokens
Returns:
variables {list} -- list of LevelVariables
tokens {list} -- list of tokens
removeScopes {list} -- indices of those tokens (/terms) which are removed as two terms in the equations get multiplied
comments {list} -- list of comments in equation solving process
"""

removeScopes = []
change = []
Expand Down

0 comments on commit 11c353d

Please sign in to comment.