fb_vars - mkraska/meclib GitHub Wiki
Checks for missing and spurious vars by comparing the lists of variables in tans and sans. If they match, then compares the terms with the variables in vars. Provide an empty list if you don't want this check (or just use two arguments).
If tans is zero, then no feedback is given.
fb_vars(sans, tans, vars, label) Returns the text to be displayed for feedback.
fb_varsOK(sans, tans, vars, label) Returns the test result (true/false). Note that this also returns true if the test is not done because tans is zero.
-
sansstudent's answer (usually the same as in the PRT node) -
tansteacher's answer (usually the same as in the PRT node) -
vars(optional) list with vars, for which a check of coefficient is made. If not needed but you want a label, set it to[] -
label(optional) Text to preceed the feedback text. Only used if there is actual feedback text (you won't get just the label with nothing to follow).
Returns a castext() expression in case anything is to say, otherwise returns an empty string ""

Based on this Github issue.
See also this Moodle forum post.
stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value.mac");
The question text must contain a [[lang ]] block to activate localization in the feedback functions.
[[lang code="de"]] [[/lang]]
[[lang code="other"]] [[/lang]]
{@fb_vars(sans, tans, vars, label)@}
If you don't want a label:
{@fb_vars(sans, tans, vars)@}
If you don't want a label and don't want to check the coefficients:
{@fb_vars(sans, tans)@}
If you want to check the coefficients of all variables:
{@fb_vars(sans, tans, listofvars(tans))@}`
Feedback for vector components in a matrix answer test. Labels are provided to specify to which component the feedback applies.
{@fb_vars(S_RF[1,1], RF[1,1], [], "\\(x\\):")@}
{@fb_vars(S_RF[2,1], RF[2,1], [], "\\(y\\):")@}
{@fb_vars(S_RF[3,1], RF[3,1], [q,F_1], "\\(z\\):")@}
Issue: This does not work for special names like alpha, they aren't converted properly to TeX. Solved in 4.4.
fb_vars(%_sans,%_tans, [%_opt] ) := block([%_vars, %_label, %_tansvar,%_sansvar,%_extras, %_missing,simp, %_txt, %_L],
if length(%_opt)>0 then %_vars: %_opt[1] else %_vars: [],
if length(%_opt)>1 then %_label: %_opt[2] else %_label: "",
%_txt: %_label,
simp: true, /* Extract vars with simp:true does mean that "x/x+y" -> [y] */
%_sansvar: setify(listofvars(%_sans)),
%_tansvar: setify(listofvars(%_tans)),
/* Say nothing if tans is free of vars (e.g. because it is zero) */
if emptyp(%_tansvar) then return(""),
/* Check for spurious (extra) vars */
%_extras: setdifference(%_sansvar, %_tansvar),
if length(%_extras) > 0 then
%_txt: sconcat(%_txt," Unerwartete Variable: \\(", stack_disp_comma_separate(listify(%_extras)), "\\)." ),
/* Check for missing vars */
%_missing: setdifference(%_tansvar, %_sansvar),
if length(%_missing) > 0 then
%_txt: sconcat(%_txt," Fehlende Variable: \\(", stack_disp_comma_separate(listify(%_missing)), "\\) (<code>", stack_disp_comma_separate(listify(%_missing)), "</code>)." ),
/* if set of vars is ok, then check for the terms with vars from given list (%_vars). */
if %_txt # %_label then return(sconcat(%_txt, "<br>")),
%_L: sublist (%_vars, lambda ([x], diff(%_sans-%_tans, x)#0)),
if length(%_L)=0 then return( ""),
if length(%_L)=1 then return(sconcat(%_label," Prüfen Sie den Term mit \\(", %_L[1], "\\).<br>")),
return(sconcat(%_label," Prüfen Sie die Terme mit \\(",stack_disp_comma_separate(%_L ), "\\).<br>")),
"" );
{@fb_vars(sans, tans, vars, label)@}
If you don't want a label:
{@fb_vars(sans, tans, vars)@}
If you don't want a label and don't want to check the coefficients:
{@fb_vars(sans, tans)@}
If you want to check the coefficients of all variables:
{@fb_vars(sans, tans, listofvars(tans))@}`
Feedback for vector components in a matrix answer test. Labels are provided to specify to which component the feedback applies.
{@fb_vars(S_RF[1,1], RF[1,1], [], "\\(x\\):")@}<br>
{@fb_vars(S_RF[2,1], RF[2,1], [], "\\(y\\):")@}<br>
{@fb_vars(S_RF[3,1], RF[3,1], [q,F_1], "\\(z\\):")@}