Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Modern Algebra Revisited: Linear Equalities

Views: 167
Kernel: SageMath (stable)
#1) prove: 1 + 2 + 3 + ... + n = n(n+1)/2 f(n) = n*(1 + n)/2 show(f(1)) show(f(2))
# prove: 1 + 2 + 3 + ... + n + (n + 1) = (n + 1)(n + 2)/2 # assume: 1 + 2 + 3 + ... + n = n(1 + n)/2 # show: n + 1 = (n + 1)(n + 2)/2 - n(1 + n)/2 show((n + 1)*(n + 2)/2 - n*(1 + n)/2) show(((n + 1)*(n + 2)/2 - n*(1 + n)/2).expand()) # other than expand(), we might also have used # simplify_rational(), simplify_radical(), or simplify_trig()
def symbolic_inverse(f, x): y = SR.var('y') g = (f - y).roots(x, multiplicities=False) return [expr.subs(y=x) for expr in g] def convert_to_mixed(n, d): m, p = divmod(abs(n), d) if n < Integer(Integer(0)): m = -m g = gcd(p, d) p = p/g d = d/g return '{} {}/{}'.format(m, p, d) if m != Integer(Integer(0)) and p > Integer(Integer(0)) else '{}'.format(m) if m != Integer(Integer(0)) else '{}/{}'.format(n, d)
convert_to_mixed(270, 16)
'16 7/8'
%display typeset symbolic_inverse(5*x - 3, x)
symbolic_inverse(x^2, x)
symbolic_inverse(log(x), x)

Modern Algebra: A Logical Approach, Book Two c.1966

Chapter 6: Functions and Other Relations

Linear Inequalities

----------------------------------------------------------------------------------

(1) Draw the graph of the relation defined by each of the following sentences.

(a) y > -2*x + 3 \lor y < x

x, y = var('x y') p = region_plot(y > -2*x + 3, (x, -200, 200), (y, -200, 200)) p += region_plot(y < x, (x, -200, 200), (y, -200, 200)) show(p)
Image in a Jupyter notebook

y > -2*x + 3 \land y < x

q = region_plot([y > -2*x + 3, y < x], (x, -50, 150), (y, -300, 300)) show(q)
Image in a Jupyter notebook

Let's experiment a little. The objective here is to learn about linear inequalities while also gaining some technical skills using Sage. This is explortative learning at age 50.

------------------------------

y > -2*x + 3 \lor y < x

p = region_plot( y > -2*x + 3, (x, -100, 100), (y, -100, 100), incol='orange') p += region_plot(y < x, (x, -100, 100), (y, -100, 100),incol='cyan') show(p, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

------------------------------

y \le 7 \lor y \ge -3

p1 = region_plot(y <= 7, (x, -100, 100), (y, -100, 100), incol='red') p1 += region_plot(y >= -3, (x, -100, 100), (y, -100, 100), incol='blue') show(p1, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

------------------------------

y <\lt 3 \lor y \ge x + 6 \lor y <\lt -x - 3

p2 = region_plot(y < 3, (x, -10, 10), (y, -10, 10), incol='red') p2 += region_plot(y > x + 6, (x, -10, 10), (y, -10, 10), incol='blue') p2 += region_plot(y < -x - 3, (x, -10, 10), (y, -10, 10), incol='green') show(p2, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

------------------------------

3x + y >\gt 5 \lor -2x + y <\lt -4

p3 = region_plot(3*x + y > 5, (x, -10, 10), (y, -10, 10), incol='orange') p3 += region_plot(-2*x + y < -4, (x, -10, 10), (y, -10, 10), incol='purple') show(p3, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

------------------------------

y >\gt x \lor y <\lt 4

p3 = region_plot(y > x, (x, -10, 10), (y, -10, 10), incol='cyan') p3 += region_plot(y < 4, (x, -10, 10), (y, -10, 10), incol='brown') show(p3, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook
p4 = region_plot([2 <= y, y <= 3], (x, -10, 10), (y, -10, 10)) show(p4)
Image in a Jupyter notebook
p5 = region_plot([2*x + 5 >= y or y >= -4*x + 1], (x, -10, 10), (y, -10, 10)) show(p5)
Image in a Jupyter notebook
p6 = region_plot([x - 2 <= y, y <= x + 2], (x, -10, 10), (y, -10, 10)) show(p6)
Image in a Jupyter notebook

--------------------------------------------------------------------------

[2] Draw the graph of the relation defined by each of the following sentences

(a) y > -2x - 5 \land y > -3x + 4

p = region_plot([y > -2*x - 5,y > -3*x + 4], (x, -10, 10), (y, -10, 10)) show(p)
Image in a Jupyter notebook

Changing this from a conjunction (intersection) to a disjunction (union):

(a) y > -2x - 5 \lor y > -3x + 4

p1 = region_plot(y > -2*x - 5, (x, -10, 10), (y, -10, 10), incol='orange') p2 = region_plot(y > -3*x + 4, (x, -10, 10), (y, -10, 10), incol='purple') show(p1 + p2, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

--------------------------------------------------------------------------

(b) 3x + 1 > y \land y > -4x - 3

p = region_plot([3*x + 1 > y,y > -4*x - 3], (x, -10, 10), (y, -10, 10)) show(p)
Image in a Jupyter notebook

Changing this from a conjunction (intersection) to a disjunction (union):

(b) 3x + 1 > y \lor y > -4x - 3

p1 = region_plot(3*x + 1 > y, (x, -10, 10), (y, -10, 10), incol='orange') p2 = region_plot(y > -4*x - 3, (x, -10, 10), (y, -10, 10), incol='purple') show(p1 + p2, axes="true", frame=False, aspect_ratio=1)
Image in a Jupyter notebook

--------------------------------------------------------------------------

(c) x >= 0 and y >= 0 \land y <= x + 4

p = region_plot([x >= 0, y >= 0, y <= x + 4], (x, -10, 25), (y, -10, 25), incol='red') show(p)
Image in a Jupyter notebook

--------------------------------------------------------------------------

(d) y <= x + 4 \land y > -x - 2 and x > 0

p = region_plot([y <= x + 4, y > -x - 2, x > 0], (x, -10, 30), (y, -40, 40), incol='yellow') show(p)
Image in a Jupyter notebook

--------------------------------------------------------------------------

(e) y <= 4 \land x <= 3 \land y > -3 \land x > -3

p = region_plot([y <= 4, x <= 3, y > -3, x > -3], (x, -5, 5), (y, -5, 5), incol='green') show(p)
Image in a Jupyter notebook
# p.316 (4) # To confirm my "pencil and paper" results: No graph p = region_plot([y < 4, y > -4, x >= 4, x > -4, y <= -x + 5, y >= x - 5, y >= -x + 5, y < x + 5], (x, -5, 10), (y, -5, 5)) show(p)
Image in a Jupyter notebook

(5) Given: A = {(x,y)| y <= -5x/3 + 7}, B = {(x,y)| y >= x - 1}, C = ((x,y)| y <= 9x + 39}, D = {(x,y)| y >= -7*x + 25},

draw the graph of:

(a) A \cap B \cap C

A = y <= -5*x/3 + 7 B = y >= x - 1 C = y <= 9*x + 39 D = y >= -7*x + 25 # (a) p = region_plot([A, B, C], (x, -10, 10), (y, -10, 15)) show(p)
Image in a Jupyter notebook

--------------------------------------------

(b) A \cap B \cap C \cap D

p = region_plot([A, B, C, D], (x, -10, 10), (y, -10, 15)) show(p)
Image in a Jupyter notebook

--------------------------------------------------------------------

(6) If M = x - y, find the greatest possible value of M subject to the condition that (x,y) are coordinates of a point in A, the region which is the graph of {(x,y)| y <= -2*x/5 + 4} \cap {(x,y)| y >= x - 3} \cap {(x,y)| y >= 0} \cap {(x,y)| x >= 0}

A = region_plot([y <= -2*x/5 + 4, y >= x - 3, y >= 0, x >= 0], (x, -5, 5), (y, -5, 5) ) show(A)
Image in a Jupyter notebook
M(x,y) = x - y M_vals = [] for X in range(4): for Y in range(5): if Y <= -2*X/5 + 4 and Y >= X - 3 and Y >= 0 and Y >= 0: M_vals.append(M(X,Y)) print('If M = x - y, the greatest possible value of M, subject to the condition ') print('that (x,y) are coordinates of a point in A, the region which is the graph of') print('{(x,y)| y <= -2*x/5 + 4} intersection {(x,y)| y >= x - 3} ') print('intersection {(x,y)| y >= 0} intersection {(x,y)| x >= 0} is ...') print('M = {}'.format(max(M_vals)))
If M = x - y, the greatest possible value of M, subject to the condition that (x,y) are coordinates of a point in A, the region which is the graph of {(x,y)| y <= -2*x/5 + 4} intersection {(x,y)| y >= x - 3} intersection {(x,y)| y >= 0} intersection {(x,y)| x >= 0} is ... M = 3

---------------------------------------------------------------------------------

(7) If K = -x/3 + y, find the least possible value of K subject to the condition that (x,y) are the coordinates of a point in B, the region which is the graph of {(x,y)| y >= -2x + 8} \cap {(x,y)| y >= 2x/3}

B = region_plot([y >= -2*x + 8, y >= 2*x/3], (x, -5, 10), (y, -5, 10) ) show(B)
Image in a Jupyter notebook
K(x,y) = -x/3 + y K_vals = [] for X in range(5): for Y in range(5): if Y >= -2*X + 8 and Y >= 2*X/3: K_vals.append(K(X,Y)) print('x = {0} and y = {1} so K = {2}'.format(X, Y, -X/3 + Y)) print('If K = -x/3 + y, the least possible value of K subject to the condition that') print('(x,y) are the coordinates of a point in B, the region which is the graph of') print('{(x,y)| y >= -2*x + 8} intersection {(x,y)| y >= 2*x/3} ...') print('is K = {:4.3}'.format(min(K_vals)))
x = 2 and y = 4 so K = 10/3 x = 3 and y = 2 so K = 1 x = 3 and y = 3 so K = 2 x = 3 and y = 4 so K = 3 x = 4 and y = 3 so K = 5/3 x = 4 and y = 4 so K = 8/3 If K = -x/3 + y, the least possible value of K subject to the condition that (x,y) are the coordinates of a point in B, the region which is the graph of {(x,y)| y >= -2*x + 8} intersection {(x,y)| y >= 2*x/3} ... is K = 1
def frange(x, y, jump=1.0): ''' Range for floats. Parameters: x: range starting value, will be included. y: range ending value, will be excluded jump: the step value. Only positive steps are supported. Return: a generator that yields floats Usage: >>> list(frange(0, 1, 0.2)) [0.0, 0.2, 0.4, 0.6000000000000001, 0.8] >>> list(frange(1, 0, 0.2)) [1.0] >>> list(frange(0.0, 0.05, 0.1)) [0.0] >>> list(frange(0.0, 0.15, 0.1)) [0.0, 0.1] ''' i = 0.0 x = float(x) # Prevent yielding integers. y = float(y) # Comparison converts y to float every time otherwise. x0 = x epsilon = jump / 2.0 yield x # yield always first value while x + epsilon < y: i += 1.0 x = x0 + i * jump yield x
K(x,y) = -x/3 + y K_vals = [] for X in frange(-5, 5, 1/3): for Y in frange(-5, 5, 1/3): if Y >= -2*X + 8 and Y >= 2*X/3: K_vals.append(K(X,Y)) print('x = {0} and y = {1} so K = {2}'.format(X, Y, -X/3 + Y)) print('If K = -x/3 + y, the least possible value of K subject to the condition that') print('(x,y) are the coordinates of a point in B, the region which is the graph of') print('{(x,y)| y >= -2*x + 8} intersection {(x,y)| y >= 2*x/3} ...') print('is K = {:4.3}'.format(min(K_vals)))
x = 1.66666666666667 and y = 5.00000000000000 so K = 4.44444444444444 x = 2.00000000000000 and y = 4.00000000000000 so K = 3.33333333333333 x = 2.00000000000000 and y = 4.33333333333333 so K = 3.66666666666667 x = 2.00000000000000 and y = 4.66666666666667 so K = 4.00000000000000 x = 2.00000000000000 and y = 5.00000000000000 so K = 4.33333333333333 x = 2.33333333333333 and y = 3.66666666666667 so K = 2.88888888888889 x = 2.33333333333333 and y = 4.00000000000000 so K = 3.22222222222222 x = 2.33333333333333 and y = 4.33333333333333 so K = 3.55555555555555 x = 2.33333333333333 and y = 4.66666666666667 so K = 3.88888888888889 x = 2.33333333333333 and y = 5.00000000000000 so K = 4.22222222222222 x = 2.66666666666667 and y = 3.00000000000000 so K = 2.11111111111111 x = 2.66666666666667 and y = 3.33333333333333 so K = 2.44444444444444 x = 2.66666666666667 and y = 3.66666666666667 so K = 2.77777777777778 x = 2.66666666666667 and y = 4.00000000000000 so K = 3.11111111111111 x = 2.66666666666667 and y = 4.33333333333333 so K = 3.44444444444444 x = 2.66666666666667 and y = 4.66666666666667 so K = 3.77777777777778 x = 2.66666666666667 and y = 5.00000000000000 so K = 4.11111111111111 x = 3.00000000000000 and y = 2.00000000000000 so K = 1.00000000000000 x = 3.00000000000000 and y = 2.33333333333333 so K = 1.33333333333333 x = 3.00000000000000 and y = 2.66666666666667 so K = 1.66666666666667 x = 3.00000000000000 and y = 3.00000000000000 so K = 2.00000000000000 x = 3.00000000000000 and y = 3.33333333333333 so K = 2.33333333333333 x = 3.00000000000000 and y = 3.66666666666667 so K = 2.66666666666667 x = 3.00000000000000 and y = 4.00000000000000 so K = 3.00000000000000 x = 3.00000000000000 and y = 4.33333333333333 so K = 3.33333333333333 x = 3.00000000000000 and y = 4.66666666666667 so K = 3.66666666666667 x = 3.00000000000000 and y = 5.00000000000000 so K = 4.00000000000000 x = 3.33333333333333 and y = 2.33333333333333 so K = 1.22222222222222 x = 3.33333333333333 and y = 2.66666666666667 so K = 1.55555555555556 x = 3.33333333333333 and y = 3.00000000000000 so K = 1.88888888888889 x = 3.33333333333333 and y = 3.33333333333333 so K = 2.22222222222222 x = 3.33333333333333 and y = 3.66666666666667 so K = 2.55555555555556 x = 3.33333333333333 and y = 4.00000000000000 so K = 2.88888888888889 x = 3.33333333333333 and y = 4.33333333333333 so K = 3.22222222222222 x = 3.33333333333333 and y = 4.66666666666667 so K = 3.55555555555556 x = 3.33333333333333 and y = 5.00000000000000 so K = 3.88888888888889 x = 3.66666666666667 and y = 2.66666666666667 so K = 1.44444444444444 x = 3.66666666666667 and y = 3.00000000000000 so K = 1.77777777777778 x = 3.66666666666667 and y = 3.33333333333333 so K = 2.11111111111111 x = 3.66666666666667 and y = 3.66666666666667 so K = 2.44444444444444 x = 3.66666666666667 and y = 4.00000000000000 so K = 2.77777777777778 x = 3.66666666666667 and y = 4.33333333333333 so K = 3.11111111111111 x = 3.66666666666667 and y = 4.66666666666667 so K = 3.44444444444444 x = 3.66666666666667 and y = 5.00000000000000 so K = 3.77777777777778 x = 4.00000000000000 and y = 3.00000000000000 so K = 1.66666666666667 x = 4.00000000000000 and y = 3.33333333333333 so K = 2.00000000000000 x = 4.00000000000000 and y = 3.66666666666667 so K = 2.33333333333333 x = 4.00000000000000 and y = 4.00000000000000 so K = 2.66666666666667 x = 4.00000000000000 and y = 4.33333333333333 so K = 3.00000000000000 x = 4.00000000000000 and y = 4.66666666666667 so K = 3.33333333333333 x = 4.00000000000000 and y = 5.00000000000000 so K = 3.66666666666667 x = 4.33333333333333 and y = 3.00000000000000 so K = 1.55555555555556 x = 4.33333333333333 and y = 3.33333333333333 so K = 1.88888888888889 x = 4.33333333333333 and y = 3.66666666666667 so K = 2.22222222222222 x = 4.33333333333333 and y = 4.00000000000000 so K = 2.55555555555556 x = 4.33333333333333 and y = 4.33333333333333 so K = 2.88888888888889 x = 4.33333333333333 and y = 4.66666666666667 so K = 3.22222222222222 x = 4.33333333333333 and y = 5.00000000000000 so K = 3.55555555555556 x = 4.66666666666667 and y = 3.33333333333333 so K = 1.77777777777778 x = 4.66666666666667 and y = 3.66666666666667 so K = 2.11111111111111 x = 4.66666666666667 and y = 4.00000000000000 so K = 2.44444444444444 x = 4.66666666666667 and y = 4.33333333333333 so K = 2.77777777777778 x = 4.66666666666667 and y = 4.66666666666667 so K = 3.11111111111111 x = 4.66666666666667 and y = 5.00000000000000 so K = 3.44444444444444 x = 5.00000000000000 and y = 3.66666666666667 so K = 2.00000000000000 x = 5.00000000000000 and y = 4.00000000000000 so K = 2.33333333333333 x = 5.00000000000000 and y = 4.33333333333333 so K = 2.66666666666667 x = 5.00000000000000 and y = 4.66666666666667 so K = 3.00000000000000 x = 5.00000000000000 and y = 5.00000000000000 so K = 3.33333333333333 If K = -x/3 + y, the least possible value of K subject to the condition that (x,y) are the coordinates of a point in B, the region which is the graph of {(x,y)| y >= -2*x + 8} intersection {(x,y)| y >= 2*x/3} ... is K = 1.0