Skip to content

Reference

jy edited this page Aug 9, 2023 · 6 revisions

Set Operators

& "intersection"

Coercion : number to a set with just that number

[1, 2, 3] & [2, 3, 4]
# [2, 3]

[2, 3, 4] & [1, 2, 3]
# [2, 3]

[1, 2, 3] & [$->mod(2)==1]
# [1, 3]

[$->mod(2)==1] & [1, 2, 3]
# [1, 3]

| "union"

Coercion : number to a set with just that number, real set to [$ in theSet]

[1, 2, 3] | [2, 3, 4]
# [1, 2, 3, 4]

[2, 3, 4] | [1, 2, 3]
# [1, 2, 3, 4]

[1, 2, 3] | [$->mod(2)==1]
# [($ in [1, 2, 3]) or ($->mod(2)==1)]

[$->mod(2)==1] | [1, 2, 3]
# [($ in [1, 2, 3]) or ($->mod(2)==1)]

^ "exclusive or"

Coercion : number to a set with just that number, real set to [$ in theSet]

[1, 2, 3] ^ [2, 3, 4]
# [1, 4]

[2, 3, 4] ^ [1, 2, 3]
# [1, 4]

[1, 2, 3] ^ [$->mod(2)==1]
# [($ in [1, 2, 3]) xor ($->mod(2)==1)]

[$->mod(2)==1] ^ [1, 2, 3]
# [($ in [1, 2, 3]) xor ($->mod(2)==1)]

- "subtract"

Coercion : number to a set with just that number, real set to [$ in theSet]

[1, 2, 3] - [2, 3, 4]
# [1]

[2, 3, 4] - [1, 2, 3]
# [4]

[1, 2, 3] - [$->mod(2)==1]
# [($ in [1, 2, 3]) and !($->mod(2)==1)]

[$->mod(2)==1] - [1, 2, 3]
# [($->mod(2)==1) and !($ in [1, 2, 3])]

Boolean Operator

Some of these I genuinely have no idea what would happen if you were to use on description set since the way I made it work is by literally the data having a field to put its AST.

== "equal"

1 == 1
[1, 2] == [2, 1]

<> "unequal / !="

1 <> 2
[1, 2] <> []

< > <= >= "lesser than, greater than, lesser than or equal to, greater than or equal to"

ONLY WORKS ON TWO SINGLE NUMBERS

1 < 3
3 > 1
2 <= 2
3 >= 2

in "is superset of"

Right hand side must NOT be a single number

1 in [1, 2]
[1] in [[1], 2]
1 in [$<5]

has "is subset of"

Left hand side must NOT be a single number

[1, 2] has 1
[[1], 2] has [1]
[$<5] has 1

and or xor "and, or, exclusive or"

ONLY WORKS ON TWO BOOLEAN VALUES

true and true
true or false
false xor true

Unary

- "negative"

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

-1 == -1
-[1, 2, -3] == [-1, -2, 3]

! "negate"

ONLY WORKS ON BOOLEAN

!false

Functions

I do plan to add function definition but I haven't implemented that, so only built-ins for now.

abs

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Absolute of every element

inputs : none

returns : set or number

-1 -> abs == 1
1 -> abs == 1
[-2, 3] -> abs == [2, 3]

collapse

DOESN'T WORK ON DESCRIPTION SET

If the source has just one item inside, return this item, if that item also just has one item inside, then that one. So on until the brackets can't be stripped off without turning into more than 1 element.

inputs : none returns : any

[] -> collapse == []
[1, 2] -> collapse == [1, 2]
[[[2]]] -> collapse == 2
[[$>0]] -> collapse == [$>0]

comb

DOESN'T WORK ON DESCRIPTION SET

Coercion : number to a set with just that number

Returns a set of sets that are each an unique combination of the source set

inputs : how many elements

returns : set of sets

[1, 2, 3] -> comb(2) == [[1, 2], [2, 3], [1, 3]]

count

DOESN'T WORK ON DESCRIPTION SET

Coercion : number to a set with just that number

Count how many items are in this set

inputs : none

returns : number

[] -> count == 0
5 -> count = 1
[1, 2] -> count == 2
[1, [], [3, [4]]] -> count == 3

div

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Divide every element by a constant

inputs : divisor

returns : set or number

6 -> div(3) == 2
[1, 2, 4] -> div(2) == [0.5, 1, 2]

floor

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Floor every element

inputs : none

returns : set or number

1.5 -> floor == 1
[1.5, 2] -> floor == [1, 2]

max

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER, OR EMPTY SET

The largest number in the set

inputs : none

returns : number

1 -> max == 1
[2, 3, 4] -> max == 4

min

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER, OR EMPTY SET

The smallest number in the set

inputs : none

returns : number

1 -> min == 1
[2, 3, 4] -> min == 2

mod

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Every element to its n-modulo

inputs : n returns : set or number

3 -> mod(2) == 1
[6, 7, 8, 9] -> mod(3) == [0, 1, 2]

offset

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Add a constant to every element

inputs : offsetAmount

returns : set or number

1 -> offset(2) == 3
[-1, 1, 2] -> offset(2) == [1, 3, 4]

pow

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Every element to the power of a constant

inputs : exponent

returns : set or number

2 -> pow(2) == 4
[2, 3] -> pow(3) == [8, 81]

print

Print the data to standard output

inputs : none

returns : empty set

1 -> print
# 1.0
[1] -> print
# {1.0}

realize

Coercion : number to [$==number], real set to [$ in theSet]

Collapse a description set within given range, both numbers are floored, the higher one is excluded

inputs : boundaryA, boundaryB

returns : real set

[$>5] -> realize(0, 11) == [6, 7, 8, 9, 10]

scale

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Multiply every element by a constant

inputs : amplitude

returns : set or number

[1, 2] -> scale(2) == [2, 4]

sum

DOESN'T WORK ON DESCRIPTION SET, OR A SET THAT HAS ANY NON-NUMBER

Sum up the set or just return the single number

inputs : none

returns : number

[1, 2, 3] -> sum == 6
6 == 6

text

ONLY WORKS ON SINGLE NUMBER

Write the Unicode character corresponding to the floored input in standard output

inputs : none

returns : empty set

65 -> text
# A
66.5 -> text
# B