Exemplo n.º 1
0
def main():
	equations = [ep.Equation("ek = 0.5 m1 v^2"),ep.Equation("ep = m2 g h")]
	equivalencies = [["m1","m2"],["ek","ep"]]
	rewrites = {"v":ss.rearrange(equations[0],"v")}

	while True:
		printState(equations,equivalencies,rewrites)

		instruction = raw_input(">> ")

		if instruction == "":
			pass
		elif instruction[:5]=="add e":
			equations.append(ep.Equation(instruction[12:]))
		elif instruction[:5]=="rewri":
			arg = instruction.split()[1]
			rewrites[arg] = ss.rewrite(arg,equations)
		elif instruction[:5]=="decla":
			equivalencies.append(instruction.split()[2:])
		elif instruction[:5]=="resta":
			args = instruction.split()
			rewrites[args[1]] = ss.removeTerm(rewrites[args[1]],args[3],
										equations[int(args[5])],equivalencies)
		elif instruction=="quit":
			return
		else:
			print "Instruction not understood"

		print
Exemplo n.º 2
0
def main():
    equations = [ep.Equation("ek = 0.5 m1 v^2"), ep.Equation("ep = m2 g h")]
    equivalencies = [["m1", "m2"], ["ek", "ep"]]
    rewrites = {"v": ss.rearrange(equations[0], "v")}

    while True:
        printState(equations, equivalencies, rewrites)

        instruction = raw_input(">> ")

        if instruction == "":
            pass
        elif instruction[:5] == "add e":
            equations.append(ep.Equation(instruction[12:]))
        elif instruction[:5] == "rewri":
            arg = instruction.split()[1]
            rewrites[arg] = ss.rewrite(arg, equations)
        elif instruction[:5] == "decla":
            equivalencies.append(instruction.split()[2:])
        elif instruction[:5] == "resta":
            args = instruction.split()
            rewrites[args[1]] = ss.removeTerm(rewrites[args[1]], args[3],
                                              equations[int(args[5])],
                                              equivalencies)
        elif instruction == "quit":
            return
        else:
            print "Instruction not understood"

        print
Exemplo n.º 3
0
def rewrite(arg,equations):
	for equation in equations:
		if arg in equation.terms:
			return ss.rearrange(equation,arg)
	raise Exception
Exemplo n.º 4
0
def rewrite(arg, equations):
    for equation in equations:
        if arg in equation.terms:
            return ss.rearrange(equation, arg)
    raise Exception