// Numbas version: finer_feedback_settings {"name": "Permutations: two-line form", "extensions": ["permutations"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"orderpossible": {"definition": "var factors = Numbas.math.factorise(n);\nvar t = 0;\nfor(var i=0;i1) {\n out += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["n", "number"]]}, "sum": {"definition": "var t = 0;\nfor(var i=0;i0) {\n var cycle_length = Math.pow(Numbas.math.primes[i],factors[i]);\n for(var j=0;j1) {\n out += ' and ';\n } else if(i>0) {\n out += ', ';\n }\n out += '$'+l[i]+'$';\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["l", "list"]]}, "permfrompartition": {"definition": "var to = [];\nvar offset = 0;\nfor(var i=0; i0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;", "type": "string", "language": "javascript", "parameters": [["l", "list"]]}, "randompartition": {"definition": "var l = [];\nwhile(n) {\n var t = Numbas.math.randomint(n)+1;\n l.push(t);\n n -= t;\n}\nreturn l;", "type": "list", "language": "javascript", "parameters": [["n", "number"]]}, "tracemap": {"definition": "n -= 1;\nvar l = perms.length;\nvar out = ''+(n+1);\nfor(var i=l-1;i>=0;i--) {\n n = perms[i].map(n);\n out += ' \\\\to '+(n+1);\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["n", "number"], ["perms", "list"]]}}, "name": "Permutations: two-line form", "tags": ["permutations"], "type": "question", "advice": "

Each number on the top row is mapped to the number directly beneath it. To find a disjoint cycle, pick a number and trace it through repeated applications of the permutation until you get back to the number you started with. Do this for each number to find every disjoint cycle.

\n

The order of the permutation $\\pi$ is the lowest common multiple of the orders of its disjoint cycles.

\n

1\">There are $\\var{ppi_num_cycles}$ nontrivial disjoint cycles, of lengths {showlist(ppi_cycle_lengths)}. The lowest common multiple of those numbers is $\\var{lcm(ppi_cycle_lengths)}$, so the order of $\\pi$ is $\\var{lcm(ppi_cycle_lengths)}$.

\n

There is one nontrivial disjoint cycle, of length $\\var{ppi_cycle_lengths[0]}$, so the order of $\\pi$ is $\\var{lcm(ppi_cycle_lengths)}$.

\n

A permutation is even if it can be written as the product of an even number of transpositions. This is true if and only if, when decomposed into a product of disjoint cycles, there are an even number of cycles of even length. $\\pi$ has $\\var{ppi_num_even_cycles}$ {pluralise(ppi_num_even_cycles,'cycle','cycles')} of even length, so is an {if(even(ppi),'even','odd')} permutation.

", "rulesets": {}, "parts": [{"prompt": "

Write $\\pi$ and $\\pi^{-1}$ as a product of disjoint cycles.

\n

$\\pi = $ [[0]]

\n

$\\pi^{-1} = $ [[1]]

", "marks": 0, "gaps": [{"marks": 1, "showCorrectAnswer": true, "displayAnswer": "{show(ppi)}", "scripts": {"validate": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry{\n Permutation.parse(this.studentAnswer);\n} catch(e) {\n this.giveWarning(\"Invalid notation\");\n return false;\n}\nreturn true;"}, "mark": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n var p = Permutation.fromString(this.studentAnswer);\n} catch(e) {\n this.setCredit(0,\"Invalid notation\");\n return;\n}\nif(!Permutation.is_disjoint(this.studentAnswer)) {\n this.setCredit(0,\"Your cycles are not disjoint\");\n}\nvar unwrapValue = Numbas.jme.unwrapValue;\nvar prod = unwrapValue(question.scope.variables.ppi);\nif(p.equal(prod)) {\n this.setCredit(1,\"Correct!\");\n} else {\n this.setCredit(0,\"Wrong\");\n}"}}, "answer": "", "type": "patternmatch"}, {"marks": 1, "showCorrectAnswer": true, "displayAnswer": "{show(ppi)}", "scripts": {"validate": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry{\n Permutation.parse(this.studentAnswer);\n} catch(e) {\n this.giveWarning(\"Invalid notation\");\n return false;\n}\nreturn true;"}, "mark": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n var p = Permutation.fromString(this.studentAnswer);\n} catch(e) {\n this.setCredit(0,\"Invalid notation\");\n return;\n}\nif(!Permutation.is_disjoint(this.studentAnswer)) {\n this.setCredit(0,\"Your cycles are not disjoint\");\n}\nvar unwrapValue = Numbas.jme.unwrapValue;\nvar prod = unwrapValue(question.scope.variables.ppi);\nprod = prod.inverse();\nif(p.equal(prod)) {\n this.setCredit(1,\"Correct!\");\n} else {\n this.setCredit(0,\"Wrong\");\n}"}}, "answer": "", "type": "patternmatch"}], "showCorrectAnswer": true, "scripts": {}, "type": "gapfill"}, {"prompt": "

What is the order of $\\pi$? [[0]]

", "marks": 0, "gaps": [{"marks": 1, "maxValue": "order(ppi)", "minValue": "order(ppi)", "showCorrectAnswer": true, "scripts": {}, "type": "numberentry", "showPrecisionHint": false}], "showCorrectAnswer": true, "scripts": {}, "type": "gapfill"}, {"prompt": "

$\\pi$ is [[0]]

", "marks": 0, "gaps": [{"maxAnswers": 0, "displayColumns": 0, "matrix": "if(even(ppi),[1,0],[0,1])", "minAnswers": 0, "shuffleChoices": false, "choices": ["

an even permutation

", "

an odd permutation

"], "displayType": "radiogroup", "maxMarks": 0, "scripts": {}, "distractors": ["", ""], "marks": 0, "showCorrectAnswer": true, "type": "1_n_2", "minMarks": 0}], "showCorrectAnswer": true, "scripts": {}, "type": "gapfill"}], "statement": "

\\[ \\pi = \\var{twoline(ppi)} \\]

", "variable_groups": [], "progress": "in-progress", "preamble": {"css": "", "js": ""}, "variables": {"ppi_num_even_cycles": {"definition": "sum(map(1-mod(x,2),x,ppi_cycle_lengths))", "templateType": "anything", "group": "Ungrouped variables", "name": "ppi_num_even_cycles", "description": ""}, "ppi_num_cycles": {"definition": "len(nontrivial_cycles(ppi))", "templateType": "anything", "group": "Ungrouped variables", "name": "ppi_num_cycles", "description": ""}, "ppi": {"definition": "perm(deal(random(6..11)))", "templateType": "anything", "group": "Ungrouped variables", "name": "ppi", "description": ""}, "ppi_cycle_lengths": {"definition": "map(len(x),x,nontrivial_cycles(ppi))", "templateType": "anything", "group": "Ungrouped variables", "name": "ppi_cycle_lengths", "description": ""}}, "metadata": {"notes": "", "description": "", "licence": "Creative Commons Attribution 4.0 International"}, "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}