1.4.5Rational and Complex Arithmetic

Multiplies the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function binary-*

Examples:

> (*)

1

> (*2)

2

> (*123)

6

(+num...)

Adds the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function binary-+.

Examples:

> (+)

0

> (+2)

2

> (+123)

6

(-numnum)

Subtracts the given numbers. If only one argument is given, returns the negation of the input.

Examples:

> (-5)

-5

> (-53)

2

(/numnum)

Divides the first number by the second. If only one argument is given, returns the reciprocal of the input.

Examples:

> (/2)

1/2

> (/164)

4

(1+num)

Adds 1 to the given number.

Examples:

> (1+1)

2

(1-num)

Subtracts 1 from the given number.

Examples:

> (1-1)

0

(binary-*xy)→t

x:(acl2-numberpx)

y:(acl2-numberpy)

Takes exactly two numbers and multiplies them together.

Examples:

> (binary-*98)

72

(binary-+xy)→t

x:(acl2-numberpx)

y:(acl2-numberpy)

Takes exactly two numbers and adds them together.

Examples:

> (binary-+98)

17

(/=xy)→t

x:(acl2-numberpx)

y:(acl2-numberpy)

Determines if the given numbers are not equal. Logically equivalent to (not(equalxy))

Examples:

> (/=22)

()

> (/=32)

t

(<xy)→t

x:(rationalpx)

y:(rationalpy)

Determines if x is less than y.

Examples:

> (<12)

t

> (<21)

()

> (<22)

()

(<=xy)→t

x:(rationalpx)

y:(rationalpy)

Determines if x is less than or equal to y.

Examples:

> (<=12)

t

> (<=21)

()

> (<=22)

t

(=xy)→t

x:(acl2-numberpx)

y:(acl2-numberpy)

Determines if x is equal to y. This is like equal, but has the guard that both of its arguments must be numbers. It usually executes more efficiently thatn equal.

Examples:

> (=12)

()

> (=21)

()

> (=22)

t

(>xy)→t

x:(rationalpx)

y:(rationalpy)

Determines if x is greater than y.

Examples:

> (>12)

()

> (>21)

t

> (>22)

()

(>=xy)→t

x:(rationalpx)

y:(rationalpy)

Determines if x is greater than or equal to y.

Examples:

> (>=12)

()

> (>=21)

t

> (>=22)

t

(acl2-numberpx)

Returns true if and only if x is a rational or complex rational number.

Examples:

> (acl2-numberp1)

t

> (acl2-numberp12/5)

t

> (acl2-numberp"no")

()

(complex-rationalpz)

Determines if z is a complex number consisting of rational parts.

Examples:

> (complex-rationalp3)

()

> (complex-rationalp(complex30))

()

> (complex-rationalpt)

()

> (complex-rationalp(complex31))

t

(complex/complex-rationalpz)→t

z:t

For most cases, this is simply a macro abbreviating complex-rationalp.

Examples:

> (complex/complex-rationalp3)

()

> (complex/complex-rationalp(complex30))

()

> (complex/complex-rationalpt)

()

> (complex/complex-rationalp(complex31))

t

(minuspx)→t

x:(real/rationalpx)

Determines whether x is a negative number.

Examples:

> (minusp1)

()

> (minusp-1)

t

(natpx)→t

x:t

Determines if x is a natural number.

Examples:

> (natp1)

t

> (natp0)

t

> (natp-1)

()

(oddpx)→t

x:(integerpx)

Determines if x is odd.

Examples:

> (oddp3)

t

> (oddp2)

()

(pluspx)→t

x:(real/rationalpx)

Determines if x is positive.

Examples:

> (plusp1)

t

> (plusp-1)

()

> (plusp1/2)

t

(pospx)→t

x:t

Determines if x is a positive integer.

Examples:

> (posp1)

t

> (posp-1)

()

> (posp1/2)

()

> (posp(complex12))

()

> (posp"asdf")

()

(rationalpx)

Determines if x is a rational number.

Examples:

> (rationalp2/5)

t

> (rationalp2)

t

> (rationalp(complex12))

()

> (rationalp"number")

()

(real/rationalpx)

In most cases, this is just a macro abbreviating rationalp.

Examples:

> (real/rationalp2/5)

t

> (real/rationalp"number")

()

(absx)→t

x:(real/rationalpx)

Computes the absolute value of x.

Examples:

> (abs1)

1

> (abs-1)

1

(ceilingij)→t

i:(real/rationalpi)

j:(and(real/rationalpj)(not(eqlj0)))

Returns the smallest integer greater the value of (/ij).

Examples:

> (ceiling42)

2

> (ceiling43)

2

(complexni)→t

n:(rationalpn)

i:(rationalpi)

Creates a complex number with real part n and imaginary part i.

Examples:

> (complex21)

2+1i

> (complex20)

2

> (complex02)

0+2i

> (complex1/23/2)

1/2+3/2i

(conjugatex)→t

x:(acl2-numberpx)

Computes the complex conjugate of x (the result of negating its imaginary part).

Examples:

> (conjugate(complex31))

3-1i

(denominatorx)→t

x:(rationalpx)

Returns the divisor of a rational number in lowest terms.

Examples:

> (denominator5)

1

> (denominator5/3)

3

> (denominator5/3)

3

(evenpx)→t

x:(integerpx)

Determines if x is even.

Examples:

> (evenp1)

()

> (evenp2)

t

(explode-nonnegative-integernr)→l

n:(and(integerpn)(>=n0))

r:(print-base-pr)

Returns a list of characters representing n in base-r, and appends l to the end.

Examples:

> (explode-nonnegative-integer92510nil)

(#\9#\2#\5)

> (explode-nonnegative-integer32516nil)

(#\1#\4#\5)

> (explode-nonnegative-integer32516(list'a'b'c))

(#\1#\4#\5abc)

> (explode-nonnegative-integer32516'a)

(#\1#\4#\5. a)

(exptij)→t

i:(acl2-numberpi)

j:(and(integerpj)(not(and(eqli0)(<j0))))

Raises i to the jth power.

Examples:

> (expt102)

100

> (expt10-2)

1/100

(fixx)→t

x:t

Coerces x to a number. If x is a number, (fixx) returns the argument unchanged. Otherwise, it returns 0.

Examples:

> (fix20)

20

> (fix2/3)

2/3

> (fix"hello")

0

> (fixnil)

0

(floorij)→t

i:(real/rationalpi)

j:(and(real/rationalpj)(not(eqlj0)))

Returns the greatest integer not exceeding the value of (/ij).

Examples:

> (floor42)

2

> (floor43)

1

(ifix[xt])

#<procedure:t>Coerces x to an integer. If x is an integer, (ifixx) returns the argument unchanged. Otherwise, it returns 0.

Examples:

> (ifix16)

16

> (ifix22/3)

0

> (ifix"hello")

0

(imagparti)→t

i:(acl2-numberpi)

Returns the imaginary part of a complex number.

Examples:

> (imagpart(complex32))

2

> (imagpart5)

0

(int=ij)

Checks to see if the two integers i and j are equal. This is like equal and =, but with the added guard that the inputs are integers. This generally executes more efficiently on integers than equal or =.

Examples:

> (int=12)

()

> (int=21)

()

> (int=22)

t

(integer-lengthx)→t

x:(integerpx)

Returns the number of bits in the two’s complement binary representation of x.

Examples:

> (integer-length12)

4

> (integer-length1234)

11

(integerpx)

Determines whether x is an integer.

Examples:

> (integerp12)

t

> (integerp'12)

t

> (integerpnil)

()

(maxij)→t

i:(real/rationalpi)

j:(real/rationalpj)

Returns the greater of the two given numbers.

Examples:

> (max12)

2

> (max43)

4

(minij)→t

i:(real/rationalpi)

j:(real/rationalpj)

Returns the lesser of the two given numbers.

Examples:

> (min12)

1

> (min43)

3

(modij)→t

i:(real/rationalpi)

j:(and(real/rationalpj)(not(eqlj0)))

Computes the remainder of dividing i by j.

Examples:

> (mod42)

0

> (mod83)

2

(nfixx)→t

x:t

Coerces x to a natural number. If x is a natural number, (nfixx) returns the argument unchanged. Otherwise, it returns 0.

Examples:

> (nfix1)

1

> (nfix-1)

0

> (nfix1/2)

0

> (nfix"5")

0

(nonnegative-integer-quotientxy)→t

x:(and(integerpx)(not(<x0)))

y:(and(integerpj)(<0j))

Returns the integer quotient of x and y. That is, (nonnegative-integer-quotientxy) is the largest integer k such that (*jk) is less than or equal to x.

Examples:

> (nonnegative-integer-quotient143)

4

> (nonnegative-integer-quotient153)

5

(numeratorx)→t

x:(rationalpx)

Returns the dividend of a rational number in lowest terms.

Examples:

> (numerator4)

4

> (numerator6/7)

6

> (numerator1/2)

1

(realfixx)→t

x:t

Coerces x to a real number. If x satisfies (real/rationalpx), then it returns the argument unchanged. Otherwise, returns 0.

Examples:

> (realfix2/5)

2/5

> (realfix(complex32))

0

> (realfix"5")

0

(realpartx)→t

x:(acl2-numberpx)

Returns the real part of a complex number.

Examples:

> (realpart(complex32))

3

> (realpart1/2)

1/2

(remij)→t

i:(real/rationalpi)

j:(and(real/rationalpj)(not(eqlj0)))

Calculates the remainder of (/ij) using truncate.

Examples:

> (rem42)

0

> (rem83)

2

(rfixx)→t

x:t

Coerces x into a rational number. If x is a rational number, then it returns x unchanged. Otherwise, it returns 0.

Examples:

> (rfix2/5)

2/5

> (rfix(complex32))

0

> (rfix"5")

0

(roundij)→t

i:(real/rationalpi)

j:(real/rationalpj)

Rounds (/ij) to the nearest integer. When the quotient is exactly halfway between to integers, it rounds to the even one.