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

a)

\n

\\[ \\var{as_transpositions(pi1)} \\]

\n

b)

\n

\\[ \\var{as_transpositions(pi2)} \\]

", "rulesets": {}, "extensions": ["permutations"], "variables": {"pi1": {"name": "pi1", "group": "Ungrouped variables", "definition": "perm(randomcycle(random(5..9)))", "description": "", "templateType": "anything"}, "pi2": {"name": "pi2", "group": "Ungrouped variables", "definition": "perm(deal(random(11..17)))", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["pi1", "pi2"], "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 the permutation $\\pi_1 = \\var{pi1}$ as a product of transpositions.

\n

$\\pi_1 = $ [[0]]\n

", "gaps": [{"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, "settings": {"correct_answer": "pi1", "must_be_disjoint": false, "must_be_transpositions": true}}], "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": "

Write the permutation $\\pi_2 = \\var{pi2}$ as a product of transpositions.

\n

$\\pi_2 = $ [[0]]\n

", "gaps": [{"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, "settings": {"correct_answer": "pi2", "must_be_disjoint": false, "must_be_transpositions": true}}], "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/"}]}