WeBWorK Problems

reduced fractions as the coordinate of a point

reduced fractions as the coordinate of a point

by Richard Lynch -
Number of replies: 2
Hello All! So we've covered forcing reduced fractions in lists and in intervals. How about points? I think it will be something similar as done in the case of intervals and we'll have to do  

  Context()->parens->set(
    '(' => {type => 'Point'},
  );
  Context()->{precedence}{Fraction} = 2.5;

or something to keep points in the fraction context. Also, this is going to be used for intercepts of a function, so there may be multiple points. So what happens if I want to put the points in a list and force reduced fractions? I have no idea how to program the custom checker in either case. Any help is very much appreciated! Thanks!!
In reply to Richard Lynch

Re: reduced fractions as the coordinate of a point

by Davide Cervone -
The custom checker is actually exactly the same as the one from the list of intervals case. Here is an example:
    Context("Fraction-NoDecimals");
    Context()->{precedence}{Fraction} = 2.5;
    Context()->parens->set('(' => {type => "Point"} );
    Context()->flags->set(reduceFractions=>0);

    $List = List("(1,2/5),(3/4,2)");

    Context()->texStrings;
    BEGIN_TEXT
    \( $List \) = \{ $List->ans_rule(20) \}
    END_TEXT
    Context()->normalStrings;
    
    ANS($List->cmp(
      checker => sub {
        my ($correct, $student, $ans, $nth, $value) = @_;
        $student->context->setError("Your $nth $value contains an unreduced fraction","",undef,undef,$Value::CMP_WARNING)
          if $student->{notReduced};
        return 0 unless $correct == $student;
        my $reduced = 1;
        foreach $x ($student->value) {
          if (Value::classMatch($x,'Fraction') && !$x->isReduced) {
            $reduced = 0;
            break;
          }
        }
        $student->{notReduced} = 1 unless $reduced || $ans->{isPreview};
        return $reduced;
      }
    ));
In reply to Davide Cervone

Re: reduced fractions as the coordinate of a point

by Richard Lynch -
Hi Davide, I know you answered a long time ago, but I want to say thanks! It works perfectly.