SemiringAlgebra.jl: Semiring Algebra

SemiringAlgebra.jl

The doc/ directory includes a paper Novel Algebras for Advanced Analytics in Julia, which describes the motivation for this package and its design.

Example usage, see the bench() function in SemringAlgebra.jl.

julia> using Pkg; Pkg.add(PackageSpec(url = pwd())); Pkg.build()

julia> Pkg.test("SemiringAlgebra")

julia> using SemiringAlgebra

julia> SemiringAlgebra.bench(100)

100x100 Float64 array
  0.000345 seconds (2 allocations: 78.203 KiB)
100x100 MPNumber{Float64} array
  0.002951 seconds (8 allocations: 78.531 KiB)

100x100 Int64 array
  0.000643 seconds (8 allocations: 78.531 KiB)
100x100 MPNumber{Int64} array
  0.000465 seconds (8 allocations: 78.531 KiB)

100x100 sparse Float64 array (dense array in sparse format)
  0.116772 seconds (198.15 k allocations: 9.675 MiB)
100x100 sparse MPNumber{Float64} array (dense array in sparse format)
  0.102237 seconds (199.09 k allocations: 9.695 MiB)

100000x100000 sparse Float64 array (sprand(n,n,1/n))
  0.007495 seconds (20 allocations: 10.677 MiB)
100000x100000 sparse MPNumber{Float64} array (sprand(n,n,1/n))
  0.007558 seconds (20 allocations: 10.677 MiB)

100000x100000 sparse Float64 array (sprand(n,n,5/n))
  0.147927 seconds (22 allocations: 65.650 MiB, 4.86% gc time)
100000x100000 sparse MPNumber{Float64} array (sprand(n,n,5/n))
  0.146088 seconds (22 allocations: 65.650 MiB, 4.94% gc time)

Download Details:

Author: JuliaComputing
Source Code: https://github.com/JuliaComputing/SemiringAlgebra.jl 

#julia #algebra 

What is GEEK

Buddha Community

SemiringAlgebra.jl: Semiring Algebra

SemiringAlgebra.jl: Semiring Algebra

SemiringAlgebra.jl

The doc/ directory includes a paper Novel Algebras for Advanced Analytics in Julia, which describes the motivation for this package and its design.

Example usage, see the bench() function in SemringAlgebra.jl.

julia> using Pkg; Pkg.add(PackageSpec(url = pwd())); Pkg.build()

julia> Pkg.test("SemiringAlgebra")

julia> using SemiringAlgebra

julia> SemiringAlgebra.bench(100)

100x100 Float64 array
  0.000345 seconds (2 allocations: 78.203 KiB)
100x100 MPNumber{Float64} array
  0.002951 seconds (8 allocations: 78.531 KiB)

100x100 Int64 array
  0.000643 seconds (8 allocations: 78.531 KiB)
100x100 MPNumber{Int64} array
  0.000465 seconds (8 allocations: 78.531 KiB)

100x100 sparse Float64 array (dense array in sparse format)
  0.116772 seconds (198.15 k allocations: 9.675 MiB)
100x100 sparse MPNumber{Float64} array (dense array in sparse format)
  0.102237 seconds (199.09 k allocations: 9.695 MiB)

100000x100000 sparse Float64 array (sprand(n,n,1/n))
  0.007495 seconds (20 allocations: 10.677 MiB)
100000x100000 sparse MPNumber{Float64} array (sprand(n,n,1/n))
  0.007558 seconds (20 allocations: 10.677 MiB)

100000x100000 sparse Float64 array (sprand(n,n,5/n))
  0.147927 seconds (22 allocations: 65.650 MiB, 4.86% gc time)
100000x100000 sparse MPNumber{Float64} array (sprand(n,n,5/n))
  0.146088 seconds (22 allocations: 65.650 MiB, 4.94% gc time)

Download Details:

Author: JuliaComputing
Source Code: https://github.com/JuliaComputing/SemiringAlgebra.jl 

#julia #algebra 

Bailee  Streich

Bailee Streich

1624447260

Course Review: Python for Linear Algebra

Because I am continuously endeavouring to improve my knowledge and skill of the Python programming language, I decided to take some free courses in an attempt to improve upon my knowledge base. I found one such course on linear algebra, which I found on YouTube. I decided to watch the video and undertake the course work because it focused on the Python programming language, something that I wanted to improve my skill in. Youtube video this course review was taken from:- (4) Python for linear algebra (for absolute beginners) — YouTube

The course is for absolute beginners, which is good because I have never studied linear algebra and had no idea what the terms I would be working with were.

Linear algebra is the branch of mathematics concerning linear equations, such as linear maps and their representations in vector spaces and through matrices. Linear algebra is central to almost all areas of mathematics.

Whilst studying linear algebra, I have learned a few topics that I had not previously known. For example:-

A scalar is simply a number, being an integer or a float. Scalers are convenient in applications that don’t need to be concerned with all the ways that data can be represented in a computer.

A vector is a one dimensional array of numbers. The difference between a vector is that it is mutable, being known as dynamic arrays.

A matrix is similar to a two dimensional rectangular array of data stored in rows and columns. The data stored in the matrix can be strings, numbers, etcetera.

In addition to the basic components of linear algebra, being a scalar, vector and matrix, there are several ways the vectors and matrix can be manipulated to make it suitable for machine learning.

I used Google Colab to code the programming examples and the assignments that were given in the 1 hour 51 minute video. It took a while to get into writing the code of the various subjects that were studied because, as the video stated, it is a course for absolute beginners.

The two main libraries that were used for this course were numpy and matplotlib. Numpy is the library that is used to carry out algebraic operations and matplotlib is used to graphically plot the points that are created in the program.

#numpy #matplotlib #python #linear-algebra #course review: python for linear algebra #linear algebra

Linear Algebra: The hidden engine of machine learning

Algebra is firstly taken from a book, written by Khwarizmi(780-850 CE), which is about calculation and equations. It is a branch of mathematics in which letters are used instead of numbers. Each letter can represent a specific number in one place, and a completely different number in another. Notations and symbols are also used in algebra to show the relationship between numbers. I remember about 17 years ago when I was an ordinary student in applied mathematics(ordinary graduate today!), I was so curious about some research in algebra, done by Maryam Mirzakhani(1977–2017), at Harvard University about analogous counting problem. This science has evolved a lot throughout history and now includes many branches.

Elementary algebra includes basic operations on four main operations. After defining the signs by which fixed numbers and variables are separated, methods are used to solve the equations. A polynomial is an expression that is the sum of a finite number of non-zero terms, each term consisting of the product of a constant and a finite number of variables raised to whole number powers.

Abstract algebra or modern algebra is a group in the algebra family that studies advanced algebraic structures such as groups, rings, and fields. Algebraic structures, with their associated homomorphisms, form mathematical categories. Category theory is a formalism that allows a unified way for expressing properties and constructions that are similar for various structures. Abstract algebra is so popular and used in many fields of mathematics and engineering sciences. For instance, algebraic topology uses algebraic objects to study topologies. The Poincaré conjecture proved in 2003, asserts that the fundamental group of a manifold, which encodes information about connectedness, can be used to determine whether a manifold is a sphere or not. Algebraic number theory studies various number rings that generalize the set of integers.

I believe that the most influencing branch of algebra in other sciences is linear algebra. Let’s suppose that you went out for jogging, that can’t be easy these days with Covid-19 lockdown, and suddenly a beautiful flower catches all your attention. Please don’t be rush and pick it, just take a picture, others can enjoy it, as well. After a while when you look at this picture, you can recognize the flower in the image, because the human brain has evolved over millions of years and able to detect such a thing. We are unaware of the operations that take place in the background of our brains and enable us to recognize the colors in the image, they are trained to do this for us automatically. But, it’s not easy to do such a thing with a machine, that’s why this is one of the most active research areas in machine learning and deep learning. Actually, the fundamental question is: “How does a machine store this image?” You probably know that today’s computers are designed to process only two numbers, 0 and 1. Now, how can an image like this with different features be stored? This is done by storing the pixel intensity in a structure called a “matrix”.

The main topics in linear algebra are vectors and matrices. Vectors are geometric objects that have length and direction. For example, we can mention speed and force, both of which are vector quantities. Each vector is represented by an arrow whose length and direction indicate the size and direction of the vector.

The addition of two or more vectors can be done based on ease of use using parallelogram methods or the method of images in which each vector is decomposed into its components along the coordinate axes. A vector space is a collection of vectors, which may be added together and multiplied by scalars. Scalars generally can be picked up from any field but normally are real numbers.

#matrice #machine-learning #linear-algebra #algebra #deep-learning #deep learning

Liya  Smith

Liya Smith

1624950677

Where Can I Get Help with My Algebra Homework?

Algebra is a subject that you will fall in love with if you understand the basics. However, if you fail to do so, it will be no less than a nightmare for you. You will have to solve the puzzling sums anyway to submit flawless homework solutions to your university or college. You will inevitably have to derive accurate solutions for algebra equations within the set time frame to achieve the highest possible grades for your program. You will always find the much-needed supportive hand at the LiveWebTutors platform. The Algebra Homework Help service by our portal is the perfect solution to all your mathematical scholarly writing requirements.

Algebra is the language of mathematics that makes it easy for an individual to present a mathematical equation with the help of the alphabet. If you desire to get impressive scores with your algebra homework assessment, fulfil the goals with the homework help service by the LiveWebTutors platform. Get in touch with our customer support executives and unlock the door to academic success instantly.

Develop better subject insight with our professional algebra homework help service

If your foundational knowledge about algebra is not clear, you will find it challenging to deal with complicated sums. You can develop a strong basis for your algebra knowledge by getting in touch with our homework help experts. The easy-to-understand outcomes developed by our Ph.D. or Master’s qualified mathematicians will help you to understand the concepts clearly and strengthen your knowledge of algebra. Our algebra homework help experts have successfully assisted tens of thousands of students in the USA to achieve better grades in their academic program and build a strong grasp of algebraic concepts.

With our unaltered assistance, you will be able to determine how to simplify an algebraic expression, determine the slope of a line from the given equation, find the distance between two points, discover the equation of a line, simplify absolute value expressions, and learn about multiple other problems. Get in touch with our dexterous panel right away and thank us later for helping you enhance your academic performance.

Save yourself some time and efforts with our comprehensive algebra homework help facility

Have you ever been stuck in a situation where you started to solve a sum only to realize that you don’t know how to finish it? If yes, we understand how frustrating, tedious, and bothersome it can be. Whether you are a high school, college, or university scholar on the lookout for algebra homework help services, feel free to get in touch with our diligent experts to get rid of all your homework and academic writing stress in a jiffy.

Instead of wasting your time trying numerous ways to solve the algebra homework, you can get accurate outcomes in the shortest possible turnaround and analyse the steps for a better understanding of the concept.

Bid adieu to late submission penalties, stress, and low-quality algebra homework solutions with our astounding assistance.

If you are sick of scoring average scores in your algebra homework question, LiveWebTutors is the ultimate option for you.

#algebra homework help #algebra #homework help #education

Bongani  Ngema

Bongani Ngema

1645518900

Algebra: Algebraic Structures

algebra

means completeness and balancing, from the Arabic word الجبر 

Algebra OnQuaternionsAndOctonions

Table Of Contents

Features

Installation

With npm do

npm install algebra

or use a CDN adding this to your HTML page

<script src="https://unpkg.com/algebra/dist/algebra.min.js"></script>

Quick start

This is a 60 seconds tutorial to get your hands dirty with algebra.

NOTA BENE Imagine all code examples below as written in some REPL where expected output is documented as a comment.

All code in the examples below should be contained into a single file, like test/quickStart.js.

First of all, import algebra package.

const algebra = require('algebra')

Scalars

Use the Real numbers as scalars.

const R = algebra.Real

Every operator is implemented both as a static function and as an object method.

Static operators return raw data, while class methods return object instances.

Use static addition operator to add three numbers.

R.add(1, 2) // 3

Create two real number objects: x = 2, y = -2

// x will be overwritten, see below
let x = new R(2)
const y = new R(-2)

The value r is the result of x multiplied by y.

// 2 * (-2) = -4
const r = x.mul(y)

r // Scalar { data: -4 }

// x and y are not changed
x.data // 2
y.data // -2

Raw numbers are coerced, operators can be chained when it makes sense. Of course you can reassign x, for example, x value will be 0.1: x -> x + 3 -> x * 2 -> x ^-1

// ((2 + 3) * 2)^(-1) = 0.1
x = x.add(3).mul(2).inv()

x // Scalar { data: 0.1 }

Comparison operators equal and notEqual are available, but they cannot be chained.

x.equal(0.1) // true
x.notEqual(Math.PI) // true

You can also play with Complexes.

const C = algebra.Complex

let z1 = new C([1, 2])
const z2 = new C([3, 4])

z1 = z1.mul(z2)

z1 // Scalar { data: [-5, 10] }

z1 = z1.conj().mul([2, 0])

z1.data // [-10, -20]

Vectors

Create vector space of dimension 2 over Reals.

const R2 = algebra.VectorSpace(R)(2)

Create two vectors and add them.

let v1 = new R2([0, 1])
const v2 = new R2([1, -2])

// v1 -> v1 + v2 -> [0, 1] + [1, -2] = [1, -1]
v1 = v1.add(v2)

v1 // Vector { data: [1, -1] }

Matrices

Create space of matrices 3 x 2 over Reals.

const R3x2 = algebra.MatrixSpace(R)(3, 2)

Create a matrix.

//       | 1 1 |
//  m1 = | 0 1 |
//       | 1 0 |
//
const m1 = new R3x2([1, 1,
                     0, 1,
                     1, 0])

Multiply m1 by v1, the result is a vector v3 with dimension 3. In fact we are multiplying a 3 x 2 matrix by a 2 dimensional vector, but v1 is traited as a column vector so it is like a 2 x 1 matrix.

Then, following the row by column multiplication law we have

//  3 x 2  by  2 x 1  which gives a   3 x 1
//      ↑      ↑
//      +------+----→  by removing the middle indices.
//
//                   | 1 1 |
//    v3 = m1 * v1 = | 0 1 | * [1 , -1] = [0, -1, 1]
//                   | 1 0 |

const v3 = m1.mul(v1)

v3.data // [0, -1, 1]

Let's try with two square matrices 2 x 2.

const R2x2 = algebra.MatrixSpace(R)(2, 2)

let m2 = new R2x2([1, 0,
                   0, 2])

const m3 = new R2x2([0, -1,
                     1,  0])

m2 = m2.mul(m3)

m2 // Matrix { data: [0, -1, 2, 0] }

Since m2 is a square matrix we can calculate its determinant.

m2.determinant // Scalar { data: 2 }

API

About operators

All operators can be implemented as static methods and as object methods. In both cases, operands are coerced to raw data. As an example, consider addition of vectors in a Cartesian Plane.

const R2 = algebra.R2

const vector1 = new R2([1, 2])
const vector2 = new R2([3, 4])

The following static methods, give the same result: [4, 6].

R2.addition(vector1, [3, 4])
R2.addition([1, 2], vector2)
R2.addition(vector1, vector2)

The following object methods, give the same result: a vector instance with data [4, 6].

const vector3 = vector1.addition([3, 4])
const vector4 = vector1.addition(vector2)

R2.equal(vector3, vector4) // true

Operators can be chained when it makes sense.

vector1.addition(vector1).equality([2, 4]) // true

Objects are immutable

vector1.data // still [1, 2]

Scalar

The scalars are the building blocks, they are the elements you can use to create vectors and matrices. They are the underneath set enriched with a ring structure which consists of two binary operators that generalize the arithmetic operations of addition and multiplication. A ring that has the commutativity property is called abelian (in honour to Abel) or also a field.

Ok, let's make a simple example. Real numbers, with common addition and multiplication are a scalar field.

The good new is that you can create any scalar field as long as you provide a set with two internal operations and related neutral elements that satisfy the ring axioms.

We are going to create a scalar field using BigInt elements to implement something similar to a Rational Number. The idea is to use a couple of numbers, the first one is the numerator and the second one the denominator.

Arguments we need are the same as algebra-ring. Let's start by unities; every element is a couple of numbers, the numerator and the denominator, hence unitites are:

  • zero: [ BigInt(0), BigInt(1) ]
  • one: [ BigInt(1), BigInt(1) ]

We need a function that computes the Great Common Divisor.

function greatCommonDivisor (a, b) {
  if (b === BigInt(0)) {
    return a
  } else {
    return greatCommonDivisor(b, a % b)
  }
}

So now we can normalize a rational number, by removing the common divisors of numerator and denominator. Also, denominator should be positive.

function normalizeRational ([numerator, denominator]) {
  const divisor = greatCommonDivisor(numerator, denominator)

  const sign = denominator > 0 ? 1 : -1

  return denominator > 0 ? (
    [numerator / divisor, denominator / divisor]
  ) : (
    [-numerator / divisor, -denominator / divisor]
  )
}
const Rational = algebra.Scalar({
  zero: [BigInt(0), BigInt(1)],
  one: [BigInt(1), BigInt(1)],
  equality: ([n1, d1], [n2, d2]) => (n1 * d2 === n2 * d1),
  contains: ([n, d]) => (typeof n === 'bigint' && typeof d === 'bigint'),
  addition: ([n1, d1], [n2, d2]) => normalizeRational([n1 * d2 + n2 * d1, d1 * d2]),
  negation: ([n, d]) => ([-n, d]),
  multiplication: ([n1, d1], [n2, d2]) => normalizeRational([n1 * n2, d1 * d2]),
  inversion: ([n, d]) => ([d, n])
})

So far so good, algebra dependencies will do some checks under the hood and will complain if something looks wrong.

Let's create few rational numbers.

const bigHalf = new Rational([BigInt(1), BigInt(2)])
const bigTwo = new Rational([BigInt(2), BigInt(1)])

Scalar.one

Is the neutral element for multiplication operator.

Rational.one // [1n, 1n]

Scalar.zero

Is the neutral element for addition operator.

Rational.zero // [0n, 1n]

scalar.data

The data attribute holds the raw data underneath our scalar instance.

bigHalf.data // [1n, 2n]

Scalar.contains(scalar)

Checks a given argument is contained in the scalar field that was defined.

Rational.contains(bigHalf) // true
Rational.contains([BigInt(1), BigInt(2)]) // true

scalar1.belongsTo(Scalar)

This is a class method that checks a scalar instance is contained in the given scalar field.

bigHalf.belongsTo(Rational) // true

Scalar.equality(scalar1, scalar2)

Rational.equality(bigHalf, [BigInt(5), BigInt(10)]) // true
Rational.equality(bigTwo, [BigInt(-4), BigInt(-2)]) // true

scalar1.equals(scalar2)

bigHalf.equals([BigInt(2), BigInt(4)])

Scalar.disequality(scalar1, scalar2)

Rational.disequality(bigHalf, bigTwo) // true

scalar1.disequality(scalar2)

bigHalf.disequality(bigTwo) // true

Scalar.addition(scalar1, scalar2)

Rational.addition(bigHalf, bigTwo) // [5n , 2n]

scalar1.addition(scalar2)

bigHalf.addition(bigTwo) // Scalar { data: [5n, 2n] }

Scalar.subtraction(scalar1, scalar2)

Rational.subtraction(bigTwo, bigHalf) // [3n , 2n]

scalar1.subtraction(scalar2)

bigTwo.multiplication(bigHalf) // Scalar { data: [1n, 1n] }

Scalar.multiplication(scalar1, scalar2)

Rational.multiplication(bigHalf, bigTwo) // [1n, 1n]

scalar1.multiplication(scalar2)

bigHalf.multiplication(bigTwo) // Scalar { data: [1n, 1n] }

Scalar.division(scalar1, scalar2)

Rational.division(bigTwo, bigHalf) // [1n, 4n]

scalar1.division(scalar2)

bigHalf.division(bigTwo) // Scalar { data: [1n, 4n] }

Scalar.negation(scalar)

Rational.negation(bigTwo) // [-2n, 1n]

scalar.negation()

bigTwo.negation() // Scalar { data: [-2n, 1n] }

Scalar.inversion(scalar)

Rational.inversion(bigTwo) // [1n, 2n]

scalar.inversion()

bigTwo.inversion() // Scalar { data: [1n, 2n] }

Real

Inherits everything from Scalar. Implements algebra of real numbers.

const Real = algebra.Real

Real.addition(1, 2) // 3

const pi = new Real(Math.PI)
const twoPi = pi.mul(2)

Real.subtraction(twoPi, 2 * Math.PI) // 0

Composition Algebra

A composition algebra is one of ℝ, ℂ, ℍ, O: Real, Complex, Quaternion, Octonion. A generic function is provided to iterate the Cayley-Dickson construction over any field.

CompositionAlgebra(field[, num])

  • num can be 1, 2, 4 or 8

Let's use for example the algebra.Boole which implements Boolean Algebra by exporting an object with all the stuff needed by algebra-ring npm package.

const CompositionAlgebra = algebra.CompositionAlgebra

const Boole = algebra.Boole

const Bit = CompositionAlgebra(Boole)

Bit.contains(false) // true
Bit.contains(4) // false

const bit = new Bit(true)
Bit.addition(false).data // true

Not so exciting, let's build something more interesting. Let's pass a second parameter, that is used to build a Composition algebra over the given field. It is something experimental also for me, right now I am writing this but I still do not know how it will behave. My idea (idea feliz) is that

A byte is an octonion of bits

Maybe we can discover some new byte operator, taken from octonion rich algebra structure. Create an octonion algebra over the binary field, a.k.a Z2 and create the eight units.

// n must be a power of two
const Byte = CompositionAlgebra(Boole, 8)

// Use a single char const for better indentation.
const t = true
const f = false

const byte1 = new Byte([t, f, f, f, f, f, f, f])
const byte2 = new Byte([f, t, f, f, f, f, f, f])
const byte3 = new Byte([f, f, t, f, f, f, f, f])
const byte4 = new Byte([f, f, f, t, f, f, f, f])
const byte5 = new Byte([f, f, f, f, t, f, f, f])
const byte6 = new Byte([f, f, f, f, f, t, f, f])
const byte7 = new Byte([f, f, f, f, f, f, t, f])
const byte8 = new Byte([f, f, f, f, f, f, f, t])

The first one corresponds to one, while the rest are immaginary units. Every imaginary unit multiplied by itself gives -1, but since the underlying field is homomorphic to Z2, -1 corresponds to 1.

byte1.mul(byte1).data // [t, f, f, f, f, f, f, f]
byte2.mul(byte2).data // [t, f, f, f, f, f, f, f]
byte3.mul(byte3).data // [t, f, f, f, f, f, f, f]
byte4.mul(byte4).data // [t, f, f, f, f, f, f, f]
byte5.mul(byte5).data // [t, f, f, f, f, f, f, f]
byte6.mul(byte6).data // [t, f, f, f, f, f, f, f]
byte7.mul(byte7).data // [t, f, f, f, f, f, f, f]
byte8.mul(byte8).data // [t, f, f, f, f, f, f, f]

You can play around with this structure.

const max = byte1.add(byte2).add(byte3).add(byte4)
                 .add(byte5).add(byte6).add(byte7).add(byte8)

max.data // [t, t, t, t, t, t, t, t]

Complex

Inherits everything from Scalar.

It is said the Gauss brain is uncommonly big and folded, much more than the Einstein brain (both are conserved and studied). Gauss was one of the biggest mathematicians and discovered many important results in many mathematic areas. One of its biggest intuitions, in my opinion, was to realize that the Complex number field is geometrically a plane. The Complex numbers are an extension on the Real numbers, they have a real part and an imaginary part. The imaginary numbers, as named by Descartes later, were discovered by italian mathematicians Cardano, Bombelli among others as a trick to solve third order equations.

Complex numbers are a goldmine for mathematics, they are incredibly rich of deepest beauty: just as a divulgative example, take a look to the Mandelbrot set, but please trust me, this is nothing compared to the divine nature of Complex numbers.

Mandelbrot Set{:.responsive}

The first thing I noticed when I started to study the Complex numbers is conjugation. Every Complex number has its conjugate, that is its simmetric counterparte respect to the Real numbers line.

const Complex = algebra.Complex

const complex1 = new Complex([1, 2])

complex1.conjugation() // Complex { data: [1, -2] }

Quaternion

Inherits everything from Scalar.

Quaternions are not commutative, usually if you invert the operands in a multiplication you get the same number in absolute value but with the sign inverted.

const Quaternion = algebra.Quaternion

const j = new Quaternion([0, 1, 0, 0])
const k = new Quaternion([0, 0, 1, 0])

// j * k = - k * j
j.mul(k).equal(k.mul(j).neg()) // true

Octonion

Inherits everything from Scalar.

Octonions are not associative, this is getting hard: a * (b * c) could be equal to the negation of (a * b) * c.

const Octonion = algebra.Octonion

const a = new Octonion([0, 1, 0, 0, 0, 0, 0, 0])
const b = new Octonion([0, 0, 0, 0, 0, 1, 0, 0])
const c = new Octonion([0, 0, 0, 1, 0, 0, 0, 0])

// a * ( b * c )
const abc1 = a.mul(b.mul(c)) // Octonion { data: [0, 0, 0, 0, 0, 0, 0, -1] }

// (a * b) * c
const abc2 = a.mul(b).mul(c) // Octonion { data: [0, 0, 0, 0, 0, 0, 0, 1] }

Octonion.equality(Octonion.negation(abc1), abc2)

Common spaces

R

The real line.

It is in alias of Real.

const R = algebra.R

R2

The Cartesian Plane.

const R2 = algebra.R2

It is in alias of VectorSpace(Real)(2).

R3

The real space.

const R3 = algebra.R3

It is in alias of VectorSpace(Real)(3).

R2x2

Real square matrices of rank 2.

const R2x2 = algebra.R2x2

It is in alias of MatrixSpace(Real)(2).

C

The complex numbers.

It is in alias of Complex.

const C = algebra.C

C2x2

Complex square matrices of rank 2.

const C2x2 = algebra.C2x2

It is in alias of MatrixSpace(Complex)(2).

H

Usually it is used the H in honour of Sir Hamilton.

It is in alias of Quaternion.

const H = algebra.H

Vector

A Vector extends the concept of number, since it is defined as a tuple of numbers. For example, the Cartesian plane is a set where every point has two coordinates, the famous (x, y) that is in fact a vector of dimension 2. A Scalar itself can be identified with a vector of dimension 1.

We have already seen an implementation of the plain: R2.

If you want to find the position of an airplain, you need latitute, longitude but also altitude, hence three coordinates. That is a 3-ple, a tuple with three numbers, a vector of dimension 3.

An implementation of the vector space of dimension 3 over reals is given by R3.

VectorSpace(Scalar)(dimension)

Vector dimension

Strictly speaking, dimension of a Vector is the number of its elements.

Vector.dimension

It is a static class attribute.

R2.dimension // 2
R3.dimension // 3

vector.dimension

It is also defined as a static instance attribute.

const vector = new R2([1, 1])

vector.dimension // 2

Vector norm

The norm, at the end, is the square of the vector length: the good old Pythagorean theorem. It is usually defined as the sum of the squares of the coordinates. Anyway, it must be a function that, given an element, returns a positive real number. For example in Complex numbers it is defined as the multiplication of an element and its conjugate: it works as a well defined norm. It is a really important property since it shapes a metric space. In the Euclidean topology it gives us the common sense of space, but it is also important in other spaces, like a functional space. In fact a norm gives us a distance defined as its square root, thus it defines a metric space and hence a topology: a lot of good stuff.

Vector.norm()

Is a static operator that returns the square of the lenght of the vector.

R2.norm([3, 4]).data // 25

vector.norm

This implements a static attribute that returns the square of the length of the vector instance.

const vector = new R2([1, 2])

vector.norm.data // 5

Vector addition

Vector.addition(vector1, vector2)

R2.addition([2, 1], [1, 2]) // [3, 3]

vector1.addition(vector2)

const vector1 = new R2([2, 1])
const vector2 = new R2([2, 2])

const vector3 = vector1.addition(vector2)

vector3 // Vector { data: [4, 3] }

Vector cross product

It is defined only in dimension three. See Cross product on wikipedia.

Vector.crossProduct(vector1, vector2)

R3.crossProduct([3, -3, 1], [4, 9, 2]) // [-15, 2, 39]

vector1.crossProduct(vector2)

const vector1 = new R3([3, -3, 1])
const vector2 = new R3([4, 9, 2])

const vector3 = vector1.crossProduct(vector2)

vector3 // Vector { data: [-15, 2, 39] }

Matrix

MatrixSpace(Scalar)(numRows[, numCols])

Matrix.isSquare

Matrix.numCols

Matrix.numRows

Matrix multiplication

Matrix.multiplication(matrix1, matrix2)

matrix1.multiplication(matrix2)

Matrix inversion

It is defined only for square matrices which determinant is not zero.

Matrix.inversion(matrix)

matrix.inversion

Matrix determinant

It is defined only for square matrices.

Matrix.determinant(matrix)

matrix.determinant

Matrix adjoint

Matrix.adjoint(matrix1)

matrix.adjoint

Author: Fibo
Source Code: https://github.com/fibo/algebra 
License: MIT License

#algebra #math #vector #matrix #node #javascript