Update of /cvsroot/stack/stack-dev/maxima In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv25820 Modified Files: stackmaxima.mac unittests_load.mac Added Files: assessment.mac rtest_assessment_simpboth.mac rtest_assessment_simpfalse.mac rtest_assessment_simptrue.mac Log Message: Assessment package Index: stackmaxima.mac =================================================================== RCS file: /cvsroot/stack/stack-dev/maxima/stackmaxima.mac,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** stackmaxima.mac 28 Nov 2010 17:34:18 -0000 1.86 --- stackmaxima.mac 1 Dec 2010 18:32:25 -0000 1.87 *************** *** 77,85 **** "|"([a]):=apply(abs,a); ! load("powers.lisp"); ! load("format/coeflist.lisp"); ! load("format/format.lisp"); load("implicit_plot.lisp"); ! load("grobner.lisp"); /* Does not quite work yet ..... */ --- 77,83 ---- "|"([a]):=apply(abs,a); ! load("implicit_plot.lisp"); ! /* Does not quite work yet ..... */ *************** *** 104,110 **** /* ********************************** */ load("stacktex.lisp"); /* Loads LaTeX adaptions and preferences */ load("mathml.lisp"); /* loads MathML */ - load("noun_arith.mac")$ make_complexJ(OPT_COMPLEXJ) := block( --- 102,109 ---- /* ********************************** */ + load("assessment.mac"); /* Currently part of the STACK distribution */ + load("stacktex.lisp"); /* Loads LaTeX adaptions and preferences */ load("mathml.lisp"); /* loads MathML */ make_complexJ(OPT_COMPLEXJ) := block( *************** *** 400,437 **** /* ********************************** */ - /* numberp() does not "work" when simp:false, since unary minus is an unevaluated function... */ - simp_numberp(ex) := block( - if numberp(ex) then return(true), - if atom(ex) then return(false), - if op(ex)="-" and numberp(first(args(ex))) then return(true), - false - )$ - - /* Do we have a real number?*/ - /* Code taken from Stack_Test */ - real_numberp(ex):= - block([keepfloat,trigexpand,logexpand], - trigexpand:true, /* see pg 80 */ - logexpand:super, - keepfloat:true, /* see pg 23 */ - ex:errcatch(ev(fullratsimp(ex),simp)), - if ex=[] then return(false), - ex:ev(float(ex[1]),simp), - if listofvars(ex)#[] then return(false), - if floatnump(ex) then return(true) else return(false) - )$ - - decimalplaces(x,n) := block([simp:true,fpprintprec],fpprintprec:n,float(round(10^n*float(x))/(10^n)))$ - - - /* Write numbers in significant figures */ - significantfigures(x,n) := block([fpprec:128,fpprintprec,simp:true,ex,ex2], - ex:floor(float(log(x)/log(10))), - ex2:round(float(x/10^(ex-n+1))), - ex2:float(ex2*10^(ex-n+1)), - if floor(ex2)=ratsimp(ex2) then ex2:ratsimp(ex2), - return(ex2) - ); - ATNumSigFigs(SA,SBL) := block([RawMark,FeedBack,AnswerNote,ret,ol,nsf,asf,c0,c1,c2,SAA,SBB], --- 399,402 ---- *************** *** 472,640 **** )$ - scientific_notation(x) := block([simp:true,fpprintprec,ex,ex2], - ex:floor(float(log(x)/log(10))), - ex2:float(x/10^ex), - return((ex2)*10^(ex)) - ); - - /* commonfac(l) returns the gcd of a list of numbers */ - commonfaclist(l) := block([i,a,ret], - if listp(l) then - ret:( a:l[1], - if length(l)>1 then - ev(for i:2 thru length(l) do (a:ev(gcd(a,l[i]),simp)),simp), - return(a)) - else ret:"fail", - return(ret) )$ - - /* Returns a list of factors of ex without multiplicities */ - factorlist(ex) := block([simp:false,ret:"",ex2], - ex:ev(factor(ex),simp), - if atom(ex) then return([ex]), - if op(ex)#"*" then - ret:[ex] - else - ret:args(ex), - /* now strip off powers */ - ret:maplist(lambda([ex2],if atom(ex2) then ex2 else if op(ex2)="^" then part(ex2,1) else ex2),ret), - return(ret) - )$ - - /* Is the fraction in its lowest terms? */ - lowesttermsp(ex) := block([simp:false,ex1,ex2,ex3], - if atom(ex) then return(true), - if op(ex)#STACK_DIV_OP then return(true), - if gcd(num(ex),denom(ex))=1 then return(true) else return(false) - )$ - - /* Create a list with all parts for which numberp(ex)=true */ - list_expression_numbers(ex) := block([ex2], - if atom(ex) then (if numberp(ex) then return([ex]) else return([])) - else ( - if op(ex)=STACK_DIV_OP and simp_numberp(num(ex)) and simp_numberp(denom(ex)) then return([ex]), - ex2:args(ex), - flatten(maplist(list_expression_numbers,ex2))) - )$ - - all_lowest_termsex(ex):= block([simp:false,ex2], - ex2:list_expression_numbers(ex), - all_listp(lowesttermsp,ex2) - )$ - - /* anyfloats(l) returns true if any of the list are floats */ - anyfloat(l) := block([ret:false], - if listp(l)=false then ret:"fail", - ev(l:map('floatnump,l),simp), - ev(for i:1 thru length(l) do (ret:ret or l[i]),simp), - return(ret) )$ - - /* Decides if any floats are in the expression. */ - anyfloatex(ex) := block([partswitch,ret,kloop], - ret:false, - ex:ev(ex,simp), - if floatnump(ex) then return(true), - if atom(ex) then return(false), - partswitch:true, - ev(for kloop:1 while part(ex,kloop)#end do - ret:ret or anyfloatex(part(ex,kloop)),simp), - return(ret) - )$ - - /* compare with*/ - /* coefl:map('first,rest(coeffs(SA,x))) */ - - /* ********************************** */ - /* General list functions */ - /* ********************************** */ - - /* all_listp(p,l) true if all elements of l satisfy p */ - all_listp(p,l):= if listp(l) then ret:apply("and",maplist(p,l)) else ret:"fail"$ - - /* any_listp(p,l) true if all elements of l satisfy p */ - any_listp(p,l):= if listp(l) then ret:apply("or",maplist(p,l)) else ret:"fail"$ - - /* Return a list containing only those elements for which the predicate p is true */ - filter(p,l):= block( - if listp(l)=false then return(false), - if l = [] then return([]), - if p(first(l)) then cons(first(l),filter(p,rest(l))) - else filter(p,rest(l)) - )$ - - /* This function applies the binary function f to two lists a and b returning a list - [ f(a[1],b[1]), f(a[2],b[2]), ... ] zip_with quietly gives up when one of the list runs out of elements. */ - zip_with(f,a,b) := block( - if not(listp(a)) then return(false), - if not(listp(b)) then return(false), - if emptyp(a) then return([]), - if emptyp(b) then return([]), - cons(f(first(a),first(b)),zip_with(f,rest(a),rest(b))) - )$ - - /* ********************************** */ - /* Parts of expressions */ - /* ********************************** */ - - /* op(ex) is unsafe on atoms: this is a fix. */ - /* This function always returns a string */ - stack_op(ex) := block( - if atom(ex) then return(""), - if op(ex)#"-" then - if stringp(op(ex)) then return(op(ex)) else return(string(op(ex))) - else - if atom(first(ex)) then - return("") - else - if stringp(op(first(ex))) then return(op((first(ex)))) else return(string(op(ex))) - )$ - - /* This function takes an expression ex and returns a list of coefficients of v */ - coeff_list(ex,v):= block([deg,kloop,cl], - cl:[], - ex:ev(expand(ex),simp), - deg:degree(ex,v), - ev(for kloop:0 thru deg do - cl:append(cl,[coeff(ex,v,kloop)]),simp), - cl - )$ - - /* This function takes an expression ex and returns a list of nonzero coefficients of v */ - coeff_list_nz(ex,v):= block([deg,kloop,cl], - cl:[], - ex:ev(expand(ex),simp), - deg:degree(ex,v), - ev(for kloop:0 thru deg do - if coeff(ex,v,kloop)#0 then cl:append(cl,[[kloop,coeff(ex,v,kloop)]]),simp), - cl - )$ - - - /* ********************************** */ - /* Type predicates */ - /* ********************************** */ - - /* Determines if we are using an equation */ - equationp(ex) := block( - if atom(ex) then return(false), - if "="= op(ex) then return(true), - return(false) - )$ - - /* Determines if we are using an inequality */ - inequalityp(ex) := block( - if atom(ex) then return(false), - if ">"= op(ex) or "<"= op(ex) or ">="= op(ex) or "<="= op(ex) then return(true), - return(false) - )$ - - expressionp(ex) := block( - if matrixp(ex) or listp(ex) or equationp(ex) or inequalityp(ex) or setp(ex) then - return (false), - return(true) - ); - /* ********************************** */ - /* Logarithms to the base 10 */ - /* ********************************** */ --- 437,441 ---- *************** *** 1067,1070 **** --- 868,1028 ---- return(subst(lv,ex)))$ + /**********************************************/ + /* */ + /* System Equivalence Test */ + /* */ + /* An addition to STACK using Grobner Bases */ + /* */ + /**********************************************/ + + + /* + + What these functions do: + + - Determine whether the student's and teacher's answers are systems of equations + - Convert the two systems of equations into two systems of expressions + - Determine whether both systems are systems of multivariate polynomials + - Compare the variables in student's and teacher's answers, if they're not the same tell the student + - Find their Buchberger polynomials of the two systems + - Use the Buchberger polynomials to compare the Grobner bases of the two systems + - If the Grobner bases are not equal, determine whether the student's is a subset of the teacher's + - If student's system has equations which should not be there, tell them which ones. + */ + + + + /* + Main function of the System Equivalence test + + Takes two inputs, checks whether they are + lists of polynomials and delegates everything + else to other functions. + + Process: + + - Is each answer a list? + - Is each list element not an atom? + - Is each list element an equation? + - Is each list element a polynomial? + */ + + /* Edited files: SysEquiv.php, AnsTestcontroller.php, lang/en/stack.php */ + + ATSysEquiv(SA,SB):=block([keepfloat,RawMark,FeedBack,AnswerNote,SAA,SAB,S1,S2,varlist,GA,GB,ret], + RawMark:0, FeedBack:"", AnswerNote:"", + keepfloat:true, /* See pg 23 */ + + /* Turn on simplification and error catch */ + SAA:errcatch(ev(SA,simp,fullratsimp,nouns)), + if (is(SAA=[STACKERROR]) or is(SAA=[])) then return(StackReturnOb("0","ATLowestTerms_STACKERROR_SAns","")), + SAB:errcatch(ev(SB,simp,fullratsimp,nouns)), + if (is(SAB=[STACKERROR]) or is(SAB=[])) then return(StackReturnOb("0","ATLowestTerms_STACKERROR_TAns","")), + + /* Are both answers lists? */ + if not listp(SA) then + return(StackReturnOb("0","ATSysEquiv_SA_not_list",StackAddFeedback("","ATSysEquiv_SA_not_list"))), + if not listp(SB) then + return(StackReturnOb("0","ATSysEquiv_SB_not_list",StackAddFeedback("","ATSysEquiv_SB_not_list"))), + + /* Are all list elements not atoms? */ + if ev(all_listp(atom,SA),simp) then + return(StackReturnOb("0","ATSysEquiv_SA_not_eq_list",StackAddFeedback("","ATSysEquiv_SA_not_eq_list"))), + if ev(all_listp(atom,SB),simp) then + return(StackReturnOb("0","ATSysEquiv_SB_not_eq_list",StackAddFeedback("","ATSysEquiv_SB_not_eq_list"))), + + /* Are all list elements equations? */ + if ev(not all_listp(equationp,SA),simp) then + return(StackReturnOb("0","ATSysEquiv_SA_not_eq_list",StackAddFeedback("","ATSysEquiv_SA_not_eq_list"))), + if ev(not all_listp(equationp,SB),simp) then + return(StackReturnOb("0","ATSysEquiv_SB_not_eq_list",StackAddFeedback("","ATSysEquiv_SB_not_eq_list"))), + + /* Turn our equations into expressions */ + S1: ev(maplist(stack_eqnprepare,stack_eval_assignments(exdowncase(SA))),simp), + S2: ev(maplist(stack_eqnprepare,stack_eval_assignments(exdowncase(SB))),simp), + kill(SB), + + /* Is each expression a polynomial? */ + if not all_listp(polynomialpsimp, S1) then + return(StackReturnOb("0","ATSysEquiv_SA_not_poly_eq_list",StackAddFeedback("","ATSysEquiv_SA_not_poly_eq_list"))), + if not all_listp(polynomialpsimp, S2) then + return(StackReturnOb("0","ATSysEquiv_SB_not_poly_eq_list",StackAddFeedback("","ATSysEquiv_SB_not_poly_eq_list"))), + + /* + At this point have two lists of polynomials. We now check whether the + student's and teacher's polynomials have the same variables. If they do, + we find their Grobner bases and determine whether the systems of + equations have the same solutions + */ + + varlist: listofvars(S2), + if not is(ev(setify(listofvars(S1)),simp)=ev(setify(varlist), simp)) then + return(ATSysEquivVars(S1,S2)), + + GA :ev(poly_buchberger(S1,varlist),simp), + GB :ev(poly_buchberger(S2,varlist),simp), + kill(S1,S2), + + /* Determine whether our two lists of polynomials have the same Grobner Bases */ + if poly_grobner_equal(GA, GB, varlist) then + return(StackReturnOb("1","","")), + + /* + We now know the student's answer is in the correct form but there is + something wrong with it. From here we use the grobner package to + determine which, if any, of their equations is correct. + */ + + return(ATSysEquivGrob(GA, GB, SA, varlist)) + + + )$ + + + /* Takes two lists of expressions and compares the variables in each */ + + ATSysEquivVars(S1,S2):=block([XA,XB], + XA: setify(listofvars(S1)), + XB: setify(listofvars(S2)), + if subsetp(XA,XB) then + return(StackReturnOb("0","ATSysEquiv_SA_missing_variables",StackAddFeedback("","ATSysEquiv_SA_missing_variables"))), + if subsetp(XB,XA) then + return(StackReturnOb("0","ATSysEquiv_SA_extra_variables",StackAddFeedback("","ATSysEquiv_SA_extra_variables"))), + return(StackReturnOb("0","ATSysEquiv_SA_wrong_variables",StackAddFeedback("","ATSysEquiv_SA_wrong_variables"))) + )$ + + /* + Grobner basis comparison + + This function takes two Grobner bases and a set of variables and determines + whether the student's system is underdetermined or overdetermined. It also + takes the student's original system so that if it is overdetermined it can + tell them which equations should not be there. + */ + + ATSysEquivGrob(GA,GB,SA,varlist):=block([retl,ret], + + /* Is the student's system underdetermined? */ + + if poly_grobner_subsetp(GA,GB,varlist) then + return(StackReturnOb("0","ATSysEquiv_SA_system_underdetermined",StackAddFeedback("","ATSysEquiv_SA_system_underdetermined"))), + + /* + Given that the student's system is neither underdetermined nor equal to + the teacher's, we need to find which equations do not belong in the system. + */ + + ret:[], + + for k:1 thru length(SA) do block([], + if ev(poly_grobner_member(stack_eqnprepare(stack_eval_assignments(exdowncase(SA[k]))), GB, varlist),simp) then + ret:append(ret,[SA[ev(k,simp)]]) + else + ret:append(ret,[texcolor("red", SA[ev(k,simp)])])), + + return(StackReturnOb("0","ATSysEquiv_SA_system_overdetermined",StackAddFeedback("","ATSysEquiv_SA_system_overdetermined", StackDISP(ret, "\$\$")))) + + )$ + /*****************************************************************/ *************** *** 1688,1692 **** subst_int_const(ex,v):=block([lv,li,ls], lv:listofvars(ex), ! li:sublist_indices(lv, lambda([ex],is(smismatch("integrationconstant",string(ex))>19)) ), if emptyp(li) then return(ex), /* If we have only one variable v, then use this */ --- 1646,1650 ---- subst_int_const(ex,v):=block([lv,li,ls], lv:listofvars(ex), ! li:sublist_indices(lv, lambda([ex],is(smismatch("integrationconstant",string(ex))>19) or is(smismatch("%c",string(ex))>2)) ), if emptyp(li) then return(ex), /* If we have only one variable v, then use this */ *************** *** 1697,1705 **** /* 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))$ --- 1655,1664 ---- /* This function strips off any trailing constant of integration from an expression, which is not a number */ ! strip_int_const(ex,v):=block([ex2,fargs], ex2:ex, ! if atom(ex) then return(ex), ! if op(ex)="+" then ! (fargs:filter(lambda([ex2],not(freeof(v,ex2)) or simp_numberp(ex2)),args(ex)), ! if length(fargs)=1 then ex2:fargs[1] else ex2:apply("+",fargs)), return(ex2))$ *************** *** 1853,1856 **** --- 1812,1820 ---- )$ + + /*********************/ + /* Matrix operations */ + /*********************/ + /* Description : forme echelonne par lignes d'une matrice rectangulaire --- NEW FILE: assessment.mac --- /****************************************************************/ /* An assessment package for Maxima */ /* */ /* Chris Sangwin, <ch...@sa...> */ /* V0.1 December 2010 */ /* */ /****************************************************************/ /* ********************************** */ /* Load contributed packages */ /* ********************************** */ load("powers.lisp"); load("format/coeflist.lisp"); load("format/format.lisp"); load("grobner.lisp"); /* ********************************** */ /* Load assessment files */ /* ********************************** */ load("noun_arith.mac")$ /* ********************************** */ /* General list and utility functions */ /* ********************************** */ /* all_listp(p,l) true if all elements of l satisfy p */ all_listp(p,l):= if listp(l) then ret:apply("and",maplist(p,l)) else ret:"fail"$ /* any_listp(p,l) true if all elements of l satisfy p */ any_listp(p,l):= if listp(l) then ret:apply("or",maplist(p,l)) else ret:"fail"$ /* Return a list containing only those elements for which the predicate p is true */ filter(p,l):= block( if listp(l)=false then return(false), if l = [] then return([]), if p(first(l)) then cons(first(l),filter(p,rest(l))) else filter(p,rest(l)) )$ /* This function applies the binary function f to two lists a and b returning a list [ f(a[1],b[1]), f(a[2],b[2]), ... ] zip_with quietly gives up when one of the list runs out of elements. */ zip_with(f,a,b) := block( if not(listp(a)) then return(false), if not(listp(b)) then return(false), if emptyp(a) then return([]), if emptyp(b) then return([]), cons(f(first(a),first(b)),zip_with(f,rest(a),rest(b))) )$ /* ********************************** */ /* Numerical operations */ /* ********************************** */ /* numberp() does not "work" when simp:false, since unary minus is an unevaluated function... */ simp_numberp(ex) := block( if numberp(ex) then return(true), if atom(ex) then return(false), if op(ex)="-" and numberp(first(args(ex))) then return(true), false )$ /* Do we have a real number?*/ /* Code taken from Stack_Test */ real_numberp(ex):= block([keepfloat,trigexpand,logexpand], trigexpand:true, /* see pg 80 */ logexpand:super, keepfloat:true, /* see pg 23 */ ex:errcatch(ev(fullratsimp(ex),simp)), if ex=[] then return(false), ex:ev(float(ex[1]),simp), if listofvars(ex)#[] then return(false), if floatnump(ex) then return(true) else return(false) )$ /* Write the number x in n decimal places */ decimalplaces(x,n) := block([simp:true,fpprintprec],fpprintprec:n,float(round(10^n*float(x))/(10^n)))$ /* Write numbers in significant figures */ significantfigures(x,n) := block([fpprec:128,fpprintprec,simp:true,ex,ex2], ex:floor(float(log(x)/log(10))), ex2:round(float(x/10^(ex-n+1))), ex2:float(ex2*10^(ex-n+1)), if floor(ex2)=ratsimp(ex2) then ex2:ratsimp(ex2), return(ex2) ); scientific_notation(x) := block([simp:true,fpprintprec,ex,ex2], ex:floor(float(log(x)/log(10))), ex2:float(x/10^ex), return((ex2)*10^(ex)) ); /* commonfac(l) returns the gcd of a list of numbers */ commonfaclist(l) := block([i,a,ret], if listp(l) then ret:( a:l[1], if length(l)>1 then ev(for i:2 thru length(l) do (a:ev(gcd(a,l[i]),simp)),simp), return(a)) else ret:"fail", return(ret) )$ /* Returns a list of factors of ex without multiplicities */ factorlist(ex) := block([simp:false,ret:"",ex2], ex:ev(factor(ex),simp), if atom(ex) then return([ex]), if op(ex)#"*" then ret:[ex] else ret:args(ex), /* now strip off powers */ ret:maplist(lambda([ex2],if atom(ex2) then ex2 else if op(ex2)="^" then part(ex2,1) else ex2),ret), return(ret) )$ /* Is the fraction in its lowest terms? */ lowesttermsp(ex) := block([simp:false,ex1,ex2,ex3], if atom(ex) then return(true), if op(ex)#STACK_DIV_OP then return(true), if gcd(num(ex),denom(ex))=1 then return(true) else return(false) )$ /* Create a list with all parts for which numberp(ex)=true */ list_expression_numbers(ex) := block([ex2], if atom(ex) then (if numberp(ex) then return([ex]) else return([])) else ( if op(ex)=STACK_DIV_OP and simp_numberp(num(ex)) and simp_numberp(denom(ex)) then return([ex]), ex2:args(ex), flatten(maplist(list_expression_numbers,ex2))) )$ all_lowest_termsex(ex):= block([simp:false,ex2], ex2:list_expression_numbers(ex), all_listp(lowesttermsp,ex2) )$ /* anyfloats(l) returns true if any of the list are floats */ anyfloat(l) := block([ret:false], if listp(l)=false then ret:"fail", ev(l:map('floatnump,l),simp), ev(for i:1 thru length(l) do (ret:ret or l[i]),simp), return(ret) )$ /* Decides if any floats are in the expression. */ anyfloatex(ex) := block([partswitch,ret,kloop], ret:false, ex:ev(ex,simp), if floatnump(ex) then return(true), if atom(ex) then return(false), partswitch:true, ev(for kloop:1 while part(ex,kloop)#end do ret:ret or anyfloatex(part(ex,kloop)),simp), return(ret) )$ /* compare with*/ /* coefl:map('first,rest(coeffs(SA,x))) */ /* ********************************** */ /* Parts of expressions */ /* ********************************** */ /* op(ex) is unsafe on atoms: this is a fix. */ /* This function always returns a string */ safe_op(ex) := block( if atom(ex) then return(""), if op(ex)#"-" then if stringp(op(ex)) then return(op(ex)) else return(string(op(ex))) else if atom(first(ex)) then return("") else if stringp(op(first(ex))) then return(op((first(ex)))) else return(string(op(ex))) )$ /* This function takes an expression ex and returns a list of coefficients of v */ coeff_list(ex,v):= block([deg,kloop,cl], cl:[], ex:ev(expand(ex),simp), deg:degree(ex,v), ev(for kloop:0 thru deg do cl:append(cl,[coeff(ex,v,kloop)]),simp), cl )$ /* This function takes an expression ex and returns a list of nonzero coefficients of v */ coeff_list_nz(ex,v):= block([deg,kloop,cl], cl:[], ex:ev(expand(ex),simp), deg:degree(ex,v), ev(for kloop:0 thru deg do if coeff(ex,v,kloop)#0 then cl:append(cl,[[kloop,coeff(ex,v,kloop)]]),simp), cl )$ /* ********************************** */ /* Type predicates */ /* ********************************** */ /* Determines if we are using an equation */ equationp(ex) := block( if atom(ex) then return(false), if "="= op(ex) then return(true), return(false) )$ /* Determines if we are using an inequality */ inequalityp(ex) := block( if atom(ex) then return(false), if ">"= op(ex) or "<"= op(ex) or ">="= op(ex) or "<="= op(ex) then return(true), return(false) )$ expressionp(ex) := block( if matrixp(ex) or listp(ex) or equationp(ex) or inequalityp(ex) or setp(ex) then return (false), return(true) ); /* Checks that an expression is a polynomial */ polynomialpsimp(e):= polynomialp(e, listofvars(e))$ Index: unittests_load.mac =================================================================== RCS file: /cvsroot/stack/stack-dev/maxima/unittests_load.mac,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** unittests_load.mac 11 Dec 2008 12:15:02 -0000 1.4 --- unittests_load.mac 1 Dec 2010 18:32:25 -0000 1.5 *************** *** 5,36 **** /* NOTE: we need to run tests with simp:false and simp:true */ - UT(ex,r):= if not(equal(ev(ex,nouns),r)) then ( - no_fails:ev(no_fails+1,simp), - all_pass:false, - print(sconcat(string(ex))," gave ",string(ev(ex,nouns))," not ",string(r)) - )$ - - /* Display the results */ - UTD(ex,r):= block( - if ev(ex,nouns)#r then ( - no_fails:ev(no_fails+1,simp), - all_pass:false, - outcome:" FAILED" - ) - else - outcome:" PASSED", - print(sconcat(string(ex))," gave ",string(ev(ex,nouns))," Expecting ",string(r),outcome) - )$ no_fails:0$ all_pass:true$ ! simp:true$ print("simp is ",simp); ! load("unittests.mac"); ! simp:false$ print("simp is ",simp); ! load("unittests.mac"); - if all_pass then - (print("All tests passed"),true) - else - (print("Number of tests which failed: "),print(string(no_fails)),false)$ --- 5,26 ---- /* NOTE: we need to run tests with simp:false and simp:true */ no_fails:0$ all_pass:true$ ! simp:true$ ! STT:batch("rtest_assessment_simptrue.mac", test); ! STB:batch("rtest_assessment_simpboth.mac", test); ! ! simp:false$ ! SFF:batch("rtest_assessment_simpfalse.mac", test); ! SFB:batch("rtest_assessment_simpboth.mac", test); ! ! print("************ simp is true"); ! print(STT); ! print(STB); ! ! print("************ simp is false."); ! print(SFF); ! print(SFB); --- NEW FILE: rtest_assessment_simpfalse.mac --- factorp(x); true$ factorp(2); true$ factorp(4); false$ factorp(2^2); true$ factorp(2^2*x^3); true$ factorp(x^2); true$ factorp(y^2*x^2); true$ factorp((y*x)^2); true$ factorp((x-1)*(1+x)); true$ factorp((x-1)^2); true$ factorp((1-x)^2); true$ factorp(2*(x-1)); true$ factorp(2*x-1); true$ factorp(x^2-1); false$ factorp(1+x^2); true$ factorp((x-1)*(1+x)); true$ factorp((x-%i)*(%i+x)); true$ factorp(4*(x-1/2)^2); false$ commonfaclist([12,15]); 3$ commonfaclist([12,15,60,9]); 3$ commonfaclist([x^2-1,x^3-1]); x-1$ commonfaclist([x = 6,8]); 1$ factorlist(15); [3,5]$ factorlist(x^3-1); [x-1,1+x+x^2]$ lowesttermsp(x); true$ lowesttermsp(0.5); true$ lowesttermsp(1/2); true$ lowesttermsp((-1)/2); true$ lowesttermsp(1/(-2)); true$ lowesttermsp((-3)/6); false$ lowesttermsp((-x)/x^2); false$ lowesttermsp(15/3); false$ lowesttermsp(3/15); false$ lowesttermsp((x-1)/(x^2-1)); false$ lowesttermsp(x/(x^2-1)); true$ lowesttermsp((2+x)/(x^2-1)); true$ all_lowest_termsex(x); true$ all_lowest_termsex(0.5); true$ all_lowest_termsex(1/2); true$ all_lowest_termsex(2/4); false$ all_lowest_termsex(15/3); false$ all_lowest_termsex(0.3*x^2+3/15); false$ all_lowest_termsex(x/(x^3+x)); true$ list_expression_numbers(0.3*x+1/2); [1/2,0.3]$ exdowncase(X-x); x-x$ StackDISP(-(x-1),""); "-\\left(x-1\\right)"$ --- NEW FILE: rtest_assessment_simpboth.mac --- decimalplaces(1.123456789,3); 1.123$ decimalplaces(1.123456789,8); 1.12345679$ decimalplaces(1.1292,2); 1.13$ decimalplaces(%pi,5); 3.14159$ decimalplaces(%pi,4); 3.1416$ significantfigures(11292,2); 11000$ significantfigures(11292,3); 11300$ significantfigures(1.1292,3); 1.13$ significantfigures(0.011292,3); 0.0113$ significantfigures(0.09999,3); 0.1$ scientific_notation(1.123); 1.123$ scientific_notation(1123); 1123.0$ all_listp(real_numberp,[1,exp(1)^(%i*%pi),sqrt(2)+1,sin(1)]); true$ any_listp(real_numberp,[%i,%i+1,3+x,sqrt(-3)+1]); false$ expandp((x-1)*(1+x)); false$ expandp(2*(x-1)); false$ expandp(2*x-1); true$ expandp(x-1); true$ expandp((p-1)*(1+p)); false$ expandp(2*(p-1)); false$ expandp(3*y+6*p); true$ stack_ineqprepare(x>1); x-1>0$ list_expression_numbers(x); []$ list_expression_numbers(%pi); []$ list_expression_numbers(1+x); [1]$ list_expression_numbers(1/2+x); [1/2]$ list_expression_numbers(4/2+x); [4/2]$ list_expression_numbers(1/sin(2*x)); [1,2]$ filter(floatnump,0.5); false$ filter(floatnump,[0.5]); [0.5]$ filter(floatnump,[1,0.5]); [0.5]$ anyfloatex(0.5); true$ anyfloatex(x); false$ anyfloatex(1+x); false$ anyfloatex(0.5*x); true$ anyfloatex(sin(x*0.2)); true$ irred_Q(0,x); [true,""]$ irred_Q(x,x); [true,""]$ irred_Q(1+x,x); [true,""]$ irred_Q(1-x,x); [true,""]$ irred_Q(2-3*x,x); [true,""]$ irred_Q(2*x-2,x); [false,"stack_trans('irred_Q_commonint'); "]$ irred_Q(t+t*x,x); [false,""]$ irred_Q(3*x^2,x); [true,""]$ irred_Q(4*x^2,x); [true,"stack_trans('irred_Q_optional_fac' , !quot!$4\\,x^2$!quot! ); "]$ irred_Q(x^2-4,x); [false,""]$ irred_Q(x^2-2,x); [true,""]$ irred_Q(n+n^2,n); [false,""]$ irred_Q(n*(1+n),n); [false,""]$ irred_Q(n^3-1,n); [false,""]$ irred_Q(0.5+x,x); [true,""]$ irred_Q(2-3*x+x^2,x); [false,""]$ irred_Q(9-3*x+3*x^5,x); [false,"stack_trans('irred_Q_commonint'); "]$ irred_Q(1+x^2+x^5,x); [true,""]$ continuousp(x^2,x,1); true$ continuousp(abs(x),x,1); true$ continuousp(abs(x),x,0); true$ continuousp(sgn(x),x,0); false$ continuousp(sin(1/x),x,0); false$ continuousp(x*sin(1/x),x,0); true$ diffp(x^2,x,1); true$ diffp(abs(x),x,1); true$ diffp(abs(x),x,0); false$ diffp(sgn(x),x,0); false$ diffp(sin(1/x),x,0); false$ diffp(x^2*sin(1/x),x,0); false$ diffp(x^3*sin(1/x),x,0); true$ listsoverlap([1,2],[2,3]); true$ listsoverlap([8,9],[2,3]); false$ listscontain([1,2],[2,3],1); false$ listscontain([8,9],[2,3],1); false$ listscontain([1,2],[1,3],1); true$ subst_int_const(x^4/4+c*x+x = %c9,k); x^4/4+c*x+x = k$ subst_int_const(x^4/4+c*x+x = %c9,v); x^4/4+c*x+x = v$ subst_int_const(x^2,k); x^2$ subst_int_const(c*x^4/4+c^2*x/2+c*x = %c9*c+%c10,[v]); c*x^4/4+c^2*x/2+c*x = %c9*c+v$ subst_int_const(c*x^4/4+c^2*x/2+c*x = %c9*c+%c10,[k1,k2]); c*x^4/4+c^2*x/2+c*x = k1+c*k2$ subst_int_const(c*x^4/4+c^2*x/2+c*x = %c9*c+%c10,[k1,k2,k3]); c*x^4/4+c^2*x/2+c*x = k1+c*k2$ subst_equiv(y+x^2,1+a^2); []$ subst_equiv(1-2*x+x^2,(X-1)^2); [x = X]$ subst_equiv(y+x^2,b+a^2); [x = a,y = b]$ subst_equiv(y+x^2,b+a^2); [x = a,y = b]$ subst_equiv(y/z+x^2,c/b+a^2); [x = a,y = c,z = b]$ subst_equiv(y/z+x^2,z/x+y^2); [x = y,y = z,z = x]$ subst_equiv(y+x^2,x^2+y^2); []$ subst_equiv(u^6+w^5+v^4+z^3+y^2+x,f+g^2+d^3+c^4+b^5+a^6); false$ subst_equiv(w+u+v+y+x^2,w+v+y+b+a^2); [u = b,x = a]$ exdowncase(1+X+X^2); 1+x+x^2$ exdowncase(%pi); %pi$ stack_assignmentp(x = 1); true$ stack_assignmentp(x = sqrt(2)); true$ stack_assignmentp(3 = 1); false$ stack_assignmentp(d = v*t); false$ stack_assignmentp(1 = x); false$ stack_op(1); ""$ stack_op(x); ""$ stack_op(%pi); ""$ stack_op(z+3); "+"$ stack_op(3*z); "*"$ stack_op(3^z); "^"$ stack_op(3/z); "/"$ stack_op(sin(3*z)); "sin"$ stack_op((-1)/(1+x^2)); "/"$ stack_op(1-x); "+"$ stack_op(x-1); "+"$ stack_op(-(x-1)); "+"$ stack_op(-1/(1+x^2)); "/"$ stack_op(-2*x); "*"$ StackDISP(a/b,""); "\\frac{a}{b}"$ StackDISP(-27,""); "-27"$ StackDISP(-sin(x^2),""); "-\\sin \\left( x^2 \\right)"$ StackDISP(asin(x),""); "\\sin^{-1} \\left( x \\right)"$ StackDISP(log(x),""); "\\ln \\left( x \\right)"$ strip_int_const(k+x,x); x$ strip_int_const(k+1+x,x); 1+x$ strip_int_const(k^2+(x-1)^2,x); (x-1)^2$ strip_int_const(c+(t-1)^4/4,t); (t-1)^4/4$ --- NEW FILE: rtest_assessment_simptrue.mac --- exdowncase(X-x); 0$ list_expression_numbers(0.3*x+1/2); [0.3,1/2]$ StackDISP(-(x-1),""); "1-x"$ |