STACK - expand/factor question

STACK - expand/factor question

by r k -
Number of replies: 5

Hello

I want to check whether a term was expanded correctly.

For example: \( (x+1)^2 \) should be written as \( x^2+2x+1 \).

I would like to have an answer like  \(x^2+x+x+1 \) rated incorrect. There should be as few summands as possible.

So far my PRT looks like this: see attachment below.


Analogously when factoring a term, e.g. \( 2x^2-2 \) should be written as \( 2(x-1)(x+1) \).

A term with fewer factors should be evaluated as incorrect. There should be as many factors as possible.

How do I do that?

Attachment attachment1.png
Average of ratings: -
In reply to r k

Re: STACK - expand/factor question

by Stephan Bach -
Hi,
in both cases you can use the answer test EqualComAss to compare the student answer and the teachers answer. The teachers answer could then be expand(ex1) respectively factor(ex1) if ex1 is the expression to be expanded or factorised.
It is also possible to use the answer tests Expanded or FacForm for the form of an expression. These will provide additional feedback but will condone if (sub-) expressions are not simplified, e.g. \(x^2+x+x+1\) or \( (1+1)(x-1)(x+1)\).
It might be a good idea to use both EqualComAss and Expanded/FacForm in different knots of your prt.
Stephan
In reply to Stephan Bach

Re: STACK - expand/factor question

by r k -
Hi Stephan

Thanks for the prompt reply.

The conversion to a sum works now as desired (with Expanded and EqualComAss).

Factoring: What exactly has to be entered in the "FacForm" test options? I can't find any good information on this.

Thanks for your help
René

In reply to r k

Re: STACK - expand/factor question

by Stephan Bach -
Hi René
it's just the variable, in your case \(x\). You can find all of this in the docs or on GitHub.
Stephan
In reply to Stephan Bach

Re: STACK - expand/factor question

by r k -
Hello Stephan

Thanks for your help and the link to the documentation.

As far as I can tell, the factorisation now works in principle.

However, \( 2\cdot x^2-2 \) (`ex1`) is corrected as wrong when written as \( (-2)\cdot(-x+1)\cdot(x+1) \) (`ans1`). Is it somehow possible
i) to recognise whether `ans1` is a product and
ii) `ans1` consists of at least `factor(ex1)` factors?

This would then correct answers like \( (-2)\cdot(-x+1)\cdot(x+1) \) or \( (-1)\cdot2\cdot(1-x)\cdot(x+1) \) as correct.

Possibly with something like `length(part(factor(ex1)));`.
In reply to r k

Re: STACK - expand/factor question

by Stephan Bach -
Hi,
FacForm should accept \( (-2)\cdot (-x+1)\cdot (x+1)\), EqualComAss will not.
Of course you could use something like is (safe_op(ans1)="*") to determine if ans1 is a product and length(args(ans1)) to count the factors. But you would have to deal with many different cases if you want to implement this in your feedback variables (\(2\cdot \left(\frac 1 2\right) \cdot (2 x^2 - 2)\) is a product with 3 factors, too.).
Depending on what you want, it's probably easier and more robust to use EqualComAss to first check on \( 2\cdot (x-1)\cdot (x+1)\) and if false also on \( (-2)\cdot (-x+1)\cdot (x+1)\).
Stephan