[Aimmath-commit] AIM/WEB-INF/maple/aim SyntaxHints.mpl,1.5,1.6
Brought to you by:
gustav_delius,
npstrick
From: <nps...@us...> - 2003-10-10 09:48:34
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim In directory sc8-pr-cvs1:/tmp/cvs-serv16686/WEB-INF/maple/aim Modified Files: SyntaxHints.mpl Log Message: Numerous minor bug fixes and improvements. There is also a new function `aim/CheckAlgebraic`(ans,vars::list(string)). This can be used for more extensive syntax checking when the answer is supposed to be an algebraic function of some single-letter variables. At the moment you need to call this function explicitly in your marking procedure. Index: SyntaxHints.mpl =================================================================== RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/SyntaxHints.mpl,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SyntaxHints.mpl 19 Sep 2003 04:11:15 -0000 1.5 --- SyntaxHints.mpl 10 Oct 2003 09:48:30 -0000 1.6 *************** *** 293,297 **** "", proc(e::{string ,name}) ! local s,i,j,k,c,badminus,found,msg,note; badminus := NULL; --- 293,297 ---- "", proc(e::{string ,name}) ! local s,t,i,j,k,c,badminus,found,msg,note; badminus := NULL; *************** *** 302,305 **** --- 302,307 ---- while ( found ) do + # j is the index of a minus sign. + # we next find the previous non-blank character k := j-1; while( k > 0 and member(substring(s,k),{" ","\t","\r","\n"})) do *************** *** 344,348 **** if member(c,{"*","^","/","-"}) then ! badminus := j,badminus; fi; fi; --- 346,350 ---- if member(c,{"*","^","/","-"}) then ! badminus := badminus,j; fi; fi; *************** *** 360,375 **** if badminus = NULL then RETURN(["",""]); fi; for j in [badminus] do ! s := ! cat( ! `HTML/Escape`(substring(s,1..(j-1))), ! "<font color='red'>-</font>", ! `HTML/Escape`(substring(s,(j+1)..-1))); od; msg := cat( "<tt><font color='blue'>", ! s, "</font></tt>", "\n<br/>\n",__("#Explain minus"),"\n<br/>\n"); --- 362,380 ---- if badminus = NULL then RETURN(["",""]); fi; + t := ""; + i := 1; for j in [badminus] do ! t := ! cat(t, ! `HTML/Escape`(substring(s,i..(j-1))), ! "<font color='red'>-</font>"); ! i := j+1; od; + t := cat(t,`HTML/Escape`(substring(s,i..(-1)))); msg := cat( "<tt><font color='blue'>", ! t, "</font></tt>", "\n<br/>\n",__("#Explain minus"),"\n<br/>\n"); *************** *** 770,774 **** proc(s::string,e::anything) ! if not(hastype(e,list) and searchtext("[",s) > 0 and searchtext("]",s) > 0) then --- 775,779 ---- proc(s::string,e::anything) ! if not((hastype(e,list) or hastype(e,indexed)) and searchtext("[",s) > 0 and searchtext("]",s) > 0) then *************** *** 917,923 **** @sin(x) * (y+z)@ ", ! proc(e::anything) ! local fx,f,x,fstring0,fstring1,xstring,msg,red; msg := ""; --- 922,929 ---- @sin(x) * (y+z)@ ", ! proc(ee::uneval) ! local e,fx,f,x,fstring0,fstring1,xstring,msg,red; + e := eval(ee,2); msg := ""; *************** *** 952,959 **** fi; ! msg := ! msg, ! sprintf(__("#Explain funny functions (%s,%s,%s)"), ! red(fstring0),red(xstring),red(fstring1,"*(",xstring,")")); RETURN(cat(msg)); --- 958,973 ---- fi; ! if type([f],[numeric]) then ! msg := ! msg, ! sprintf(__("#Explain constant functions (%s,%s,%s,%A,%s)"), ! fstring0,xstring,red(fstring1,"*(",xstring,")"), ! fx,fstring0); ! else ! msg := ! msg, ! sprintf(__("#Explain funny functions (%s,%s,%s)"), ! red(fstring0),red(xstring),red(fstring1,"*(",xstring,")")); ! fi; RETURN(cat(msg)); *************** *** 1002,1005 **** --- 1016,1144 ---- RETURN(eval(t)); + end + ): + + ###################################################################### + + `Package/Assign`( + `aim/CheckAlgebraic`, + "The expression @ans@ is expected to be an algebraic function of the + variables in @vars@. (Here @vars@ is expected to be a set of + strings, each of length one.) If it is not, then this procedure will + look for things like @a(b+c)@ (should be @a*(b+c)@) or @ab@ (should + be @a*b@) or @a2@ (should be @a^2@) or @A@ (should be @a@). It will + return an HTML string reporting any such problems that it has + detected. + ", + proc(ans::anything,vars::set(string)) + local func, head, body, bbody, msg, nams, lcvars, n, lcn, ucn, goodn, badn, + isalpha, isdigit, chars, greenchars, i, m, lcm, ucm, goodm, badm; + + if map(length,vars) <> {1} then + error(__("Variable names in `aim/CheckAlgebraic` must have length one.")); + fi; + + nams := `aim/AllNames`(ans) minus + (vars union {op(`aim/SafeParse/OKNames`)}); + lcvars := map(`Util/ToLowerCase`,vars); + for n in nams do + lcn := `Util/ToLowerCase`(n); + ucn := `Util/ToUpperCase`(n); + if member(lcn,lcvars) then + goodn := `if`(member(lcn,vars),lcn,ucn); + badn := `if`(member(lcn,vars),ucn,lcn); + return( + sprintf( + __("Your answer involves the variable <tt><font color='red'>%s</font></tt>, which is not relevant for this question. Perhaps you mean <tt><font color='green'>%s</font></tt> instead. (Remember that Maple is case-sensitive.)"), + badn,goodn)); + fi; + + isalpha := proc(c) + local cc; + cc := op(1,convert(c,bytes)); + evalb((cc >=65 and cc <= 90) or + (cc >=97 and cc <= 122)) + end; + + isdigit := proc(c) + local cc; + cc := op(1,convert(c,bytes)); + evalb(cc >=48 and cc <= 57); + end; + + if length(n) > 1 then + chars := map(c -> convert([c],bytes),convert(n,bytes)); + if isalpha(chars[1]) and isalpha(chars[2]) then + i := 2; + while i < nops(chars) and isalpha(chars[i+1]) do + i := i+1; + od; + chars := chars[1..i]; + greenchars := + map( s-> cat("<tt><font color='green'>",s,"</font></tt>"), + chars); + msg := + sprintf( + __("Your answer involves the variable <tt><font color='red'>%s</font></tt>, which is not relevant in this problem. Perhaps you mean the product of %s and %s instead, in which case you should enter %s. "), + cat(op(chars)), + `Util/CommaJoin`(op(greenchars[1..-2])), + greenchars[-1], + `Util/JoinString`("<font color='red'>*</font>",op(chars))); + for m in chars do + lcm := `Util/ToLowerCase`(m); + ucm := `Util/ToUpperCase`(m); + if not(member(m,vars) and member(lcm,lcvars)) then + goodm := `if`(member(lcm,vars),lcm,ucm); + badm := `if`(member(lcm,vars),ucm,lcm); + msg := cat(msg, + sprintf( + __("If so, you should note that this involves the variable <tt><font color='red'>%s</font></tt>, which is not relevant for this question. Perhaps you mean <tt><font color='green'>%s</font></tt> instead. (Remember that Maple is case-sensitive.)"), + badm,goodm)); + return(msg); + fi; + od; + return(msg); + elif isalpha(chars[1]) and isdigit(chars[2]) then + i := 2; + while i < nops(chars) and isdigit(chars[i+1]) do + i := i+1; + od; + chars := chars[1..i]; + msg := + sprintf( + __("Your answer involves the variable <tt><font color='red'>%s</font></tt>, which is not relevant in this problem. Perhaps you mean <font color='blue'>%s<sup>%s</sup></font> instead, in which case you should enter <tt><font color='green'>%s</font></tt> "), + cat(op(chars)), + chars[1], + cat(op(chars[2..-1])), + cat(chars[1],"^",op(chars[2..-1]))); + return(msg); + fi; + fi; + return( + sprintf( + __("Your answer involves the variable <tt><font color='red'>%s</font></tt>, which is not relevant in this problem; so there is some confusion somewhere. "),n)) + + od; + + func := indets(ans,function); + + if func <> {} then + func := op(1,func); + head := op(0,func); + if type([head],[symbol]) then + body := sprintf("%Q",op(func)); + bbody := cat("(",body,")"); + if nops(func) > 1 then body := bbody; fi; + head := convert(head,string); + if not(member(head,{op(`aim/SafeParse/OKNames`)})) then + msg := + sprintf( + __("Your answer contains the expression <font color='red'>%A</font>. To Maple, this means the function <font color='blue'>%s</font> applied to the argument(s) <font color='blue'>%s</font>, just as <font color='blue'>f(x+y)</font> refers to the function <font color='blue'>f</font> applied to <font color='blue'>x+y</font>. This is probably not what you mean here. Perhaps you mean <font color='blue'>%s</font> times <font color='blue'>%s</font>, in which case you should enter <tt><font color='green'>%s*%s</font></tt> instead."),func,head,body,head,body,head,bbody); + return(msg); + fi; + fi; + fi; + + return(""); end ): |