[Aimmath-commit] AIM/WEB-INF/maple/aim Test.mpl,1.8,1.8.2.1
Brought to you by:
gustav_delius,
npstrick
From: Neil S. <nps...@us...> - 2004-10-07 11:21:12
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19514/WEB-INF/maple/aim Modified Files: Tag: aim-xml Test.mpl Log Message: Improved numerical testing Index: Test.mpl =================================================================== RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/Test.mpl,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** Test.mpl 10 Mar 2004 02:06:54 -0000 1.8 --- Test.mpl 7 Oct 2004 11:20:52 -0000 1.8.2.1 *************** *** 161,165 **** marginspec_::`aim/Test/MarginSpecification`) ! local ANS,RIGHTANS,err,lhs,rhs,n; RIGHTANS := traperror(evalf(rightans)); --- 161,165 ---- marginspec_::`aim/Test/MarginSpecification`) ! local ANS,RIGHTANS,magnitude,err,lhs,rhs,n; RIGHTANS := traperror(evalf(rightans)); *************** *** 167,180 **** ERROR(__("Second argument is not numeric")); fi; ! ! ANS := traperror(evalf(ans)); ! if not(type([ANS],[numeric])) then ! RETURN(false); fi; - err := abs(ANS - RIGHTANS); if nargs < 3 then ! # just use the default tolerance of 5% of the correct answer ! RETURN(evalb(err <= 0.05 * abs(RIGHTANS))); else # the third argument specifies the tolerance --- 167,178 ---- ERROR(__("Second argument is not numeric")); fi; ! if abs(RIGHTANS) < 1 then ! magnitude := 0; ! else ! magnitude := floor(log10(abs(RIGHTANS))); fi; if nargs < 3 then ! Digits := 10; else # the third argument specifies the tolerance *************** *** 183,213 **** rhs := op(2,marginspec_); if lhs = 'margin' then ! RETURN(evalb(err <= rhs)); ! elif lhs = 'tolerance' then ! RETURN(evalb(err <= abs(RIGHTANS) * rhs)); ! elif lhs = 'sf' then ! if not(type([rhs],[posint])) then ! ERROR(__("Invalid margin specification")); fi; ! n := 10^(rhs - 1 - floor(log10(abs(RIGHTANS)))); ! RETURN(evalb(trunc(n * ANS) = trunc(n * RIGHTANS))); ! elif lhs = 'dp' then ! if not(type([rhs],[integer])) then ! ERROR(__("Invalid margin specification")); fi; ! n := 10^(-rhs); ! RETURN(evalb(trunc(n * ANS) = trunc(n * RIGHTANS))); ! elif lhs = 'sfround' then if not(type([rhs],[posint])) then ERROR(__("Invalid margin specification")); fi; ! n := 10^(rhs - 1 - floor(log10(abs(RIGHTANS)))); ! RETURN(evalb(round(n * ANS) = round(n * RIGHTANS))); ! elif lhs = 'dpround' then if not(type([rhs],[integer])) then ERROR(__("Invalid margin specification")); fi; ! n := 10^(-rhs); ! RETURN(evalb(round(n * ANS) = round(n * RIGHTANS))); else ERROR(__("Invalid margin specification")); --- 181,203 ---- rhs := op(2,marginspec_); if lhs = 'margin' then ! if not(type([rhs],[positive])) then ! ERROR(__("Invalid margin specification - margin must be positive")); fi; ! Digits := max(10,magnitude - floor(evalf(log10(rhs))) + 3); ! elif lhs = 'tolerance' then ! if not(type([rhs],[positive])) then ! ERROR(__("Invalid margin specification - tolerance must be positive")); fi; ! Digits := max(10, -floor(evalf(log10(rhs))) + 3); ! elif lhs = 'sf' or lhs = 'sfround' then if not(type([rhs],[posint])) then ERROR(__("Invalid margin specification")); fi; ! Digits := max(10,rhs+3); ! elif lhs = 'dp' or lhs = 'dpround' then if not(type([rhs],[integer])) then ERROR(__("Invalid margin specification")); fi; ! Digits := max(10,magnitude - rhs + 3); else ERROR(__("Invalid margin specification")); *************** *** 217,220 **** --- 207,252 ---- fi; fi; + + # re-evaluate the right answer, possibly to higher precision + # than before (if Digits has been increased). + RIGHTANS := traperror(evalf(rightans)); + if not(type([RIGHTANS],[numeric])) then + ERROR(__("Second argument is not numeric")); + fi; + + ANS := traperror(evalf(ans)); + if not(type([ANS],[numeric])) then + RETURN(false); + fi; + + err := abs(ANS - RIGHTANS); + + if nargs < 3 then + # just use the default tolerance of 5% of the correct answer + RETURN(evalb(err <= 0.05 * abs(RIGHTANS))); + else + # the third argument specifies the tolerance + lhs := op(1,marginspec_); + rhs := op(2,marginspec_); + if lhs = 'margin' then + RETURN(evalb(err <= rhs)); + elif lhs = 'tolerance' then + RETURN(evalb(err <= abs(RIGHTANS) * rhs)); + elif lhs = 'sf' then + n := 10^(rhs - 1 - floor(log10(abs(RIGHTANS)))); + RETURN(evalb(trunc(n * ANS) = trunc(n * RIGHTANS))); + elif lhs = 'dp' then + n := 10^(-rhs); + RETURN(evalb(trunc(n * ANS) = trunc(n * RIGHTANS))); + elif lhs = 'sfround' then + n := 10^(rhs - 1 - floor(log10(abs(RIGHTANS)))); + RETURN(evalb(round(n * ANS) = round(n * RIGHTANS))); + elif lhs = 'dpround' then + n := 10^(-rhs); + RETURN(evalb(round(n * ANS) = round(n * RIGHTANS))); + else + ERROR(__("Invalid margin specification")); + fi; + fi; end ): |