// Numbas version: exam_results_page_options {"name": "Lois's copy of 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": {"tracemap": {"parameters": [["n", "number"], ["perms", "list"]], "type": "string", "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;", "language": "javascript"}, "orderpossible": {"parameters": [["n", "number"], ["s_n", "number"]], "type": "boolean", "definition": "var factors = Numbas.math.factorise(n);\nvar t = 0;\nfor(var i=0;i0) {\n var cycle_length = Math.pow(Numbas.math.primes[i],factors[i]);\n for(var j=0;j0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;", "language": "javascript"}, "showlist": {"parameters": [["l", "list"]], "type": "string", "definition": "var out = '';\nfor(var i=0;i1) {\n out += ' and ';\n } else if(i>0) {\n out += ', ';\n }\n out += '$'+l[i]+'$';\n}\nreturn out;", "language": "javascript"}, "show_factorisation": {"parameters": [["n", "number"]], "type": "string", "definition": "var factors = Numbas.math.factorise(n);\nvar out = '';\nfor(var i=0;i1) {\n out += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;", "language": "javascript"}}, "tags": [], "statement": "

Note that to enter cycles in this question you need to put commas between each element and you should also not leave spaces between each cycle. For example you would input something like: (2, 3, 5)(1,8).

\n

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

\n

", "parts": [{"variableReplacementStrategy": "originalfirst", "prompt": "

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

\n

$\\pi = $ [[0]]

\n

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

", "marks": 0, "showFeedbackIcon": true, "variableReplacements": [], "type": "gapfill", "scripts": {}, "gaps": [{"variableReplacementStrategy": "originalfirst", "answer": "", "marks": 1, "showFeedbackIcon": true, "variableReplacements": [], "type": "patternmatch", "scripts": {"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}"}, "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;"}}, "matchMode": "regex", "showCorrectAnswer": true, "displayAnswer": "{show(ppi)}"}, {"variableReplacementStrategy": "originalfirst", "answer": "", "marks": 1, "showFeedbackIcon": true, "variableReplacements": [], "type": "patternmatch", "scripts": {"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}"}, "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;"}}, "matchMode": "regex", "showCorrectAnswer": true, "displayAnswer": "{show(ppi)}"}], "showCorrectAnswer": true}, {"variableReplacementStrategy": "originalfirst", "prompt": "

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

", "marks": 0, "showFeedbackIcon": true, "variableReplacements": [], "type": "gapfill", "scripts": {}, "gaps": [{"scripts": {}, "allowFractions": false, "variableReplacements": [], "showFeedbackIcon": true, "maxValue": "order(ppi)", "showCorrectAnswer": true, "correctAnswerFraction": false, "correctAnswerStyle": "plain", "minValue": "order(ppi)", "marks": 1, "type": "numberentry", "mustBeReducedPC": 0, "notationStyles": ["plain", "en", "si-en"], "variableReplacementStrategy": "originalfirst", "mustBeReduced": false}], "showCorrectAnswer": true}, {"variableReplacementStrategy": "originalfirst", "prompt": "

$\\pi$ is [[0]]

", "marks": 0, "showFeedbackIcon": true, "variableReplacements": [], "type": "gapfill", "scripts": {}, "gaps": [{"displayType": "radiogroup", "scripts": {}, "choices": ["

an even permutation

", "

an odd permutation

"], "showFeedbackIcon": true, "shuffleChoices": false, "variableReplacements": [], "showCorrectAnswer": true, "maxMarks": 0, "marks": 0, "minMarks": 0, "displayColumns": 0, "variableReplacementStrategy": "originalfirst", "type": "1_n_2", "matrix": "if(even(ppi),[1,0],[0,1])"}], "showCorrectAnswer": true}], "name": "Lois's copy of Permutations: two-line form", "rulesets": {}, "ungrouped_variables": ["ppi_num_even_cycles", "ppi", "ppi_cycle_lengths", "ppi_num_cycles"], "variablesTest": {"maxRuns": 100, "condition": ""}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "advice": "

a) Each number on the top row of the permutation 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 not already included in a cycle until you have accounted for them all.

\n

To find the inverse we can just reverse the order of each disjoint cycle.

\n

(Note that although this question will mark your answer to $\\pi^{-1}$ correctly the expected answer shown is $\\pi$.)

\n

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

\n

There are $\\var{ppi_num_cycles}$ nontrivial (i.e not including those of length one) 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 (i.e. not of length 1) disjoint cycle, of length $\\var{ppi_cycle_lengths[0]}$, so the order of $\\pi$ is $\\var{lcm(ppi_cycle_lengths)}$.

\n

c) Recall that a  permutation is even if it can be written as the product of an even number of transpositions and odd if it can be written as the product of an odd number of transpositions. In this case $ \\pi$ is {if(even(ppi),'even','odd')}.

\n

(Notice that when a cycle of length $k, k \\neq 1$ is written as a product of transpositions there  will be $k-1$ transpositions in that product. A cycle of length 1 can be written as the product of two transpositions. That means we could work out how many transpositions will be in our product without finding them explicitly.In fact there is a general result that a permutation is even 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.)

", "variables": {"ppi_num_even_cycles": {"description": "", "group": "Ungrouped variables", "definition": "sum(map(1-mod(x,2),x,ppi_cycle_lengths))", "templateType": "anything", "name": "ppi_num_even_cycles"}, "ppi": {"description": "", "group": "Ungrouped variables", "definition": "perm(deal(random(6..11)))", "templateType": "anything", "name": "ppi"}, "ppi_num_cycles": {"description": "", "group": "Ungrouped variables", "definition": "len(nontrivial_cycles(ppi))", "templateType": "anything", "name": "ppi_num_cycles"}, "ppi_cycle_lengths": {"description": "", "group": "Ungrouped variables", "definition": "map(len(x),x,nontrivial_cycles(ppi))", "templateType": "anything", "name": "ppi_cycle_lengths"}}, "preamble": {"css": "", "js": ""}, "extensions": ["permutations"], "variable_groups": [], "type": "question", "contributors": [{"name": "Lois Rollings", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/326/"}]}]}], "contributors": [{"name": "Lois Rollings", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/326/"}]}