How do you write this in lisp



Incidentally: There is a CL predicate betweenp. The functions min and
max use this predicate to remove items "in the middle." This can be
spendy, so it's not done by default (for a n element list, the
check is O(n^3)). Example: for real x either x/2 <= x <= 3x/2 or
3x/2 <= x <= x/2; thus

(%i2) :lisp(trace betweenp);
(BETWEENP)
(%i2) :lisp(setf *print-circle* nil);
NIL
(%i2) max(x/2, x, 3*x/2);
(%o2) max(x/2,x,(3*x)/2)
(%i3) put(trylevel,inf,maxmin)$
(%i4) max(x/2, x, 3*x/2);
  1> (BETWEENP ((MTIMES SIMP) ((RAT SIMP) 3 2) $X)
         ($X ((MTIMES SIMP) ((RAT SIMP) 1 2) $X))
         ($X ((MTIMES SIMP) ((RAT SIMP) 1 2) $X)))
  <1 (BETWEENP NIL)
  1> (BETWEENP $X
         (((MTIMES SIMP) ((RAT SIMP) 1 2) $X)
          ((MTIMES SIMP) ((RAT SIMP) 3 2) $X))
         (((MTIMES SIMP) ((RAT SIMP) 1 2) $X)
          ((MTIMES SIMP) ((RAT SIMP) 3 2) $X)))
  <1 (BETWEENP T)
  1> (BETWEENP ((MTIMES SIMP) ((RAT SIMP) 1 2) $X)
         (((MTIMES SIMP) ((RAT SIMP) 3 2) $X) $X)
         (((MTIMES SIMP) ((RAT SIMP) 3 2) $X) $X))
  <1 (BETWEENP NIL)
(%o4) max(x/2,(3*x)/2)

The CL function betweenp isn't a user-level function. Even 
trace(?betweenp)
doesn't work (the arguments to betweenp are CL lists).

--Barton

maxima-bounces at math.utexas.edu wrote on 04/09/2010 09:44:44 AM:

> [image removed] 
> 
> Re: [Maxima] How do you write this in lisp
> 
> Stavros Macrakis 
> 
> to:
> 
> Richard Hennessy
> 
> 04/09/2010 09:44 AM
> 
> Sent by:
> 
> maxima-bounces at math.utexas.edu
> 
> Cc:
> 
> Maxima List, Barton Willis
> 
> Ina fresh Maxima, 'between' has no properties (check :lisp (mapcar 
> 'symbol-plist '($between %between)) and integrate(x^2*between
> (x,a,b,'closed),x); causes no errors. So presumably the problem is 
> in your pw code.

> On Thu, Apr 8, 2010 at 23:45, Richard Hennessy 
<rich.hennessy at verizon.net
> > wrote:
>  
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima