WeBWorK Main Forum

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

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

by Davide Cervone -
Number of replies: 0
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.