Skip to content

The Standard Library (stdlib)

Broad collection of Rel relations that perform essential and commonly used tasks.

^Char

View source
^Char(y, x)

Construct a Char, x, from its corresponding UInt32 value, y.

^Date

View source
^Date(n, d)

Create a Date, d, representing the date at day n of the proleptic Gregorian calendar.

Example:

def output(d) = ^Date(734503, d)
//output> 2012-01-01

For more details, see the rel:base:^Date docstring.

^Date

View source
^Date[year in Int, month in Int, day in Int]

Create a Date from its three components: year, month and day. The three arguments are required to be Int64.

^Date

View source
^Date[dt in DateTime, tz in String]

Create a Date from a DateTime, with timezone tz.

The timezone argument is necessary for the Date because DateTime is an instant of time that is timezone independent. For different locations on earth (timezones), a DateTime has different dates.

^DateTime

View source
^DateTime(n, dt)

Create a DateTime, dt, representing the date at millisecond n of the proleptic Gregorian calendar.

Example:

def output(dt) = ^DateTime(63568386000000, dt)
//output> 2015-05-27T05:00:00.000Z

For more details, see the rel:base:^DateTime docstring.

^DateTime

View source
^DateTime[year, month, day, hour, minute, second, millisecond, tz in String]

Create a DateTime from a year, month, day, hour, minute, second, and millisecond.

The timezone argument tz is necessary to correctly interpret what instant in time this is.

There can be multiple DateTime values for one set of arguments: for example, with the ending of daylight saving time at 2am, every time between 1am and 2am occurs twice and has two corresponding instants of time.

For part values that are out of range, there are no tuples (there is no error).

^DateTime

View source
^DateTime[date, hour, minute, second, millisecond, tz in String]

Create a DateTime from a date, hour, minute, second, and millisecond.

This constructor uses the year, month, and day from the date and then constructs a DateTime in the same way as the constructor with all parts as arguments.

^DateTime

View source
^DateTime[year, month, day, tz in String]

Create a DateTime for the given year, month, and day, with the time components all set to 0. The resulting DateTime is the first millisecond for the given date and time zone tz.

See the ^DateTime constructor with time components as arguments for more details.

^DateTime

View source
^DateTime[date in Date, tz in String]

Create a DateTime for the given Date, with the time components all set to 0. The resulting DateTime is the first millisecond of the given Date and time zone tz.

See the ^DateTime constructor with time components as arguments for more details.

^Day

View source
^Day[n]

Create a period of n days.

^FilePos

View source
^FilePos(y, x)

Brings the value type constructor ^FilePos from the module rel:base into the global namespace. For more details, see the rel:base:^FilePos docstring.

^Hour

View source
^Hour[n]

Create a period of n hours.

^Microsecond

View source
^Microsecond[n]

Create a period of n microseconds.

^Millisecond

View source
^Millisecond[n]

Create a period of n milliseconds.

^Minute

View source
^Minute[n]

Create a period of n minutes.

^Month

View source
^Month[n]

Create a period of n months.

^Nanosecond

View source
^Nanosecond[n]

Create a period of n nanoseconds.

^Second

View source
^Second[n]

Create a period of n seconds.

^Week

View source
^Week[n]

Create a period of n weeks.

^Year

View source
^Year[n]

Create a period of n years.

¬

View source
not F
¬F

Logical negation, for boolean (arity 0, true or false) argument F.

View source
F and G
F  G

Logical and (conjunction).

View source
F or G
F  G

Logical or (disjunction), for boolean (arity 0, true or false) arguments F and G.

View source
F  G

Relational inequality, see equal.

abs

View source
abs[x]

The absolute value of x.

Examples:

abs[-2] = 2
abs[-2.0] = 2.0

acos

View source
acos[x]
acos(x, ac)

Arccosine of x. ac is the arccosine of x given in radians.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Cosine of ac. Must be grounded.
acFloatBinary[#64]Arccosine of x in radians.

Explanation

Defined for x between -1 and 1 (inclusive). The value of ac ranges from 0 to π.

Arccosine is sometimes called “inverse cosine.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the arccosine of 0:

def output = acos[0]
//output> 1.5707963267948966

Calculate the arccosine of -1 using full expression:

def output(x) = acos(-1, x)
//output> 3.141592653589793

Confirm that 1.5707963267948966 is the arccosine of 0:

def output = acos(0, 1.5707963267948966)
//output> ()  // true

See Also

sin, cos, asin, asinh, acosh, sinh, cosh, and haversine.

acosh

View source
acosh[x]
acosh(x, ach)

Hyperbolic arccosine. ach is the hyperbolic arccosine of x.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Hyperbolic cosine of ach. Must be grounded.
achFloatBinary[#64]Hyperbolic arccosine of x.

Explanation

Defined for x >= 1.

Hyperbolic arccosine is sometimes called “inverse hyperbolic cosine.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the hyperbolic arccosine of 90:

def output = acosh[90]
//output> 5.192925985263684

Calculate the hyperbolic arccosine of 180 using full expression:

def output(x) = acosh(180, x)
//output> 5.886096315311465

Confirm that 5.192925985263684 is the hyperbolic arccosine of 90:

def output = acosh(90, 5.192925985263684)
//output> ()  // true

See Also

sin, cos, asin, acos, asinh, acosh, sinh, and haversine.

acot

View source
acot[x]
acot(x, act)

Arccotangent. act is the arccotangent of x.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Cotangent of act. Must be grounded.
actFloatBinary[#64]Arccotangent of x.

Explanation

Arccotangent is sometimes called “inverse cotangent.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the arccotangent of 1:

def output = acot[1]
//output> 0.7853981633974483

Calculate the arccotangent of -1 using full expression:

def output(x) = acot(-1, x)
//output = -0.7853981633974483

Confirm that 0.7853981633974483 is the arccotangent of 1:

def output = acot(1, 0.7853981633974483)
//output> ()  // true

See Also

tan, atan, atan2, cot, tanh, and atanh.

add

View source
add[x, y]
add(x, y, s)
x + y

Addition of two numbers. Addition of a DateTime/Date, x, with a time duration y.

Parameters

Numeric Data

ParameterTypeDescription
xNumberFirst summand.
yNumberSecond summand.
sNumberSum x + y.

Not all numeric values can be mixed with each other. The following combinations work:

xys
NumberSame as xSame as x
Rational, FixedDecimalSignedInteger[#64]Same as x
SignedInteger[#64]SignedInteger[#128], Rational, FixedDecimal, FloatBinary[#64]Same as y
SignedInteger[#128]SignedInteger[#64]SignedInteger[#128]
FloatBinary[#64]SignedInteger[#64]FloatBinary[#64]

Two of the three arguments need to be grounded. Valid grounding combinations are as follows:

  • x and y.
  • x and s.
  • y and s.

Time Data

ParameterTypeDescription
xDate, DateTime, date period, time periodFirst summand.
yDate, DateTime, date period, time periodSecond summand.
sDate, DateTime, date period, time periodSum x + y.

The following combinations work:

xys
date period, time periodSame date period, time period as xSame date period, time period as x
date period, time periodDateTimeDateTime
DateTimedate period, time periodDateTime
date periodDateDate
Datedate periodDate

Two of the three arguments need to be grounded. Valid grounding combinations are as follows:

  • x and y.
  • x and s.
  • y and s.

Explanation

Addition evaluates the sum of x and y and assigns it to s. In procedural languages, usually x and y are given. In Rel — a declarative language — addition can be thought of as a mapping where x and y are the keys and s is the value, which is functionally dependent on x and y.

However, with addition — add(x, y, s) — it is sufficient to know any two of the three arguments. The third one can always be inferred. Usually x and y are given, but knowing x and s is enough to infer y.

Examples

Addition of Numbers

Add two integers using +:

def output = 1 + 2
//output> 3

Add an integer and a float using add:

def output = add[1, 2.5]
//output> 3.5

Add two floats using full expression:

def output(x) = add(1.7, 2.8, x)
//output> 4.5

Add integer to a rational:

def output = 1 + rational[16][2, 3]
//output> 5/3

Addition of Time

Add time to a timestamp:

def output:tomorrow = datetime_now + ^Day[1]
def output:next_hour = datetime_now + ^Hour[1]

Add weeks to a date:

def output = 2022-12-24 + ^Week[2]
//output> 2023-01-07

Add seconds together:

def output = ^Second[1] + ^Second[2]
//output> 3

See Also

subtract, divide, and multiply.

Any

View source
Any(x)

Holds for any x, where x exists. (Any functions as a wildcard.)

Example:

Integrity constraint that tests whether x is of any type:

def R = (1, 3) ; (1, "foo")
 
ic any_ic {subset(R, (Int, Any) )}

approx_eq

View source
approx_eq(tolerance, x, y)

Approximate equality. Use to compare scalar numbers and check if x and y are within the absolute tolerance (tolerance) of each other.

Parameters

ParameterTypeDescription
toleranceSignedInteger[#64] or FloatBinary[#64]Tolerance of the approximation. A positive number. Must be grounded.
xNumberA valid number. Must be the same data type as y. Must be grounded.
yNumberA valid number. Must be the same data type as x. Must be grounded.

Explanation

“approximately equal” is defined as number values being within the absolute tolerance (tolerance) of each other, or non-number values being equal.

The parameter tolerance stands for the absolute tolerance and must be of type SignedInteger[#64] or FloatBinary[#64]. Also, tolerance must be a positive number; negative numbers will return false

x and y should be of the exact same data type. For example, x and y can be of type FixedDecimal or Rational, but types must have the same bits and precision.

If x or y is not a number, approx_eq defaults to eq.

Examples

Approximate equality determined as true:

def output = approx_eq(0.05, 0.1, 0.15)
//output> ()  // true

Approximate equality determined as false:

def output = approx_eq(0.01, 0.1, 0.15)
//output>    // false

See Also

equal, eq, approx_equal, and full_relation_approx_equal.

approx_equal

View source
approx_equal(tolerance, R, S)

Approximate relational equality. To hold true, the values in the last column of R must be approximately equal to values in the last column of S given the same key (prefix).

Parameters

ParameterTypeDescription
toleranceSignedInteger[#64] or FloatBinary[#64]A positive integer or float. Must be grounded.
RRelationA relation with corresponding keys and last elements that can be compared to S. Must be grounded.
SRelationA relation with corresponding keys and last elements that can be compared to R. Must be grounded.

Explanation

Two relations R and S are considered “relationally approximately equal” when for each tuple (k..., x) in S there exists a tuple (k..., y) in R where x and y are considered approximately equal. This approximate equality is symmetric and holds equally true when the places of R and S are swapped.

See approx_eq for the details about approximate equality between two data values.

The parameter tolerance stands for the absolute tolerance and must be of type SignedInteger[#64] or FloatBinary[#64]. tolerance must be a positive number; negative numbers will evaluate to false.

Keys must match for approx_equal to be true.

All values of the last column in R and S must be of the exact same data type. For example, the values can all be of type FixedDecimal or Rational, but types must have the same bits and precision. Otherwise, approx_equal evaluates to false.

Note the correspondence between approx_equal and equal: approx_equal(0, R, S) if and only if equal(R, S).

approx_equal applies only to the values in the last column in R and S. That is, if the values are not within tolerance, approx_equal will evaluate to false even if other arguments in the relations are within tolerance. If full relation comparison functionality is required, see full_relation_approx_equal.

Examples

Approximate relational equality determined as true:

def salary1 = {("John", 10.0) ; ("Mary", 20.0); ("Paul", 17.0) ; ("Peter", 15.0) }
def salary2 = {("John", 9.99) ; ("Mary", 20.01); ("Paul", 17.0) ; ("Peter", 15.0) }
 
def output = approx_equal(0.1, salary1, salary2)
//output> ()  // true

Approximate relational equality determined as false:

def salary1 = {("John", 10.0) ; ("Mary", 20.0); ("Paul", 17.0) ; ("Peter", 15.0) }
def salary2 = {("John", 11.0) ; ("Mary", 21.0); ("Paul", 17.0) ; ("Peter", 15.0) }
 
def output = approx_equal(0.1, salary1, salary2)
//output>    // false

Approximate relational equality determined as false because keys are different:

def salary1 = {("John", 10.0) ; ("Mary", 20.0); ("Paul", 17.0) ; ("Peter", 15.0) }
def salary3 = {("John", 9.99) ; ("Ben", 20.0); ("Paul", 17.0) ; ("Peter", 15.0) }
 
def output = approx_equal(0.1, salary1, salary3)
//output>    // false

Approximate relational equality determined as false, even though the first arguments are within tolerance:

def coordinates1 = (1.0, 2.0); (3.0, 6.0)
def coordinates2 = (1.0000001, 2.0); (2.9999999, 6.0000001)
 
def output = approx_equal(0.001, coordinates1, coordinates2)
//output>    // false

See Also

full_relation_approx_equal, approx_eq, equal, and eq.

argmax

View source
argmax[R]
argmax(R, am)

For a relation R, find the tuples whose last elements are largest and return those tuples with the last element omitted.

Parameters

ParameterTypeDescription
RRelationA relation whose tuples contain key-value pairs. Must be grounded.
amNumberA tuple in R with the largest last element, with last element omitted.

Explanation

If tuples in R contain keys and values, argmax returns all the keys for the largest value. Typically, argmax is used when the last elements of each tuple are numeric.

argmax is typically used with relations whose shortest tuple has length two. Note that, for all unary relations, argmax results in a relation containing an empty tuple.

Examples

Find key for largest value of R:

def R = {("A", 7.5); ("B", 8.6); ("C", 9.7); ("D", 7.5)}
def output(am) = argmax(R, am)
//output> "C"

Find key for largest value of R where values are rationals:

def R = {("A", rational[64, 8, 3]); ("B", rational[64, 9, 7]); ("C", rational[64, 11, 4]); ("D", rational[64, 8, 3])}
def output = argmax[R]
//output> "C"

Find the teams with the largest aggregated salary:

def salary = {("Burrow", 11,515,044); ("Chase", 18,211,606); ("Allen", 77,289,124); ("Diggs", 45,466,111)}
def member = {("Bengals", "Burrow"); ("Bengals", "Chase"); ("Bills", "Allen"); ("Bills", "Diggs")}
def team = {"Bengals"; "Bills"}
def output = argmax[d in team: sum[salary[p] for p in member[d]]]
//output> "Bengals"

See Also

argmin, maximum, min, argmax, sum, product, and average.

ArgMax

View source
ArgMax[R]

Please use argmax[R]. Deprecates in near future

argmin

View source
argmin[R]
argmin(R, am)

For a relation R, find the tuples whose last elements are smallest and return those tuples with the last element omitted.

Parameters

ParameterTypeDescription
RRelationSource relation. Must be grounded.
amAnyA tuple in R with the smallest last element, with last element omitted.

Explanation

If tuples in R contain keys and values, argmin returns all the keys for the smallest value. Typically, argmin is used when the last elements of each tuple are numeric.

argmin is typically used with relations whose shortest tuple has length two. Note that, for all unary relations, argmin results in a relation containing an empty tuple.

Examples

Find key for smallest value of R:

def R = {("A", 7.5); ("B", 8.6); ("C", 9.7); ("D", 7.5)}
def output(am) = argmin(R, am)
//output> "A"
//        "C"

Find key for smallest value of R where values are rationals:

def R = {("A", rational[64, 8, 3]); ("B", rational[64, 9, 7]); ("C", rational[64, 11, 4]); ("D", rational[64, 7, 3])}
def output = argmin[R]
//output> "B"

Find key for smallest value of R with tuples of various arity:

def R = {("A", 7.5); ("B", 8.6); ("C", "W", 9.7); ("D", "X", 7.5)}
def output = argmin[R]
//output> "A"
//        "D", "X"

Find the teams with the smallest aggregated salary:

def salary = {("Burrow", 11,515,044); ("Chase", 18,211,606); ("Allen", 77,289,124); ("Diggs", 45,466,111)}
def member = {("Bengals", "Burrow"); ("Bengals", "Chase"); ("Bills", "Allen"); ("Bills", "Diggs")}
def team = {"Bengals"; "Bills"}
def output = argmin[d in team: sum[salary[p] for p in member[d]]]
//output> "Bills"

See Also

argmax, minimum, min, argmax, sum, product, and average.

ArgMin

View source
ArgMin[R]

Please use argmin[R]. Deprecates in near future

arity

View source
arity[R]

The arity of a relation. In some cases, it can be an over-approximation.

Arity is a higher-order relation that is always evaluated at compile-time.

Examples:

def output = arity[3]
//output> 1
def output = arity[{1; 2; 3}]
//output> 1
def output = arity[(1, 2)]
//output> 2
def output = arity[add]
//output> 3
def output = arity[{1; 2; (1,2)}]
//output> 1
//        2

Arity can be used to do meta-programming in logic. For example, the following abstraction verbalize implements specific cases using arity.

Examples:

@inline def verbalize[R] = "nullary", arity[R] = 0;
                           "unary", arity[R] = 1;
                           "binary", arity[R] = 2
def output = verbalize[true]
//output> "nullary"
def output = verbalize[1]
//output> "unary"

Arity can be used in higher-order abstractions to check at compile-time that they are used correctly.

Arity can be used in integrity constraints to state expectation on EDB or IDB relations. Because arity is evaluated at compile-time, it can catch mistakes in the logic before the logic executes.

Example:

def p = (1, 2, 3)
ic { arity[p] = 3 }

Note that there is a difference between R(_, _) and arity(R) = 2. The first requires R to be non-empty, which is a run-time property of R.

asin

View source
asin[x]
asin(x, as)

Arcsine of x. ac is the arcsine of x given in radians.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Sine of as. Must be grounded.
asFloatBinary[#64]Arcsine of x.

Explanation

Defined for x between -1 and 1 (inclusive). The value of as ranges from -π/2 to π/2.

Only 64-bit float and 64-bit integer values for x are supported.

Arcsine is sometimes called “inverse sine.”

Examples

Calculate the arcsine of 1:

def output = asin[1]
//output> 1.5707963267948966

Calculate the arcsine of -.5 using full expression:

def output(x) = asin(-.5, x)
//output> -0.5235987755982989

Confirm that 1.5707963267948966 is the arcsine of 1:

def output = asin(1, 1.5707963267948966)
//output> ()  // true

See Also

sin, cos, acos, asinh, acosh, sinh, cosh, and haversine.

asinh

View source
asinh[x]
asinh(x, ash)

Hyperbolic arcsine. ash is the hyperbolic arcsine of x.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Hyperbolic sine of ash. Must be grounded.
ashFloatBinary[#64]Hyperbolic arcsine of x.

Explanation

Hyperbolic arcsine is sometimes called “inverse hyperbolic sine.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the hyperbolic arcsine of 10:

def output = asinh[10]
//output> 2.99822295029797

Calculate the hyperbolic arcsine of -1 using full expression:

def output(x) = asinh(-1, x)
//output> -0.881373587019543

Confirm that 2.99822295029797 is the hyperbolic arcsine of 10:

def output = asinh(10, 2.99822295029797)
//output> ()  // true

See Also

sin, cos, asin, acos, acosh, sinh, cosh, and haversine.

atan

View source
atan[x]
atan(x, at)

Arctangent. at is the arctangent of x in radians.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Tangent of at. Must be gounded.
atFloatBinary[#64]Arctangent of x.

Explanation

Arctangent is sometimes called “inverse tangent.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the arctangent of π/4:

def output = atan[pi_float64/4]
//output> 0.6657737500283538

Convert degrees to radians and calculate arctangent using full expression:

def x = deg2rad[90]
def output(at) = atan(x, at)
//output> 1.0038848218538872

Confirm that 0.6657737500283538 is the tangent of π/4:

def output = atan(pi_float64/4, 0.6657737500283538)
//output> ()  // true

See Also

tan, atan2, cot, acot, tanh, and atanh.

atan2

View source
atan2[y, x]
atan2(y, x, at)

Arctangent. at is the arctangent of the quotient y/x in radians.

Parameters

ParameterTypeDescription
yFloatBinary[#64], SignedInteger[#64], UnsignedInteger[#64]yy coordinate of the 2D point (x,y)(x, y). Must be gounded.
xUnsignedInteger[#64], SignedInteger[#64], FloatBinary[#64]xx coordinate of the 2D point (x,y)(x, y). Must be gounded.
atFloatBinary[#64]Arctangent of x.

Explanation

Arctangent is sometimes called “inverse tangent.” The parameters x and y can be thought of as the xx and yy coordinates of the 2D point (x,y)(x, y).

Examples

Calculate the arctangent of 50:

def output = atan2[100, 2.0]
//output> 1.550798992821746

See Also

atan, tan, cot, acot, tanh, and atanh.

atanh

View source
atanh[x]
atanh(x, ath)

Hyperbolic arctangent. ath is the hyperbolic arctangent of x.

Parameters

ParameterTypeDescription
xFloatBinary[#64], SignedInteger[#64]Hyperbolic tangent of ath. Must be grounded.
athFloatBinary[#64]Hyperbolic arctangent of x.

Explanation

Hyperbolic arctangent is sometimes called “inverse hyperbolic tangent.”

Only 64-bit float and 64-bit integer values for x are supported.

Examples

Calculate the hyperbolic arctangent of -.7:

def output = atanh[-.7]
//output> -0.8673005276940532

Calculate the hyperbolic arctangent of .7 using full expression:

def output(x) = atanh(.7, x)
//output> 0.8673005276940532

Confirm that -0.8673005276940532 is the hyperbolic arctangent of -.7:

def output = atanh(-.7, -0.8673005276940532)
//output> ()  // true

See Also

tan, atan, atan2, cot, acot, tanh, and atanh.

average

View source
average[R]
average(R, m)

The average (arithmetic mean) of a relation R. average is an alias for mean. For details, see the docstring for mean.

bigint

View source
bigint[i]

Create a BigInteger value from the given integer.

Examples:

string[factorial[bigint[50]]] = "30414093201713378043612608166064768844377641568960512000000000000"

bigint_int64_convert

View source
Convert a BigInteger to an Int64.

Examples:

bigint_int64_convert[bigint[50]] = 50

bitwise_and

View source
bitwise_and[x, y]
bitwise_and(x, y, z)

Bitwise and of two integers.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerLeft operand. Must be grounded.
ySignedInteger, UnsignedIntegerRight operand. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise and of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Examples

Bitwise and of 3 and 2:

def output = bitwise_and[3, 2]
//output> 2

Bitwise and of two unsigned integers using full expression:

def output(z) = bitwise_and(0x11100, 0x00101, z)
//output> 256

Bitwise and of unsigned and signed integers:

def output = bitwise_and[0x010b, -265]
//output> 3  // is an UnsignedInteger[#16]

See Also

bitwise_or, bitwise_xor, bitwise_left_shift, bitwise_right_shift, bitwise_unsigned_right_shift, and bitwise_not.

bitwise_left_shift

View source
bitwise_left_shift[x, y]
bitwise_left_shift(x, y, z)

Bitwise left shift of an integer x by y bits.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerOperand. Must be grounded.
ySignedInteger, UnsignedIntegereBits for left shift. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise left shift of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Explanation

The type of shift done depends on the type of x. If x is signed, bitwise_left_shift performs a signed left shift (also known as an “arithmetic left shift”). If x is unsigned, bitwise_left_shift performs an unsigned left shift (also known as a “logical left shift”).

Examples

Bitwise left shift of 8 by 1 bit:

def output = bitwise_left_shift[8, 1]
//output> 16

Bitwise left shift of 1 by 10 bits using full expression:

def output(z) = bitwise_left_shift(1, 10, z)
//output> 1024

Bitwise left shift of 0xf by 1 bit:

def output = bitwise_left_shift[0xF, 1]
//output> 30

Bitwise left shift of unsigned integer:

def output = bitwise_left_shift[uint[64, 4028], 1]
//output> 8056

See Also

bitwise_and, bitwise_or, bitwise_xor, bitwise_right_shift, bitwise_unsigned_right_shift, and bitwise_not.

bitwise_not

View source
bitwise_not[x]
bitwise_not(x, z)

Bitwise not of an integer.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerOperand. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise not of x.

Not all numeric values can be mixed with each other. The following combinations work:

xz
SignedInteger, UnsignedIntegerSame as x.Same as x.

Examples

Bitwise not of -9:

def output = bitwise_not[-9]
//output> 8

Bitwise not of 8 using full expression:

def output(z) = bitwise_not(8, z)
//output> -9

Bitwise not of 0x00011:

def output = bitwise_not[0x00011]
//output> 4294967278

See Also

bitwise_and, bitwise_or, bitwise_xor, bitwise_left_shift, bitwise_right_shift, and bitwise_unsigned_right_shift.

bitwise_or

View source
bitwise_or[x, y]
bitwise_or(x, y, z)

Bitwise or of two integers.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerLeft operand. Must be grounded.
ySignedInteger, UnsignedIntegerRight operand. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise or of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Examples

def output = bitwise_or[3, 2]
//output> 3

Bitwise or of 0x00011 and 0x11100 using full expression:

def output(z) = bitwise_or(0x00011, 0x11100, z)
//output> 69905

Bitwise xor of two unsigned integers:

def output = bitwise_or[uint[64, 1024], uint[64, 2048]]
//output> 3072

See Also

bitwise_and, bitwise_xor, bitwise_left_shift, bitwise_right_shift, bitwise_unsigned_right_shift, and bitwise_not.

bitwise_right_shift

View source
bitwise_right_shift[x, y]
bitwise_right_shift(x, y, z)

Bitwise right shift of an integer x by y bits that preserves the sign.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerOperand. Must be grounded.
ySignedInteger, UnsignedIntegerBits for right shift. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise right shift of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Examples

Bitwise right shift of 1024 by 1 bit:

def output = bitwise_right_shift[1024, 1]
//output> 512

Bitwise right shift of -1024 by 1 bit using full expression:

def output(z) = bitwise_right_shift(-1024, 1, z)
//output> -512

Bitwise right shift of unsigned integer by 2 bits:

def output = bitwise_right_shift[uint[64, 2048], 2]
//output> 512

See Also

bitwise_and, bitwise_or, bitwise_xor, bitwise_left_shift, bitwise_unsigned_right_shift, and bitwise_not.

bitwise_unsigned_right_shift

View source
bitwise_unsigned_right_shift[x, y]
bitwise_unsigned_right_shift(x, y, z)

Bitwise unsigned right shift of an integer by y bits.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerOperand. Must be grounded.
ySignedInteger, UnsignedIntegerBits for unsigned right shift. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise unsigned right shift of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Examples

Bitwise unsigned right shift of 8 by 1 bit:

def output = bitwise_unsigned_right_shift[8, 1]
//output> 4

Bitwise unsigned right shift of -8 by 2 bits:

def output(z) = bitwise_unsigned_right_shift(-8, 2, z)
//output> 4611686018427387902

Bitwise unsigned right shift of unsigned integer by 3 bits:

def output = bitwise_unsigned_right_shift[uint[64, 8], 3]
//output> 1

See Also

bitwise_and, bitwise_or, bitwise_xor, bitwise_left_shift, bitwise_right_shift, and bitwise_not.

bitwise_xor

View source
bitwise_xor[x, y]
bitwise_xor(x, y, z)

Bitwise xor (exclusive or) of two integers.

Parameters

ParameterTypeDescription
xSignedInteger, UnsignedIntegerLeft operand. Must be grounded.
ySignedInteger, UnsignedIntegerRight operand. Must be grounded.
zSignedInteger, UnsignedIntegerThe bitwise xor of x and y.

Not all numeric values can be mixed with each other. The following combinations work:

xyz
SignedInteger, UnsignedIntegerSame as x.Same as x.
SignedInteger, UnsignedIntegerSignedInteger[#64], UnsignedInteger[#32]Same as x.

Examples

Bitwise xor of 3 and 2:

def output = bitwise_xor[3, 2]
//output> 1  // is a SignedInteger[#64]

Bitwise xor of 0x00011 and 0x11100 using full expression:

def output(z) = bitwise_xor(0x00011, 0x11100, z)
//output> 69905

Bitwise xor of two unsigned integers:

def output = bitwise_xor[uint[64, 1024], uint[64, 2048]]
//output> 3072

See Also

bitwise_and, bitwise_or, bitwise_left_shift, bitwise_right_shift, bitwise_unsigned_right_shift, and bitwise_not.

Boolean

View source
Boolean(x)

Holds if x is a Boolean.

Example:

def json = parse_json["""{"a": true, "b": false}"""]
def output(x) = json(:a, x) and Boolean(x)

boolean_and

View source
boolean_and(x, y, z)

Logical AND operator for the Boolean data type.

Example:

def output(x, y, z) = boolean_and(x, y, z) and boolean_true(z)

boolean_false

View source
boolean_false(x)

Holds if x is a Boolean of value false.

boolean_not

View source
boolean_not(x,y)

Negation(not) operator for the Boolean data type. Example:

def output(x, y) = boolean_not(x, y) and boolean_false(x)

boolean_or

View source
boolean_or(x, y, z)

Logical or operator for the Boolean data type. Example:

def output(x, y, z) = boolean_or(x, y, z) and boolean_false(z)

boolean_true

View source
boolean_true(x)

Holds if x is a Boolean of value true.

bottom

View source
bottom[k, R]
bottom(k, R, index, x...)

Select the bottom k tuples of relation R according to the sort order of R and add enumeration.

Parameters

ParameterTypeDescription
RRelationSource relation. Must be grounded.
kIntNumber of tuples to sort from the bottom of R. Must be grounded.
indexIntThe new enumeration index starting at 1.
x...TupleA tuple in R associated with the new index index.

Explanation

bottom is reverse_sort restricted to the last k tuples of R. bottom puts the tuples of R in lexicographical order and then limits the result to the last k tuples. The index indicates the tuples of R in reverse order. For details on lexicographical ordering — particularly across data types — see enumerate.

Simlar to reverse_sort, bottom takes a relation R(x...) and produces a relation with the tuples (index, x...), where the first element of each tuple (index) is an integer index that enumerates the bottom k tuples in the original relation R.

Examples

Apply bottom to a relation with arity-1 tuples:

def output =  bottom[2, {'a'; 'b'; 'c'; 'd'}]
//output> (1, 'd')
//        (2, 'c')

Apply bottom to a relation with arity-2 tuples:

def R = {('a', 1); ('b', 2); ('c', 3); ('d', 4); ('e', 5)}
def output = bottom[3, R]
//output> 1, e, 5
//        2, d, 4
//        3, c, 3

See Also

top, enumerate, sort, and reverse_sort.

byte

View source
byte[str]
byte[str, i]
byte(str, i, b)

Indexes into a string at byte position i, mapping each position i to a byte b, as a UInt8 value.

If a string contains Unicode characters, the byte at index i might be only a partial character. Be careful with your indexing logic.

Both i and b can be optionally bound externally. When only str is bound, this is the mapping from each index to its corresponding byte.

Examples: Indexing into a known byte index:

byte["abcd", 2] = 0x62
byte["中文例子", 2] = 0xb8

Abstracting over the byte index:

equal(byte["中文"],
        { 1, 0xe4;
          2, 0xb8;
          3, 0xad;
          4, 0xe6;
          5, 0x96;
          6, 0x87; })
equal((i : byte["awesome", i](0x65)), {3; 7})

capture_group_by_index

View source
capture_group_by_index[regex, input_string, offset]

A set of capture groups, each of the form (index, substring), where index is the capture group index, and