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.function

v0.1.0

Published

algebra set

Downloads

2

Readme

math.function

Function to work with mathemathic concepts.

Javascript function does not have useful properties like domain and image. This package solves it creating a constructor that returns a function with this properties.

Version

0.1.0

Install

npm install math.function

Usage

var MFunction = require('math.function')
var MSet = require('math.set')

var sum = new MFunction(intervalSum)

sum.domain // returns [new MSet('-Infinity, Infinity'), new MSet('-Infinity, Infinity')]
sum.image // returns (-Infinity, Infinity) instance of math.set

sum(5, 6) // returns 11

sum.domain = ['(2, 3] U {4}', '(1, 2) U {3}']
sum.domain // returns [new MSet('(2, 3] U {4}'), new MSet('(1, 2) U {3}')]
sum.image // returns new MSet('(3, 5) U (5, 6] U {7}')

sum(2, 3) // throws an error (2 does not belongs to domain)

function intervalSum (a, b) {
    return [{
        value: a[0].value + b[0].value,
        limit: a[0].limit || b[0].limit
    }, {
        value: a[1].value + b[1].value,
        limit: a[1].limit || b[1].limit
    }]
}

API

Function

constructor(intervalFunction, domain)

Constructor creates an instance of javascript Function based on a function parameter intervalFunction. intervalFunction function defines the behaviour of the created function when it is applied to intervals with this data structure.

For example, in sum operation, given intervals (a, b] and [c, d), the result is the interval (a + c, b + d). Investigating a bit, it is posible to deduce that the function that given two intervals returns the interval that represents the sum of intervals is:

function intervalSum (interval1, interval2) {
    return [{
        value: interval1[0].value + interval2[0].value,
        limit: interval1[0].limit || interval2[0].limit
    }, {
        value: interval1[1].value + interval2[1].value,
        limit: interval1[1].limit || interval2[1].limit
    }]
}

Then, passing this function as parameter the sum function is created:

var MFunction = require('math.function')
var sum = new MFunction(intervalSum)
sum(2, 6) // returns 8
sum(5, 5) // returns 10
intervalFunction (...intervals)

This parameter function has the same arity as function created by constructor. It must receive interval parameters and return a SetCastable value that represents the image function that created function when is applied to these intervals.

domain

domain is an optional parameter. It is an array of SetCastable values that defines the domain of created function.

.domain

domain property is an array of instances of math.set. The length of array corresponds with the number of parameters of function instance. The domain property is an array of Real sets by default:

var MFunction = require('math.function')
var MSet = require('math.set')

var sum = new MFunction(intervalSum)
sum.domain // it returns default value new [new MSet('(-Infinity, Infinity)'), new MSet('(-Infinity, Infinity)')]

Besides, if domain is set with an array of SetCastable values, it return a set that represents this value:

sum.domain = ['(2, 4)', '{3, 4, 5} U [0, 1)']
sum.domain // now it returns [new MSet('(2, 4)'), new MSet('{3, 4, 5} U [0, 1)')]

.image

image property is an instance of math.set that depends on the domain of function instance and intervalFunction constructor parameter. For example:

var MFunction = require('math.function')
var MSet = require('math.set')

var sum = MFunction(intervalSum)

sum.domain = ['[2, 3]'), '{5}']
sum.image // returns new MSet('[7, 8]')

sum.domain = ['(2, 3] U {4}', '(1, 2) U {3}']
sum.image // returns new MSet('(3, 5) U (5, 6] U {7}')

LICENSE

MIT