Geometric Algebra in Haskell

Slides:



Advertisements
Similar presentations
Vectors, Points, Lines and Planes Jim Van Verth Lars M. Bishop
Advertisements

Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
Now Playing: My Mathematical Mind Spoon From Gimme Fiction Released May 10, 2005.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Review of Matrix Algebra
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
Oersted Medal Lecture 2002: Reforming the Mathematical Language of Physics David Hestenes Arizona State University.
Vectors.
Exponents and Polynomials
VECTORS AND THE GEOMETRY OF SPACE 12. VECTORS AND THE GEOMETRY OF SPACE So far, we have added two vectors and multiplied a vector by a scalar.
2IV60 Computer Graphics Basic Math for CG
UNIVERSITI MALAYSIA PERLIS
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
1 February 24 Matrices 3.2 Matrices; Row reduction Standard form of a set of linear equations: Chapter 3 Linear Algebra Matrix of coefficients: Augmented.
Recap of linear algebra: vectors, matrices, transformations, … Background knowledge for 3DM Marc van Kreveld.
Systems of Linear Equation and Matrices
Chapter 5: The Orthogonality and Least Squares
1.1 – 1.2 The Geometry and Algebra of Vectors.  Quantities that have magnitude but not direction are called scalars. Ex: Area, volume, temperature, time,
Polynomials Algebra I.
ANPA 2002: Quantum Geometric Algebra 8/15/2002 DJM Quantum Geometric Algebra ANPA Conference Cambridge, UK by Dr. Douglas J. Matzke Aug.
Polynomial Expressions Section P.3. Definition of Polynomial An algebraic expression of the form Where all coefficients a i are real numbers, The degree.
MULTIPLICATION OF POLYNOMIALS CHAPTER 4 SECTION 5 MTH Algebra.
VECTORS (Ch. 12) Vectors in the plane Definition: A vector v in the Cartesian plane is an ordered pair of real numbers:  a,b . We write v =  a,b  and.
AGC DSP AGC DSP Professor A G Constantinides©1 Signal Spaces The purpose of this part of the course is to introduce the basic concepts behind generalised.
Geometric Algebra 4. Algebraic Foundations and 4D Dr Chris Doran
Geometric Algebra Dr Chris Doran ARM Research 2. Geometric Algebra in 3 Dimensions.
{ What is a Number? Philosophy of Mathematics.  In philosophy and maths we like our definitions to give necessary and sufficient conditions.  This means.
Commutative and Associative Properties. Properties are rules in mathematics. You can use math properties to simplify algebraic expressions!
Geometric Algebra Dr Chris Doran ARM Research 7. Conformal Geometric Algebra.
Geometric Algebra Dr Chris Doran ARM Research 3. Applications to 3D dynamics.
Mathematical Tools of Quantum Mechanics
Copyright © Cengage Learning. All rights reserved. 12 Vectors and the Geometry of Space.
4. Affine transformations. Reading Required:  Watt, Section 1.1. Further reading:  Foley, et al, Chapter  David F. Rogers and J. Alan Adams,
1 Objective To provide background material in support of topics in Digital Image Processing that are based on matrices and/or vectors. Review Matrices.
Graphics Graphics Korea University kucg.korea.ac.kr Mathematics for Computer Graphics 고려대학교 컴퓨터 그래픽스 연구실.
0 PROGRAMMING IN HASKELL Typeclasses and higher order functions Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and.
Geometric Algebra 8. Conformal Geometric Algebra Dr Chris Doran
Addition, Subtraction, and Multiplication of Polynomials
Geometric Algebra 9. Unification Dr Chris Doran ARM Research.
Introduction to Seismology
Polymorphic Functions
Chapter 7 Inner Product Spaces
1.1 Real Numbers.
Spaces.
CSE 167 [Win 17], Lecture 2: Review of Basic Math Ravi Ramamoorthi
Geometric Algebra 6. Geometric Calculus Dr Chris Doran ARM Research.
CHAPTER R: Basic Concepts of Algebra
Types CSCE 314 Spring 2016.
Polynomial Expressions
Geometric Algebra 7. Implementation Dr Chris Doran ARM Research.
Outline Addition and subtraction of vectors Vector decomposition
A Mathematica Program for Geometric Algebra
Lecture 03: Linear Algebra
Introduction to Algebra
PROGRAMMING IN HASKELL
Lecture on Linear Algebra
1.1 Real Numbers.
Chapter 3 Linear Algebra
A definition we will encounter: Groups
Arab Open University Faculty of Computer Studies Dr
Linear Algebra A gentle introduction
Math review - scalars, vectors, and matrices
Honors Precalculus 4/19/18 IDs on and showing
Game Programming Algorithms and Techniques
PROGRAMMING IN HASKELL
Linear Vector Space and Matrix Mechanics
Matho083 Bianco Warm Up Multiply: 1) (x2) (x3) 2) (3x2) (4x3)
Presentation transcript:

Geometric Algebra in Haskell Dr Chris Doran Arm & Cambridge University Haskell Exchange 2017

What is a vector? A vector is a directed line segment (for now, at least) This is not a vector: This is a vector: b a b a+b c b+c a a+b a+b+c

The problem How do you multiply together two vectors? Inner product Cross product Commutative Returns a scalar Anti-commutative Returns a vector perpendicular to a plane Right-handed set

Geometric algebra W.K. Clifford (1845-1879) introduced the geometric product of two vectors. The product of two vectors is the sum of a scalar and a bivector. Think of the sum as like the real and imaginary parts of a complex number.

The rules The geometric product The geometric product is associative and distributive over addition. The square of any vector is a scalar. This makes the product invertible. Define the inner (scalar) and outer products in terms of the geometric product. Guaranteed to be a scalar

Two dimensions 2D sufficient to understand basic results. Construct an orthonormal basis. Parallel vectors commute. Orthogonal vectors anti-commute. This is the key property. We build everything up from this idea.

The bivector The unit bivector has negative square. Follows purely form the axioms of geometric algebra. We have not said anything about complex numbers, or solving polynomial equations. We have invented complex numbers! They arise naturally in the geometric algebra of the plane.

A type for multivectors

Multivectors and blades A multivector is a sum of basis blades 2D basis 3D Basis Zeros added to aid readability Can see that a form of reverse binary representation will capture each basis blade

Strong typing for geometry Use a newtype so that we can add Multivector to the num class. Store each blade as a tuple of the integer represented by the reverse binary expression, and a value. A multivector is then a list (sparse representation). Function for smaller spaces (up to 16d). Implement as an ADT, so don’t expose the constructor. blade function reads a string, E1E2, and converts to integer. Function for exploring larger spaces. Replaces Int by Integer. newtype Multivector n a = Mv [(n,a)] mv :: (Num a, Eq a) => [(a,String)] -> Multivector Int a mv xs = Mv (bladeListSimp (sortBy bladeComp (map blade xs))) longMv :: (Num a, Eq a) => [(a,String)] -> Multivector Integer a longMv xs = Mv (bladeListSimp (sortBy bladeComp (map blade xs)))

Blade product The product of two blade results in a new blade that is a binary xor of the input blades, and a sign: The xor is a form of long zipWith as we don’t discard the value in the longer list. Does not seem to be any simpler maths function. resBld xs [] = xs resBld [] ys = ys resBld (x:xs) (y:ys) = ((x+y) `mod` 2) : (resBld xs ys)

Blade product – counting swaps (blade running) The sign in the blade product is determined by the number of swaps 2 2 Total number of swaps = 4

Blade product – counting swaps NB This is the grade of [1,1,0,1] countSwap :: [Int] -> [Int] -> Int countSwap xs ys =foldl' (+) 0 zs where zs = zipWith (*) (tail xs) (scanl1 (+) (ys++zeroes)) By far the most compact formulation I have ever seen Note – used laziness in zeroes to pad out RHS blade to length of LHS

On to multivectors bladeProd :: (Num a, Integral n) => (n,a) -> (n,a) -> (n,a) bladeProd (n,a) (m,b) = (r,x) where (r,fn) = bldProd n m x = fn (a*b) bladeListProduct :: (Integral n, Num a, Eq a) => [(n,a)] -> [(n,a)] -> [(n,a)] bladeListProduct xs ys = bladeListSimp (sortBy bladeComp res) where res = [bladeProd x y | x <- xs, y <- ys] Take all of the blades and multiply them all together. Sort the result so that common blades are together. Simplify the final sum. That’s it!

Adding some class instance (Integral n, Eq a) => Eq (Multivector n a) where (Mv xs) == (Mv ys) = xs == ys instance (Integral n, Num a, Eq a) => Num (Multivector n a) where (Mv xs) * (Mv ys) = Mv (bladeListProduct xs ys) (Mv xs) + (Mv ys) = Mv (bladeListAdd xs ys) fromInteger n = Mv [(0,fromInteger n)] negate (Mv xs) = Mv (bldListNegate xs) abs (Mv xs) = Mv xs signum (Mv xs) = Mv xs Can now write A*B for the multivector product in code. Code is now much closer to the maths it represents. (May not seem like much, but I’ve always wanted to be able to do this.)

Typical session Set

Typical session Set Find

3D Algebra Summarise as:

3D Algebra Summarise as:

3D Basis Grade 0 1 Scalar Grade 1 3 Vectors Grade 2 3 Plane / bivector 1 Volume / trivector A linear space of dimension 8 Note the appearance of the binomial coefficients - this is general General elements of this space are called multivectors

Products in 3D We recover the cross product from duality: Can only do this in 3D

Projection Most expressions in GA take the form The angle brackets denote projecting out a given grade Laziness helps here! No need to manually simplify the code. We only calculate the bit of the product that we need. A valuable optimization for free. projGrade :: (Integral n, Num a) => Multivector n a -> Int -> Multivector n a projGrade (Mv xs) m = Mv (filter isGrade xs) where isGrade (fst,_) = bladeGrade fst == m rs = projGrade (a*b) 0

Outermorphism Mathsy name for a simple concept 2D example Matrix form

Outermorphism Mathsy name for a simple concept 2D example Matrix form Any dimension, any signature

Fine details Turns out to be really useful to cope with different signatures, so interleave positive and negative signature basis vectors. Gives us special relativity, conformal geometry … Want to add memorization. Not completely clear on best way. Optimization not consistent with polymorphism. Other optimization work would be valuable. Blade Bit vector Integer 1 e1 f1 01 2 e2 001 4 f2 0001 8 e1f1 11 3 e1e2 101 5

Unification Design choices in mathematics mirror those in computer science Coordinate geometry Complex analysis Vector calculus Tensor analysis Matrix algebra Lie groups Lie algebras Spinors Gauge theory Grassmann algebra Differential forms Quantum computing Twistors Quaternions Octonions Pauli operators Dirac theory QFT Gravity…

Thank You! geometry.mrao.cam.ac.uk chris.doran@arm.com cjld1@cam.ac.uk Resources geometry.mrao.cam.ac.uk chris.doran@arm.com cjld1@cam.ac.uk @chrisjldoran #geometricalgebra github.com/ga