// Numbas version: exam_results_page_options {"name": "Information rate and minimum distance", "extensions": ["codewords", "permutations"], "custom_part_types": [], "resources": [], "navigation": {"preventleave": false, "allowregen": true, "showfrontpage": false}, "question_groups": [{"questions": [{"metadata": {"description": "

Compute the information rate and minimum distance of some binary codes.

", "licence": "Creative Commons Attribution 4.0 International"}, "ungrouped_variables": ["word_lengths", "num_words", "codes", "minimum_distances", "information_rates"], "variables": {"num_words": {"definition": "repeat(random(3..8),3)", "templateType": "anything", "description": "

Number of words in each code

", "name": "num_words", "group": "Ungrouped variables"}, "minimum_distances": {"definition": "map(minimum_distance(x),x,codes)", "templateType": "anything", "description": "

Minimum distance of each code

", "name": "minimum_distances", "group": "Ungrouped variables"}, "codes": {"definition": "map(\n code(shuffle(allwords(word_lengths[j],2))[0..num_words[j]]),\n j,\n 0..2\n)", "templateType": "anything", "description": "

Each code picks num_words random binary words of length word_lengths

", "name": "codes", "group": "Ungrouped variables"}, "information_rates": {"definition": "map(information_rate(code),code,codes)", "templateType": "anything", "description": "

Information rate of each code

", "name": "information_rates", "group": "Ungrouped variables"}, "word_lengths": {"definition": "repeat(random(3..6),3)", "templateType": "anything", "description": "

Lengths of the words in each code

", "name": "word_lengths", "group": "Ungrouped variables"}}, "advice": "

#### a)

\n

$C_1 = \\var{codes[0]}$ has $\\var{num_words[0]}$ words, each of length $\\var{word_lengths[0]}$.

\n

Its information rate is therefore $\\displaystyle\\frac{\\log_2 \\var{num_words[0]}}{\\var{word_lengths[0]}} = \\var{precround(information_rates[0],3)}$ to 3 decimal places.

\n

The minimum distance $d(C_1)$ of $C_1$ is the smallest Hamming distance between distinct codewords of $C_1$.

\n

Here's a table of the Hamming distances between the words in $C_1$.

\n

{distance_table(codes[0])}

\n

The minimum distance between distinct codewords of $C_1$ is $d(C_1) = \\var{minimum_distances[0]}$.

\n

#### b)

\n

$C_2 = \\var{codes[1]}$ has $\\var{num_words[1]}$ words, each of length $\\var{word_lengths[1]}$.

\n

Its information rate is therefore $\\displaystyle\\frac{\\log_2 \\var{num_words[1]}}{\\var{word_lengths[1]}} = \\var{precround(information_rates[1],3)}$ to 3 decimal places.

\n

The minimum distance $d(C_2)$ of $C_2$ is the smallest Hamming distance between distinct codewords of $C_2$.

\n

Here's a table of the Hamming distances between the words in $C_2$.

\n

{distance_table(codes[1])}

\n

The minimum distance between distinct codewords of $C_2$ is $d(C_2) = \\var{minimum_distances[1]}$.

\n

#### c)

\n

$C_3 = \\var{codes[2]}$ has $\\var{num_words[2]}$ words, each of length $\\var{word_lengths[2]}$.

\n

Its information rate is therefore $\\displaystyle\\frac{\\log_2 \\var{num_words[2]}}{\\var{word_lengths[2]}} = \\var{precround(information_rates[2],3)}$ to 3 decimal places.

\n

The minimum distance $d(C_3)$ of $C_3$ is the smallest Hamming distance between distinct codewords of $C_3$.

\n

Here's a table of the Hamming distances between the words in $C_3$.

\n

{distance_table(codes[2])}

\n

The minimum distance between distinct codewords of $C_3$ is $d(C_3) = \\var{minimum_distances[2]}$.

", "parts": [{"prompt": "

$C_1 = \\var{codes[0]}$

\n

Information rate: [[0]]

\n

Minimum distance: [[1]]

", "unitTests": [], "gaps": [{"precisionType": "dp", "variableReplacements": [], "mustBeReducedPC": 0, "showCorrectAnswer": true, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "precision": "3", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "marks": 1, "correctAnswerFraction": false, "strictPrecision": false, "precisionPartialCredit": "0", "showPrecisionHint": false, "scripts": {}, "precisionMessage": "You have not given your answer to the correct precision.", "minValue": "information_rates[0]", "variableReplacementStrategy": "originalfirst", "maxValue": "information_rates[0]"}, {"correctAnswerFraction": false, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "scripts": {}, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "variableReplacements": [], "marks": 1, "minValue": "minimum_distances[0]", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "maxValue": "minimum_distances[0]"}], "variableReplacements": [], "scripts": {}, "sortAnswers": false, "extendBaseMarkingAlgorithm": true, "customMarkingAlgorithm": "", "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "type": "gapfill", "marks": 0}, {"prompt": "

$C_2 = \\var{codes[1]}$

\n

Information rate: [[0]]

\n

Minimum distance: [[1]]

", "unitTests": [], "gaps": [{"precisionType": "dp", "variableReplacements": [], "mustBeReducedPC": 0, "showCorrectAnswer": true, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "precision": "3", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "marks": 1, "correctAnswerFraction": false, "strictPrecision": false, "precisionPartialCredit": "0", "showPrecisionHint": false, "scripts": {}, "precisionMessage": "You have not given your answer to the correct precision.", "minValue": "information_rates[1]", "variableReplacementStrategy": "originalfirst", "maxValue": "information_rates[1]"}, {"correctAnswerFraction": false, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "scripts": {}, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "variableReplacements": [], "marks": 1, "minValue": "minimum_distances[1]", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "maxValue": "minimum_distances[1]"}], "variableReplacements": [], "scripts": {}, "sortAnswers": false, "extendBaseMarkingAlgorithm": true, "customMarkingAlgorithm": "", "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "type": "gapfill", "marks": 0}, {"prompt": "

$C_3 = \\var{codes[2]}$

\n

Information rate: [[0]]

\n

Minimum distance: [[1]]

", "unitTests": [], "gaps": [{"precisionType": "dp", "variableReplacements": [], "mustBeReducedPC": 0, "showCorrectAnswer": true, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "precision": "3", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "marks": 1, "correctAnswerFraction": false, "strictPrecision": false, "precisionPartialCredit": "0", "showPrecisionHint": false, "scripts": {}, "precisionMessage": "You have not given your answer to the correct precision.", "minValue": "information_rates[2]", "variableReplacementStrategy": "originalfirst", "maxValue": "information_rates[2]"}, {"correctAnswerFraction": false, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "scripts": {}, "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "customMarkingAlgorithm": "", "variableReplacements": [], "marks": 1, "minValue": "minimum_distances[2]", "showFeedbackIcon": true, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "type": "numberentry", "maxValue": "minimum_distances[2]"}], "variableReplacements": [], "scripts": {}, "sortAnswers": false, "extendBaseMarkingAlgorithm": true, "customMarkingAlgorithm": "", "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "type": "gapfill", "marks": 0}], "preamble": {"css": ".distance-table td {\n text-align: center;\n}\n.distance-table th:first-child {\n border-right: 1px solid black;\n}\n.distance-table tr:first-child th {\n border-bottom: 1px solid black;\n}\n.distance-table td.empty {\n background: #eee;\n}", "js": ""}, "statement": "

Find the information rates and minimum distances of the following three codes.

\n

", "extensions": ["codewords", "permutations"], "functions": {"distance_table": {"definition": "// table of distances between each of the words in code\n\nvar hamming_distance = Numbas.extensions.codewords.hamming_distance;\n\nvar table = document.createElement('table');\ntable.setAttribute('class','distance-table');\nvar header = document.createElement('tr');\nheader.appendChild(document.createElement('td'));\ntable.appendChild(header);\nvar rows = [];\nfor(var i=0;ii){\n td.setAttribute('class','empty');\n } else {\n td.textContent = '$0$';\n }\n tr.appendChild(td);\n }\n}\nreturn table;", "language": "javascript", "type": "html", "parameters": [["code", "code"]]}}, "rulesets": {}, "variablesTest": {"condition": "max(minimum_distances)>1 // at least one code has minimum distance greater than 1\nand\nlen(distinct(information_rates))=len(information_rates) // all the codes have different information rates", "maxRuns": 100}, "tags": [], "name": "Information rate and minimum distance", "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/"}], "type": "question", "variable_groups": []}], "pickingStrategy": "all-ordered"}], "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/"}]}