# Ko

## A language for programming recursive circuits

Ko
2. Language
2.4. Macros
2.4.6. Macros for generic arithmetic
2.4.6. Macros for generic arithmetic

Programming languages typically provide arithmetic and boolean operators to perform basic algebraic operation over the respective types. In Ko, this is accomplished by a few arithmetic macros. (Additional arithmetic macros will be added as the language evolves.)

## Operations over integers

Macros for integer operations are placed in a builtin package "integer" which must be imported before using the macros. E.g.

import "integer"

ThreeXPlus1(x) {
return: integer.Sum(
integer.Prod(3, x)
1
)
}

Equal expects a sequence of integral arguments. It returns true if all argument integers are equal, and false otherwise. If no arguments are passed, the default return value is true .

Less expects a sequence of integral arguments. It returns true if the sequence of argument integers is strictly increasing (each argument is smaller than the next one).

Prod , Ratio , Sum expect a sequence of integral arguments. Prod returns the product of its arguments; Ratio returns the ratio of its arguments, and Sum returns the sum of its arguments.

Negative expects a single integral argument and returns its negation.

## Operations over booleans

And , Or , Xor expect a sequence of boolean arguments. And returns the conjunction of its arguments; Or returns the disjunction of its arguments, and Xor returns the result of applying exclusive-or to all of its arguments.

Not expects a single boolean argument and returns its negation.

For instance, one could define NAND (not-and) as:

NotAnd(seq?) {
return: Not(And(seq))
}