Core Functions

add(Soup Soup) → Soup

Implements addition, the binary operation of a semigroup. So this does not only encompass the addition of numbers, but also operations such as set union or the non-commutative text concatenation. The related function sum accepts a variable number of arguments.

# Examples
add(1, 2);                  # 3
add("Hello ", "world!");    # "Hello world!"
add({1, 3} {2, 3, 4});      # {1, 2, 3, 4}
add(x^2+1/2x-3, -x^3+1/4x); # -x^3+x^2+3/4x-3

arg(Complex) → Angle

Returns the complex argument, that is the positive angle between positive real axis and the line from the origin to the given number in the complex plane. The complex argument is not defined for 0.

# Examples
arg(3);        # 0t
arg(!-1);      # !0.5t
arg(2-2i);     # 7/8t
arg(0.1+0.9i); # !0.23238835626136137t;

con(Complex) → Complex

Returns the conjugate of a complex number, that is its real part minus its imaginary part.

# Examples
con(3);        # 3
con(!-1);      # !-1
con(2-2i);     # 2+2i
con(0.1+0.9i); # 1/10-9/10i;

deg(Pol) → Int+Beyond

Returns the degree of the given polynomial. This is the highest exponent of x, since polynomials are univariate in Quirl. Returns -& for the zero polynomial.

# Examples
deg(0);         # -&
deg(1);         # 0
deg(x^2-x-1);   # 2
deg(1+2x-3x^5); # 5

den(Rat) → Int

Returns the positive denominator of the given rational expressed as a fraction reduced to its lowest terms.

# Examples
den(0);     # 1 because 0 is 0/1
den(-0.5);  # 2 because -0.5 is -1/2
den(2/3);   # 3
den(15/12); # 4 because 15/12 is 5/4

except(Bool Text)

Causes an exception with the given text as message except when the given boolean value is true, in which case it returns nothing. This can be used for testing. Exceptions abort the computation of the current statement, but do not stop the program.

# Example
except(ord(1 0.'9) "Failed to compute repeating decimal.");

exp(Float) → Float

Returns Euler's number e to the power of the given number.

# Examples
exp(0);                            # !1
exp(!1);                           # !2.718281828459045
exp(-1);                           # !0.36787944117144233
exp(mul(!3.141592653589793 1/3i)); # !0.5000000000000001+0.8660254037844386i;

in(Text Lang) → Bool

Returns whether a given text belongs to a given context-free language. (The in function is later extended to also tell whether a given item is an element of a given set.)

# Examples
CHESS_FILE ~ "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h";
CHESS_RANK ~ "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8";
CHESS_SQUARE ~ CHESS_FILE CHESS_RANK;

in("d5", CHESS_SQUARE);   # T
in("🐴", U+2654..U+265F); # F

inv(Field) → Field

Returns the multiplicative inverse, that is the inverse element in respect to the second field operation. The relationship between the given argument and its inverse is that they result in the multiplicative identity element when multiplied. The multiplicative inverse is also known as reciprocal, x⁻¹ or 1/x. It exists for all elements except for the additive identity element, zero.

# Examples
inv(2);    # 1/2
inv(!2);   # !0.5
inv(2%7);  # 4%7
inv(\2+i); # 1/3\2-1/3i
inv(1);    # 1

mod(Int Int) → Int

The remainder when the first argument is divided by the second argument according to Euclidean division. The result is always non-negative and smaller than the absolute value of the second argument.

# Examples
mod(8, 4);   # 0
mod(4, 3);   # 1
mod(-4, 3);  # 2
mod(4, -3);  # 1
mod(-4, -3); # 2

mul(Sing Sing) → Sing

Implements multiplication, the second binary operation (besides addition) of a semiring. This is classical multiplication of numbers, but also exists for other types, for example as the intersection of sets. The operation must be associative, but does not have to be commutative. The related function prod accepts a variable number of arguments.

# Examples
mul(4, 3);                  # 12
mul(i, -i);                 # 1
mul({1, 3} {2, 3, 4});      # {3}
mul(x^2+1/2x-3, -x^3+1/4x); # -x^5-1/2x^4+13/4x^3+1/8x^2-3/4x

neg(Group) → Group

Returns the additive inverse element. The relationship of the given argument and its additive inverse is that they result in the additive identity element, usually called zero, when added together. The additive inverse of x is also called minus x.

# Examples
neg(8);    # -8
neg(-1-i); # 1+i
neg(2%7);  # 5%7
neg(5/6t); # 1/6t
neg(0);    # 0

ord(Ordered Ordered) → Bool

Returns whether two elements from a totally and weakly ordered type satisfy the type's default order relation. The relation must be reflexive, anti-symmetric and transitive. For example, ord would be true for integer arguments, if the first argument is less than or equal to the second argument, and otherwise false. It is also true, if two text arguments are in ascending lexicographical order.

# Examples
ord(2, 1);         # F
ord(2/5, 1/2);     # T
ord(1, 0.'9);      # T
ord("dog", "cat"); # F

peel(Peelable) → List

Returns the elements from a bracketed collection, for instance the elements of a set or a tuple.

# Examples
peel({0});         # 0
peel([1, 3]);      # 1, 3
peel([[1, 3]]);    # [1, 3]
peel({"m", i, x}); # "m", i, x

root(Rootable Int) → ?

Returns a single $b-th root of the first argument. Mind that it is not guaranteed to be the principal one. The second parameter $b must be a positive integer.

# Examples
root(3, 2);                # \3
root(-1, 2);               # i
root(7/8, 3);              # !0.9564655913861946
root(3121/81-392/27\5, 4); # -2/3+\5

scale(Scalable Rat) → Scalable

Implements scalar multiplication: the first argument is scaled by the rational factor given as second argument.

# Examples
scale(1, 0);          # 0
scale(!1.5, 7);       # !10.5
scale(x^2+4x-3, 1/2); # 1/2x^2+2x-3/2
scale(1/6t, 3/2);     # 1/4t

sin(Angle) → ?

Returns the sine of the given angle.

# Examples
sin(1/6t);          # 1/2\3
sin(!0.25t);        # !1
sin(1/2000000000t); # !3.141592653589793/10^9;
sin(100°);          # !0.984807753012208;
sin(234°);          # -1/4-1/4\5;

split(Splittable) → List

Returns the atomic additive terms from a splittable value, for example symbols in a text or monomials in a polynomial. Additive identity elements do not occur in a split. For instance, the empty text and the zero polynomial split into nothing.

# Examples
split("Hello!"); # "H", "e", "l", "l", "o", "!"
split("H");      # "H"
split(1+\2-3i);  # 1, \2, -3i
split(x^2-3x+1); # x^2, -3x, 1

text(...?) → Text

Returns a textual representation of the whole argument list. Mind that the quotation mark " gets duplicated within text.

# Examples
text(!i);      # "!i"
text(1, 2);    # "1, 2"
text(inv@neg); # "inv@neg"
text("Hi!");   # """Hi!"""

type(?) → Type

Returns the argument's type. This is mostly for test purposes. Types are dynamic anyway.

# Examples
type(1);   # Int
type(i);   # Quad
type(!i);  # Float
type("i"); # Text