• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript DSL for functional Set Theory

Seth

Seth is JavaScript DSL for functional Set Theory. This DSL aims to present set theory in its abstract mathematical form instead of manually dealing with literal arrays and their elements in a programming environment.

Seth is available on both NPM and Bower with support for AMD and contains tiny shims to support pre-ES6.

npm install seth
bower install seth

Seth is pretty intuitive to use if already familiar with common set operations and comparisons. It looks like this, required in Node.js:

var Seth = require('seth'),
	Set = Seth.Set;

var C = Set([1,2,3]).union(Set([1,4,5]));
//> C = Set([1,2,3,4,5]);

var Zc = Seth.Integers.complement();
// Numbers is the set of all Numbers. (U)
// Integers is the set of all Integers within the Numbers universe. (A)
// thus, Zc is the set of all Numbers that are not Integers. (U\A)

var CAndZc = C.intersect(Zc);
//> CAndZc = Set([..all Numbers that are not Integers and are in C..]);
// therefore, CAndZc is an empty set.

var proof = CAndZc.isSubsetOf(Seth.Nothing);
// Nothing is an empty set.

// Proofs allow assertions to be made more easily
proof.confirms(2) //> true
proof.confirmsAll([1,2,3,4,5]) //> true

Features

Seth is a set theory DSL with universe awareness that is composed functionally. Set Operations include union, intersect, difference, symmetricDifference, cartesianProduct, complement, and inverse. Comparisons include isSupersetOf, isSubsetOf, isProperSubsetOf, isComplementOf, and isInverseOf. All comparisons return Proofs that make assertions based on sets easier to handle and reason with methods like confirms, confirmsAll, confirmsAllExcept, and testArray.

Seth includes common sets such as Everything, Nothing (alias Empty), Numbers (alias R), and Integers (alias Z) for convenience.

What is Functional Set Theory?

I made it up.

Functional Set Theory is not a mathematical concept or a subset of set theory. When I say "functional set theory," what I mean is set theory composed of functions instead of definite elements in a manner similarly expressed by functional programming languages. A functional set is not a list or range of elements, but it is instead a Boolean function that states whether a given element matches a given set's criteria of containment.

Why would I use such big words to construct an imaginary concept, one that is not even mathematically sound? Performance, duh. The real theory is computationally inefficient. For example, how would a computer store a set of everything, all combinations and deviations of numbers, strings, and objects? A computer will never have enough memory to capture everything. Even the smaller set of all numbers could not be stored in the memory of a computer. Yet Seth could not be limited to simple, short-length arrays of values.

Seth needed something faster, more concise, and most importantly composable. The solution was functions and logic. Functions are awesome because they are lazy, exempt from depleting memory resources until they are evaluated. Logic is awesome because it is lightning fast and expressive. Combined they can efficiently express set theory.

Instead of writing out every possible value in the universe, a set of everything in Seth can be expressed with one simple function.

// The exact implementation of Seth.Everything
var Everything = Set(function(x) {
	return true;	
});

No matter what x is, the function returns true because the set contains everything. The set of all numbers is just as easy to create.

// Seth.Numbers
var Numbers = Set(function(x) {
	return typeof x === 'number';
});

These sets can then be composed into new sets with different meanings.

var NonNumbers = Numbers.complement();
// Everything is the default universe.

// NonNumbers is equivalent to:
var NonNumber = Set(function(x) {
	return typeof x !== 'number';
});

That's amazing. What's more is the performance of this abstraction: in personal testing of Seth, 75 tests of the entire codebase only took 24ms. This is only the scratching surface of what is feasible with Seth.

Contributing

I have never taken a class on set theory (heck I'm still in high school). I did read the Wikipedia page a few dozen times. This is just an interest of mine that I saw was lacking in implementation in the open-source community at large, so I wanted to attempt to fill the gap.

If you are a professional set theorist or even an amateur like me, if there is a bug please open an issue. If there is a feature this DSL should have, more common operations or comparisons, please point me to them or be hardcore and send me the pull request.

Contributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core assert module.

# running tests
npm run test
npm run test-spec # spec reporter

Follow me on Twitter for updates or just for the lolz and please check out my other repositories if I have earned it. I thank you for reading.

More Repositories

1

himalaya

JavaScript HTML to JSON Parser
JavaScript
915
star
2

raj

The Elm Architecture for JavaScript
JavaScript
193
star
3

periodic-table

Periodic elements data
JavaScript
148
star
4

reactbone

React extensions for Backbone
JavaScript
44
star
5

affection

Wish I had some..declarative side-effects
JavaScript
40
star
6

raj-by-example

The guide to building applications with Raj
36
star
7

smithsonian

web interface for Metalsmith
JavaScript
36
star
8

fakegoose

Faker + Mongoose
JavaScript
32
star
9

reem

rambunctious static site generator
JavaScript
27
star
10

truth-table

Visualize your propositions as a truth table
JavaScript
25
star
11

tagmeme

Simple tagged unions
JavaScript
20
star
12

angle-input

Angle input for jQuery, React, and vanilla JavaScript
JavaScript
18
star
13

dn-paint

a paint tool for DN profile headers and portraits
JavaScript
15
star
14

solvent

A calculator with equations and variables
JavaScript
13
star
15

matt

JavaScript DSL for Matrices
JavaScript
13
star
16

paul

Tree traversal and transform functions
JavaScript
13
star
17

raj-web-debugger

Web debugger for Raj
JavaScript
12
star
18

pokever

PokΓ©mon Versioning
11
star
19

slinky

web crawler just for links
JavaScript
11
star
20

raj-react

React bindings for Raj
JavaScript
9
star
21

trent

Type specifications
JavaScript
9
star
22

srepl

Save-Read-Eval-Print-Loop: The file is the REPL
TypeScript
9
star
23

n-level-cache

Multi-level cache with any number of levels and gracefully fallback to the computed value
JavaScript
8
star
24

colton

Contract testing for JavaScript
JavaScript
7
star
25

raj-compose

Program composition for Raj
JavaScript
7
star
26

dribbble-responses

Hides short, useless comments on Dribbble shots
JavaScript
7
star
27

permutest

Test all possible permutations of values sanely
JavaScript
6
star
28

console-hook

Hook into the console
JavaScript
6
star
29

rove

Name-based routing library
JavaScript
6
star
30

storeo

A data store with subscriptions
JavaScript
6
star
31

illuminatify

turn animated gifs into subliminal messengers
JavaScript
6
star
32

cla

Command-Line Awesome
JavaScript
6
star
33

emf

Classes and Integrations for Flux
JavaScript
6
star
34

constance

Constants with prefix and postfix options
JavaScript
5
star
35

please-update

Notify when you release a new version
JavaScript
5
star
36

ap-compsci-2015

AP Computer Science 2015 Free Response Solutions
Java
5
star
37

querie

SQL query builder
JavaScript
5
star
38

raj-ts

Raj written in Typescript
TypeScript
5
star
39

raj-react-realworld

A Single Page Application written with React and Raj
JavaScript
5
star
40

glaze

the database-agnostic caching layer for mongoose
CoffeeScript
4
star
41

dotfiles

Configuration files
Shell
4
star
42

urinal-picker

The urinal picking game
JavaScript
4
star
43

civ

Search stdout output in realtime
JavaScript
4
star
44

raj-spa

Single Page Applications for Raj
JavaScript
4
star
45

bottle

sample node, express, passport, mongoose app
JavaScript
4
star
46

remove

Move it or lose your it (your mind)
JavaScript
4
star
47

txt2text

Replaces a customizable list of acronyms with their expanded forms.
JavaScript
3
star
48

independency

Source code dependency graph generator
JavaScript
3
star
49

tactic

Promise utilities for just the worst people
JavaScript
3
star
50

gravitas

A gravity game
JavaScript
3
star
51

vainglory

an interface that makes it look like you're hardcore programming
C
3
star
52

raj-subscription

Subscription utilities for Raj
JavaScript
3
star
53

throw-return

Return using throw
JavaScript
3
star
54

hoo

command-line contact information scrapper
JavaScript
3
star
55

introspec

Dependencies and configuration described through data
JavaScript
3
star
56

interest

Calculate the principal amount of money needed to achieve a self-sustaining revenue stream from compound interest.
JavaScript
3
star
57

time-track

Simple time tracking tool
JavaScript
2
star
58

ember-subscription

Ember event handling that sucks less
JavaScript
2
star
59

react-types

React.PropTypes with less suck
JavaScript
2
star
60

justin

timekeeper and activity log
JavaScript
2
star
61

stachedown

you got mustache in my markdown
JavaScript
2
star
62

professor-chaos

Create non-life-threatening chaos in your programs
JavaScript
2
star
63

babel-plugin-taft

JavaScript Maxifier ft. President Taft
JavaScript
2
star
64

color-me-shocked

a better color converter
JavaScript
2
star
65

ascii-codes

ASCII table reference and lookup functions
JavaScript
2
star
66

object-mock

Mock object properties temporarily
JavaScript
2
star
67

sprose

S-expressive prose language
JavaScript
2
star
68

codo

Code TODO-driven development
Rust
2
star
69

chrome-torso

Chrome Headless from Node.js
2
star
70

strurl

Type anything and send it as a link to anyone.
JavaScript
1
star
71

stash-logger

Buffered logger with customizable log levels
JavaScript
1
star
72

andrejewski.github.io

HTML
1
star
73

comics

Check out my web comics
JavaScript
1
star
74

reem-draft

Drafting plugin for Reem
JavaScript
1
star
75

reem-flow

Middleware flow controls for Reem
JavaScript
1
star
76

reem-markdown

Markdown for Reem
JavaScript
1
star
77

odn

Ops Defined Network
1
star
78

result

Typescript result type
TypeScript
1
star
79

fill-line

Fill cups up to their fill lines in rapid succession.
TypeScript
1
star
80

hyponym

subtypes for JavaScript objects and primitives
JavaScript
1
star
81

color-converter

Realtime color converter
JavaScript
1
star
82

characters

Pop culture characters
JavaScript
1
star
83

chasers

HTML canvas mini-game(/art maybe?)
JavaScript
1
star
84

tagged-routes

Routing with tagged unions
JavaScript
1
star
85

ipman

a lorem ipsum tool for jQuery/Zepto
JavaScript
1
star
86

simple-torso

Super dumb headless browser for Node
JavaScript
1
star
87

color-blind

Color simple shapes from memory
TypeScript
1
star
88

reem-coffee

Compile CoffeeScript files to JavaScript files with Reem
JavaScript
1
star
89

raj.cljs

The Raj Architecture for ClojureScript
Clojure
1
star
90

xsync

a/synchronous function checking
JavaScript
1
star
91

libro

JavaScript Helper Library
CoffeeScript
1
star
92

bmp

node package version bumper
JavaScript
1
star
93

express-responses

HTTP error responses for Express
JavaScript
1
star
94

connectivity

determine if a graph is connected using its adjacency matrix
JavaScript
1
star
95

ost

The Original Soundtrack
JavaScript
1
star
96

filtrate

A little image filter
JavaScript
1
star
97

better-router

a more better Express Router
JavaScript
1
star
98

birthday-card

(2013) A digital birthday card
CSS
1
star
99

youtube-frame

Full window YouTube videos (not fullscreen, full window)
JavaScript
1
star
100

repo-cloud

Github repositories in a word cloud
JavaScript
1
star