From: Chris S. <san...@us...> - 2010-10-27 13:34:34
|
Update of /cvsroot/stack/stack-dev/maxima In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv10961/maxima Modified Files: unittests.mac stackmaxima.mac Log Message: Bug fix in Maxima 5.22.1 forced us to update our code. Index: stackmaxima.mac =================================================================== RCS file: /cvsroot/stack/stack-dev/maxima/stackmaxima.mac,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** stackmaxima.mac 13 Oct 2010 14:32:11 -0000 1.82 --- stackmaxima.mac 27 Oct 2010 13:34:24 -0000 1.83 *************** *** 393,401 **** /* ********************************** */ - if is(MAXIMA_VERSION_NUM <= 5.12) then block( - round(x) := ?round(x), - truncate(x) := ?truncate(x) - ); - /* numberp() does not "work" when simp:false, since unary minus is an unevaluated function... */ simp_numberp(ex) := block( --- 393,396 ---- *************** *** 420,437 **** )$ - - stack_matrix_size(m) := block( - mLength : length(m), - if(mLength > 0) then mWidth : length(m[1]) - else mWidth : 0, - - ret : [mLength, mWidth], - return(ret))$ - - if is(MAXIMA_VERSION_NUM <= 5.11) then block( - matrix_size(x) := stack_matrix_size(x) - ); /* MAXMA >= 5.12 includes matrix_size function. JPH 10-12-07 */ - - decimalplaces(x,n) := block([simp:true,fpprintprec],fpprintprec:n,float(round(10^n*float(x))/(10^n)))$ --- 415,418 ---- *************** *** 520,533 **** )$ - /* Old code 25/9/9 - ex1:part(ex,1), - ex2:part(ex,2), - ex1:ev(setify(factorlist(ex1)),simp), - ex2:ev(setify(factorlist(ex2)),simp), - ex3:intersect(ex1,ex2), - if ex3={} then return(true), - return(false) - */ - /* Create a list with all parts for which numberp(ex)=true */ list_expression_numbers(ex) := block([ex2], --- 501,504 ---- *************** *** 815,819 **** )$ ! /* Equationss */ stack_eqnprepare(ex):=block([ret], ret:fullratsimp(trigexpand(rhs(ex)-lhs(ex))), --- 786,790 ---- )$ ! /* Equations */ stack_eqnprepare(ex):=block([ret], ret:fullratsimp(trigexpand(rhs(ex)-lhs(ex))), *************** *** 1085,1143 **** - - /******************************************************************/ - - /* This takes an expression of the student and a list of expressions from the teacher. - The purpose of this test is to allow many comparisons with a single call to the CAS. - The results are returned in the AnswerNote as a list of lists, one list for each test - - 0 = false - 1 = true - -1 = test not applied (eg SameType=false, means no point in looking for algebraic equivalence) - - Three tests applied. - (1) SameType - (2) AlgEquiv - (3) Equal_com_ass - Validity, errors and feedback are not used in the main test. The "raw mark" is always 0. - */ - ATMultiEquiv(SA,SBl) :=block([ret,k,SAe,SB,SBe,SBlen,SBSameType,SBALgEquiv,SBEqualComAss,AnswerNote], - /* Error catch */ - if listp(SBl)=false then return(StackReturnOb("0","Teacher's answer not list","")), - SAe:errcatch(ev(SA,simp,fullratsimp,nouns)), - if is(SAe=[STACKERROR]) then return(StackReturnOb(0,"ATMultiEquiv_STACKERROR_SAns","")), - SBe:errcatch(ev(SBl,simp,fullratsimp,nouns)), - if is(SBe=[STACKERROR]) then return(StackReturnOb(0,"ATMultiEquiv_STACKERROR_TAns","")), - /* Set up return arrays */ - SBlen:length(SBl), - SBSameType:makelist(0,i,1,SBlen), - SBALgEquiv:makelist(0,i,1,SBlen), - SBEqualComAss:makelist(0,i,1,SBlen), - /* Loop over SBl */ - for k:1 thru SBlen step 1 do block( - k:ev(k,simp), - SB:SBl[k], - /* Are the expressions the same type? */ - ret:ATSameTypefun(SA,SB), - SBSameType[k]:ret[2], - if ret[2]=0 then - (SBALgEquiv[k]:-1,SBEqualComAss[k]:-1) - else block( - /* Check for Algebraic Equivalence */ - ret:block([simp:true,ret],ATAlgEquivfun(SA,SB)), - SBALgEquiv[k]:ret[2], - if ret[2]=0 then - (SBEqualComAss[k]:-1) - else block( - SBEqualComAss[k]:if equals_commute_associate(SA,SB) then 1 else 0 - ) - ) /* End of if AlgEquiv */ - ), /* End of loop over SBL */ - /* Send back results */ - AnswerNote:[SBSameType,SBALgEquiv,SBEqualComAss], - return(StackReturnOb("0",string(AnswerNote),"")) - )$ - - /*****************************************************************/ --- 1056,1059 ---- *************** *** 1486,1524 **** )$ - /*********************************************************/ - /* Test added by Chris Sangwin, 21/2/8. */ - /* Extends notion of "partial fractions" to equations */ - /* Needed for ECP's trials of the ODE code */ - /*********************************************************/ - - PartFracEq(SA,TA,var) := block([ret], - ret:ATAlgEquivfun(SA,SB), - if ret[2]=1 then block( - if equationp(TA) then - block ([ret1,ret2], - ret1:PartFracfun(lhs(SA),lhs(TA),var), - ret2:PartFracfun(rhs(SA),rhs(TA),var), - if ret1[2]=1 then - (if rhs(SA)=rhs(TA) then - true - else if ret2[2]=1 then - true - else - false - ) - else if ret2[2]=1 then - (if lhs(SA)=lhs(TA) then - true - else - false - ) - ) else - block ([ret:PartFracfun(SA,TA,var)], - ret[2] - ) - ) else - false - )$ - /* ************************ATSingFracTest****************************** */ /* requires: Student Answer */ --- 1402,1405 ---- *************** *** 1803,1806 **** --- 1684,1695 ---- )$ + /* This function strips off any trailing constant of integration from an expression, which is not a number */ + strip_int_const(ex,v):=block([ex2], + ex2:ex, + if not(atom(ex)) then + if op(ex)="+" then + ex2:apply("+",filter(lambda([ex2],not(freeof(v,ex2)) or simp_numberp(ex2)),args(ex))), + return(ex2))$ + /* An answer test for integration questions.*/ /* sa is the students' ansewer, sbl is a list consisting of (1) the answer, and (2) the variable */ *************** *** 1843,1850 **** val:true, rawmk:0, fb:"", ansnote:"", ret:[val,rawmk,ansnote,fb], ! SB:ev(SB,logexpand:super), /* This expands out logarithms for constants eg ln(k*|x|) */ ! if freeof(v,coeff(SB,v,0)) then SB:SB-coeff(SB,v,0), /* This strips off any trailing constant of integration from the teacher's answer */ ! SAa:ev(SA,logexpand:super)-coeff(ev(SA,logexpand:super),v,0), /* This strips off any trailing constant of integration */ ! /* check for constant of integration - code copied from Stack_Test */ ex:errcatch(ev(fullratsimp(SA-SB),simp,trigexpand:true,logexpand:super,keepfloat:true)), if ex=[] then return(false), --- 1732,1742 ---- val:true, rawmk:0, fb:"", ansnote:"", ret:[val,rawmk,ansnote,fb], ! /* This expands out logarithms for constants, e.g. ln(k*|x|) */ ! SB:ev(SB,logexpand:super), ! /* This strips off any trailing constant of integration from the teacher's answer */ ! SB:strip_int_const(SB,v), ! /* This strips off any trailing constant of integration from the student's answer */ ! SAa:strip_int_const(ev(SA,logexpand:super),v), ! /* Check for constant of integration - code copied from Stack_Test */ ex:errcatch(ev(fullratsimp(SA-SB),simp,trigexpand:true,logexpand:super,keepfloat:true)), if ex=[] then return(false), *************** *** 1976,2163 **** )$ - ATEquationfun(SA,SB,var,AT) := block([ret,ret0,ret1,ret2,lLHSv,lRHSv,mLHSv,mRHSv], - ret:ATEqnRet(SA,SB,var,"AE"), - ret0:ret, - - /* if is("I"=AT) then ( - lLHSv:append(listofvars(lhs(SA)),listofvars(lhs(SB))), - lRHSv:append(listofvars(rhs(SA)),listofvars(rhs(SB))), - mLHSv:member(var,lLHSv), - mRHSv:member(var,lRHSv) - ),*/ - - /* print("ATEqnRet for AE of SA with SB ",ret),*/ - if (is(ret[1]=true) and not(is("AE"=AT)))then block( - if (equationp(SB) and equationp(SA)) then block ([ret1,ret2], - ret1:ATEqnRet(lhs(SA),lhs(SB),var,AT), - /* print("ATEqnRet for AT LHSs of SA with SB ",ret1),*/ - ret2:ATEqnRet(rhs(SA),rhs(SB),var,AT), - /* print("ATEqnRet for AT RHSs of SA with SB ",ret2),*/ - if (ret1[3]=concat("ATE_unknowntest_",AT) or ret2[3]=concat("ATE_unknowntest_",AT)) then - ret:[false,0,ret1[3],""] - else ( - if (is(ret1[1]=false)) then /* Checks for validity of L and RHSs before continuing */ - if (is(ret2[1]=false)) then - ret:[false,0,concat(AT,"E_LF_RF"),""] - else - ret:[false,0,concat(AT,"E_LF_RV"),""] - else - if (is(ret2[1]=false)) then - ret:[false,0,concat(AT,"E_LV_RF"),""] - else block( - /* print("In [1]<>false else loop"),*/ - if (is(ret1[2]=1) and is(ret2[2]=1) and not(is(rhs(SA)=rhs(SB))) and not(is(lhs(SA)=lhs(SB)))) then - ret:[true,1,concat(AT,"E_L",AT,"_R",AT),""] /* e.g. PFE_LPF_RPF or IE_LI_RI */ - else - if (is(ret1[2]=0) and is(ret2[2]=0)) then block( - ret[2]:0, - ret[3]:concat(concat(AT,"E_N",AT)," ",ret1[3]," ",ret2[3]), /* the inner concat is probably unnecessary but is there for clarity, for now */ - ret[4]:concat(ret1[4],ret2[4]), - return(ret) - ) - else - if is(rhs(SA)=rhs(SB)) then block( - /* print("RHSs equal"),*/ - if is(lhs(SA)=lhs(SB)) then - if is(ret1[2]=1) then - if is(ret2[2]=1) then - ret[3]:concat(AT,"E_LU_RU") - else - (ret[3]:concat(concat(AT,"E_LU_RU")," ",ret2[3]),ret[2]:0) - else - if is(ret2[2]=1) then - (ret[3]:concat(concat(AT,"E_LU_RU")," ",ret1[3]),ret[2]:0) - else /* ret1[2]=0=ret2[2] */ - (ret[3]:concat(concat(AT,"E_LU_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else /* RHS equal, LHSs not equal */ - if is(ret1[2]=1) then - if is(ret2[2]=1) then - (ret[3]:concat(AT,"E_L",AT,"_RU"),ret[2]:1) - else - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret2[3]),ret[2]:0) - else - if is(ret2[2]=1) then - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RU")," ",ret1[3]," ",ret2[3]),ret[2]:0), - /* if is(ret1[2]=1) then - ret[3]:concat(AT,"E_L",AT,"_RU") - else - (ret[3]:concat(concat(AT,"E_LN",AT,"_RU")," ",ret1[3]),ret[2]:0), */ - return(ret) - ) /* RHSs not equal */ - else - if is(lhs(SA)=lhs(SB)) then block( - if is(ret1[2]=1) then - if is(ret2[2]=1) then - (ret[3]:concat(AT,"E_LU_R",AT),ret[2]:1) - else - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret2[3]),ret[2]:0) - else /* ret1[2]=0 */ - if is(ret2[2]=1) then - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_R",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_R",AT)," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_LU_R",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_LU_R",AT)," ",ret1[3]),ret[2]:0) - else - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_LU_RN",AT)," ",ret1[3]),ret[2]:0), - return(ret) - ) - else - if is(ret1[2]=1) then - if (is(AT="I")) then - if (is(ret1[3]="ATInt_const") and is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RN")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else if (is(ret1[3]="ATInt_const") or is(ret2[3]="ATInt_const")) then - (ret[3]:concat(concat(AT,"E_L",AT,"_RN")," ",ret1[3]," ",ret2[3]),ret[2]:1) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RN")," ",ret1[3]," ",ret2[3]),ret[2]:0) - else - (ret[3]:concat(concat(AT,"E_L",AT,"_RN")," ",ret2[3]),ret[2]:0) - else block( - ret[3]:concat(concat(AT,"E_LN_R",AT)," ",ret1[3]), - ret[2]:0, - return(ret) - ) - ) - ) - ) - else block( - ret:ATEqnRet(SA,SB,var,AT), - if is(ret[2]=0) then - ret[3]:concat(concat(AT,"E_not_eqns")," ",ret[3]) - else - ret[3]:concat(AT,"E_not_eqns") - ) - ) - else ( - if not(is("AE"=AT)) then - if equationp(SA) then - ret:[false,0,concat(AT,"E_SAE_SBN"),"ATAlgEquiv_SA_not_equation"] - else - if equationp(SB) then - ret:[false,0,concat(AT,"E_SBE_SAN"),"ATAlgEquiv_TA_not_equation"] - else - ret:[false,0,concat(AT,"E_NAE_other"),""] - ), - return(ret) - )$ - - ATEqnRet(cl,ll,opt,test) := block([rt], - if is(test="I") then - rt:Intfun(cl,ll,opt) - else if is(test="D") then - rt:Difffun(cl,ll,opt) - else if is(test="PF") then - if (atom(cl) or atom(ll)) then - rt:ATAlgEquivfun(cl,ll) - else - rt:PartFracfun(cl,ll,opt) - else if is(test="FF") then - rt:FacFormfun(cl,ll,opt) - else if is(test="AE") then - rt:ATAlgEquivfun(cl,ll) - else /* Something invalid passed */ - rt:[false,0,concat("ATE_unknowntest_",test),""], /* val,rawmk,ansnote,fb */ - return(rt) - )$ - /* Description : forme echelonne par lignes d'une matrice rectangulaire --- 1868,1871 ---- Index: unittests.mac =================================================================== RCS file: /cvsroot/stack/stack-dev/maxima/unittests.mac,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** unittests.mac 13 Oct 2010 16:57:50 -0000 1.16 --- unittests.mac 27 Oct 2010 13:34:24 -0000 1.17 *************** *** 195,196 **** --- 195,200 ---- UT('StackDISP(log(x),""),"\\ln \\left( x \\right)"); + UT('strip_int_const(x+k,x),x); + UT('strip_int_const(x+1+k,x),x+1); + UT('strip_int_const((x-1)^2+k^2,x),(x-1)^2); + UT('strip_int_const((t-1)^4/4+c,x),(t-1)^4/4); |