// Numbas version: exam_results_page_options {"name": "Write a permutation as a product of disjoint cycles", "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": "Write a permutation as a product of disjoint cycles", "tags": ["checked2015", "groups", "permutations"], "metadata": {"description": "", "licence": "None specified"}, "statement": "", "advice": "

Each set of brackets represents a cycle, with each number being mapped to the one on its right, and the last number in the sequence mapped to the first.

\n

Follow each number through the cycles, starting with the rightmost cycle and reading leftwards. For example, here's how $1$ is mapped to $\\var{prod[1]}$:

\n

\\[ \\var{latex(tracemap(1,perms))} \\]

\n

Then repeat this for $\\var{prod[1]}$, until you get back to $1$. This is a single cycle. If any number is not included in this cycle, repeat this process starting at that number to get another, disjoint, cycle. Some numbers are mapped to themselves - these are trivial cycles and you don't need to write them down. Once you've covered every number, you should have the following:

\n

\\[ \\var{prod} \\]

\n", "rulesets": {}, "extensions": ["permutations"], "variables": {"prod": {"name": "prod", "group": "Ungrouped variables", "definition": "compose(perms[0],perms[1],perms[2],perms[3])", "description": "", "templateType": "anything"}, "n": {"name": "n", "group": "Ungrouped variables", "definition": "random(4..9)", "description": "", "templateType": "anything"}, "perms": {"name": "perms", "group": "Ungrouped variables", "definition": "repeat(perm(randomcycle(n)),4)", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["perms", "prod", "n"], "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;"}, "show_factorisation": {"parameters": [["n", "number"]], "type": "string", "language": "javascript", "definition": "var factors = Numbas.math.factorise(n);\nvar out = '';\nfor(var i=0;i1) {\n out += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;"}, "permfrompartition": {"parameters": [["cycle_sizes", "list"]], "type": "list", "language": "javascript", "definition": "var to = [];\nvar offset = 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;i0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "write-a-permutation-in-cycle-notation", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Write as a product of disjoint cycles

\n

\\[\\var{perms[0]} \\var{perms[1]} \\var{perms[2]} \\var{perms[3]} \\]

", "settings": {"correct_answer": "prod", "must_be_disjoint": true, "must_be_transpositions": false}}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}, {"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": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}, {"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/"}]}