WeBWorK Main Forum

How can I get "All real numbers" with contextInequalities?

How can I get "All real numbers" with contextInequalities?

by Robin Cruz -
Number of replies: 3

I cannot seem to get the answer checker to recognize the answer "All real numbers".  I've tried "(-inf, inf)" and

""(-infty, infty)", and "R". 

--rac

In reply to Robin Cruz

Re: How can I get "All real numbers" with contextInequalities?

by Davide Cervone -
If you are using Context("Inequalities"), then you should be able to use either "R" or "(-inf,inf)". On the other hand, if you are using Context("Inequalities-Only"), then you can not enter intervals, so "(-inf,inf)" will not be allowed. Similarly, "R" is not an inequality (it's a set), so is not allowed in the Inequalities-Only context.

If you want to allow R as an answer, you can add it bad in as follows:

    Context()->constants->redefine("R",from=>"Interval");
This causes the current context to get a copy of the definition of R from the Interval context.

I guess the way to specify this as an inequality would be to use -inf < x < inf (although either -inf < x or x &lt inf by itself would also work). This was not allowed, but I have modified contextInequalities.pl to permit these inequalities.

Davide

In reply to Davide Cervone

Re: How can I get "All real numbers" with contextInequalities?

by Robin Cruz -

OK, I now can use "R" and "-inf < x < inf", thank you.

Next, is there a way to let the students enter "All real numbers" as an alias for "R"?  I'd like to have this as an option because for Intermediate Alg students, if they enter "inf" on their homework, they will continue to do so on their quizzes and tests.  At least "All real numbers" makes sense to everyone all the time, but it's not a big deal. 

Here's what I've tried and the only thing that happens is the student's answer now shows up as "R"after the submit button is pressed, but it is scored as incorrect.

Context()->strings->add("All real numbers"=>{alias=>"R"});
Context()->constants->redefine("R",from=>"Interval");

Thanks again -- rac

In reply to Robin Cruz

Re: How can I get "All real numbers" with contextInequalities?

by Davide Cervone -
This is a nice try, but there is a problem with it. The alias directive can only be used as an alias for items of the same type. I.e., a string alias can only be for another string, not a constant. It is an interesting idea, though, and I'll think about it.

If you want "All real numbers" to be equal to (-inf,inf), then you need to make "All real numbers" be a constant, not a string. That would be

    Context()->constants->redefine("All real numbers",from=>"Interval",using=>"R");
The problem is that constant names are not allowed to contain spaces. So in order to do this, you need to change the allowed constant names first:
    Context()->constants->{namePattern} = qr/.*/;
    Context()->constants->redefine("All real numbers",from=>"Interval",using=>"R");
This first line allows names to be anything (any string of any characters). Note, however, that this is case-sensitive, and that students could use this just as they could (-inf,inf), so could make formulas that include "All real numbers", as in
    1 < x or  all  real  numbers

Alternatively, you can make "All real numbers" into a string

    Context()->strings->add("All real numbers"=>{});
(which will be case-insensitive), and use "All real numbers" when that is the correct answer. Students can enter a string without an error message (though it will be marked incorrect). When it is the correct answer, however, you may want to add typeMatch=>"Interval" to the cmp() call in order to get the proper type checking on the student's answers.

Hope that helps.

Davide