help with pattern matching

3 views
Skip to first unread message

Julia Goedecke

unread,
Nov 10, 2022, 4:57:08 AM11/10/22
to Numbas Users
Hello,
I'm struggling to work out a correct pattern matching.

I want students to factorise a polynomial (in this case with complex
factors). So that they can't just write down the unfactorised
polynomial, I have pattern matching. It works well for real factors, but
I can't get it to work for complex factors.

I'm currently trying
(x+ `+- complex:$n)(x+ `+- complex:$n) `| (x- `+- complex:$n)(x-`+-
complex:$n) `| (x+`+- complex:$n)(x-`+- complex:$n)

but it does not accept for example (x-4i)(x+4i) nor things like
(x-(3-2i))(x-(3+2i)), with or without brackets around the complex number.

I've tried also the equivalent combinations with (x+ '+- $n) and with
(x+ ?) and I can't get anything to work.

Julia
--
www.julia-goedecke.de

Julia Goedecke

unread,
Nov 10, 2022, 9:00:44 AM11/10/22
to Numbas Users
Ok, I've worked it out now... I just put (x + ?)(x + ?) `| (x+ ? + ?)(x+
? + ?)

(You can tell I do not fully understand pattern matching and am always
quite confused whether I have to put + and - as options or not... but
this works also with negative numbers at the question mark, so I could
get rid of many of my cases, and just have this extra case for when it
is a complex number with real and imaginary part.)

Julia
Reply all
Reply to author
Forward
0 new messages