Pattern matching for exactly one x

5 views
Skip to first unread message

Adam Povey

unread,
Aug 20, 2025, 7:34:44 AMAug 20
to Numbas Users
Can anyone help me work out the regex for "one and only one x"?

Specifically, I have a question where I want to force students to simplify `(1 + x/sqrt(1+x^2)) / (x + sqrt(1+x^2))` but I haven't found something that will accept all of,
`(1+x^2)^(-1/2)`
`1/(1+x^2)^(1/2)`
`1/sqrt(1+x^2)`

Sorry,
Adam

Christian Lawson-Perfect

unread,
Aug 26, 2025, 5:33:05 AMAug 26
to numbas...@googlegroups.com
That's a tricky one! I assume you'd also accept `sqrt(1+x^2)^-1`, but you don't like `sqrt(1+x^2)/(1+x^2)`, which is what you get by 'rationalising the denominator'? 

I'd be inclined to prompt the student with something like "write your answer in the form "1/sqrt(f(x))", and just ask for the "f(x)". Otherwise, explaining what you will and won't accept will be very difficult, never mind working out how to get the pattern matcher to do it for you.

--
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, visit https://groups.google.com/d/msgid/numbas-users/a7882fa3-269c-471b-919d-15e169c0c648n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages