WeBWorK Problems

Symbolic answers in inequality questions

Symbolic answers in inequality questions

by Ian Delbridge -
Number of replies: 7
Hello,

I'm trying to get a question of the form

|ax+b|<9

(solve for x) to work. However, I'm not sure how get this to work very well. I'm looking at some college of Idaho questions by RA Cruz, and these work very nicely with contextInequalitiesAllowStrings.pl, which is a macro that uses the contextInequalities and adds the ability to answer with "none" and "all real" or something to that effect (though I'm not sure that it every got up and running completely. This page http://webwork.maa.org/pod/NationalProblemLibrary_TRUNK/macros/CollegeOfIdaho/contextInequalitiesAllowStrings.pl.html says that the "none" part doesn't work, but that's a whole different issue). 

Initially I thought I could use it, or at least contextInequalties, but to my knowledge, I'm not allowed to have variables in them, like this  "-5b < x <= 8b". First of all, is this the case? 

If it is, this is really tragic, because I'd like to have the capability in the question of the nature of the solution changing based on the seed - that is, for some, there would be no solution, for some, there would only be one equality describing x, and for some there would need to be two inequalities describing x. If I had an answering system like the University of Rochester questions that I'm looking at, "

To say that x726 is the same as saying x is in the closed interval [A,B] 
What is A, and what is B?"

 This doesn't work nearly as well in terms of the flexibility in the nature of answers that I'd like to have. I theoretically could have a large series of if statements determining the nature of the answer ans formatting the question in three different ways for each kind of answer, and I'll probably end up doing that if it turns out that no one has any very bright ideas on the subject. 

Does anyone have any very bright ideas on the subject? 

(I'd provide some code, but there really isn't any specific problem I'm having, so it doesn't make too much sense to post anything. If someone requests some I'll post it.)








In reply to Ian Delbridge

Re: Symbolic answers in inequality questions

by Alex Jordan -
Intervals in WeBWorK are always pairs of numbers, even when it looks like it involves a variable, like "1<x<2". That object is just converted to "(1,2)".

The first thing that comes to mind is to make a, b into named constants instead of treating them like variables. See http://webwork.maa.org/wiki/Introduction_to_Contexts#Constants.

Also, see http://webwork.maa.org/wiki/Modifying_contexts_%28advanced%29#More_about_Constants.

Make a and b constants that are extremely unlikely to be typed directly or numerically by a student, like exp(2)/cos(3), etc. You can even randomize what they are.

You would need to tend to various context flags to make sure that these constants are always displayed by their name, and never by the defining formula or as a decimal.

Also, you may be interested in making use of contextInequalitySetBuilder.pl (https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/macros/PCC/contextInequalitySetBuilder.pl) written by Davide Cervone and implemented in many problems in the basic algebra library that I posted about here: http://webwork.maa.org/moodle/mod/forum/discuss.php?d=3320
In reply to Alex Jordan

Re: Symbolic answers in inequality questions

by Ian Delbridge -
Oh that's a great idea! I hadn't thought of that. And the contextInequlitySetBuilder.pl looks like a good idea too! Thanks a bunch!
In reply to Ian Delbridge

Re: Symbolic answers in inequality questions

by Davide Cervone -
Just a small addition to Alex's suggestion. You will probably want to use
  Context()->flags->set(formatStudentAnswer=>'parsed');
so that the "Entered" column of the results table will show the constant names rathe than the resting values.

Another thing to keep in mind is that the answer to your question is different depending on the sign of a (with a= 0 a singular case that then depends on the value of b, so you may want to specify that a > 0 in the problem.

In reply to Davide Cervone

Re: Symbolic answers in inequality questions

by Ian Delbridge -
I am now implementing both of those, but despite having included the flag, the entered column shows the numerical value that is used for comparison rather than the constant names, though it shows it with the constant names in the preview and in the correct answer. Below is what it looks like. I've also attached the .pg file for the question. This isn't what it's supposed to do is it? Is there a way of changing it?


EnteredAnswer PreviewCorrectResult
x = 421.653
x=ba
x=ba
correct

In reply to Ian Delbridge

Re: Symbolic answers in inequality questions

by Davide Cervone -
The flag is formatStudentAnswer (singular), not formatStudentAnswers (plural). If you change that, I think it will work for you.
In reply to Davide Cervone

Re: Symbolic answers in inequality questions

by Ian Delbridge -
Wow. That was it. I feel so stupid for having missed that, but the code ran, so I didn't second-guess myself. Thanks for catching that!
In reply to Ian Delbridge

Re: Symbolic answers in inequality questions

by Davide Cervone -
It is easy to get these things wrong. I often have to look up the names to get them right. Glad it is working now.