Answered Essay: Computer Laboratory 1 CSCI 1913: Introduction to Algorithms, Data Structures, and Program Development September 12-13, 2017 0. Introductio

Computer Laboratory 1 CSCI 1913: Introduction to Algorithms, Data Structures, and Program Development September 12-13, 2017 0. Introduction. Its possible to solve an equation numerically, by substituting numbers for its variables Its also possible to solve an equation symbolically, by using algebra. For example, to solve the equation m ×x+b y symbolically for x, youd first subtract b from both sides, giving m × z = y-b. Then youd divide both sides by m, giving z (y-b) / m. You may assume that no variable is equal to zero. In this laboratory exercise, youll write a Python program that uses algebra to solve simple equations symbolically. Your program will use Python tuples to represent equations, and Python strings to represent variables. To simplify the problem, the equations will use only the binary arithmetic operators 4, , ‘x, andゾ. Also, your program need only solve for a variable that appears exactly once in an equation. 1. Theory Heres a mathematical description of how your program must work. First, L → R means that an equation L is algebraically transformed into a new equation R. For example: Second, a variable is said to be inside an expression if it appears in that expression at least once. For example, the variable x is inside the expression m × x + b, but it isnt inside the expression u - v. Each variable is considered to be inside itself, so that x is inside x Now suppose that Ao B = C is an equation, where A, B, and C are expressions, and suppose that the variable a is inside o is one of the four binary arithmetic operators. Also either A or B. Then the following rules show how this equation can be solved for x A = C-B B if z is inside A is inside B /1 + B = C → C-A if A-B-C^[A-C+B if z is inside A B-A-C A C / B B = C / A A=C× B if z is inside B if is inside A if x is inside B ifx is inside A A/B=C→ B=A/C ifxīs inside B For example, I can use the rules to solve the equation m × z + b = y for z. In Rule 1, A is m × x, and B is b. Since is inside A, I can transform the equation to m × = y-b Then in Rule 3, A is m, and B is z. Since r is inside B, I can transform the equation to x -(y -b)/m. Now x is alone on the left side of the equal sign, so the equation is solved This solution used only two rules, but a more complex equation might use more rules, and it might use rules more than once.

Computer Laboratory 1 CSCI 1913: Introduction to Algorithms, Data Structures, and Program Development September 12-13, 2017 0. Introduction. It’s possible to solve an equation numerically, by substituting numbers for its variables It’s also possible to solve an equation symbolically, by using algebra. For example, to solve the equation m ×x+b y symbolically for x, you’d first subtract b from both sides, giving m × z = y-b. Then you’d divide both sides by m, giving z (y-b) / m. You may assume that no variable is equal to zero. In this laboratory exercise, you’ll write a Python program that uses algebra to solve simple equations symbolically. Your program will use Python tuples to represent equations, and Python strings to represent variables. To simplify the problem, the equations will use only the binary arithmetic operators 4, , ‘x’, andゾ. Also, your program need only solve for a variable that appears exactly once in an equation. 1. Theory Here’s a mathematical description of how your program must work. First, L → R means that an equation L is algebraically transformed into a new equation R. For example: Second, a variable is said to be inside an expression if it appears in that expression at least once. For example, the variable x is inside the expression m × x + b, but it isn’t inside the expression u – v. Each variable is considered to be inside itself, so that x is inside x Now suppose that Ao B = C is an equation, where A, B, and C are expressions, and suppose that the variable a is inside o is one of the four binary arithmetic operators. Also either A or B. Then the following rules show how this equation can be solved for x A = C-B B if z is inside A is inside B /1 + B = C → C-A if A-B-C^[A-C+B if z is inside A B-A-C A C / B B = C / A A=C× B if z is inside B if is inside A if x is inside B ifx is inside A A/B=C→ B=A/C ifxīs inside B For example, I can use the rules to solve the equation m × z + b = y for z. In Rule 1, A is m × x, and B is b. Since is inside A, I can transform the equation to m × = y-b Then in Rule 3, A is m, and B is z. Since r is inside B, I can transform the equation to x -(y -b)/m. Now x is alone on the left side of the equal sign, so the equation is solved This solution used only two rules, but a more complex equation might use more rules, and it might use rules more than once.

Expert Answer

 

def left(e):
return e[0]
def right(e):
return e[2]
def op(e):
return e[1]

def isInside(v,e):
if type(e) != tuple:
if v == e:
return True
else:
return False
else:
if isInside(v,left(e)):
return True
if isInside(v,right(e)):
return True
return False

def solve(v,q):
if isInside(v,left(q)):
return solving(v,q)
elif isInside(v,right(q)):
r = (right(q),op(q),left(q))
return solving(v,r)
else:
return None

def solving(v,q):
if v == left(q):
return q
elif op(left(q)) == ‘+’:
return solvingAdd(v,q)
elif op(left(q)) == ‘-‘:
return solvingSubtract(v,q)
elif op(left(q)) == ‘*’:
return solvingMultiply(v,q)
elif op(left(q)) == ‘/’:
return solvingDivide(v,q)

def solvingAdd(v,q):
if isInside(v,left(left(q))):
return (left(left(q)), ‘=’, (right(q), ‘-‘,right(left(q))))
elif isInside(v,right(left(q))):
return (right(left(q)), ‘=’,(right(q), ‘-‘,left(left(q))))
def solvingSubtract(v,q):
if isInside(v,left(left(q))):
return (left(left(q)),’=’,(right(q), ‘+’,right(left(q))))
elif isInside(v,right(left(q))):
return (right(left(q)),’=’,(right(left(q)),’-‘, right(q)))
def solvingMultiply(v,q):
if isInside(v,left(left(q))):
return (left(left(q)), ‘=’, (right(q), ‘/’,right(left(q))))
elif isInside(v,right(left(q))):
return (right(left(q)), ‘=’,(right(q), ‘/’,left(left(q))))
def solvingDivide(v,q):
if isInside(v,left(left(q))):
return (left(left(q)),’=’,(right(q), ‘*’,right(left(q))))
elif isInside(v,right(left(q))):
return (right(left(q)),’=’,(right(left(q)),’/’, right(q)))

print(isInside(‘x’, ‘x’))                          # True
print(isInside(‘x’, ‘y’))                          # False
print(isInside(‘x’, (‘x’, ‘+’, ‘y’)))              # True
print(isInside(‘x’, (‘a’, ‘+’, ‘b’)))              # False
print(isInside(‘x’, ((‘m’, ‘*’, ‘x’), ‘+’, ‘b’))) # True

print(solve(‘x’, ((‘a’, ‘+’, ‘x’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘-‘, ‘a’))
print(solve(‘x’, ((‘x’, ‘+’, ‘b’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘-‘, ‘b’))

print(solve(‘x’, ((‘a’, ‘-‘, ‘x’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘a’, ‘-‘, ‘c’))
print(solve(‘x’, ((‘x’, ‘-‘, ‘b’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘+’, ‘b’))

print(solve(‘x’, ((‘a’, ‘*’, ‘x’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘/’, ‘a’))
print(solve(‘x’, ((‘x’, ‘*’, ‘b’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘/’, ‘b’))

print(solve(‘x’, ((‘a’, ‘/’, ‘x’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘a’, ‘/’, ‘c’))
print(solve(‘x’, ((‘x’, ‘/’, ‘b’), ‘=’, ‘c’))) # (‘x’, ‘=’, (‘c’, ‘*’, ‘b’))

print(solve(‘x’, (‘y’, ‘=’, ((‘m’, ‘*’, ‘x’), ‘+’, ‘b’))))
# (‘x’, ‘=’, ((‘y’, ‘-‘, ‘b’), ‘/’, ‘m’)

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.