import numpy as np
import sympy as sp
from IPython.display import HTML, IFrame
import ipywidgets as widgets
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
import pandas as pd
import itertools
from IPython.display import Image
import math
import itertools as iter
# function to print latex
def renderListToLatex(e):
latex_rendering = []
for i in range(len(e)):
latex_rendering.append("$$" + sp.latex(e[i]) + "$$")
return(HTML("".join(latex_rendering[0:])))
Aim: Introduce the scope and geometrical assumptions that can be used to describe Algebraic Calculus.
Observe: The problem of Calculus relates to both the fundamental problem of finding an area of a given region and the fundamental problem of finding tragectory of a particle given the forces on it, both of which were cirtical concerns for Netwon.
Observe: The connection between these fundamental problems demonstrates the intimate relationship between physics and geometry and highlights the difficuly of defining area.
Observe: In the more standard treatment of Calculus, the rectangle is used as the fundamental measurement. of area.
Observe: The use of rectangles to compute area requires a prior notion of both perpendicularity and distance.
Observe: It can be difficult to use rectangles as a means to prove that area is additive, rotationally invariant, and this makes it difficult to create generalise related theorems.
Observe: The use of rectangles assumes the constraints of a Cartesian style geometry, however there are other geometries besides Cartesian such as Affine, Projective, Relativistic, Spherical, Hyperbolic
Observe: It is possible to characterise different geometries by the the the operations that are permitted in relation to them (such as incidence, paralellism, perpendicularity, etc.)
Observe: Different geometries can be also be categorised as metrical (those which allow an assumption of distance/quadrance) and non-metrical (those which do not allow this).
Observe: Of all different geometries, Projective geometry has the fewest allowable operations. It allows points, lines, and incidence, and is non-metrical.
Observe: Affine geometry allows all the operations of Projective geometry, as well as parallel lines, and is also non-metrical.
Observe: It is possible to establish Calculus from a purely Affine geometry point of view (which does not allow rectangles, perpendicularity, distance, etc.) and this allows for more generality and more powerful formulas that have a broader applicability.
Aim: Introduce the definitions of data structures that will play an important role in Algebraic Calculus
Observe: There are 4 critical data structures that can be used across many areas of mathematics which are Lists, Ordered-sets, Multi-sets and Sets. These are collectively referred to as the LOMS data structures and refer to containers of unknown types that do or do not allow order and repetition.
Defintion: A List is a structure which contains one or more unknown types. Order is allowed. Repetition is allowed.
Example: List examples include $[3,4,5,6]$ and $[3, 3, 3, 3]$.
Definition: An Ordered-set is a structure which contains one or more unknown types. Order is allowed. Repetition is not allowed.
Example: Ordered-set examples include $\{3,4,5,6\}$ and $\{6, 7, 8\}$
Definition: A Multi-set is a structure which contains one or more unknown types. Order is not allowed. Repetition is allowed.
Example: Multi-set examples include $[3 \text{ } 4 \text{ } 4 \text{ } 5]$ and $[6\text{ } 5 \text{ } 6 \text{ } 7]$.
Definition: A Set is a structure which contains one or more unknown types. Order is not allowed. Repetition is not allowed.
Example: Set examples include $\{3 \text{ } 4\text{ } 5\text{ } 6\}$
Observe: The use of the notation $[]$ indicates that repetition is permitted in the LOMS data structure. The use of the notation $,$ indicates that order is permitted in the LOMS data structure.
Defintion: A data structure is denoted as Cyclic if both order and repetition is allowed (i.e. it is a list) and a cyclic rotation of the elements is also allowed.
Example: The following examples of Cyclic Lists are all equivalent:
$$ C=\langle [4,5,4,3,3] \rangle= \langle [5,4,3,3,4] \rangle=\langle [4,3,3,4,5] \rangle=\langle [3,3,4,5,4] \rangle=\langle [3,4,5,4,3] \rangle .$$Aim: Establish the geometrical definitions that will be used in Algebraic Calculus</b>
Observe: As a set can contain any any unknown types, it it possible to have a set of points, such as $\{A \text{ }B\}$ where $A$ and $B$ are points.
Definition: A Side, denoted $\overline{A \text{ } B } $ is a set of two points, where $A$ and $B$ are both points.
Definition: An Orientated Side, denoted $\widetilde{A, B} $ is an ordered set of two points, where $A$ and $B$ are both points.
Definition: A vector, denoted $\overset{\rightharpoonup}{A \text{ }, B}$ is an ordered set of two points, where $A$ and $B$ are both points but is differentiated from the Orientated Side in that the points contained in a vector can be translated and this does not affect equivalency.
Defintion: A triangle, denoted$\overline{ABC}$ is a cyclic list of three orientated sides, where $\overline{A,B}$, $\overline{B,C}$ and $\overline{C,A}$ are sides, constructed points $A, B$ and $C$.
Observe: As a triangle is a cyclic list, it is the case that:
$$ \widetilde{ABC} = \widetilde{BCA} = \widetilde{CAB}$$Theorem:
The signed area of the orientated triangle, denoted as $\widetilde{OAB}$, where $A = [a, b]$ and $B = [c, d]$ are points and $O$ is the point $[0, 0]$ is:
$$ s(\widetilde{OAB} \equiv \frac{1}{2}(ad - bc) $$Observe: A signed area can be both negative and positive.
Let $X1$ be a a function that implements the signed area of a triangle.
def X1(A, B):
return(1/2) * (A[0] * B[1] - A[1] * B[0])
Let $A$ and $B$ be points.
A = np.array([2,3])
B = np.array([4,1])
Example: Consider the triangle $\widetilde{OAB}$ where $O$ is the the point $[0, 0]$, $B$ is the point $[2, 3]$ and $C$ is the point $[4, 1]$.
Image("./Images/AC2_1.PNG", width=500)
Let $X2$ be signed area of the triangle $\widetilde{OAB}$
X2 = X1(A, B)
X2
-5.0
Aim: Extend the theorem of a signed area of a triangle to a more general theorem of an orientated edge
Observe: The signed area of the of the orientated triangle, $\widetilde{OAB}$ uses only informatin from $A$ and $B$ to compute answer. Because of this fact it is posssible to generalise the special case of the the orientated triangle $\widetilde{OAB}$ so it is equivalent to an orientated edge.
Definition: An orientated edge, denoted $\vec{AB}$ is an ordered set of points, where $A$ and $B$ are points.
Theorem: The signed area of an orientated edge, $\vec{AB}$, where $A = [a_1, b_1]$ and $B = [b_1, b_2]$:
$$ s(\vec{AB}) = \frac{1}{2}(a_1b_2 - a_2b_1) $$Observe: This theorem is equivalent to the theorem of the signed area of an orientated triangle, $\vec{OAB}$ and, as such, $X1$ can be used as an implementation of this theorem.
Example: The following example demonstrates the equivalence of both theorems
Let: $O, A, B$ and $C$ be points.
O = np.array([0, 0])
A = np.array([4, 2])
B = np.array([6, 6])
C = np.array([2, 6])
Image("./Images/DCB5_7.PNG", width = 500)
Let $OAB$ be the area of the orientated triangle formed from the points $O, A$ and $B$ and $OBA$ be the area of the orientated triangle formed from the points $O, B$ and $A$.
OAB = X1(A, B)
OBA = X1(B, A)
OAB, OBA
(6.0, -6.0)
Observe: The order of the points (or orientation) affects the sign of the answer.
Let $AB$ be the are of the orientated edge constructed from points $A$ and $B$, and $BA$ be the are of the orientated edge constructed from points $B$ and $A$.
AB = X1(A, B)
BA = X1(B, A)
AB, BA
(6.0, -6.0)
Observe: The theorem and signs for the area of orientated triangles and area of orientated sides is the same.
Let: $AB, BA, BC, CB, CA$ adn $AC$ be the area of orientated sides constructed from points, $A, B$ and $C$
AB = X1(A, B)
BC = X1(B, C)
CA = X1(C, A)
BA = X1(B, A)
AC = X1(A, C)
CB = X1(C, B)
Theorem: The area of the orientated triangle $\widetilde{ABC}$ is the sum of the area of the orientated edges that form the same triangle, $\vec{AB}, \vec{BC}$ and $\vec{CA}$ and this area is equivalent to the standard formula of the area of a triangle ($\frac{1}{2}$), however it does not require a prior notion of and perpendicularity or a distance calculation.
np.sum([AB, BC, CA])
8.0
Aim: Extend the summative propery of orientated edges to arbitrarily sized polygons to determine thier area.
Observe: It is possible to extend the notion of area as being the summation of the orientated sides of a triangle to polygons of an arbitrary number of sides.
Observe: As part the generalisation of this formula, a new definition of one of the components of the signed area of an orientated triangle, $s(\widetilde{OAB} \equiv \frac{1}{2}(ad - bc)$ will be introduced, called the cross product.
Defintion: The Cross Product (different from the standard definition) for 2 points $A = [a, b]$ and $B = [c, d]$ is defined as $ac - bd$
Observe: The implication of introducing the cross product is that the signed area of an orientated triangle ($\widetilde{OAB}$) or orientated edge ($\vec{AB}$) (where $O, A, B$ are points), is equivalent to half of its cross product.
Definition: An Orientated Polygonal Spline (OPS) $\overrightarrow{A_0,A_1\ldots,A_n} = [A_0,A_1\ldots,A_n]$ is an ordered list of affine points, $A_0, A_1, \ldots A_n$.
Theorem: The signed area of an orientated polygonal spline is defined to be:
$$ s(\overrightarrow{A_0,A_1\ldots,A_n}) = \Sigma_{k = 0}^{n-1} s(\overrightarrow{A_kA_{k + 1}})$$Observe: If this If $A_0 = A_n$, then $s(\overrightarrow{A_0,A_1\ldots,A_n}) $ is a closed polygon and independent of translation.
Theorem (Meister's Formula) Meister's formula calculates the signed area for an arbitrary number of points. In the case of 4 points $A = [x_1, y_1], B = [x_12, y_2], C = [x_3, y_3]$ and $D = [x_4, y_4]$, Meister's formula can be computed as:
$$ s(\widetilde{A_1A_2A_3A_4})=s(\widetilde{A_1A_2})+s(\widetilde{A_2A_3})+s(\widetilde{A_3A_4}+s(\widetilde{A_4A_1})\\=\frac12(x_1y_2-y_1x_2)+\frac12(x_2y_3-y_2x_3)+\frac12(x_3y_4-y_3x_4)+\frac12(x_4y_1-y_4x_1))\\=\frac{1}{2}(x_1y_2-y_1x_2+x_2y_3-y_2x_3+x_3y_4-y_3x_4+x_4y_1-y_4x_1). $$Observe: Meister's formula follows from the additive property of the area of orientated edges.
Let $X3, X4$ and $X5$ be function that implement the cross product, the signed area of an orientated edge, and the signed area using Meister's formula.
def X3(points_list):
c = points_list[0][0] * points_list[1][1] - points_list[0][1] * points_list[1][0]
return(c)
def X4(points_list):
c = X3(points_list)
signed_area = c / 2
return(signed_area)
def X5(points_list):
total_signed_area = 0
for each_point in range(len(points_list) - 1):
signed_area = X4([points_list[each_point], points_list[each_point + 1]])
total_signed_area = total_signed_area + signed_area
final_signed_area = compute_signed_area_of_triangle_from_two_points([points_list[-1], points_list[0]])
total_signed_area = total_signed_area + final_signed_area
return(total_signed_area)
Example Consider the following polygon:
Image("./Images/DCB5_6.PNG", width = 500)
Let $O, A, B, C, D, E$ and $F$ be points
O = np.array([0, 0])
A = np.array([1, 4])
B = np.array([5, 6])
C = np.array([9, 3])
D = np.array([7, 1])
E = np.array([2, 1])
F = np.array([2, 4])
Let $X6$ and $X7$ be the signed area of an orientated polygonal splines calculated using Meister's formula.
X6 = X5([A,B, C, D, E, F, A])
X7 = X5([A, F, E, D, C, B, A])
X6, X7
(-25.0, 25.0)
Observe: The calculation of the area of the polygon enclosed by the points $A, B, C, D, E$ and $F$ is the same as calculuating this in a standard way (breaking up the polygon into rectangles and triangles with a prior notion or perpendicularity).
Observe: The order of these points matters and if they are in a different order, the area will be different and the lines will overlap if rendered as a visualisation.
Observe: The order of these points can be changed cyclically and the area will remain equivalent.
Aim: Examine signed area in the context of polygons whose points satisfy $y = x^2$
Observe: For any value $t_i$, it must the case that $[t_i, t_i^2]$ will satisfy the formula for a parabola.
Let $C = [t_1,t_1^2], D = [t_2,t_2^2]$, and $ E = [t_3,t_3^2]$ be points that are incident to the parabola $y = x^2$ where $x$ and $y$ are the axes of an affine plane.
Let $X10$ and $X11$ be the orientated signed area for the points $C, D$ and $E$.
t1, t2, t3 = sp.symbols('t1, t2, t3')
C = np.array([t1,t1**2])
D = np.array([t2,t2**2])
E = np.array([t3,t3**2])
X8 = np.array([C, D, E])
X9 = np.array([E, D, C])
X10 = X5(X8).factor()
X11 = X5(X9).factor()
renderListToLatex([X10, " ", X11])
Observe: This derivation can be used as a formula for the signed area of a polygon enclosed by any 3 points on a parabola.
Let $X12$ be an implementation of the signed area of an orientated triangle on a parabola formula $\frac{\left(t_{1} - t_{2}\right) \left(t_{1} - t_{3}\right) \left(t_{2} - t_{3}\right)}{2}$
def X12(t1, t2, t3):
numerator = - ((t1 - t2) * (t1 - t3) * (t2 - t3))
return(numerator / 2)
Example: Verify that this formula accords with the standard area of a triangle on the parabola calculated in Geogebra.
Let $X13, X14$ and $X15$ be the $x$ coordinates of points on the parabola $y = x^2$
X13 = -1.75
X14 = 1.95
X15 = 1.13
Let $X16$ be $X12$ evaluated with $X13, X14$ and $X15$
X16 = X12(X15, X14, X13)
X16
4.36896
Observe this is approximately equivalent to the area calculated in Geogebra.
Image("./Images/AC2_2.PNG", width = 500)
Observe: It is possible to extend this other polygons with more than 3 sides and derive a formula based on the $x$ coordinates of the points.
Let: Let $X17$ and $X18$ be the formula derived for the polygon enclosed by 4 points on a parabola.
t1, t2, t3, t4 = sp.symbols('t1, t2, t3, t4')
C = np.array([t1,t1**2])
D = np.array([t2,t2**2])
E = np.array([t3,t3**2])
F = np.array([t4, t4**2])
X17 = np.array([C, D, E, F])
X18 = np.array([F, E, D, C])
X19 = X5(X17).factor()
X20 = X5(X18).factor()
renderListToLatex([X19, " ", X20])
Let $X21$ be an implementation of the formula for the orientated area of a quadrilateral where each point is incident to the parabola $y = x^2$
def X21(t1, t2, t3, t4):
return(((t4 - t2) * (t3 - t1)* (t4 - t1 + t2 - t3)) / 2)
Example: It is possible to use this formula to verify that the quadrilateral whose vertices are enclosed by the parabola $y = x^2$ is is equivalent to the area calculated by Geogebra.
Image("./Images/AC2_3.PNG", width = 500)
Let $X22, X23, X24$ and $X25$ be the coordinates of the points seen above inicident to the parabola.
X22 = -1.75
X23 = 1.95
X24 = 1.13
X25 = -0.93
Let $X26$ be $X21$ evaluated with $X22, X23, X24$ and $X25$
X26 = X21(X22, X23, X24, X25)
X26
-6.801408
Observe: the values of the area are equivalent.
Aim: It is possible to extend this technology to maximise the area of a quadrilateral whose vertices are incident to a parabola given 3 fixed points
Observe If the parabola, $y = x^2$ has 3 fixed points, there is some fourth point $t$ that can be chosen to maximise the area of the quadrilateral
Let $X22$ be $X21$ evaluated with 3 known inputs and one unknown type.
t = sp.symbols('t')
X22 = X21(4, -3, -1, t).factor()
X22
Observe It is known that that a product (or area in the case) of two numbers is maximised when those two numbers are the same.
Let $X24$ be the value of $t$ when both factors in $X22$ are the same. It is possible to obtain this value while ignoring the factor $\frac{-5}{2}$ as it will not affect the equality between the factors containing $t$.
X23 = sp.Eq((t + 3), (6 - t))
X24 = sp.solve(X23, t)
X24
[3/2]
Conclusion: If 3 points are chosen on a parabola in the example above, and a fourth point with $t = \frac{3}{2}$ will ensure the quadrilateral area is maximised.