[LON-CAPA-users] Simplifying polynomial expressions

Seema Ali sali at vsb.bc.ca
Wed Nov 7 23:52:46 EST 2012


Sorry for the emails.  I figured it out.

>From Seema.
________________________________________
From: lon-capa-users-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Seema Ali [sali at vsb.bc.ca]
Sent: 07 November 2012 17:40
To: Discussion list for LON-CAPA users
Subject: Re: [LON-CAPA-users] Simplifying polynomial expressions

I'm having problems trying to extract info from Maxima in the custom response.

Assume:
$submission = "3a + b - c";
$answer = "3*a + b - 1.0*c";

I have the following Perl lines:
$equivalent = &cas('maxima', "is(trigsimp($submission-$answer)=0)");
if($equivalent eq "true" ){ return 'EXACT_ANS'; }

I'm not sure what I'm doing wrong, it worked (under possibly different $submission and $answer values) in the Perl Script section, before my HTML/Text portion of the problem. I even tried entering the same text as $answer and it was still marked incorrect.

Is there a better way to find out if 2 expressions are equivalent with Maxima and Perl?

Thanks.

>From Seema.
________________________________________
From: lon-capa-users-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Seema Ali [sali at vsb.bc.ca]
Sent: 06 November 2012 14:47
To: Discussion list for LON-CAPA users
Subject: Re: [LON-CAPA-users] Simplifying polynomial expressions

Hmmmm. I had a feeling this wasn't going to be easy.

Maxima does like to simplify the expression right away.  So I might have to try Michael's suggestion.  How do I get the Lon Capa response into a Perl Script? I would still like to use Maxima to check for equivalent expressions.

Thanks for all the feedback.

>From Seema.

________________________________________
From: lon-capa-users-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Peter Riegler [p.riegler at ostfalia.de]
Sent: 06 November 2012 09:19
To: lon-capa-users at mail.lon-capa.org
Subject: Re: [LON-CAPA-users] Simplifying polynomial expressions

We usually do this kind of problems by parsing the expression with
maxima's op command. The idea is, once you have a parsing tree, you can
ask questions like these: Is there only one plus in the expression and
is it the highest level operation? Is the depth of the parsing tree not
larger than we want it to be?

However, all this might not work for rather simple (i.e. purely
algebraic) expressions like
3a + 2b - 4a + 6b
as maxima might internally simplify that before parsing the expression.

I hope this helps.

Peter


On 06.11.2012 13:10, Michael Dugdale wrote:
> A thought (probably not a good one) -- couldn't you do a check of the
> response string with perl to count the number of occurrences of the
> variable?  Count that each variable appears no more than once before
> sending it to maxima?
>
>
>
> Sent from my mobile phone, so please forgive any spehling errers.
>
> On 2012-11-05, at 23:12, "Seema Ali" <sali at vsb.bc.ca
> <mailto:sali at vsb.bc.ca>> wrote:
>
>> I'd like to create dynamic polynomial questions that require students
>> to simplify them. I was wondering how to do I check to see if the
>> students actually entered a simplified version of the expression, but
>> keep it still free enough to allow the order of terms to be different.
>>
>> For example:
>> 1. 3a + 2b - 4a + 6b
>> Students could enter: -a + 8*b, or 8*b - a, or -1*a + 8*b, or 8*b +
>> -a, etc for it to be correct.
>> I'm concerned that a student could also enter equivalent unsimplified
>> responses like:
>> 3*a + 2*b - 4*a + 6*b or -a + 2b + 6b and still have it marked correctly.
>>
>> I'd like to create a variety of short answer polynomial questions, but
>> I'm not sure how much work it will be.
>>
>> The code below contains an example with a,b,c variables. It creates
>> polynomials and it marks it correct if the answer entered is
>> equivalent to the question, not necessarily the simplified form.
>>
>> Any insight on this will be appreciated.
>>
>> <problem>
>> <script type="loncapa/perl">$coeff_a1 = &random(-1,1,2)*&random(2,10,1);
>> $coeff_a2 = &random(-1,1,2)*&random(2,10,1);
>> $coeff_b1 = &random(-1,1,2)*&random(2,10,1);
>> $coeff_b2 = &random(-1,1,2)*&random(2,10,1);
>> $coeff_c1 = &random(-1,1,2)*&random(2,10,1);
>> $coeff_c2 = &random(-1,1,2)*&random(2,10,1);
>>
>> $answer = &cas('maxima', "$coeff_a1*a + $coeff_b1*b + $coeff_c1*c +
>> $coeff_a2*a + $coeff_b2*b + $coeff_c2*c");
>>
>> $answershow = &xmlparse($answer);</script><startouttext />Simplify.
>> <m eval='on'>
>> \[\Large
>>    $coeff_a1 a + $coeff_b1 b + $coeff_c1 c + $coeff_a2 a + $coeff_b2 b
>> + $coeff_c2 c
>> \]
>> </m>
>>
>> $answershow
>> <br />
>> Answer:<endouttext />
>> <mathresponse cas="maxima" answerdisplay="$answer" args="$answer">
>>     <answer>f(x) := RESPONSE[1];
>> g(x) := LONCAPALIST[1];
>> is(trigsimp(f(x)-g(x))=0);</answer>
>>     <textline readonly="no" />
>>     <hintgroup showoncorrect="no">
>>         <startouttext />
>>
>>         <endouttext />
>>     </hintgroup>
>> </mathresponse>
>> </problem>
>>
>>
>>
>> Thanks.
>> <ATT00001..c>
>
>
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users at mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>

--
Peter Riegler
Ostfalia Hochschule für angewandte Wissenschaften
Hochschule Braunschweig/Wolfenbüttel
Salzdahlumer Str. 46/48
38302 Wolfenbüttel

Fakultät Informatik
Fon: ++49 5331 939 31540
http://public.rz.fh-wolfenbuettel.de/~riegler

Zentrum für erfolgreiches Lehren und Lernen
Fon: ++49 5331 939 17200
http://www.ostfalia.de/zell

_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users


More information about the LON-CAPA-users mailing list