// Numbas version: finer_feedback_settings
{"name": "Find a generator matrix for a code and decide if it is standard - ternary", "extensions": ["codewords", "permutations"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [{"variables": ["word_length", "field_size", "num_words", "nary"], "name": "Setup"}, {"variables": ["num_skips", "data_vectors", "independent_combos", "extra_combos", "skips", "rest", "g_standard_bit"], "name": "Random stuff"}, {"variables": ["initial_g", "shuffled_g", "combos", "codewords", "g", "is_standard", "encoded_data_vectors"], "name": "Generator matrix"}, {"variables": ["to_decode", "decoded_word"], "name": "Invert codeword"}], "variables": {"g_standard_bit": {"templateType": "anything", "group": "Random stuff", "definition": "matrix(map(\n let(pos,skip_pos(j,skips),\n map(switch(c If G is a standard matrix, this is $I_{num_words} + 0_{\\text{num_words} \\times \\text{word_length}}$. Otherwise, it's a matrix with 1s in the leading columns, random numbers in the skipped columns when they're to the right of a leading 1, and 0 everywhere else. columns which would be leading columns in a standard matrix but are instead skipped over The length of each codeword. The number of basis words to generate. Reduced row echelon form generator matrix. We'll create the codewords to show the student by taking combinations of the rows of the reduced echelon matrix. To make sure they're independent, combo $n$ has a non-zero value in column $n$, zeros to the right, and any value to the left. Number of columns to skip over in the echelon part. For a standard matrix, this is zero. Codewords shown to the student. They're linear combinations of the rows of shuffled_g. Add a couple of extra combinations which aren't already used, so the size of the set given to the student is bigger than the dimension of the generating matrix. Vectors which, when multiplied by the generator matrix, give the basis vectors. The codeword for which the student needs to find the corresponding data vector. The field the code is defined over. Random numbers to add on the columns to the right of all of the leading 1s in the generator matrix. The rows of the reduced generator matrix, shuffled. Generator matrix for the code generated by basis.
Yes
", "No
"], "extendBaseMarkingAlgorithm": true, "matrix": "if(is_standard,[1,0],[0,1])", "customMarkingAlgorithm": "", "prompt": "Is there a standard generator matrix for this code?
", "unitTests": [], "shuffleChoices": false, "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "displayColumns": 0, "showCorrectAnswer": true, "variableReplacements": [], "marks": 0}, {"customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "prompt": "Encode each of the following data vectors as codewords using the generator matrix you have just found.
\n$\\var{data_vectors[0]} \\mapsto $ [[0]]
\n$\\var{data_vectors[1]} \\mapsto $ [[1]]
\n$\\var{data_vectors[2]} \\mapsto $ [[2]]
", "unitTests": [], "showFeedbackIcon": true, "scripts": {}, "gaps": [{"answer": "{string(encoded_data_vectors[0])}", "displayAnswer": "{string(encoded_data_vectors[0])}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "type": "patternmatch", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{string(encoded_data_vectors[1])}", "displayAnswer": "{string(encoded_data_vectors[1])}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "type": "patternmatch", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{string(encoded_data_vectors[2])}", "displayAnswer": "{string(encoded_data_vectors[2])}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "type": "patternmatch", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}], "type": "gapfill", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 0, "sortAnswers": false}, {"answer": "{string(decoded_word)}", "displayAnswer": "{string(decoded_word)}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "prompt": "What data vector is encoded as $c = \\var{to_decode}$?
", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "type": "patternmatch", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}], "statement": "Let $C$ be the {nary} code generated by the following set of codewords.
\n\\[ \\var{join_words(codewords)} \\]
", "tags": [], "rulesets": {}, "extensions": ["codewords", "permutations"], "type": "question", "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "Given a set of codewords generating a code, give a generating matrix, encode three data vectors, and decode one codeword.
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "Write down the matrix whose rows are the given codewords:
\n\\[ \\var{codeword_matrix(codewords)} \\]
\nNow reduce this matrix to row echelon form. That means the first non-zero entry in each row is further right than in the row above it and that entry is a 1 and there are only zeros above and below that entry. Remove any rows made up of all zeros.
\nFrom the matrix above, we obtain:
\n\\[ \\mathrm{G} = \\var{codeword_matrix(g)} \\]
\nA generator matrix for a code is a standard generator matrix if it is of the form $(\\mathrm{I}_{k}|\\mathrm{A})$, that is, the $k \\times k$ identity matrix attached to an arbitrary matrix $\\mathrm{A}$.
\nIf a code has a standard generator matrix, the row reduced echelon form will be it.
\n$\\mathrm{G}$ is of the required form, so it is a standard generator matrix.$\\mathrm{G}$ is not of the required form, so it is not a standard generator matrix.
\nTo encode a data vector $\\mathbf{v}$, multiply it on the right by the generator matrix for the code.
\nSo we have:
\n\\begin{align}
\\simplify[rowvector]{{vector(data_vectors[0])}*{codeword_matrix(g)}} &= \\var[rowvector]{vector(encoded_data_vectors[0])} \\\\[0.5em]
\\simplify[rowvector]{{vector(data_vectors[1])}*{codeword_matrix(g)}} &= \\var[rowvector]{vector(encoded_data_vectors[1])} \\\\[0.5em]
\\simplify[rowvector]{{vector(data_vectors[2])}*{codeword_matrix(g)}} &= \\var[rowvector]{vector(encoded_data_vectors[2])} \\\\[0.5em]
\\end{align}
That is,
\n\\begin{align}
\\var{data_vectors[0]} &\\mapsto \\var{encoded_data_vectors[0]} \\\\[1em]
\\var{data_vectors[1]} &\\mapsto \\var{encoded_data_vectors[1]} \\\\[1em]
\\var{data_vectors[2]} &\\mapsto \\var{encoded_data_vectors[2]} \\\\[1em]
\\end{align}
We are looking for a data vector of length $\\var{len(g)}$ which is encoded as $c = \\var{to_decode}$.
\nNote that, since $\\mathrm{G}$ is in reduced echelon form, the leading non-zero entry in each row is $1$, so the elements of the data vector are the digits of $c$ corresponding to each of the columns of $G$ containing a leading non-zero entry. The leading $1$s in $\\mathrm{G}$ are in columns {join(leading_columns(g),', ')}. The corresponding digits of $c$ give the data vector $\\var{decoded_word}$.
\nWe can confirm that this vector is encoded as $c$:
\n\\[ \\simplify[rowvector]{ {vector(decoded_word)}*{codeword_matrix(g)} } = \\var[rowvector]{vector(to_decode)} \\]
", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}