// Numbas version: finer_feedback_settings {"name": "Solve a pair of congruences", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [], "variables": {"s1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(5..sd-1)", "description": "", "name": "s1"}, "r1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(5..sb-1)", "description": "", "name": "r1"}, "sb": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(10..20)", "description": "", "name": "sb"}, "csc": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd1(sc,sd)", "description": "", "name": "csc"}, "pans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "a1*sd*invd+a2*sb*invb", "description": "", "name": "pans"}, "sc": {"templateType": "anything", "group": "Ungrouped variables", "definition": "chcop(sd,sd,3,sd-1)", "description": "", "name": "sc"}, "a2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(s*ansp2,sd)", "description": "", "name": "a2"}, "a1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(r*ansp1,sb)", "description": "", "name": "a1"}, "sd": {"templateType": "anything", "group": "Ungrouped variables", "definition": "chcop(sb,sb,sb-5,sb+5)", "description": "", "name": "sd"}, "ans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(pans,sd*sb)", "description": "", "name": "ans"}, "invd": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd1(sd,sb)", "description": "", "name": "invd"}, "r": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(r1=sa,r1-1,r1)", "description": "", "name": "r"}, "temp": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sd*sb", "description": "", "name": "temp"}, "csd": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sc,sd)", "description": "", "name": "csd"}, "s": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(s1=sc,s1-1,s1)", "description": "", "name": "s"}, "csb": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sa,sb)", "description": "", "name": "csb"}, "csa": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd1(sa,sb)", "description": "", "name": "csa"}, "sa": {"templateType": "anything", "group": "Ungrouped variables", "definition": "chcop(sb,sb,5,sb-1)", "description": "", "name": "sa"}, "ansp2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(csc>0, mod(csc,sd),sd+mod(csc,sd))", "description": "", "name": "ansp2"}, "ansp1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(csa>0, mod(csa,sb),sb+mod(csa,sb))", "description": "", "name": "ansp1"}, "invb": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd1(sb,sd)", "description": "", "name": "invb"}}, "ungrouped_variables": ["pans", "ansp1", "sb", "r1", "temp", "csd", "s1", "csa", "csc", "csb", "a1", "s", "r", "ans", "sc", "ansp2", "sa", "invd", "invb", "a2", "sd"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Solve a pair of congruences", "functions": {"mdescext1gcd": {"type": "string", "language": "jme", "definition": "\n \n \n if(a
$\\var{a}$ | $\\var{b}$ | $\\simplify[std]{{c1}a+{c2}b}$ | $\\simplify[std]{{d1}a+{d2}b}$ |
Solve the equations:
\\[\\begin{eqnarray*}\n \n x\\;&\\equiv&\\;\\var{mod(a1,sb)}\\;\\mod\\;\\var{sb}\\\\\n \n \\\\\n \n x\\;&\\equiv&\\;\\var{mod(a2,sd)}\\;\\mod\\;\\var{sd}\n \n \\end{eqnarray*}\n \n \\]
$x=\\;\\;$ [[0]]
Your value of $x$ should satisfy $0 \\leq x \\lt \\var{sb*sd}$
\n \n ", "steps": [{"type": "information", "prompt": "\n \n \nIf we have two simultaneous congruences:
\\[\\begin{eqnarray*}\n \n x\\;&\\equiv&\\;a_1\\;&\\mod&\\;n_1\\\\\n \n \\\\\n \n x\\;&\\equiv&\\;a_2\\;&\\mod&\\;n_2\\\\\n \n \\end{eqnarray*}\n \n \\]
where $\\operatorname{gcd}(n_1,n_2)=1$.
Then there is a simple formula to find a solution $\\mod\\;n$ where $n=n_1n_2$
\n \n \n \nThis is given by:
\\[x=a_1 n_2 y_2+a_2 n_1 y_1 \\mod\\;n\\]
where $y_2 = n_2^{-1} \\mod\\;n_1$ and $y_1= n_1^{-1} \\mod\\;n_2$.
This works as we have:
\n \n \n \n$ x \\mod\\; n_1=a_1 \\times 1+0=a_1 \\mod\\;n_1$ as $n_2 y_2 = 1 \\mod \\;n_1,\\;\\;a_2 n_1 y_1=0\\mod\\;n_1$
\n \n \n \n$ x \\mod\\; n_2=0+a_2 \\times 1=a_2 \\mod\\;n_2$ as $n_1 y_1 = 1 \\mod \\;n_2,\\;\\;a_1 n_2 y_2=0\\mod\\;n_2$
\n \n ", "showCorrectAnswer": true, "scripts": {}, "marks": 0}], "showCorrectAnswer": true, "marks": 0}], "statement": "", "tags": ["checked2015", "congruences", "coprime", "euclidean algorithm", "MAS3214", "Modular arithmetic", "modular arithmetic", "simultaneous congruences", "solving a pair of congruences", "solving equations", "Solving equations"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "", "licence": "Creative Commons Attribution 4.0 International", "description": "Solving a pair of congruences of the form \\[\\begin{align}x &\\equiv b_1\\;\\textrm{mod} \\;n_1\\\\x &\\equiv b_2\\;\\textrm{mod}\\;n_2 \\end{align}\\] where $n_1,\\;n_2$ are coprime.
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "\n \n \nIn order to solve the following two congruences we use the formula from Steps:
\\[\\begin{eqnarray*}\n \n x\\;&\\equiv&\\;\\var{mod(a1,sb)}\\;\\mod\\;\\var{sb}\\\\\n \n \\\\\n \n x\\;&\\equiv&\\;\\var{mod(a2,sd)}\\;\\mod\\;\\var{sd}\n \n \\end{eqnarray*}\n \n \\]
Let $n=\\var{sb}\\times \\var{sd}=\\var{sb*sd}$
Since $\\var{sb}$ and $\\var{sd}$ are coprime we find by using the Extended Euclidean Algorithm that:
\n \n \n \n1) The inverse of $\\var{sb}\\;\\mod\\;\\var{sd}$ is $y_1=\\var{invb}$
\n \n \n \n2) The inverse of $\\var{sd}\\;\\mod\\;\\var{sb}$ is $y_2=\\var{invd}$
\n \n \n \n(You may get different values, but they should be the same as those above $\\mod\\;\\var{sd}$ and $\\mod\\;\\var{sb}$ respectively.)
\n \n \n \nSo $x=\\simplify[std]{{mod(a1,sb)}* {sd} * {invd}+{mod(a2,sd)}*{sb}*{invb}}=\\var{pans}=\\var{ans} \\;\\mod\\;\\var{sb*sd}$
\n \n ", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}