-
Notifications
You must be signed in to change notification settings - Fork 1
/
algebra_problems
executable file
·122 lines (103 loc) · 2.65 KB
/
algebra_problems
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
from __future__ import print_function
import z3
def print_solutions(problem, solver):
print("Solution to problem %s:" % problem)
if solver.check() == z3.sat:
model = solver.model()
for v in model:
print("* %s = %s" % (v, model[v]))
else:
print("* Can't solve the problem")
def problem_01():
solver = z3.Solver()
x = z3.Real("x")
solver.add(5*(-3*x - 2) - (x - 3) == -4*(4*x + 5) + 13)
print_solutions("01", solver)
# No nice way to say x is unconstrained
def problem_03():
def declare_abs(var, expr):
solver.add(z3.Or(
z3.And(var == expr, expr >= 0),
z3.And(var == -expr, expr <= 0)
))
solver = z3.Solver()
x = z3.Real("x")
xm2abs = z3.Real("|x-2|")
declare_abs(xm2abs, x-2)
m6abs = z3.Real("|-6|")
declare_abs(m6abs, -6)
solver.add(x < 2)
solver.add(xm2abs == 4*m6abs)
print_solutions("03", solver)
def problem_04():
def declare_distance(a_b, ax, ay, bx, by):
solver.add(a_b >= 0)
solver.add(a_b**2 == (ax-bx)**2 + (ay-by)**2)
solver = z3.Solver()
ax = z3.Real("ax")
ay = z3.Real("ay")
bx = z3.Real("bx")
by = z3.Real("by")
a_b = z3.Real("|a-b|")
declare_distance(a_b, ax, ay, bx, by)
solver.add(ax == -4)
solver.add(ay == -5)
solver.add(bx == -1)
solver.add(by == -1)
print_solutions("04", solver)
def problem_05():
solver = z3.Solver()
x = z3.Real("x")
y = z3.Real("y")
solver.add(2*x - 4*y == 9)
solver.add(y == 0)
print_solutions("05", solver)
def problem_06():
solver = z3.Solver()
def declare_f(x,y):
solver.add(y == 6*x + 1)
x1 = z3.Real("x1")
y1 = z3.Real("y1")
x2 = z3.Real("x2")
y2 = z3.Real("y2")
answer = z3.Real("answer")
solver.add(x2 == 2)
solver.add(x1 == 1)
declare_f(x1, y1)
declare_f(x2, y2)
solver.add(answer == y2 - y1)
print_solutions("06", solver)
def problem_10():
def declare_abs(var, expr):
solver.add(z3.Or(
z3.And(var == expr, expr >= 0),
z3.And(var == -expr, expr <= 0)
))
solver = z3.Solver()
x = z3.Real("x")
y = z3.Real("|-2x + 2|")
declare_abs(y, -2*x + 2)
solver.add(y - 3 == -3)
print_solutions("10", solver)
problem_01()
problem_03()
problem_04()
problem_05()
problem_06()
problem_10()
"""
http://www.analyzemath.com/Algebra1/Algebra1.html
Problem 1: Solve the equation
5(-3x - 2) - (x - 3) = -4(4x + 5) + 13
Problem 3: If x <2, simplify
|x - 2| = 4|-6|
(actually I misread original, whatever)
Problem 4: Find the distance between the points (-4 , -5) and (-1 , -1).
Problem 5: Find the x intercept of the graph of the equation
2x - 4y = 9
Problem 6: Evaluate f(2) - f(1)
f(x) = 6x + 1
Problem 10: Solve the equation
|-2x + 2| -3 = -3
"""