I'm creating problems for a Mathematical Logic homework set, and I'd like to have problems where students translate compound statements in English into symbolic form using given simple statements p, q, r.
Right now, (from other suggestions in the forum), I'm using string objects, overriding all error messages that might be confusing to students with either vague ones (like "This is incorrect") or more relevant ones.
I'm using /\ for "And", \/ for "Or", -> for "If/then", ~ for "Not".
Using the backslash in answers produces really odd results as I imagine this is messing with the parser. It'll mark correct answers correct (happy about this), ..but it removes all backslashes from the student's answer and shows parts of their answer preview in red.
I'm wondering how doable making a simple logic parser would be with the symbols as above or if there's some special way of representing a backslash (like how $ is $DOLLAR). A parser would be a lot nicer for the students (accepting spaces, ignoring extraneous parentheses, etc.).
Again, I want to reiterate, the problem 'works'.. it just has odd results I'd like to avoid if possible.
I've put the coding of my problem below.
Thank you,
Spyro Roubos
=======================
# Write the following statement in Symbolic Notation - Decide on Parentheses
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"parserAutoStrings.pl"
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("Numeric");
Context()->strings->clear;
Context()->constants->clear;
Context()->variables->clear;
Context()->functions->clear;
Context()->operators->clear;
Context()->parens->clear;
Context()->{error}{msg}{"Variable '%s' is not defined in this context"} =
"This is incorrect.";
Context()->{error}{msg}{"Unexpected character '%s'"} =
"This is incorrect.";
Context()->{error}{msg}{"'%s' is not defined in this context"} =
"This is incorrect.";
AutoStrings();
$C1 = String("p\/(q/\r)");
$C2 = String("(p\/q)/\r");
$C3 = String("(p\/q)/\~r");
$C4 = String("~p/\~q");
$C5 = String("~(p/\q)");
##############################################################
#
# Text
#
#
Context()->texStrings;
BEGIN_TEXT
Consider the following simple statements:
$BR $BR
p = "We need to do the laundry" $BR
q = "We need to go grocery shopping" $BR
r = "We need to stop for gas" $BR $BR
Represent the following compound statements using symbols. Use the forward and back-slashes on your keyboard to make "And" and "Or". The ~ is to the left of "1" on your keyboard. Use -> for the "Conditional". $BBOLD Do NOT use spaces in your answer here. $EBOLD Use parentheses where appropriate.
$BR $BR
We need to do the laundry, or we need to go grocery shopping and we need to stop for gas.: \{ans_rule(30)\}
$BR $BR
We need to do the laundry or we need to go grocery shopping, and we need to stop for gas.: \{ans_rule(30)\}
$BR $BR
We need to do the laundry or we need to go grocery shopping, but we do not need to stop for gas.: \{ans_rule(30)\}
$BR $BR
We do not need to do the laundry and we do not need to go grocery shopping.: \{ans_rule(30)\}
$BR $BR
It's false that we need to do the laundry and we do need to go grocery shopping.: \{ans_rule(30)\}
END_TEXT
Context()->normalStrings;
##############################################################
#
# Answers
#
#
ANS( $C1->cmp);
ANS( $C2->cmp);
ANS( $C3->cmp);
ANS( $C4->cmp);
ANS( $C5->cmp);
ENDDOCUMENT();