// Numbas version: exam_results_page_options {"name": "Modular Arithmetic: prime multiplication table", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Modular Arithmetic: prime multiplication table", "tags": [], "metadata": {"description": "
Introduction to modular arithmetic using a multiplication table and lookup.
", "licence": "Creative Commons Attribution-ShareAlike 4.0 International"}, "statement": "Multiplication in modular arithmetic looks different to regular multiplication. Here is an example for multiplication in modulo $\\var{p}$.
\n{table(p)}
\nUse this multiplication table to answer following questions.
", "advice": "This question introduces the concept of multiplication in modular arithmetic. All the answers can be found by looking up the appropriate row and column in the given multiplication table.
\nAside: It is easy to find the inverse of $a$ when working in $\\mathbb Z_p$ for some prime number $p$. By Fermat's Little Theorem $a^p \\equiv a \\pmod{p}$, so if $a$ is not a multiple of $p$ then $a^{-1} \\equiv a^{p-2} \\pmod{p}$.
", "rulesets": {}, "extensions": [], "variables": {"a": {"name": "a", "group": "Ungrouped variables", "definition": "random(2..p except p)", "description": "", "templateType": "anything"}, "inversea": {"name": "inversea", "group": "Ungrouped variables", "definition": "mod(a^(p-2),p)", "description": "The inverse of a mod p.
", "templateType": "anything"}, "p": {"name": "p", "group": "Ungrouped variables", "definition": "random(5,7,11,13)", "description": "", "templateType": "anything"}, "x2": {"name": "x2", "group": "Ungrouped variables", "definition": "random(2..p except [x1,p])", "description": "", "templateType": "anything"}, "x3": {"name": "x3", "group": "Ungrouped variables", "definition": "random(2..p except [p,b,a])", "description": "", "templateType": "anything"}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random(2..p except [p,a])", "description": "", "templateType": "anything"}, "x1": {"name": "x1", "group": "Ungrouped variables", "definition": "random(2..p except [p,a])", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "1 = mod(a*inversea,p) and 1 < mod(a*x1,p) and 1 < mod(a*x2,p)", "maxRuns": 100}, "ungrouped_variables": ["p", "a", "x1", "b", "x3", "x2", "inversea"], "variable_groups": [], "functions": {"table": {"parameters": [["p", "number"]], "type": "html", "language": "javascript", "definition": "var table = \"$\\\\times$ | \";\nfor (var i = 0; i < p; i++) {\n table += \"\" + i + \" | \";\n}\ntable += \"
---|---|
\" + i + \" | \";\n for (var j = 0; j < p; j++) {\n table += \"\" + (i*j % p) + \" | \";\n }\n table += \"
The number $x$ such that $\\var{a} x \\equiv 1 \\pmod{\\var{p}}$ is called the inverse of $\\var{a}$ in $\\mathbb Z_{\\var{p}}$. Find the inverse of $\\var{a}$ in $\\mathbb Z_{\\var{p}}$.
", "minValue": "{inversea}", "maxValue": "{inversea}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {"mark": {"script": "// extract question variables\nvar variables = this.question.scope.variables;\nvar unwrap = Numbas.jme.unwrapValue;\nvar p = unwrap(variables.p);\nvar a = unwrap(variables.a);\nvar x1 = unwrap(variables.x1);\n\n// compute its derivative\nvar tree;\ntry {\n tree = Numbas.jme.compile(this.studentAnswer);\n var ans = unwrap(Numbas.jme.evaluate(tree,this.question.scope));\n \n if (0 == ((ans-x1) % p)) { \n this.setCredit(1,\"$\" + a + \" \\\\times \" + ans + \" = \" + (a*x1 %p) + \" \\\\pmod{\" + p +\"}$.\");\n if (ans >= p || ans < 0) {\n this.multCredit(0.5,\"But in modulo $\" +p+\"$ arithmetic you should present your answer as an integer between $0$ and $\" + (p-1)+ \"$. \");\n }\n } else { \n this.setCredit(0,\"You were asked to find $x$ where $\" + a + \" x = \" + (a*x1 %p) + \" \\\\pmod{\" + p +\"}$. But your answer gives $\" + a + \" \\\\times \" + ans + \" = \" + (a*ans %p) + \" \\\\pmod{\" + p +\"}$.\");\n }\n \n}\ncatch(e) {\n this.markingComment(e);\n}", "order": "instead"}, "validate": {"script": "return true;", "order": "instead"}}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "Solve $ \\var{a} x \\equiv \\var{mod(a*x1,p)} \\pmod{\\var{p}}$ for $x$.
", "minValue": "{x1}", "maxValue": "{x1}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {"mark": {"script": "// extract question variables\nvar variables = this.question.scope.variables;\nvar unwrap = Numbas.jme.unwrapValue;\nvar p = unwrap(variables.p);\nvar a = unwrap(variables.a);\nvar x = unwrap(variables.x2);\n\n// compute its derivative\nvar tree;\ntry {\n tree = Numbas.jme.compile(this.studentAnswer);\n var ans = unwrap(Numbas.jme.evaluate(tree,this.question.scope));\n \n if (0 == ((ans-x) % p)) { \n this.setCredit(1,\"$\" + a + \" \\\\times \" + ans + \" = \" + (a*x %p) + \" \\\\pmod{\" + p +\"}$.\");\n if (ans >= p || ans < 0) {\n this.multCredit(0.5,\"But in modulo $\" +p+\"$ arithmetic you should present your answer as an integer between $0$ and $\" + (p-1)+ \"$. \");\n }\n } else { \n this.setCredit(0,\"You were asked to find $x$ where $\" + a + \" x = \" + (a*x %p) + \" \\\\pmod{\" + p +\"}$. But your answer gives $\" + a + \" \\\\times \" + ans + \" = \" + (a*ans %p) + \" \\\\pmod{\" + p +\"}$.\");\n }\n \n}\ncatch(e) {\n this.markingComment(e);\n}", "order": "instead"}, "validate": {"script": "return true;", "order": "instead"}}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "Solve $ \\var{a} x \\equiv \\var{mod(a*x2,p)} \\pmod{\\var{p}}$ for $x$.
", "minValue": "{x2}", "maxValue": "{x2}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {"mark": {"script": "// extract question variables\nvar variables = this.question.scope.variables;\nvar unwrap = Numbas.jme.unwrapValue;\nvar p = unwrap(variables.p);\nvar a = unwrap(variables.a);\nvar b = unwrap(variables.b);\nvar x = unwrap(variables.x3);\n\n// compute its derivative\nvar tree;\ntry {\n tree = Numbas.jme.compile(this.studentAnswer);\n var ans = unwrap(Numbas.jme.evaluate(tree,this.question.scope));\n \n if (0 == ((ans-x) % p)) { \n this.setCredit(1,\"$\" + a + \" \\\\times \" + ans + \" + \" + b + \" = \" + (a*x %p) + \" \\\\pmod{\" + p +\"}$.\");\n if (ans >= p || ans < 0) {\n this.multCredit(0.5,\"But in modulo $\" +p+\"$ arithmetic you should present your answer as an integer between $0$ and $\" + (p-1)+ \"$. \");\n }\n } else { \n this.setCredit(0,\"You were asked to find $x$ where $\" + a + \" x + \" + b + \" = \" + ((a*x +b) %p) + \" \\\\pmod{\" + p +\"}$. But your answer gives $\" + a + \" \\\\times \" + ans + \" + \" + b + \" = \" + ((a*ans +b) %p) + \" \\\\pmod{\" + p +\"}$.\");\n }\n \n}\ncatch(e) {\n this.markingComment(e);\n}", "order": "instead"}, "validate": {"script": "return true;", "order": "instead"}}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "Solve $ \\var{a} x + \\var{b} \\equiv \\var{mod(a*x3 + b,p)} \\pmod{\\var{p}}$ for $x$.
", "minValue": "{x3}", "maxValue": "{x3}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "contributors": [{"name": "Daniel Mansfield", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/743/"}, {"name": "Sean Gardiner", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2443/"}]}]}], "contributors": [{"name": "Daniel Mansfield", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/743/"}, {"name": "Sean Gardiner", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2443/"}]}