1.4.5 Rational and Complex Arithmetic
(* num ...) |
Multiplies the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function binary-*
(+ num ...) |
Adds the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function binary-+.
(- num num) |
Subtracts the given numbers. If only one argument is given, returns the negation of the input.
(/ num num) |
Divides the first number by the second. If only one argument is given, returns the reciprocal of the input.
(1+ num) |
Adds 1 to the given number.
Example: |
> (1+ 1) |
2 |
(1- num) |
Subtracts 1 from the given number.
Example: |
> (1- 1) |
0 |
(binary-* x y) → t |
x : (acl2-numberp x) |
y : (acl2-numberp y) |
Takes exactly two numbers and multiplies them together.
Example: |
> (binary-* 9 8) |
72 |
(binary-+ x y) → t |
x : (acl2-numberp x) |
y : (acl2-numberp y) |
Takes exactly two numbers and adds them together.
Example: |
> (binary-+ 9 8) |
17 |
(/= x y) → t |
x : (acl2-numberp x) |
y : (acl2-numberp y) |
Determines if x is less than y.
Determines if x is less than or equal to y.
(= x y) → t |
x : (acl2-numberp x) |
y : (acl2-numberp y) |
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.
Determines if x is greater than y.
Determines if x is greater than or equal to y.
(acl2-numberp x) |
Returns true if and only if x is a rational or complex rational number.
Examples: |
> (acl2-numberp 1) |
't |
> (acl2-numberp 12/5) |
't |
> (acl2-numberp "no") |
'() |
Determines if z is a complex number consisting of rational parts.
Examples: |
> (complex-rationalp 3) |
'() |
> (complex-rationalp (complex 3 0)) |
'() |
> (complex-rationalp t) |
'() |
> (complex-rationalp (complex 3 1)) |
't |
(complex/complex-rationalp z) → t |
z : t |
For most cases, this is simply a macro abbreviating complex-rationalp.
Examples: |
> (complex/complex-rationalp 3) |
'() |
> (complex/complex-rationalp (complex 3 0)) |
'() |
> (complex/complex-rationalp t) |
'() |
> (complex/complex-rationalp (complex 3 1)) |
't |
This is a test for the base case (zero) of recursion on the natural numbers.
Examples: |
> :eval |
reference to undefined identifier: :eval |
> the-evaluator |
reference to undefined identifier: the-evaluator |
> (zp 0) |
reference to undefined identifier: zp |
> (zp 1) |
reference to undefined identifier: zp |
(minusp x) → t |
x : (real/rationalp x) |
Determines whether x is a negative number.
Determines if x is a natural number.
Determines if x is odd.
(plusp x) → t |
x : (real/rationalp x) |
Determines if x is positive.
Determines if x is a positive integer.
Examples: |
> (posp 1) |
't |
> (posp -1) |
'() |
> (posp 1/2) |
'() |
> (posp (complex 1 2)) |
'() |
> (posp "asdf") |
'() |
(rationalp x) |
Determines if x is a rational number.
Examples: |
> (rationalp 2/5) |
't |
> (rationalp 2) |
't |
> (rationalp (complex 1 2)) |
'() |
> (rationalp "number") |
'() |
(real/rationalp x) |
In most cases, this is just a macro abbreviating rationalp.
Examples: |
> (real/rationalp 2/5) |
't |
> (real/rationalp "number") |
'() |
(abs x) → t |
x : (real/rationalp x) |
Computes the absolute value of x.
(ceiling i j) → t |
i : (real/rationalp i) |
j : (and (real/rationalp j) (not (eql j 0))) |
Creates a complex number with real part n and imaginary part i.
(conjugate x) → t |
x : (acl2-numberp x) |
Computes the complex conjugate of x (the result of negating its imaginary part).
(denominator x) → t |
x : (rationalp x) |
Returns the divisor of a rational number in lowest terms.
Examples: |
> (denominator 5) |
1 |
> (denominator 5/3) |
3 |
> (denominator 5/3) |
3 |
Determines if x is even.
(explode-nonnegative-integer n r) → l |
n : (and (integerp n) (>= n 0)) |
r : (print-base-p r) |
Returns a list of characters representing n in base-r, and appends l to the end.
Examples: |
> (explode-nonnegative-integer 925 10 nil) |
'(#\9 #\2 #\5) |
> (explode-nonnegative-integer 325 16 nil) |
'(#\1 #\4 #\5) |
> (explode-nonnegative-integer 325 16 (list 'a 'b 'c)) |
'(#\1 #\4 #\5 a b c) |
> (explode-nonnegative-integer 325 16 'a) |
'(#\1 #\4 #\5 . a) |
Raises i to the jth power.
Coerces x to a number. If x is a number, (fix x) returns the argument unchanged. Otherwise, it returns 0.
(floor i j) → t |
i : (real/rationalp i) |
j : (and (real/rationalp j) (not (eql j 0))) |
Coerces x to an integer. If x is an integer, (ifix x) returns the argument unchanged. Otherwise, it returns 0.
(imagpart i) → t |
i : (acl2-numberp i) |
Returns the imaginary part of a complex number.
(int= i j) |
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 =.
(integer-length x) → t |
x : (integerp x) |
Returns the number of bits in the two’s complement binary representation of x.
Examples: |
> (integer-length 12) |
4 |
> (integer-length 1234) |
11 |
(integerp x) |
Determines whether x is an integer.
(max i j) → t |
i : (real/rationalp i) |
j : (real/rationalp j) |
Returns the greater of the two given numbers.
(min i j) → t |
i : (real/rationalp i) |
j : (real/rationalp j) |
Returns the lesser of the two given numbers.
(mod i j) → t |
i : (real/rationalp i) |
j : (and (real/rationalp j) (not (eql j 0))) |
Computes the remainder of dividing i by j.
Coerces x to a natural number. If x is a natural number, (nfix x) returns the argument unchanged. Otherwise, it returns 0.
(nonnegative-integer-quotient x y) → t |
x : (and (integerp x) (not (< x 0))) |
y : (and (integerp j) (< 0 j)) |
Returns the integer quotient of x and y. That is, (nonnegative-integer-quotient x y) is the largest integer k such that (* j k) is less than or equal to x.
Examples: |
> (nonnegative-integer-quotient 14 3) |
4 |
> (nonnegative-integer-quotient 15 3) |
5 |
Returns the dividend of a rational number in lowest terms.
Coerces x to a real number. If x satisfies (real/rationalp x), then it returns the argument unchanged. Otherwise, returns 0.
(realpart x) → t |
x : (acl2-numberp x) |
Returns the real part of a complex number.
(rem i j) → t |
i : (real/rationalp i) |
j : (and (real/rationalp j) (not (eql j 0))) |
Coerces x into a rational number. If x is a rational number, then it returns x unchanged. Otherwise, it returns 0.
(round i j) → t |
i : (real/rationalp i) |
j : (real/rationalp j) |
Rounds (/ i j) to the nearest integer. When the quotient is exactly halfway between to integers, it rounds to the even one.
(signum x) → t |
x : (real/rationalp x) |
Returns 0 if x is 0, -1 if it is negative, and 1 if it is positive.
(truncate i j) → t |
i : (real/rationalp i) |
j : (and (real/rationalp j) (not (eql j 0))) |
(unary-- x) → t |
x : (acl2-numberp x) |
Computes the negative of the input.
Computes the reciprocal of the input.