Skip to content

Sig fig context#1474

Open
pstaabp wants to merge 20 commits into
openwebwork:PG-2.21from
pstaabp:sig-fig-context
Open

Sig fig context#1474
pstaabp wants to merge 20 commits into
openwebwork:PG-2.21from
pstaabp:sig-fig-context

Conversation

@pstaabp

@pstaabp pstaabp commented Jul 21, 2026

Copy link
Copy Markdown
Member

This creates a context for Significant Figures and huge thanks to @dpvc for all the help and @sfiedle1 for ideas, code and other suggestions.

In short, this handles the creation of a number type that keeps track of the number of its significant figures. Although the number is stored as a floating point, the string method rounds to the appropriate number of significant figures.

Here are a few features:

  • The operations +, -, *, /, ^ are all defined with operations between SigFig numbers. See Sig fig improvements pstaabp/pg#25 for a post from @dpvc about thoughts about this.
  • There is ability to define a number with infinite number of significant figures. This would allow an operation like 1.23^3 to result in an expected number with 3 sigfigs instead of 1, since 3 only has 1 sig fig.
  • There are two flags that allow authors to specify some partial credit as well as informational messages if a student answer is either close to the real answer with correct number of sig figs OR the correct answer with an incorrect number of sigfigs. Note: I think these flags can use some better names.
  • There is a LimitedSignificantFigures context which disallows computations similar to other contexts.
  • Using the contextExtensions.pl macro, problems using both SignificantFigures and Units can be used together.

There are two test suites. significant_figures.t tests only numbers and operations between numbers. significant_figures_units.t includes some simple tests for numbers with units.

I have attached 4 sample problems.

  1. This has addition, subtraction and multiplication of 2 numbers.
  2. This has a basic number with units.
  3. This shows the two flags mentioned above.
  4. An example with the LimitedSignificantFigure context.

setsig_fig.zip

If we can get this into 2.21, that would be great. It doesn't affect anything else. If not, I'll retarget to develop.

Also, for historical purposes, there is other discussion: pstaabp/pull/25 pstaabp/pull/32, pstaabp/pull/34 and pstaabp/pull/36

@dpvc

dpvc commented Jul 22, 2026

Copy link
Copy Markdown
Member

One thing to note is that this context only handles constant computations, not formulas involving significant figures. That can be added later, but will take more work that hasn't been done yet.

Similarly, as Peter mentions, the current context only supports addition, subtraction, multiplication, division, and powers. So other functions, like trigonometric functions, logs, roots, etc., aren't yet implemented. The comments that I made that Peter links to above give one approach that could be taken for such functions.

A full significant figures context should handle these other situations, but this is certainly useful as it stands.

@pstaabp

pstaabp commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

@dpvc I think the use case that @sfiedle1 had originally was only for computations, but will look into extending to Formulas and also adding additional functions.

pstaabp and others added 20 commits July 23, 2026 10:16
This includes flags for determining if a problem is to check to see if an answer has the correct # of sig figs and/or is close and give partial credit.
when using the extension with Units context and added a test for units with significant figures.
Also fixed an issue with the testing for "closeness" between student and correct sigfig answers.
Also, some improvements to language on tests.
And add in a test for partial credit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants