unexpected behaviour when precision restriction not set in marking settings

12 views
Skip to first unread message

merryn....@gmail.com

unread,
May 22, 2022, 11:48:37 PM5/22/22
to Numbas Users
I have  a question set up with a number entry gap.
The question asks students to evaluate a number to a decimal power and give the answer to 1 d.p.

The minimum and maximum accepted value for the number entry are:

precround(base4^index4,1)

For some combinations of base and index, this was not accepting the correct answer: see the following screenshot:
image1.png
You can see that the minvalue and the maxvalue are unexpectedly not numbers to 1 d.p.

We found that setting the precision restriction to 1 digit in the marking settings fixed the problem:
image2.png
I am puzzled about why the precision restriction affected the expected answer, that was already specified to be rounded to 1 d.p. I had also tried forcing the expected answer to decimal type, both decimal(precround ...), and precround(decimal(...),1), but neither of these made it work without setting the precision restriction.

Christian Lawson-Perfect

unread,
Jun 6, 2022, 5:56:04 AM6/6/22
to numbas...@googlegroups.com
Can you give a link to the question on the editor, please?

(Sorry for the slow reply - I just found this in my spam folder!)

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/numbas-users/43b0c670-335f-4765-8421-5b15436a3444n%40googlegroups.com.

merryn....@gmail.com

unread,
Jun 7, 2022, 5:14:37 AM6/7/22
to Numbas Users
Sure, thanks Christian.


It is Part b, gap 2b) (evaluate, using a calculator, (b)).
I have set the base and index variables to 4 and 7.9, which is one pair that causes it to break.

merryn....@gmail.com

unread,
Jun 21, 2022, 2:19:30 AM6/21/22
to Numbas Users
Hi Christian,


Regards,

Merryn

Christian Lawson-Perfect

unread,
Jun 28, 2022, 8:36:12 AM6/28/22
to numbas...@googlegroups.com
I've finally had a moment to look at this. Thanks for your patience.

The problem here is that a small floating-point error is introduced during the calculation, because of the way that numbers are represented internally. For historic reasons, Numbas uses javascript's built-in floating-point number representation by default. This can only be relied on to be accurate to about 15 significant figures.
In order to account for this, Numbas adds a bit of "wiggle room" to the minimum and maximum accepted values for number entry parts. Until now, this was a fixed value of 10^-12. When the given values are big, this difference can't be represented in floating-point, so the value stays incorrect. Numbas then converts the values to the more precise "decimal" representation, which can tell such small differences. So when you give as your answer the correct value, Numbas says it's not the value it was expecting, which has a small error added on, so says it's wrong.
The reason it works when you turn on the "decimal places" precision restriction is that this forces Numbas to round off both student and expected values in the decimal format, ensuring they're equal.
I've changed the logic so that the size of the wiggle room depends on the size of the original number: for a number on the order of 10^n, the wiggle room will be 10^(n-12).

Everything about this is unsatisfying: ideally, there'd be no rounding errors at all, and I wouldn't have to think about this. But exact arithmetic is very slow, and has its own set of complications.
(If anyone is interested, I have actually ported an exact constructive real arithmetic library to javascript, and there's an item on the to-do list to integrate it with Numbas: https://github.com/numbas/Numbas/issues/893)

Merryn Horrocks

unread,
Jun 29, 2022, 5:04:51 AM6/29/22
to numbas...@googlegroups.com
Thanks for taking the time to explain this Christian. That all makes perfect sense.

You received this message because you are subscribed to a topic in the Google Groups "Numbas Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/numbas-users/jcyO85H75PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to numbas-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/numbas-users/CAEMHSOjO%3DwKAd362RPgnHoLDa%3DKboFo2WwLtW%2BxNfBqhDjxphA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages