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

math.real-set

v0.4.0

Published

Class to work with sets of real numbers.

Downloads

10

Readme

math.real-set

travis ci npm version Coverage Status Dependency Status

Class to work with subsets of real numbers.

Version

0.4.0

Install

npm install math.real-set

Usage

const RealSet = require('math.real-set')

const A = RealSet.parse('(0, 2] U {6, 7, 8}')
const B = RealSet.parse('(5, 5)')
const C = RealSet.parse('[1, 2)')
const D = RealSet.parse('(2, 7)')
const E = RealSet.parse('(8, 9]')

// emptyness
A.isEmpty() // false
B.isEmpty() // true

// Containing numbers
A.contains(4) // false
A.contains(6) // true
B.contains(3) // false

// Containing sets
A.contains(C) // true

// joining sets
A.union(D) // A U D is equivalent to RealSet.parse('(0, 7] U {8}')
A.union(E) // A U E is equivalent to RealSet.parse('(0, 2] U {6, 7} U [8, 9]')

// converting to string
A.toString() // '{6, 7, 8} U (0, 2]'
B.toString() // '{}'
const F = RealSet.parse('[3, 3]')
F.toString() // '{3}'

API

Real subsets creation

parse :: String -> RealSet

Static method that takes and string as a representation of RealSet and returns a RealSet instance. It throws an error if string is not parsable to RealSet.

Example:

const RealSet = require('math.real-set')

const set = RealSet.parse('(2, 5] U {6} U [8, 9)')

fromIntervals :: [Interval] -> RealSet

Static method that takes an array of Intervals and returns a RealSet instance.

Example:

const RealSet = require('math.real-set')

const set = RealSet.fromIntervals([
    [{value: 2, limit: 1}, {value: 5, limit: 0}], // (2, 5]
    [{value: 6, limit: 0}, {value: 6, limit: 0}], // {6}
    [{value: 8, limit: 0}, {value: 9, limit: -1}] // [8, 9)
])

Predicates

contains :: RealSet ~> RealSet -> Boolean

Returns true or false depending on real set param is contained inside the set or not, respectively.

Example:

const RealSet = require('math.real-set')

const A = RealSet.parse('[1, 3) U [4, 8]')
const B = RealSet.parse('(1, 2) U [4, 7)')
const C = RealSet.parse('{3, 6}')

A.contains(B) // true
A.contains(C) // false
C.contains(A) // false

has :: RealSet ~> Number -> Boolean

Returns true or false if the set has a number or not, respectively.

Example:

const RealSet = require('math.real-set')
const set = RealSet.parse('(1, 5] U {8}')

set.has(1) // false
set.has(3) // true
set.has(5) // true
set.has(7) // false
set.has(8) // true

isEmpty :: RealSet ~> Boolean

Returns true or false if set is empty or not.

Example:

const RealSet = require('math.real-set')

const A = RealSet.parse('[2, 4)')
const B = RealSet.parse('[4, 2)')

A.isEmpty() // false
B.isEmpty() // true

Real subset operations

union :: RealSet ~> RealSet -> RealSet

Instance method that returns the union of two sets.

const RealSet = require('math.real-set')

const A = RealSet.parse('[1, 3) U (3, 4]')
const B = RealSet.parse('(2, 4) U {5}', '{5} U (6, 7)')

A.union(B) // [1, 4] U {5} U (6, 7)

union :: [RealSet] -> RealSet

Static method that takes an array of RealSet instances and returns a RealSet instance that represents the union of the list of sets.

const RealSet = require('math.real-set')
const A = RealSet.parse('[1, 3) U (3, 4]')
const B = RealSet.parse('(2, 4) U {5}')
const C = RealSet.parse('{5} U (6, 7)')

RealSet.union([A, B, C]) // [1, 4] U {5} (6, 7)

RealSet converters

toString :: RealSet ~> String

Converts the real set into a string representation.

const RealSet = require('math.real-set')

const A = RealSet.parse('(5, 2] U (3, 3)') // empty
const B = RealSet.parse('[2, 2] U (5, 6)') // singleton interval

A.toString() // '{}'
B.toString() // '{2} U (5, 6)'

toIntervals :: RealSet ~> [Interval]

Converts the real set into an array of disjoint Intervals ordered from lowest to highest.

const RealSet = require('math.real-set')

const A = RealSet.parse('(5, 6) U [2, 2] U {4, 8}')

A.toIntervals() /* [
    [{value: 2, limit: 0}, {value: 2, limit: 0}], // {2}
    [{value: 4, limit: 0}, {value: 4, limit: 0}], // {4}
    [{value: 5, limit: 1}, {value: 6, limit: -1}], // (5, 6)
    [{value: 8, limit: 0}, {value: 8, limit: 0}]  // {8}
]

LICENSE

MIT