npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cayley-dickson

v0.5.4

Published

implements Cayley-Dickson construction to produce a sequence of algebras over a field

Downloads

23

Readme

cayley-dickson

implements Cayley-Dickson construction to produce a sequence of algebras over a field

Installation | Usage : Real > Complex > Quaternion > Octonion > Sedenion | License

NPM version Build Status JavaScript Style Guide

Installation

With npm do

npm install cayley-dickson

Usage

Every code snippet below it is intended to be contained in a single file.

Define real operators, see also algebra-ring. Note that you could use any operators definition, for example using a big numbers lib.

const real = {
  zero: 0,
  one: 1,
  equality: (a, b) => (a === b),
  contains: (a) => (typeof a === 'number' && isFinite(a)),
  addition: (a, b) => (a + b),
  negation: (a) => -a,
  multiplication: (a, b) => (a * b),
  inversion: (a) => (1 / a)
}

Import cayley-dickson.

const iterateCayleyDickson = require('cayley-dickson')

Now you can use Cayley-Dickson constructions to build algebras. Every iteration doubles the dimension. Let's take a trip through Cayley-Dickson algebras.

Real

start from here

Well, iteration 0 gives the common Real numbers. The result is just the return value of the algebra-ring function, nothing really exciting.

// Real numbers.
const R = iterateCayleyDickson(real, 0)

R.equality(2, 2) // true
R.disequality(1, 2) // true
R.contains(Math.PI) // true
R.notContains(Infinity) // true
R.addition(1, 2) // 3
R.subtraction(1, 2) // -1
R.negation(2) // -2
R.multiplication(-3, 2) // -6
R.division(10, 2) // 5
R.inversion(2) // 0.5

Complex

a beautiful plane

First iteration gives Complex numbers, they are a field like the Real numbers.

// Complex numbers.
const C = iterateCayleyDickson(real, 1)

C.equality([1, 2], [1, 2]) // true
C.disequality([1, 2], [0, 1]) // true
C.contains([Math.PI, 2]) // true
C.notContains(1) // true
C.addition([1, 2], [-1, 2], [2, 2]) // [2, 6]
C.subtraction([1, 1], [2, 3]) // [-1, -2]
C.negation([1, 2]) // [-1, -2]
C.multiplication([1, 2], [1, -2]) // [5, 0]
C.division([5, 0], [1, 2]) // [1, -2]
C.inversion([0, 2]) // [0, -0.5]
C.conjugation([1, 2]) // [1, -2]

Quaternion

here you loose commutativity

Second iteration gives Quaternion numbers, usually denoted as ℍ in honour of sir Hamilton. They are used in computer graphics cause rotations are far easier to manipulate in this land.

Let's check the famous formula for Quaternion multiplication ijk = i² = j² = k² = -1

ijk-1

// Quaternion numbers.
const H = iterateCayleyDickson(real, 2)

const minusOne = new H([-1, 0, 0, 0])
j
const i = new H([0, 1, 0, 0])
const j = new H([0, 0, 1, 0])
const k = new H([0, 0, 0, 1])

H.equality(H.multiplication(i, i), minusOne) // true
H.equality(H.multiplication(j, j), minusOne) // true
H.equality(H.multiplication(k, k), minusOne) // true

// ijk - 1 = 0
H.subtraction(H.multiplication(i, j, k), minusOne) // [0, 0, 0, 0]

Octonion

here you loose associativity

Third iteration gives Octonion numbers. A byte could be seen as an octonion of bits, which should define a new kind of bit operator.

// Octonion numbers.
const O = iterateCayleyDickson(real, 3)

const minusOne = [-1, 0, 0, 0, 0, 0, 0, 0]

const i1 = [0, 1, 0, 0, 0, 0, 0, 0]

O.equality(O.multiplication(i1, i1), minusOne) // true

O.conjugation([1, 2, 3, 4, 5, 6, 7, 8]) // [1, -2, -3, -4, -5, -6, -7, -8]

Sedenion

hic sunt leones

Fourth iteration gives Sedenion numbers, that are out of my scope sincerely. They are not a division ring, there are elements that divide zero 😱.

// Sedenion numbers.
const S = iterateCayleyDickson(real, 4)

License

MIT