Maybe I was not clear enough. Here is some documentation of between.
The function between takes three arguments x, a, b, and optionally a 4th argument and returns 1 if x is between a and b.
Between is defined by the optional 4th argument. If it is omitted then between returns 1 when x is in the open interval
(a,b), it returns 1/2 at the endpoints. If x < a or x > b then between always returns 0. It is assumed a < b. If the
option 4th argument is included then it can be 'lclosed, 'rclosed, 'closed, 'open, or 'fourier. If it is 'fourier then
the behavior is the same as if the argument was omitted. If the 4th argument is 'closed then between returns 1 if x is
in the closed interval [a,b] and 0 otherwise. If is is 'lclosed or 'rclosed then between returns 1 if x is in the half
open interval [a,b) or (a,b] and 0 otherwise. if the 4th argument is 'open then between returns 1 if x is in the open
interval (a,b) and 0 otherwise.
If it cannot be determined from the facts list that x is between a and b then between returns the noun form
'between(x,a,b) or 'between(x,a,b,option). The arguments x, a and b can be expressions or atoms. Between also returns
a noun form composed of 'signum() expression if the 4th argument is omitted or equal to 'fourier and a = 'minf or b =
'inf and it cannot be determined x is between a and b. The function returns an equivilent expression in terms of the
signum() function in this case.
Here are some examples.
assume (x>4)$
between(x,4,5);
-> 'between(x,4,5)
assume (x<5)$
between(x,4,5);
-> 1
forget(x>4,x<5)$
between(5,5,10);
-> 1/2
between(10,5,10);
-> 1/2
between(6,5,10);
-> 1
between(0,5,10);
-> 0
between(5,5,10,'open);
-> 0
between(5,5,10, 'lclosed);
-> 1
between(10, 5, 10, 'rclosed);
-> 1
between(5, 5, 10, 'rclosed);
-> 0
between(x, 5, 'inf);
-> (signum(x-5)+1)/2
I hope this helps.
Rich
From: Richard Hennessy
Sent: Sunday, April 04, 2010 10:29 PM
To: Maxima List
Subject: How do you write this in lisp
I have a simplifying function called between() which is pretty slow. Could anyone be kind enough to show me how to
write the same function in Lisp so it is faster and still works in Maxima. Compiling this does not produce significant
improvement.
load("simplifying.lisp");
simpbetween(__x,__a,__b, [__option]):=
block(
[prederror:false],
if emptyp(__option) or first(__option) = 'fourier then
if is(__x > __a) = true and is(__x < __b)=true then
1
elseif is(__x < __a)=true or is(__x > __b)=true then
0
elseif is(equal(__x,__a))=true or is(equal(__x,__b))=true then
1/2
elseif __b = 'inf then
(
(1 + signum(__x - __a))/2
)
elseif __a = 'minf then
(
(1 - signum(__x - __b))/2
)
elseif __a = 'minf and __b = 'inf then
1
elseif __a = 'minf and __b = 'minf then
0
elseif __a = 'inf and __b = 'inf then
0
else
if emptyp(__option) then
simpfuncall('between, __x, __a, __b)
else
simpfuncall('between, __x, __a, __b, first(__option))
elseif first(__option) = 'closed then
if is(__x >= __a) = true and is(__x <= __b)=true then
1
elseif is(__x < __a)=true or is(__x > __b)=true then
0
elseif __a = 'minf and __b = 'inf then
1
elseif __a = 'minf and __b = 'minf then
0
elseif __a = 'inf and __b = 'inf then
0
else
simpfuncall('between, __x, __a, __b, first(__option))
elseif first(__option) = 'open then
if is(__x > __a) = true and is(__x < __b)=true then
1
elseif is(__x <= __a)=true or is(__x >= __b)=true then
0
elseif __a = 'minf and __b = 'inf then
1
elseif __a = 'minf and __b = 'minf then
0
elseif __a = 'inf and __b = 'inf then
0
else
simpfuncall('between, __x, __a, __b, first(__option))
elseif first(__option) = 'rclosed then
if is(__x > __a) = true and is(__x <= __b)=true then
1
elseif is(__x <= __a)=true or is(__x > __b)=true then
0
elseif __a = 'minf and __b = 'inf then
1
elseif __a = 'minf and __b = 'minf then
0
elseif __a = 'inf and __b = 'inf then
0
else
simpfuncall('between, __x, __a, __b, first(__option))
elseif first(__option) = 'lclosed then
if is(__x >= __a) = true and is(__x < __b)=true then
1
elseif is(__x < __a)=true or is(__x >= __b)=true then
0
elseif __a = 'minf and __b = 'inf then
1
elseif __a = 'minf and __b = 'minf then
0
elseif __a = 'inf and __b = 'inf then
0
else
simpfuncall('between, __x, __a, __b, first(__option))
else
simpfuncall('between, __x, __a, __b, first(__option))
)$
simplifying(between, simpbetween)$