# Checking Math Input for Correct Rational Expression

**URL:** <https://cl.desmos.com/t/checking-math-input-for-correct-rational-expression/2829>\
**Category:** Questions\
**Tags:** validation, correctness\
**Created:** [March 4, 2021, 4:25pm UTC](https://cl.desmos.com/t/checking-math-input-for-correct-rational-expression/2829 "2021-03-04T16:25:46Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [March 4, 2021, 6:17pm UTC](https://cl.desmos.com/t/checking-math-input-for-correct-rational-expression/2829/3 "2021-03-04T18:17:31Z")

</div>

The more complicated (but stable) method is to evaluate a function AND check that certain numbers were used (since you’re looking for a particular format), so for your example above:

```auto
#student expression
exp=this.latex
#student input as a function
f=simpleFunction(exp)
check= f.evaluateAt(3)=0 and f.evaluateAt(2)=-0.2
    and countNumberUsage(exp,3)=1 and countNumberUsage(exp,2)=1
    and countNumberUsage(exp,1)=1

```

You want to evaluate at as many values you feel is adequate. I only did a few but you can add more. `countNumberUsage` counts the occurrence of a particular number (not digit) in an expression. It does not take negatives. So, both -2x and 2x would count one 2, but evaluating the expression takes care of ambiguity.

You do need to consider if you want to accept a student writing “1x”, so you may want:

```auto
... and (countNumberUsage(exp,1)=1 or countNumberUsage(exp,1)=2)

```

---

_[View the full topic](https://cl.desmos.com/t/checking-math-input-for-correct-rational-expression/2829)._
