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

algebra-ring

v0.6.4

Published

defines an algebra ring structure

Downloads

31

Readme

algebra-ring

defines an algebra ring structure

Installation | Example | API | License

NPM version Build Status JavaScript Style Guide

Installation

With npm do

npm install algebra-ring

Example

All code in the examples below is intended to be contained into a single file.

Real

Create a ring structure over real numbers.

const ring = require('algebra-ring')

// Define operators.
function contains (a) {
  // NaN, Infinity and -Infinity are not allowed
  return (typeof a === 'number' && isFinite(a))
}

function equality (a, b) { return a === b }

function addition (a, b) { return a + b }

function negation (a) { return -a }

function multiplication (a, b) { return a * b }

function inversion (a) { return 1 / a }

// Create a ring by defining its identities and operators.
const R = ring([0, 1], {
  equality: equality,
  contains: contains,
  addition: addition,
  negation: negation,
  multiplication: multiplication,
  inversion: inversion
})

You get a Ring that is a Group with multiplication operator. The multiplication operator must be closed respect the underlying set; its inverse operator is division.

This is the list of ring operators:

  • contains
  • notContains
  • equality
  • disequality
  • addition
  • subtraction
  • negation
  • multiplication
  • division
  • inversion

The neutral element for addition and multiplication are, as usual, called zero and one respectively.

R.contains(10) // true
R.contains(-1, 0.5, Math.PI, 5) // true
R.notContains(Infinity) // true

R.addition(1, 2) // 3
R.addition(2, 3, 5, 7) // 17

R.equality(R.negation(2), -2) // true

R.subtraction(2, 3) // -1

R.multiplication(2, 5) // 10
R.multiplication(2, 2, 2, 2) // 16

R.equality(R.inversion(10), 0.1) // true

R.division(1, 2) // 0.5

R.equality(R.addition(2, R.zero), 2) // true
R.equality(R.subtraction(2, 2), R.zero) // true

R.equality(R.multiplication(2, R.one), 2) // true
R.equality(R.division(2, 2), R.one) // true

R.division(1, 0) // will complain
R.inversion(R.zero) // will complain too

Boolean

It is possible to create a ring over the booleans.

const Boole = ring([false, true], {
  equality: (a, b) => (a === b),
  contains: (a) => (typeof a === 'boolean'),
  addition: (a, b) => (a || b),
  negation: (a) => (a),
  multiplication: (a, b) => (a && b),
  inversion: (a) => (a)
})

There are only two elements, you know, true and false.

Boole.contains(true, false) // true

Check that false is the neutral element of addition and true is the neutral element of multiplication.

Boole.addition(true, Boole.zero) // true
Boole.multiplication(true, Boole.one) // true

As usual, it is not allowed to divide by zero: the following code will throw.

Boole.division(true, false)
Boole.inversion(Bool.zero)

API

ring(identities, operator)

  • @param {Array} identities
  • @param {*} identities[0] a.k.a zero
  • @param {*} identities1 a.k.a one
  • @param {Object} operator
  • @param {Function} operator.contains
  • @param {Function} operator.equality
  • @param {Function} operator.addition
  • @param {Function} operator.negation
  • @param {Function} operator.multiplication
  • @param {Function} operator.inversion
  • @returns {Object} ring

ring.error

An object exposing the following error messages:

  • cannotDivideByZero
  • doesNotContainIdentity
  • identityIsNotNeutral

License

MIT