1 eliminate(eqns,vars):=block([teqns,sv,se,l,flag,dispflag],
2 modedeclare([l,i],fixnum,flag,boolean),flag:dispflag:false,
3 if not (listp(eqns) and listp(vars)) then error("the arguments must both be lists"),
4 if length(vars)>l:length(eqns) then error("more variables then equations"),
5 if l=1 then error("can't eliminate from only one equation"),
6 if length(vars)=l then (vars:reverse(vars),sv:vars[1], vars:reverse(rest(vars)),flag:true),
7 /* ?meqhk turns [a=b] into [a-b] */
8 eqns:map('?meqhk,eqns),
11 for j:1 thru l while(freeof(v,first(eqns))) do(
12 teqns:cons(first(eqns),teqns), eqns:rest(eqns)),
13 if eqns=[] then eqns:teqns else (teqns:append(teqns,rest(eqns)), eqns:first(eqns), l:l-1, se:[],
14 for j:1 thru l do se:cons(resultant(eqns,teqns[j],v),se),
16 if flag then [rhs(apply('ev,[last(solve(eqns[1],sv)),eval]))] else eqns)$