Skip to content

Commit d7c3a4b

Browse files
authored
Merge pull request #1416 from maths/iss1403
Documentation, updated files, and example questions for the linear algebra libraries
2 parents 58fffdf + e1cb93a commit d7c3a4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4760
-595
lines changed

doc/en/Authoring/Inclusions.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Inclusions
22

3-
This is an expert level topic, please avoid this feature unless you feel that you understand the implications and consequences of it. Note that using this feature goes against the self-contained material principle present in [the future proof guidelines](../STACK_question_admin/Future_proof.md).
3+
STACK provides a mechanism for sharing code between questions. For example, you can include small libraries of Maxima functions, dedicated to specific topics, in the question variables.
44

5-
That being said, a common request on the wish-list has been to provide some means of sharing code between questions. The inclusion-feature is the first step towards such a feature, however, it is not perfect nor do we expect it to be the solution that will finally be selected. But we provide it now that the back-end has the tools to provide it, for those adventurous enough.
5+
There is a tension between (i) reusing libraries of functions between questions and (ii) the self-contained material principle present in [the future proof guidelines](../STACK_question_admin/Future_proof.md).
6+
7+
This is an expert level topic, please avoid this feature unless you feel that you understand the implications and consequences of it.
68

79
Technical note: Currently, inclusions within inclusions are not supported, due to loop detection and security validation reasons.
810

911
## Inclusions life-cycle
1012

11-
For all current types of inclusions the inclusion happens at the time of compilation,
12-
which means that the source will be fetched when the question gets compiled and will
13-
stay in the cached compilation product. Compilation happens during the first use of
14-
the question after it has been saved or the cache has been purged.
13+
For all current types of inclusions the inclusion happens at the time of question compilation,
14+
which means that the source will be fetched when the question gets compiled and will stay in the cached compilation product.
15+
Compilation happens during _the first use_ of the question after it has been saved or the cache has been purged.
1516

16-
The logic will not track changes to the source material, if one wants to fetch it
17-
again one must re-compile the question, either by purging the caches or by editing
17+
The inclusion logic will not track changes to the source material.
18+
If one wants to fetch it again one must re-compile the question, either by purging the caches or by editing
1819
the question.
1920

20-
Note that in the current solution during export we export only the source address
21-
and the exported material will only work if the address is accessible at the end
22-
that imports it.
21+
Note that in the current solution during export we export only the _source address_
22+
and the exported material will only work if the address is accessible at the end that imports it.
2323

2424

2525
## Inclusions within text
@@ -58,7 +58,8 @@ math-mode is not quite ready to understand all of these context switches.
5858
## Inclusions within CAS-logic
5959

6060
You can also include code into keyvals, i.e. question-variables or into feedback-variables.
61-
This type of an inclusion will again act just as if written directly by the question author at that place in the code. If one writes this type of an inclusion within an if-statement it will simply get written open within
61+
This type of an inclusion will act just as if written directly by the question author at that place in the code.
62+
If one writes this type of an inclusion within an if-statement it will simply get written open within
6263
an if-statement, the `if` will only decide if it executes, but it will still take that space and bandwidth.
6364

6465
The included material must follow all the rules of normal STACK keyvals.
@@ -70,7 +71,7 @@ The included material must follow all the rules of normal STACK keyvals.
7071

7172
Note that we do not do "tree-shaking" at this point to remove unnecessary code. If you include a massive library of functions that you do not use the question will still have to load those functions into the CAS and that may take some time. If you have libraries, used in many questions, please consider contributing these to the core of STACK.
7273

73-
To include external CAS code call the `stack_include()`-function with a string argument. The argument must be a raw string, containing the URL of the code. You cannot reference a variable containing such a string. For example,
74+
To include external CAS code call the `stack_include()` - function with a string argument. The argument must be a raw string, containing the URL of the code. You cannot reference a variable containing such a string. For example,
7475

7576
```
7677
a: rand(3)+2;
@@ -99,6 +100,7 @@ Notes.
99100
1. We will try to keep files in the contrib folder small, and stable.
100101
2. We intend to move commonly used contributed code into the core in due course. At that point we will localise language strings for automatic translation.
101102
3. Please contact the developers about naming conventions. For example, external validators should start the function name with `validator_`.
103+
4. If you wish to use the libraries locally, on your server, prepend the file name with `contribl://`, e.g. `stack_include_contrib("matchlib.mac");` will load the local file, not the file on github. This is mostly for local development, before code is pushed to the master branch. We advise against this for live questions.
102104

103105
### Sandbox testing
104106

doc/en/CAS/Matrix.md

+6-114
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Matrices and vectors in STACK
22

3-
This page documents the use of matrices in STACK. There is a topics page for setting [linear algebra](../Topics/Linear_algebra.md) STACK questions.
3+
This page documents the use of matrices in STACK. There is a topics page for setting [linear algebra](../Topics/Linear_algebra/index.md) STACK questions.
44

55
## Matrices ##
66

7-
Note that in Maxima, the operator `.` represents noncommutative multiplication and scalar product. The star `A*B` gives element-wise multiplication.
7+
The operator `.` represents noncommutative multiplication and scalar product. The star `A*B` gives element-wise multiplication.
88

9+
Maxima functions `addrow` and `addcol` appends rows/columns onto the matrix.
910

10-
The following functions are part of Maxima, but are very useful for us.
11+
Maxima functions perform row operations
1112

1213
rowswap(m,i,j)
1314
rowadd(m,i,j,k)
@@ -17,13 +18,10 @@ Where ` m[i]: m[i] + k * m[j]`.
1718
rowmul(m,i,k)
1819

1920
Where `m[i]: k * m[i]`.
20-
And a function to compute reduced row echelon form
2121

22-
rref(m)
23-
24-
(Note the Maxima functions `addrow` and `addcol` appends rows/columns onto the matrix.)
22+
STACK provides a function to compute reduced row echelon form
2523

26-
STACK has a library for creating [structured random matrices](Random.md).
24+
rref(m)
2725

2826
## Assigning individual elements ##
2927

@@ -82,41 +80,6 @@ Now it makes no sense to include the point wise multiplication of elements as a
8280

8381
There must be a more elegant way to do this!
8482

85-
## Matrices and answer tests
86-
87-
Some answer tests accept matrices as arguments. E.g. algebraic equivalence (`ATAlgEquiv`) will accept matrices, even of different sizes, and return feedback underlining which elements are different. This is a rather blunt tool, since it is all or nothing. And, it's often necessary to apply other answer tests to corresponding elements of matrices.
88-
89-
1. Every answer test in STACK has a corresponding function in Maxima. The Maxima function name of AlgEquiv is `ATAlgEquiv`, et.
90-
2. The Maxima code for every answer in STACK returns a list of four elements. The _second_ element is the result of the test. See the [documentation](../Authoring/Answer_Tests/index.md) for details of the other elements. For example `second(ATComAss(x+y,y+x))` is `true` because \(x+y=y+x\) up to commutativity etc (using `ATComAss`).
91-
3. Some answer tests take an optional agument, e.g. numerical accuracy. to use `zip_with_matrix` we need to create an un-named (lambda) function of two arguments. E.g. `lambda([ex1,ex2], ATNumAbsolute(ex1,ex2,0.01)` can be used to test corresponding matrix elements are within \(0.01\) of each other.
92-
93-
Once you have a matrix `M` of boolean values, you could count the number which are false.
94-
95-
n:length(sublist(flatten(args(M)),lambda([ex],not(ex))));
96-
97-
Or you could locate the false elements and give specific feedback.
98-
99-
#### Example 1. ####
100-
101-
Here we test two matrices with elements with `ATEqualComAss`. This returns a matrix `M` of boolean values.
102-
103-
````
104-
M1:matrix([x*(x+1),sqrt(x^2)],[2/3,1/2]);
105-
M2:matrix([x^2+x,abs(x)],[0.666,0.5]);
106-
M:matrixmap(second,zip_with_matrix(ATEqualComAss, M1, M2));
107-
````
108-
109-
#### Example 2. ####
110-
111-
Here we test two matrices with elements with `ATNumAbsolute`, and argument \(0.01\). This returns a matrix `M` of boolean values.
112-
113-
````
114-
M1:matrix([3.1415,10.0]);
115-
M2:matrix([%pi,%pi^2]);
116-
M:matrixmap(second,zip_with_matrix(lambda([ex1,ex2], ATNumAbsolute(ex1,ex2,0.01)), M1, M2));
117-
````
118-
119-
12083
## Display of matrices ## {#matrixparens}
12184

12285
You can set the type of parentheses used to surround matrices in a number of ways. Firstly, the admin user should set the site default in the qtype_stack options page.
@@ -151,74 +114,3 @@ To change to right aligned columns, switch `"c"` to `"r"`. This function takes
151114

152115
For this function to take effect in the whole question, including validation of students' input, place the redefinition before `%_stack_preamble_end;` in the question variables.
153116

154-
## Vectors ## {#vectors}
155-
156-
If you are trying to use the vector notation such as \(3i+4j\) you will probably want to redefine \(i\) to be an abstract symbol, not a complex number.
157-
More information on this is given under [Numbers](Numbers.md). In particular, use the question level option "Meaning and display of sqrt(-1)" value `symi` to stop interpreting `i` with `i^2=-1` and return it to being an abstract symbol.
158-
159-
Another way to do this is to create matrices as follows:
160-
161-
ordergreat(i,j,k);
162-
%_stack_preamble_end;
163-
p:matrix([-7],[2],[-3]);
164-
q:matrix([i],[j],[k]);
165-
166-
Now we can use the dot product to create the vector. The STACK function `texboldatoms` wraps all atomic variable names in the ephemeral function `stackvector`, which is typeset in bold.
167-
168-
v:texboldatoms(dotproduct(p,q));
169-
170-
If you turn the option "Multiplication sign" to none, this should display as
171-
\[-7\,{\bf{i}}+2\,{\bf{j}}-3\,{\bf{k}}\]
172-
Notice the use of the function `ordergreat`. `ordergreat` can only be used once at the beginning of the question.
173-
174-
If you use the special constant `%_stack_preamble_end;` then anything before this constant will be available everywhere in the question, including the inputs.
175-
176-
The vector `stackvector(a)` and the atom `a` are different, and are not considered algebraically equivalent. While students may type in `stackvector(a)` as an answer, they are likely to type in `a`. The teacher can either (1) add in `stackvector` ephemeral forms to the student's answer in the feedback variables using `texboldatoms` or (2) remove all `stackvector` forms from the teacher's answer by using the `destackvector(ex)` function on their answer. In the future we may have an option in the input to apply texboldatoms to student's expressions.
177-
178-
The display of the ephemeral form of `stackvector` is controlled by the function `stackvectortex`, e.g. you can display vectors differently using the following examples.
179-
180-
stackvectortex(ex):= block(sconcat("{\\bf \\vec{", tex1(first(args(ex))), "}}"));
181-
stackvectortex(ex):= block(sconcat("{\\bf \\underline{", tex1(first(args(ex))), "}}"));
182-
183-
which should go in the question variables.
184-
185-
Any `texput` commands in the question variables now become "context variables" and will be available to the inputs. So, if in the context of your question you would like a variable such as `x` to be considered as a vector and displayed as a vector you can add one of the following to the question variables.
186-
187-
texput(x, "\\mathbf{\\vec{x}}");
188-
texput(x, "\\mathbf{\\underline{x}}");
189-
190-
Whenever `x` is then displayed in any part of the question, including the student's input validation or feedback generated by the answer tests, we will have the updated tex for this atom. E.g.
191-
192-
texput(x, "\\mathbf{\\vec{x}}");
193-
texput(y, "\\mathbf{\\vec{y}}");
194-
195-
and a student types in `a*x+b*y` then the tex output will be \(a\cdot \mathbf{\vec{x}}+b\cdot \mathbf{\vec{y}}\).
196-
197-
### Vector cross product ###
198-
199-
The wedge product operator is denoted by the tilde `~`. This is the `itensor` package. This package is not normally loaded by STACK, and in any case the package takes lists and not matrices. For convenience, the following function has been added which requires `3*1` matrices.
200-
201-
crossproduct(a,b);
202-
203-
Another advantage of this function is the ability to return an un-simplified version with `simp:false`.
204-
205-
## Student input ##
206-
207-
Students do find typing in matrices very tedious. Some teachers have asked for a convenient notation such as
208-
209-
c(1,2,3)
210-
211-
for column vectors and
212-
213-
v(1,2,3,4)
214-
215-
For row vectors. This is not a core part of STACK currently, but in individual questions you can convert such notation easily into mainstream Maxima using code such as the following.
216-
217-
ta1:c(1,2,3);
218-
ta2:v(1,2,3);
219-
vec_convert(sa) := if op(sa)=c then transpose(matrix(args(sa))) elseif op(sa)=v then matrix(args(sa));
220-
vec_convert(ta1);
221-
vec_convert(ta2);
222-
223-
Once converted into Matrices, the student's answer will be evaluated by PRTs as matrices. Of course, this will not be reflected in the valuation. If there is sufficient demand for this contact the developers.
224-

doc/en/CAS/Maxima_background.md

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ By default, the list does not contain multiplicities. If the list should contain
9292
| `comp_square(ex,v)` | Returns a quadratic `ex` in the variable `v` in completed square form.
9393
| `degree(ex,v)` | Returns the degree of the expanded form of `ex` in the variable `v`. See also Maxima's `hipow` command.
9494
| `unary_minus_sort(ex)` | Tidies up the way unary minus is represented within expressions when `simp:false`. See also [simplification](Simplification.md).
95-
| `texboldatoms(ex)` | Displays all non-numeric atoms in bold. Useful for vector questions.
9695

9796
## Assignment ## {#assignment}
9897

doc/en/Developer/Development_track.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ We use the [github issue tracker](https://github.com/maths/moodle-qtype_stack/is
77

88
## Version 4.9.0
99

10-
Done.
1110
1. Introduce `ta` as the default teacher's answer in the question variables, and use this in the input and default prt. Allow addition of multiple nodes in a PRT with one click.
12-
2. Support `allowrmpty` for dropdown, radio and checkbox inputs.
13-
3. Include the `rand_matrix.mac` contributed library, a collection of matrix randomisation functions for use in linear algebra, with the local STACK source code. See the [random](../CAS/Random.md) documentation for details.
11+
2. Support `allowempty` for dropdown, radio and checkbox inputs.
12+
3. Add in the `space` option, i.e. `make_multsgn("space")` in the [options](../Authoring/Question_options.md).
1413
4. Convert input "syntax hint" to castext.
15-
5. Add in the `space` option, i.e. `make_multsgn("space")` in the [options](../Authoring/Question_options.md).
16-
14+
5. Include the `rand_matrix.mac` contributed library, a collection of matrix randomisation functions for use in linear algebra, with the local STACK source code. See the [random](../Topics/Linear_algebra/Random_Matrices.md) documentation for details.
15+
6. Add in a substantial library for dealing with [linear algebra problems](../Topics/Linear_algebra/index.md).
16+
7. Load Maxima's `eigen` library.
1717

1818
Issues with [github milestone 4.9.0](https://github.com/maths/moodle-qtype_stack/issues?q=is%3Aissue+milestone%3A4.9.0) include
1919

doc/en/Developer/Releasing.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ Unless you want to discuss something confidential with the developers, please do
3030
* Run `php cli/ast_test_generator.php` to confirm if auto-generated tests have not changed.
3131
* Run Maxima unit tests of contributed packages by re-defining `stacklocation` and running `s_test_case.mac` in the sandbox. E.g.
3232

33+
````
3334
stacklocation:"/var/www/html/m40/question/type/stack"$
3435
load("s_test_case.mac");
36+
````
3537

3638
* Run PHP [unit tests](Unit_tests.md).
3739
* Run code checker.

doc/en/Specialist_tools/Drag_and_drop/Grid.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You will use the `"<ID>"` string to write solutions and assess student inputs; t
3636
For our example, the _Question variables_ field looks as follows.
3737

3838
```
39-
stack_include("contribl://matchlib.mac");
39+
stack_include_contrib("matchlib.mac");
4040
4141
steps : [
4242
["f", "\\(y = x^2\\)"],
@@ -128,8 +128,9 @@ This item should appear in the index and not in the header.
128128
### Question variables
129129

130130
The question variables with an index is as follows.
131+
131132
```
132-
stack_include("contribl://matchlib.mac");
133+
stack_include_contrib("matchlib.mac");
133134
134135
steps : [
135136
["dfdx", "\\(y' = 2x\\)"],

doc/en/Specialist_tools/Drag_and_drop/Grouping.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ You will use the `"<ID>"` string to write solutions and assess student inputs; t
105105
This should be column grouped.
106106

107107
For our example, the _Question variables_ field looks as follows.
108+
108109
```
109-
stack_include("contribl://matchlib.mac");
110+
stack_include_contrib("matchlib.mac");
110111
111112
steps : [
112113
["sq", "\\(f(x) = x^2\\)"],

doc/en/Specialist_tools/Drag_and_drop/Parsons.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ It shows the proof that _\(\log_2(3)\) is irrational_.
5454
Define the following question variables:
5555

5656
````
57-
stack_include("contribl://prooflib.mac");
57+
stack_include_contrib("prooflib.mac");
5858
5959
proof_steps: [
6060
["assume", "Assume, for a contradiction, that \\(\\log_2(3)\\) is rational."],
@@ -143,7 +143,7 @@ The following Parson's question is an _if and only if_ proof, containing two blo
143143
### Question variables
144144

145145
````
146-
stack_include("contribl://prooflib.mac");
146+
stack_include_contrib("prooflib.mac");
147147
148148
ta: proof_iff(proof("assodd","defn_odd","alg_odd","def_M_odd","conc_odd"), proof("contrapos","assnotodd","even","alg_even","def_M_even","conc_even"));
149149

doc/en/Specialist_tools/Drag_and_drop/Question_block.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The question author should write all steps to be shown to the student as a list
1919
the steps. Note the `\` character needs to be protected within strings, so for example we have to type `\\(n=2m+1\\)` rather than just `\(n=2m+1\)`.
2020

2121
```
22-
stack_include("contribl://prooflib.mac");
22+
stack_include_contrib("prooflib.mac");
2323
2424
proof_steps: [
2525
["assume", "Assume that \\(n\\) is odd."],

0 commit comments

Comments
 (0)