Skip to content

Commit

Permalink
Merge pull request #1 from aerospaceresearch/dev
Browse files Browse the repository at this point in the history
Dev update
  • Loading branch information
8hantanu authored May 21, 2018
2 parents 8c4a428 + 2a69f32 commit 3f180a4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 22 deletions.
61 changes: 61 additions & 0 deletions visma/calculus/differentiation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
This file is to differentiate a function and is made along similar lines to that of integration.py
"""
import solve

def differntiate_variable(variable):
if len(variable["value"]) == 1:
if solve.is_number(variable["power"][0]):
if variable["power"][0] != 0:
variable["coefficient"] *= variable["power"][0]
variable["power"][0] -= 1
return variable
else:
#log
return variable
else:
tokens = []
for i in xrange(len(variable["value"])):
if i != 0:
binary = {}
binary["type"] = 'binary'
binary["value"] = '+'
tokens.append(binary)
var = copy.deepcopy(variable)
var["coefficient"] *= var["power"][i]
var["power"][i] -= 1
tokens.append(var)
return tokens

def trigonometry(variable):
if variable["type"] == 'cos':
variable["type"] = 'sin'
variable["coefficient"] *= -1
return variable
elif variable["type"] == 'sin':
variable["type"] = 'cos'
return variable
elif variable["type"] == 'tan':
if variable["power"] == 1:
variable["power"] = 2
variable["type"] = 'sec'
return variable
elif variable["type"] == 'cot':
if variable["power"] == 1:
variable["power"] = 2
variable["type"] = 'cosec'
variable["coefficient"] *= -1
return variable
return variable

def differentiate_tokens(tokens):
for token in tokens:
pass

def differentiate(lTokens, rTokens):
integratedLTokens = differentiate_tokens(lTokens)
integratedRTokens = differentiate_tokens(rTokens)


if __name__ == '__main__':
pass
44 changes: 30 additions & 14 deletions visma/calculus/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def integrate_variable(variable):
variable["coefficient"] /= variable["power"][0]
return variable
else:
# log
#log
variable["type"]='log'
variable["power"]=1
return variable
else:
tokens = []
Expand All @@ -36,19 +38,33 @@ def integrate_variable(variable):


def trigonometry(variable):
if variable["type"] == 'cos':
variable["type"] = 'sin'
return variable
elif variable["type"] == 'sin':
variable["type"] = 'cos'
variable["coefficient"] *= -1
return variable
elif variable["type"] == 'sec':
if variable["power"] == 2:
variable["power"] = 1
variable["type"] = 'tan'
return variable
return variable
if variable["type"] == 'cos':
variable["type"] = 'sin'
return variable
elif variable["type"] == 'sin':
variable["type"] = 'cos'
variable["coefficient"] *= -1
return variable
elif variable["type"] == 'sec':
if variable["power"] == 2:
variable["power"] = 1
variable["type"] = 'tan'
return variable
elif variable["type"]=='cosec':
if variable["power"] == 2:
variable["power"]=1
variable["type"] = 'cot'
variable["coefficient"] *= -1
return variable


def hyperbolic(variable):
if variable["type"] == 'sinh':
variable["type"] = 'cosh'
return variable
elif variable["type"] == 'cosh':
variable["type"] = 'sinh'
return variable


def integrate_constant(constant, var):
Expand Down
26 changes: 18 additions & 8 deletions visma/input/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
inputLaTeX = ['\\times', '\\div', '+', '-', '=', '^', '\\sqrt']
inputGreek = ['*', '/', '+', '-', '=', '^', 'sqrt']

words = ['tan', 'sqrt', 'sin', 'sec', 'cos', 'cosec', 'log', 'cot']
words = ['tan', 'sqrt', 'sin', 'sec', 'cos', 'cosec', 'log', 'cot', 'sinh', 'cosh']


def is_variable(term):
Expand Down Expand Up @@ -107,9 +107,14 @@ def get_terms(eqn):
if i < len(eqn):
buf += eqn[i]
if buf == "sin":
terms.append(buf)
x = i + 1
continue
if buf + eqn[i+1] == "sinh":
terms.append(buf + eqn[i+1])
x = i + 2
continue
else:
terms.append(buf)
x = i + 1
continue

i = x
buf = eqn[x]
Expand Down Expand Up @@ -175,10 +180,15 @@ def get_terms(eqn):
if i < len(eqn):
buf += eqn[i]
if buf == "cos":
terms.append(buf)
x = i + 1
continue

if buf + eqn[i+1] == "cosh":
terms.append(buf + eqn[i+1])
x = i + 2
continue
else:
terms.append(buf)
x = i + 1
continue

i = x
buf = eqn[x]
while (i - x) < len("ot"):
Expand Down

0 comments on commit 3f180a4

Please sign in to comment.