// Numbas version: exam_results_page_options {"name": "Permutations: two-line form", "extensions": ["permutations"], "custom_part_types": [{"source": {"pk": 68, "author": {"name": "Christian Lawson-Perfect", "pk": 7}, "edit_page": "/part_type/68/edit"}, "name": "Write a permutation in cycle notation", "short_name": "write-a-permutation-in-cycle-notation", "description": "

The student must write a permutation in cycle notation. You can optionally require the cycles to be disjoint and/or all of length 2.

", "help_url": "", "input_widget": "string", "input_options": {"correctAnswer": "let(ans,\n if(settings[\"must_be_transpositions\"],\n as_transpositions(settings[\"correct_answer\"]),\n show(settings[\"correct_answer\"])\n ),\n if(ans=\"\",settings[\"identity_name\"],ans)\n)", "hint": {"static": false, "value": "if(settings[\"show_hint\"],\n if(settings[\"must_be_disjoint\"],\n if(settings[\"must_be_transpositions\"],\n \"Write a permutation in cycle notation as a product of disjoint transpositions.\",\n \"Write a permutation in cycle notation as a product of disjoint cycles.\"\n ),\n if(settings[\"must_be_transpositions\"],\n \"Write a permutation in cycle notation as a product of transpositions.\",\n \"Write a permutation in cycle notation.\"\n )\n ),\n \"\"\n)"}, "allowEmpty": {"static": true, "value": false}}, "can_be_gap": true, "can_be_step": true, "marking_script": "mark:\napply(student_permutation);\napply(is_correct);\napply(is_disjoint);\napply(is_transpositions)\n\ninterpreted_answer:\nstudent_permutation\n\nis_correct:\ncorrectif(student_permutation=settings[\"correct_answer\"])\n\nis_disjoint:\nif(is_disjoint(studentAnswer),\n true\n,\n assert(not settings[\"must_be_disjoint\"],\n set_credit(0,\"You have not written your answer as a product of disjoint cycles.\"),\n );\n false\n)\n\nstudent_permutation:\ntry(\n if(studentAnswer=settings[\"identity_name\"],\n permutation(\"\"), \n permutation(studentAnswer)\n ),\n message,\n warn(\"Your answer is not valid cycle notation: \"+message);\n fail(\"Your answer is not valid cycle notation: \"+message)\n)\n\nis_transpositions:\nif(is_transpositions(studentAnswer),\n true\n,\n assert(not settings[\"must_be_transpositions\"],\n set_credit(0,\"You have not written your answer as a product of transpositions.\")\n );\n false\n)", "marking_notes": [{"name": "mark", "description": "This is the main marking note. It should award credit and provide feedback based on the student's answer.", "definition": "apply(student_permutation);\napply(is_correct);\napply(is_disjoint);\napply(is_transpositions)"}, {"name": "interpreted_answer", "description": "A value representing the student's answer to this part.", "definition": "student_permutation"}, {"name": "is_correct", "description": "", "definition": "correctif(student_permutation=settings[\"correct_answer\"])"}, {"name": "is_disjoint", "description": "", "definition": "if(is_disjoint(studentAnswer),\n true\n,\n assert(not settings[\"must_be_disjoint\"],\n set_credit(0,\"You have not written your answer as a product of disjoint cycles.\"),\n );\n false\n)"}, {"name": "student_permutation", "description": "", "definition": "try(\n if(studentAnswer=settings[\"identity_name\"],\n permutation(\"\"), \n permutation(studentAnswer)\n ),\n message,\n warn(\"Your answer is not valid cycle notation: \"+message);\n fail(\"Your answer is not valid cycle notation: \"+message)\n)"}, {"name": "is_transpositions", "description": "", "definition": "if(is_transpositions(studentAnswer),\n true\n,\n assert(not settings[\"must_be_transpositions\"],\n set_credit(0,\"You have not written your answer as a product of transpositions.\")\n );\n false\n)"}], "settings": [{"name": "correct_answer", "label": "Correct answer", "help_url": "", "hint": "", "input_type": "code", "default_value": "", "evaluate": true}, {"name": "show_hint", "label": "Show answer input hint?", "help_url": "", "hint": "", "input_type": "checkbox", "default_value": true}, {"name": "must_be_disjoint", "label": "Must the cycles be disjoint?", "help_url": "", "hint": "", "input_type": "checkbox", "default_value": false}, {"name": "must_be_transpositions", "label": "Must the cycles be transpositions?", "help_url": "", "hint": "", "input_type": "checkbox", "default_value": false}, {"name": "identity_name", "label": "Name of the identity permutation", "help_url": "", "hint": "The student should write this string for the identity permutation.", "input_type": "string", "default_value": "e", "subvars": true}], "public_availability": "always", "published": true, "extensions": ["permutations"]}], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Permutations: two-line form", "tags": ["permutations"], "metadata": {"description": "", "licence": "None specified"}, "statement": "

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

", "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": {}, "extensions": ["permutations"], "variables": {"ppi_num_even_cycles": {"name": "ppi_num_even_cycles", "group": "Ungrouped variables", "definition": "sum(map(1-mod(x,2),x,ppi_cycle_lengths))", "description": "", "templateType": "anything"}, "ppi_cycle_lengths": {"name": "ppi_cycle_lengths", "group": "Ungrouped variables", "definition": "map(len(x),x,nontrivial_cycles(ppi))", "description": "", "templateType": "anything"}, "ppi": {"name": "ppi", "group": "Ungrouped variables", "definition": "perm(deal(random(6..11)))", "description": "", "templateType": "anything"}, "ppi_num_cycles": {"name": "ppi_num_cycles", "group": "Ungrouped variables", "definition": "len(nontrivial_cycles(ppi))", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["ppi_num_even_cycles", "ppi_num_cycles", "ppi", "ppi_cycle_lengths"], "variable_groups": [], "functions": {"randompartition": {"parameters": [["n", "number"]], "type": "list", "language": "javascript", "definition": "var l = [];\nwhile(n) {\n var t = Numbas.math.randomint(n)+1;\n l.push(t);\n n -= t;\n}\nreturn l;"}, "tracemap": {"parameters": [["n", "number"], ["perms", "list"]], "type": "string", "language": "javascript", "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;"}, "sum": {"parameters": [["l", "list"]], "type": "number", "language": "javascript", "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;"}, "orderpossible": {"parameters": [["n", "number"], ["s_n", "number"]], "type": "boolean", "language": "javascript", "definition": "var factors = Numbas.math.factorise(n);\nvar t = 0;\nfor(var i=0;i1) {\n out += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;"}, "showsum": {"parameters": [["l", "list"]], "type": "string", "language": "javascript", "definition": "var t = 0;\nvar out = '';\nfor(var i=0;i0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

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

\n

$\\pi = $ [[0]]

\n

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

", "gaps": [{"type": "write-a-permutation-in-cycle-notation", "useCustomName": true, "customName": "$\\pi$", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [{"variables": [{"name": "ppi_num_even_cycles", "value": "1"}, {"name": "ppi_num_cycles", "value": "1"}, {"name": "ppi", "value": "perm(\"(1,6,7,5,4,2)\")"}, {"name": "ppi_cycle_lengths", "value": "[ 6 ]"}], "answer": {"empty": false, "valid": true, "value": "(1,6,7,5,4,2)"}, "notes": [{"name": "mark", "expected": {"value": "nothing", "messages": ["Your answer is correct.\n\nYou were awarded 1 mark."], "warnings": [], "error": "", "valid": true, "credit": 1}}]}], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "settings": {"correct_answer": "ppi", "must_be_disjoint": true, "must_be_transpositions": false}}, {"type": "write-a-permutation-in-cycle-notation", "useCustomName": true, "customName": "$\\pi^{-1}$", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "settings": {"correct_answer": "inverse(ppi)", "must_be_disjoint": true, "must_be_transpositions": false}}], "sortAnswers": false}, {"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

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

", "gaps": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "order(ppi)", "maxValue": "order(ppi)", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}, {"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$\\pi$ is [[0]]

", "gaps": [{"type": "1_n_2", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minMarks": 0, "maxMarks": 0, "shuffleChoices": false, "displayType": "radiogroup", "displayColumns": 0, "showCellAnswerState": true, "choices": ["

an even permutation

", "

an odd permutation

"], "matrix": "if(even(ppi),[1,0],[0,1])"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}