// 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 \\var{sa}x\\;&\\equiv&\\;\\var{r}\\;\\mod\\;\\var{sb}\\\\\n \n \\\\\n \n \\var{sc}x\\;&\\equiv&\\;\\var{s}\\;\\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": "If we have two simultaneous congruences:
\\[\\begin{eqnarray*} c_1x\\;&\\equiv&\\;b_1\\;&\\mod&\\;n_1\\\\ \\\\ c_2x\\;&\\equiv&\\;b_2\\;&\\mod&\\;n_2\\\\ \\end{eqnarray*} \\]
where $\\operatorname{gcd}(c_1,n_1)=1$ and $\\operatorname{gcd}(c_2,n_2)=1$
Then we can find the inverse $d_1$ of $c_1$ in $\\mathbb{Z}_{n_1}$ and the inverse $d_2$ of $c_2$ in $\\mathbb{Z}_{n_2}$ using the Extended Euclidean Algorithm or by inspection.
\nMultiplying both sides of the first equation by $d_1$ and multiplying both sides of the second equation by $d_2$ gives the equations in the form:
\n\\[\\begin{eqnarray*} x\\;&\\equiv&\\;a_1\\;&\\mod&\\;n_1\\\\ \\\\ x\\;&\\equiv&\\;a_2\\;&\\mod&\\;n_2\\\\ \\end{eqnarray*} \\]
\nSince $n_1$ and $n_2$ are coprime there is a simple formula to find a solution $\\mod\\;n$ where $n=n_1n_2$
\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$ 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$ 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$
", "showCorrectAnswer": true, "scripts": {}, "marks": 0}], "showCorrectAnswer": true, "marks": 0}], "statement": "", "tags": ["checked2015", "congruences", "coprime", "euclidean algorithm", "gcd", "hcf", "MAS3214", "Modular arithmetic", "modular arithmetic", "simultaneous congruences", "solving equations", "Solving equations", "udf"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "", "licence": "Creative Commons Attribution 4.0 International", "description": "Solving two simultaneous congruences:
\n\\[\\begin{eqnarray*} c_1x\\;&\\equiv&\\;b_1\\;&\\mod&\\;n_1\\\\ c_2x\\;&\\equiv&\\;b_2\\;&\\mod&\\;n_2\\\\ \\end{eqnarray*} \\] where $\\operatorname{gcd}(c_1,n_1)=1,\\;\\operatorname{gcd}(c_2,n_2)=1,\\;\\operatorname{gcd}(n_1,n_2)=1$
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "\n \n \nUsing the method given in Steps:
\n \n \n \nFirst we find:
\n \n \n \nThe inverse of $\\var{sa}$ in $\\mathbb{Z}_{\\var{sb}}$ is $\\var{ansp1}$, the inverse of $\\var{sc}$ in $\\mathbb{Z}_{\\var{sd}}$ is $\\var{ansp2}$.
\n \n \n \n(You can use the Extended Euclidean Algorithm to do this, and and your answers may differ from those above, but must be the same $\\mod\\;\\var{sb}$ and $\\mod\\;\\var{sd}$ respectively.)
\n \n \n \nThen multiplying both sides of the first equation by $\\var{ansp1}$ and both sides of the second equation by $\\var{ansp2}$ gives the pair of equations:
\n \n \n \n\\[\\begin{eqnarray*}\n \n x\\;&\\equiv&\\;\\var{a1}\\;\\mod\\;\\var{sb}\\\\\n \n \\\\\n \n x\\;&\\equiv&\\;\\var{a2}\\;\\mod\\;\\var{sd}\n \n \\end{eqnarray*}\n \n \\]
\n \n \n \nNow we use the formula given in Steps.
\n \n \n \nLet $n=\\var{sb}\\times \\var{sd}=\\var{sb*sd}$
\n \n \n \nSince $\\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]{{a1}* {sd} * {invd}+{a2}*{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/"}]}