// Numbas version: finer_feedback_settings {"name": "Truth tables 4 (v2)", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [{"variables": ["logic_symbol_list", "latex_symbol_list", "s"], "name": "Lists of symbols"}, {"variables": ["a", "b", "op", "pre_ev1", "ev1"], "name": "First Bracket"}, {"variables": ["a1", "b1", "op2", "pre_ev2", "ev2"], "name": "Second Bracket"}, {"variables": ["p", "q", "r", "bool_p", "bool_q", "bool_r"], "name": "Truth values"}, {"variables": ["a2", "pre_ev3", "c2", "d2", "ev3"], "name": "Last "}, {"variables": ["op1", "pre_t_value", "t_value"], "name": "First and Second Brackets"}], "variables": {"a": {"group": "First Bracket", "templateType": "anything", "definition": "latex(latex_symbol_list[s[0]])", "description": "", "name": "a"}, "op": {"group": "First Bracket", "templateType": "anything", "definition": "latex(random(\"\\\\lor\",\"\\\\land\",\"\\\\to\"))", "description": "", "name": "op"}, "op4": {"group": "Ungrouped variables", "templateType": "anything", "definition": "latex(random(\"\\\\lor\",\"\\\\land\",\"\\\\to\"))", "description": "", "name": "op4"}, "a1": {"group": "Second Bracket", "templateType": "anything", "definition": "latex(latex_symbol_list[s[2]])", "description": "", "name": "a1"}, "op2": {"group": "Second Bracket", "templateType": "anything", "definition": "latex(random(\"\\\\lor\",\"\\\\land\",\"\\\\to\"))", "description": "", "name": "op2"}, "c2": {"group": "Last ", "templateType": "anything", "definition": "latex(switch(a2=\"\\\\neg p\",\"p\",a2=\"\\\\neg q\",\"q\",\"r\"))", "description": "", "name": "c2"}, "d2": {"group": "Last ", "templateType": "anything", "definition": "switch(a2=\"\\\\neg p\",p,a2=\"\\\\neg q\",q,r)", "description": "", "name": "d2"}, "logic_values": {"group": "Ungrouped variables", "templateType": "anything", "definition": "transpose(bool_matrix(cart(3)))", "description": "", "name": "logic_values"}, "ev1": {"group": "First Bracket", "templateType": "anything", "definition": "bool_to_label(pre_ev1)", "description": "", "name": "ev1"}, "b": {"group": "First Bracket", "templateType": "anything", "definition": "latex(latex_symbol_list[s[1]])", "description": "", "name": "b"}, "ev3": {"group": "Last ", "templateType": "anything", "definition": "bool_to_label(pre_ev3)", "description": "", "name": "ev3"}, "p": {"group": "Truth values", "templateType": "anything", "definition": "bool_to_label(list_to_boolean(list(logic_values[0])))", "description": "", "name": "p"}, "a2": {"group": "Last ", "templateType": "anything", "definition": "latex(random(\"\\\\neg p\",\"\\\\neg q\",\"\\\\neg r\"))", "description": "", "name": "a2"}, "bool_p": {"group": "Truth values", "templateType": "anything", "definition": "list_to_boolean(list(logic_values[0]))", "description": "", "name": "bool_p"}, "final_value": {"group": "Ungrouped variables", "templateType": "anything", "definition": "bool_to_label(pre_final_value)", "description": "", "name": "final_value"}, "pre_ev1": {"group": "First Bracket", "templateType": "anything", "definition": "map(evaluate(convch(a)+\" \"+conv(op)+\" \"+convch(b),[bool_p[t],bool_q[t],bool_r[t]]),t,0..7)", "description": "", "name": "pre_ev1"}, "q": {"group": "Truth values", "templateType": "anything", "definition": "bool_to_label(list_to_boolean(list(logic_values[1])))", "description": "", "name": "q"}, "latex_symbol_list": {"group": "Lists of symbols", "templateType": "anything", "definition": "[\"p\",\"q\",\"\\\\neg p\",\"\\\\neg q\",\"r\",\"\\\\neg r\"]", "description": "", "name": "latex_symbol_list"}, "pre_ev3": {"group": "Last ", "templateType": "anything", "definition": "map(evaluate(convch(a2),[bool_p[t],bool_q[t],bool_r[t]]),t,0..7)", "description": "", "name": "pre_ev3"}, "ev2": {"group": "Second Bracket", "templateType": "anything", "definition": "bool_to_label(pre_ev2)", "description": "", "name": "ev2"}, "bool_r": {"group": "Truth values", "templateType": "anything", "definition": "list_to_boolean(list(logic_values[2]))", "description": "", "name": "bool_r"}, "b1": {"group": "Second Bracket", "templateType": "anything", "definition": "latex(latex_symbol_list[s[3]])", "description": "", "name": "b1"}, "t_value": {"group": "First and Second Brackets", "templateType": "anything", "definition": "bool_to_label(pre_t_value)", "description": "", "name": "t_value"}, "r": {"group": "Truth values", "templateType": "anything", "definition": "bool_to_label(list_to_boolean(list(logic_values[2])))", "description": "", "name": "r"}, "pre_ev2": {"group": "Second Bracket", "templateType": "anything", "definition": "map(evaluate(convch(a1)+\" \"+conv(op2)+\" \"+convch(b1),[bool_p[t],bool_q[t],bool_r[t]]),t,0..7)", "description": "", "name": "pre_ev2"}, "pre_final_value": {"group": "Ungrouped variables", "templateType": "anything", "definition": "map(evaluate(pre_t_value[t]+\" \"+conv(op4)+\" \"+pre_ev3[t],[]),t,0..7)", "description": "", "name": "pre_final_value"}, "logic_symbol_list": {"group": "Lists of symbols", "templateType": "anything", "definition": "[\"p\",\"q\",\"not p\",\"not q\",\"r\",\"not r\"]", "description": "", "name": "logic_symbol_list"}, "s": {"group": "Lists of symbols", "templateType": "anything", "definition": "repeat(random(0..5),6)", "description": "", "name": "s"}, "bool_q": {"group": "Truth values", "templateType": "anything", "definition": "list_to_boolean(list(logic_values[1]))", "description": "", "name": "bool_q"}, "op1": {"group": "First and Second Brackets", "templateType": "anything", "definition": "latex(random(\"\\\\lor\",\"\\\\land\",\"\\\\to\"))", "description": "", "name": "op1"}, "pre_t_value": {"group": "First and Second Brackets", "templateType": "anything", "definition": "map(evaluate(pre_ev1[t]+\" \"+conv(op1)+\" \"+pre_ev2[t],[]),t,0..7)", "description": "", "name": "pre_t_value"}}, "ungrouped_variables": ["pre_final_value", "op4", "logic_values", "final_value"], "name": "Truth tables 4 (v2)", "functions": {"conv": {"type": "string", "language": "jme", "definition": "switch(op=\"\\\\land\",\"and\",op=\"\\\\lor\",\"or\",\"implies\")", "parameters": [["op", "string"]]}, "cart": {"type": "list", "language": "jme", "definition": "if(n=2,[[true,true],[true,false],[false,true],[false,false]],map([true]+cart(n-1)[x],x,0..2^(n-1)-1)+map([false]+cart(n-1)[x],x,0..2^(n-1)-1))", "parameters": [["n", "number"]]}, "evaluate": {"type": "number", "language": "javascript", "definition": "return scope.evaluate(expr);", "parameters": [["expr", "string"], ["dependencies", "list"]]}, "bool_matrix": {"type": "matrix", "language": "jme", "definition": "matrix(map(map(if(c,1,0),c,row),row,m))", "parameters": [["m", "list"]]}, "convch": {"type": "string", "language": "jme", "definition": "switch(ch=\"\\\\neg p\",\"not bool_p[t]\",ch=\"\\\\neg q\",\"not bool_q[t]\",ch=\"p\",\"bool_p[t]\",ch=\"q\",\"bool_q[t]\",ch=\"r\",\"bool_r[t]\",\"not bool_r[t]\")", "parameters": [["ch", "string"]]}, "bool_to_label": {"type": "number", "language": "jme", "definition": "map(if(l[x],'T','F'),x,0..length(l)-1)", "parameters": [["l", "list"]]}, "list_to_boolean": {"type": "list", "language": "jme", "definition": "map(if(l[x]<>0,true,false),x,0..length(l)-1)", "parameters": [["l", "list"]]}}, "parts": [{"prompt": "

Complete the following truth table:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$p$$q$$r$$((\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1}))\\var{op4}\\var{a2} $
$\\var{p[0]}$$\\var{q[0]}$$\\var{r[0]}$[[0]]
$\\var{p[1]}$$\\var{q[1]}$$\\var{r[1]}$[[1]]
$\\var{p[2]}$$\\var{q[2]}$$\\var{r[2]}$[[2]]
$\\var{p[3]}$$\\var{q[3]}$$\\var{r[3]}$[[3]]
$\\var{p[4]}$$\\var{q[4]}$$\\var{r[4]}$[[4]]
$\\var{p[5]}$$\\var{q[5]}$$\\var{r[5]}$[[5]]
$\\var{p[6]}$$\\var{q[6]}$$\\var{r[6]}$[[6]]
$\\var{p[7]}$$\\var{q[7]}$$\\var{r[7]}$[[7]]
", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "useCustomName": false, "customName": "", "unitTests": [], "showFeedbackIcon": true, "scripts": {}, "gaps": [{"answer": "{final_value[0]}", "displayAnswer": "{final_value[0]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[1]}", "displayAnswer": "{final_value[1]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[2]}", "displayAnswer": "{final_value[2]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[3]}", "displayAnswer": "{final_value[3]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[4]}", "displayAnswer": "{final_value[4]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[5]}", "displayAnswer": "{final_value[5]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[6]}", "displayAnswer": "{final_value[6]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}, {"answer": "{final_value[7]}", "displayAnswer": "{final_value[7]}", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customName": "", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "extendBaseMarkingAlgorithm": true, "type": "patternmatch", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1}], "type": "gapfill", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 0, "sortAnswers": false}], "variablesTest": {"condition": "a1 <>b1 and\nif(a='p' or a='\\\\neg p',b=random('q','\\\\neg q'),b=random('p','\\\\neg p'))\n", "maxRuns": "150"}, "statement": "

In the following question you are asked to construct a truth table for:

\n

\\[((\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1}))\\var{op4}\\var{a2}.\\]

\n

\n

Enter T if true, else enter F.

\n

\n

\n

\n

\n

\n

\n

\n

\n

\n

\n

", "tags": [], "rulesets": {}, "preamble": {"css": "", "js": ""}, "type": "question", "extensions": [], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Create a truth table for a logical expression of the form $((a \\operatorname{op1} b) \\operatorname{op2}(c \\operatorname{op3} d))\\operatorname{op4}e $ where each of $a, \\;b,\\;c,\\;d,\\;e$ can be one the Boolean variables $p,\\;q,\\;r,\\;\\neg p,\\;\\neg q,\\;\\neg r$ and each of $\\operatorname{op1},\\;\\operatorname{op2},\\;\\operatorname{op3},\\;\\operatorname{op4}$ one of $\\lor,\\;\\land,\\;\\to$.

\n

For example: $((q \\lor \\neg r) \\to (p \\land \\neg q)) \\land \\neg r$

"}, "advice": "

First we find the truth table for $\\var{a} \\var{op} \\var{b}$:

\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$p$$q$$r$$\\var{a} \\var{op} \\var{b}$
$\\var{p[0]}$$\\var{q[0]}$$\\var{r[0]}$$\\var{ev1[0]}$
$\\var{p[1]}$$\\var{q[1]}$$\\var{r[1]}$$\\var{ev1[1]}$
$\\var{p[2]}$$\\var{q[2]}$$\\var{r[2]}$$\\var{ev1[2]}$
$\\var{p[3]}$$\\var{q[3]}$$\\var{r[3]}$$\\var{ev1[3]}$
$\\var{p[4]}$$\\var{q[4]}$$\\var{r[4]}$$\\var{ev1[4]}$
$\\var{p[5]}$$\\var{q[5]}$$\\var{r[5]}$$\\var{ev1[5]}$
$\\var{p[6]}$$\\var{q[6]}$$\\var{r[6]}$$\\var{ev1[6]}$
$\\var{p[7]}$$\\var{q[7]}$$\\var{r[7]}$$\\var{ev1[7]}$
\n

Then the truth table for $\\var{a1} \\var{op2} \\var{b1}$:

\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n
$p$$q$$r$$\\var{a1} \\var{op2} \\var{b1}$
$\\var{p[0]}$$\\var{q[0]}$$\\var{r[0]}$$\\var{ev2[0]}$
$\\var{p[1]}$$\\var{q[1]}$$\\var{r[1]}$$\\var{ev2[1]}$
$\\var{p[2]}$$\\var{q[2]}$$\\var{r[2]}$$\\var{ev2[2]}$
$\\var{p[3]}$$\\var{q[3]}$$\\var{r[3]}$$\\var{ev2[3]}$
$\\var{p[4]}$$\\var{q[4]}$$\\var{r[4]}$$\\var{ev2[4]}$
$\\var{p[5]}$$\\var{q[5]}$$\\var{r[5]}$$\\var{ev2[5]}$
$\\var{p[6]}$$\\var{q[6]}$$\\var{r[6]}$$\\var{ev2[6]}$
$\\var{p[7]}$$\\var{q[7]}$$\\var{r[7]}$$\\var{ev2[7]}$
\n

Putting these together to find $(\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1})$:

\n

\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n
$p$$q$$r$$\\var{a} \\var{op} \\var{b}$$\\var{a1} \\var{op2} \\var{b1}$$(\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1})$
$\\var{p[0]}$$\\var{q[0]}$$\\var{r[0]}$$\\var{ev1[0]}$$\\var{ev2[0]}$$\\var{t_value[0]}$
$\\var{p[1]}$$\\var{q[1]}$$\\var{r[1]}$$\\var{ev1[1]}$$\\var{ev2[1]}$$\\var{t_value[1]}$
$\\var{p[2]}$$\\var{q[2]}$$\\var{r[2]}$$\\var{ev1[2]}$$\\var{ev2[2]}$$\\var{t_value[2]}$
$\\var{p[3]}$$\\var{q[3]}$$\\var{r[3]}$$\\var{ev1[3]}$$\\var{ev2[3]}$$\\var{t_value[3]}$
$\\var{p[4]}$$\\var{q[4]}$$\\var{r[4]}$$\\var{ev1[4]}$$\\var{ev2[4]}$$\\var{t_value[4]}$
$\\var{p[5]}$$\\var{q[5]}$$\\var{r[5]}$$\\var{ev1[5]}$$\\var{ev2[5]}$$\\var{t_value[5]}$
$\\var{p[6]}$$\\var{q[6]}$$\\var{r[6]}$$\\var{ev1[6]}$$\\var{ev2[6]}$$\\var{t_value[6]}$
$\\var{p[7]}$$\\var{q[7]}$$\\var{r[7]}$$\\var{ev1[7]}$$\\var{ev2[7]}$$\\var{t_value[7]}$
\n

Next we find the truth table for $\\var{a2}$:

\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$\\var{c2}$$\\var{a2}$
$\\var{d2[0]}$$\\var{ev3[0]}$
$\\var{d2[1]}$$\\var{ev3[1]}$
$\\var{d2[2]}$$\\var{ev3[2]}$
$\\var{d2[3]}$$\\var{ev3[3]}$
$\\var{d2[4]}$$\\var{ev3[4]}$
$\\var{d2[5]}$$\\var{ev3[5]}$
$\\var{d2[6]}$$\\var{ev3[6]}$
$\\var{d2[7]}$$\\var{ev3[7]}$
\n

Putting this all together to obtain the truth table we want:

\n\n\n \n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n \n\n\n\n\n\n
$p$$q$$r$$(\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1})$$\\var{a2}$$((\\var{a} \\var{op} \\var{b})\\var{op1}(\\var{a1} \\var{op2} \\var{b1}))\\var{op4}\\var{a2} $
$\\var{p[0]}$$\\var{q[0]}$$\\var{r[0]}$$\\var{t_value[0]}$$\\var{ev3[0]}$$\\var{final_value[0]}$
$\\var{p[1]}$$\\var{q[1]}$$\\var{r[1]}$$\\var{t_value[1]}$$\\var{ev3[1]}$$\\var{final_value[1]}$
$\\var{p[2]}$$\\var{q[2]}$$\\var{r[2]}$$\\var{t_value[2]}$$\\var{ev3[2]}$$\\var{final_value[2]}$
$\\var{p[3]}$$\\var{q[3]}$$\\var{r[3]}$$\\var{t_value[3]}$$\\var{ev3[3]}$$\\var{final_value[3]}$
$\\var{p[4]}$$\\var{q[4]}$$\\var{r[4]}$$\\var{t_value[4]}$$\\var{ev3[4]}$$\\var{final_value[4]}$
$\\var{p[5]}$$\\var{q[5]}$$\\var{r[5]}$$\\var{t_value[5]}$$\\var{ev3[5]}$$\\var{final_value[5]}$
$\\var{p[6]}$$\\var{q[6]}$$\\var{r[6]}$$\\var{t_value[6]}$$\\var{ev3[6]}$$\\var{final_value[6]}$
$\\var{p[7]}$$\\var{q[7]}$$\\var{r[7]}$$\\var{t_value[7]}$$\\var{ev3[7]}$$\\var{final_value[7]}$
", "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/"}]}