Matrix inputs: preserve c(...) and r(...) model-answer types - #1847
Conversation
|
Thanks @adamant-pwn that's a very helpful suggestion, and not one I'd thought of myself.
I always thought of @LukeLongworth do you have any thoughts or comments, I know you've made a lot of contributions to the linear algebra libraries in STACK. @adamant-pwn thank you so much for adding in test cases, that's super helpful and very welcome indeed. I think you'll also need the same for the matrix of variable size? https://github.com/maths/moodle-qtype_stack/blob/master/stack/input/varmatrix/varmatrix.class.php |
| - `syntaxHintType`: If the Syntax hint should be displayed as a placeholder, or as initial value. Supported for the types `algebraic, numerical, string, units` | ||
| - `options`: Key-Value Object containing the options for choice like input types. Supportet for the types `checkbox, dropdown, radio` | ||
| - `matrixbrackets`: The desired matrix bracket style. One of `matrixroundbrackets`, `matrixsquarebrackets`, `matrixbarbrackets`, `matrixnobrackets`. Supported for the types `matrix` and `varmatrix` | ||
| - `casValueType`: The Maxima constructor returned by a fixed matrix grid: `matrix`, `c`, or `r`. Supported for the `matrix` type. |
There was a problem hiding this comment.
@EJMFarrow could you review the proposed modifications to the API please?
59ab850 to
3372043
Compare
|
Thanks! I've added the same handling for the variable-size matrix input and rebased onto I also included the small parenthesis fix discussed in #1848: |
|
API changes are minimal and look good, @sangwinc . Thanks, @adamant-pwn ! (Almost everyone will be using the pre-rendered inputs but great to have the info there for anyone who needs it.) CSS changes have also been added to the mobile CSS - lovely. |
e1036a6 to
31d9cf0
Compare
|
Hi! Thanks for this input, I think it's great. I'll be very transparent and say that this was always a rather hacked-together solution. My programming experience is limited and this worked for my particular use-case so I didn't look further! Integrating these functions more naturally into the broader STACK ecosystem sounds great. |
|
Thanks @LukeLongworth if you have any capacity to test/comment on these developments then I'd very much appreciate your continued input. |
The iss1848 integration branch now includes PR maths#1847, which overlaps the matrix and variable-matrix renderers, API documentation, and tests changed here. Resolve those overlaps by retaining c()/r() CAS value-type support together with the curly-bracket renderer and its API value. This keeps PR maths#1849 conflict-free without rewriting its published history.
Summary
STACK's fixed and variable-size matrix inputs currently reconstruct every response as
matrix(...). A column vector, a row vector, and a one-column or one-row matrix therefore lose the distinction already represented by STACK'sc(...),r(...), andmatrix(...)forms.This extends the
c(...)/r(...)input convention discussed in #109 to both structured matrix inputs.This patch makes the instantiated model answer the single source of truth:
matrix(...)model answer keeps the existing input and response unchanged;c(...)orr(...)model answer makes either input reconstruct the same vector form;data-stack-input-value-type="c"or"r", while the API reportscasValueType: matrix|c|rfor both input types.This deliberately does not infer semantics from dimensions:
matrix([1],[2])remains a matrix, whilec(1,2)remains a column vector.Authoring example
Choose either matrix input and use
vas its model answer. The fixed grid creates one box per component; the variable-size input keeps its existing free-size textarea. Both returnc(...). Usevec_convert(ans1)in a PRT when an answer test or calculation requires a matrix.The same pattern works for a row vector whose model answer is
r(...).Why retain the structured inputs?
An algebraic input already accepts
c(1,-2,1), but it requires students to type the function name, commas and balanced parentheses in one field. The fixed grid exposes the expected dimension and gives each component its own box; the variable-size input keeps the lighter whitespace notation without fixing the dimension. This patch preserves both interactions without discarding the CAS type.Compatibility
Existing
matrix(...)model answers render and validate as before. The patch adds no question setting, language string or migration step. Questions opt into the behavior by using STACK's existingc(...)orr(...)value as the model answer.The HTML inputs continue to use the existing question-level
matrixparensoption.stack_linear_algebra_declare(true)now sendsc(...)andr(...)throughstack_matrix_disp(...), so their TeX output respects the same option instead of hardcodingbmatrix. #1848 remains open for the separate question of independent matrix and vector settings.Verification
php -lpasses for both changed PHP classes and their focused test files in the current STACK API image.c(...)andr(...), preserved them in validation and API metadata, and formatted column- and row-vector sample solutions vertically and horizontally respectively.[,(,{,|and no delimiters. An integrated API test confirmed that fixed and variable-size C/R inputs use the same round HTML and TeX delimiters whenmatrixparensis(.c/rlisted inforbidWords: the generated top-level constructor is allowed, while the original rules still apply to each student-entered cell.