Thanks. That was obviously the line I intended. If you're curious, I've
written a few interesting things. I even found a way to write quicksort and
merge sort in Maxima:
qsort (L,R) := block ([S,B],S: [],B: [],
if length(L)<=1 then return(L) else
for i:2 thru length(L) do(
if R(L[i],L[1]) then (S: endcons(L[i],S))
else (B: endcons(L[i],B))),
append(qsort(S,R),[L[1]],qsort(B,R)))$
qsort([montgomery,birmingham,juneau,anchorage,phoenix,little_rock,sacramento,
los_angeles,san_diego,san_francisco,denver,boulder,fort_collins,aspen,hartford,
bridgeport,groton,new_london,dover,tallahassee,gainesville,miami,tampa,
jacksonville,atlanta,honolulu,boise,topeka,frankfort,louisville,lexington,
kansas_city,albany,new_york,boston,providence,hope_valley,columbia,greenville,
charleston,spartanburg,nashville,memphis,chattanooga,knoxville,oak_ridge,austin,
dallas,fort_worth,amarillo,houston,san_antonio,el_paso,albuquerque,richmond,
portland,seattle,washington_d_c,carson_city,las_vegas,detroit,lansing,ann_arbor,
milwaukee,minneapolis,st_paul,chicago,indianapolis,springfield],orderlessp);
msort (L,R) := block([left: [],right: []],
if length(L)<=1 then return(L) else
for i:1 thru length(L) do(
if i<=length(L)/2 then (left: endcons(L[i],left))
else (right: endcons(L[i],right))),
left: msort(left,R), right: msort(right,R),
L: [],
unless(left=[] or right=[]) do(
if R(left[1],right[1]) then
(L: endcons(left[1],L), left: rest(left)) else
(L: endcons(right[1],L), right: rest(right))),
if right=[] then L: append(L,left)
else L: append(L,right), L)$
msort([montgomery,birmingham,juneau,anchorage,phoenix,little_rock,sacramento,
los_angeles,san_diego,san_francisco,denver,boulder,fort_collins,aspen,hartford,
bridgeport,groton,new_london,dover,tallahassee,gainesville,miami,tampa,
jacksonville,atlanta,honolulu,boise,topeka,frankfort,louisville,lexington,
kansas_city,albany,new_york,boston,providence,hope_valley,columbia,greenville,
charleston,spartanburg,nashville,memphis,chattanooga,knoxville,oak_ridge,austin,
dallas,fort_worth,amarillo,houston,san_antonio,el_paso,albuquerque,richmond,
portland,seattle,washington_d_c,carson_city,las_vegas,detroit,lansing,ann_arbor,
milwaukee,minneapolis,st_paul,chicago,indianapolis,springfield],orderlessp);
I read somewhere that Lisp (which Maxima runs on) "likes" merge sort, so
perhaps merge sort is close to Maxima's built-in sort algorithm. Is that
correct?
On Fri, Jun 25, 2010 at 14:56, Leo Butler <l.butler at ed.ac.uk> wrote:
>
>
> On Fri, 25 Jun 2010, Jeffrey Hankins wrote:
>
> < Thanks, Leo. This is what is happening in Maxima:
> <
> < drop (L,n) := if n=1 then delete(mini(L),L,1) else drop(drop(L,n-1),1);
> < drop(L,n):=if n=1 then delete(mini(L),L,1) else drop(drop(L,n-1),1)
> <
> < replace (L,x) := if x>mini(L) then cons(x,drop(L,1)) else L;
> < replace(L,x):=if x>mini(L) then cons(x,drop(L,1)) else L
> <
> < finalgrade (dq,midterm,final) := ([fg],
> < dq: drop(dq,2),
> < midterm: replace(midterm,final),
> < fg: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*final/10,
> < if fg>=89.5 then print("student got an A")
> < elseif fg>=84.5 then print("student got a B+")
> < elseif fg>=79.5 then print("student got a B")
> < elseif fg>=74.5 then print("student got a C+")
> < elseif fg>=69.5 then print("student got a C")
> < elseif fg>=66.5 then print("student got a D+")
> < elseif fg>=59.5 then print("student got a D")
> < else print("student got an F"), fg)$
> <
> < needgrade (dq,midterm,desired) := ([need,lower,cutoff],
> < dq: drop(dq,2),
> < lower: lmin(midterm),
> < cutoff: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*lower/10,
> < if desired>cutoff then block([],
> < drop(midterm,1),
>
> Change the line above to
> midterm : drop(midterm,1),
>
>
> < need: 2*(desired-3*sum(dq[i],i,1,13)/13-midterm[1]/5))
> < else need:
> 10/3*(desired-3*sum(dq[i],i,1,13)/13-(midterm[1]+midterm[2])/5),need)$
> <
> < needgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],8.45b1);
> < 8.881538461538462b1
> <
> < finalgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],8.88b1);
> < "student got a B+"
> < 8.909230769230769b1
>
> I get, with the one change above, and my earlier change to use 'block',
>
> needgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],84.5);
> finalgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],%);
>
> (%o7) 79.61538461538461
> (%i8) student got a B+
> (%o8) 84.5
>
> which is what you want, if I understood correctly.
>
> Leo
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>