(Redirecting to -dev)
As long as we are dreaming, here's what I would probably like to see. I hope I'm not stepping on too many toes. And there’s probably a ton of things I’m missing.
I think the bottom line is I like Rob’s suggestion for using some existing computation engine and would like to see the idea hashed out more. Though I would rather not limit the computation engine/language.
1. First a suggestion for a #context block that can go almost anywhere and is used to define a dictionary-map of name-value pairs, with values randomly generated or specific. It has an associated label used to reference it from elsewhere. Then #var entries can be used to get its values. An alternative to this would be a "setup" block to be delegated to the API described below, but to be ran on problem generation (i.e. when user views page, not when answering). I think this can have usefulness aside from this particular use-case.
2. The #evaluation tag gets a @language attribute and an @api attribute. Language can be anything and is simply passed to the API (with one exception below). The API is either a direct https link or a name for a link defined in the configs. A @context may also be specified.
3. PreTeXt does not specify or provide any APIs, but perhaps provides an in-browser javascript (possibly also python?) implementation. I.e. if language is js and no api is provided, we handle it in-browser.
4. An optional <code> block inside evaluation, for code to be run on user submission.
5. Each #evaluate -> #test can contain #apiobj whose body (or @value) is a boolean-evaluating expression in the language.
6. The API is given a json document containing the language, the context, the code block, and an array of the #apiobj test expressions. It is expected to "evaluate the code block and each test expression in the provided context and return the results of the test expressions".
7. I think that the PreTeXt team should be minimal in just specifying the form of the API request/response format, and not try to actually implement any APIs, beyond any in-browser things.
Here's the overall format I am envisioning:
<exercise>
<context label="..." seed="..">
<!-- Optional new thing, based on RNG work? Allows the creation of a context of RNG- or specific values --!>
<!-- To be accessed using <var ...> elsewhere --!>
<!-- Seed provided for static version or generated. --!>
<rng name="b" /> b set to random in [0,1] (type="double" implicit)
<rng name="c" type="integer" min=0 max=5 />
<rng name="d" type="double" min=3 max=4 />
<const name="foo" type="string" value="A fixed name here" />
</context>
<statement>
... use <fillin name="a" /> <-- entry by user, always named
... use <var context="..." name="b" /> <-- dynamically generated value provided by "context" above. Maybe use new <value> tag instead?
</statement>
<evaluation language="js" api="..." context="...">
<code>
... Code ran by the API on user submission.
... Receives as "local variables" the vars from context.
</code>
<evaluate>
<test>
<apicmp> ... expression in the language ... </apicmp>
</test>
<test> ... </test>
</evaluate>
</evaluation>
</exercise>
API request:
{
language: ...,
context: { seed: ..., b: ..., c: ... },
code: "...from <code> block...",
tests: ["testcode1", "testcode2", ...]
}
The API is responsible for placing the context appropriately in the code so they are local variables, and to add the testcode blocks and store their results.
API response:
{
success: true/false, // True if all tests passed
tests: [ true, false, false, ...] // Answer for each test.
}
Example (with context):
<exercise>
<context label="modulo">
<rng name="a" type="integer" min="12" max="20" />
<rng name="b" type="integer" min="4" max="8" />
</context>
<statement>
Compute the modulo: <var context="modulo" name="a" /> modulo <var context="modulo" name="a" /> equals <fillin name="c" />.
</statement>
<evaluation language="js" context="modulo">
<!-- No code needed--!>
<evaluate><test><apicmp> c == a % b </apicmp></test></evaluate>
</evaluation>
</exercise>
Charilaos Skiadas
Department of Mathematics
Hanover College
Begin forwarded message:
Subject: Re: [pretext-support] dynamic fill-in exercise allowed operations
Date: January 22, 2026 at 12:08:31 AM EST
Nothing here should be construed as minimizing Hunter's request.
The possible requests for supported operators is vast. How about polynomial multiplication with coefficients over a finite field? ;-) Yes, I know, out of scope right now.
Years ago, the WeBWorK folks added for me a function to pass computations to Sage and get back the results. It was a bit cumbersome to use (nobody's fault). Suppose there was a dedicated Sage Cell server that FITB problems could utilize? Imagine randomized questions about non-commutative rings for an abstract algebra course.
Not sure what markup, or much else, would look like. Just dreamin'.
Rob
On January 21, 2026 4:06:41 PM HST, "D. Brian Walton" <
dbrian...@gmail.com> wrote:
Hunter,
The mod operator has not been implemented. It could be possible but would
require a dependent package is updated and could take some time. Note that
the library was designed for floating point arithmetic, and I haven't
thought about what happens with the modulus. Also, there is no integer
division implemented.
I do need to get back to that and will see about implementing that operator.
Brian
On Wed, Jan 21, 2026 at 3:38 PM Hunter Lehmann <hlehm...@gmail.com>
wrote:
Hi,
I am trying to create a dynamic exercise to compute the Hamming weight of
a random vector in F_p^n, say with entries x_1,...,x_6 in {0,1,..p-1}. Is
it possible to use a mod operator somehow in the computation of dynamic
values in PreTeXT?
The computation I would like to do is (x_1^4+x_2^4+...+x_6^4) mod 5. I
tried using % to invoke the mod operator but that just breaks the code.
Current exercise code below also.
Best,
Hunter
<exercise xml:id="daily-prep-fp-hamming-weight">
<setup seed="123456">
<de-object name="x1" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="x2" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="x3" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="x4" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="x5" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="x6" context="number">
<de-random distribution="discrete" min="0" max="4" by="1" />
</de-object>
<de-object name="wt" context="number">
<de-number>(x1^4+x2^4+x3^4+x4^4+x5^4+x6^4)%5</de-number>
</de-object>
</setup>
<statement>
<p>
Compute the Hamming weight of <m>(<eval obj="x1"/>,<eval
obj="x2"/>,<eval obj="x3"/>,<eval obj="x4"/>,<eval obj="x5"/>,<eval
obj="x6"/>)</m>.
</p>
<p>
<fillin mode="math" name="hamming_wt" ansobj="wt"
width="4"></fillin>
</p>
</statement>
<evaluation>
<evaluate name="hamming_wt">
<test correct="yes">
<mathcmp obj="wt" />
</test>
</evaluate>
</evaluation>
</exercise>
--
You received this message because you are subscribed to the Google Groups
"PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to pretext-suppo...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/pretext-support/a06d053c-6eca-43e9-9aa9-abc0456b254cn%40googlegroups.com
<https://groups.google.com/d/msgid/pretext-support/a06d053c-6eca-43e9-9aa9-abc0456b254cn%40googlegroups.com?utm_medium=email&utm_source=footer>
.
--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
pretext-suppo...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/pretext-support/MTAwMDAyOC5iZWV6ZXI.1769058521%40pnsh.