restart: with(Maplets[Elements]): with(Maplets[Tools]): with(combinat): StartEngine(); lightorange:="#FFB300": randomize(): great := [ " Bullseye. ", " Right on the mark. ", " Great. ", " That's absolutely right. ", " Awesome. You're unstoppable. ", " Correct. ", " WOW, nailed that one. ", " You got it! ", " YES! Right on. ", " Way to go. ", " Don't stop now. ", " I knew you could do it! ", " Perfect. You're unstoppable. ", " Radical Dude. ", " Power house. ", " Sweet! Keep on Rockin'. ", " You rock! ", " You got those mad skills. ", " Awesome! ", " Wowzers! That was great! ", " Awesome man! ", " Good job! You really know what you are doing. ", " You're awesome kid. ", " Tearing it up. ", " Right on the money. ", " High Five!!!!! ", " Cool Beans. ", " What a nerd! ", " You're so money. ", " You're a genious. ", " You hit the nail on the head. ", " Excellent! ", " If I had a cookie, I'd give it to you. ", " You're a winner. ", " That's a winner. ", " Whoop! Way to go. ", " That's the way, ah ha ah ha, I like it. ", " Oh yeah! ", " You're the bomb! ", " That was fantastic! ", " Oh Snap! ", " That's krunk! " ]: randgreat := rand(1..nops(great)): nextquest := [ "Keep it up.", "Keep going.", "On to the next function.", "Find another partial fraction expansion.", "Find another partial fraction decomposition.", "Expand another function.", "Decompose another function." ]: randnext := rand(1..nops(nextquest)): sorry := [ " Sorry, that's not right. ", " Nope, but don't give up. ", " Not quite, it's a little off. ", " Bummer, thought you would get it this time. ", " Close, but no cigar. ", " Slightly off. ", " If you need help, please ask a human. ", " I don't know where you went wrong. ", " Sorry, killer problem. ", " No, but don't blow it off. ", " D'oh! ", " That's whack. ", " Yikes! Really close. You'll get it next time. ", " Pucha! Thought you would get it this time. ", " Nice try, but your answer is wrong. ", " Ask your neighbor for help. ", " Brutal kid. ", " That won't fly. ", " So close and yet so far. ", " So, that was just practice. ", " Ooooh...close. ", " A swing and a miss. ", " Better luck next time. ", " Oops. ", " Tilt. Play again. ", " I know you can do better. ", " Sorry Charlie. ", " Better luck next time. ", " Tisk, tisk. It's a tough one. ", " It takes a lot of wrongs to make a right. ", " Even Einstein didn't get everything right. ", " Oh man, you were so close. ", " Today's not your lucky day. ", " Don't quit your day job. ", " You're colder than a polar bear's toenail. " ]: randsorry := rand(1..nops(sorry)): tryagain := [ "Try the hints.", "Fix your answer and check it again.", "Give it another try.", "Try again.", "Please try again." ]: randtry := rand(1..nops(tryagain)): showit := [ " OK That's just practice. But try doing it yourself.", " That's fine for practice. Try doing it yourself.", " Think about it and enter an answer yourself.", " Next time, try the hints.", " Next time, compute an answer yourself.", " So that was practice. Try doing it yourself." ]: randshow := rand(1..nops(showit)): rand13:=rand(1..3): rand14:=rand(1..4): rand02:=rand(0..2): rand03:=rand(0..3): randm22:=rand(-2..2): as:=[$-5..5]: bs:=[$-5..5]: nbs:=nops(bs): #if completing the square cs:=[$1..9]: ncs:=nops(cs): bcs1:=[seq(seq([b,c],b=bs),c=cs)]: #if completing the square bcs0:=[seq( [0,c], c=cs)]: #if not completing the square ps:=[$0..4]: qs:=[$0..4]: F:=(s,t) -> evalb(s[1] evalb(s[1]4 do nlinf,nquadf := rand03(), rand02(): end do: af:=randperm(randcomb(as,nlinf)); #if Get(CBCompSq) then # CompSq:=true; # bcf:=randperm(randcomb(bcs1,nquadf)); #else CompSq:=false; bcf:=randperm(randcomb(bcs0,nquadf)); #end if; nterms:=8; while nterms>6 do tot:=7: while tot>5 do pf:=[seq(rand13(), i=1..nlinf)]; qf:=[seq(rand13(), j=1..nquadf)]; tot:=add(pf[i],i=1..nlinf)+add(qf[j],j=1..nquadf); end do; ap := [seq( seq( [af[i] ,k], k=1..pf[i]), i=1..nlinf)]; bcq := [seq( seq( [bcf[j][],k], k=1..qf[j]), j=1..nquadf)]; nlin:=nops(ap); nquad:=nops(bcq); decomp:=add( A[i]/(x-ap[i,1])^ap[i,2], i=1..nlin) + add( (B[j]*(x-bcq[j,1])+C[j])/( ((x-bcq[j,1])^2 + bcq[j,2]) )^bcq[j,3], j=1..nquad); n:=0; for i to nlinf do for k to pf[i] do n:=n+1; if k=pf[i] then Av[n]:=op(randcomb([-2,-1,1,2], 1)); else Av[n]:=randm22(); end if; end do; end do; n:=0; for j to nquadf do for k to qf[j] do n:=n+1; if k=qf[j] then Bv[n]:=op(randcomb([-2,-1,1,2], 1)); Cv[n]:=op(randcomb([-2,-1,1,2], 1)); else Bv[n]:=randm22(); Cv[n]:=randm22(); end if; zeroout:=rand13(); if zeroout=1 then Bv[n]:=0; elif zeroout=2 then Cv[n]:=0; end if; end do; end do; decomp2:=subs(seq(A[i]=Av[i], i=1..nlin), seq(B[j]=Bv[j], j=1..nquad), seq(C[k]=Cv[k], k=1..nquad),decomp); #RIGHT HAND SIDE INTEGRAND func:=simplify(decomp2); num:=sort(expand(numer(func))): den:=denom(func); nterms:=nops(num); func:=num/den; #LEFT HAND SIDE INTEGRAND end do; Set('MMLintegral' = MathML[Export](Int(func,x))): Set('Answer' = ""): Set('reply' = "", reply(background)=white): Set('MMLAnswer' = ""): end proc: Expand_Integral:=proc() global decomp2, func; Set('MMLintegral' = MathML[Export](Int(func,x)=Int(decomp2,x))); Set('MMLAnswer' = MathML[Export](Int(decomp2,x)="?")); end proc: Type_One:=proc() Set('HintBox' = "Use the substitution u = x - a.\n\nRemember Int(1/u du) = ln(u) + C\nand Int(1/u^n du) = u^(-n+1)/(-n+1) + C"); end proc: Type_Two:=proc() Set('HintBox' = "Use the substitution u = x^2 + c.\n\nRemember Int(1/u du) = ln(u) + C\nand Int(1/u^n du) = u^(-n+1)/(-n+1) + C"); end proc: Type_Three:=proc() Set('HintBox' = "Use the trig substitution x = b * tan(theta)."); end proc: Check_Answer:=proc() global decomp2; local useranswer, check; useranswer:=Maplets:-Tools:-Get('Answer'::algebraic); check:=normal(simplify(diff(useranswer,x)-decomp2)); Set('MMLAnswer'=MathML[Export](Int(decomp2,x)= useranswer)): if check=0 then Set('reply' = great[randgreat()], reply(background)=green, 'reply'(foreground) = black); else Set('reply' = sorry[randsorry()], 'reply'(background) = red, 'reply'(foreground) = white); end if; end proc: Show_Answer:=proc() global decomp2; options `Copyright 2005, Philip B. Yasskin, Texas A&M Univ.`; Set('MMLAnswer'=MathML[Export](Int(decomp2,x)= int(decomp2,x))): Set('Answer'=int(decomp2,x)): Set('reply' = showit[randshow()], reply(background)=lightorange, 'reply'(foreground) = black): end proc: Preview:=proc() global decomp2; local useranswer; options `Copyright 2005, Philip B. Yasskin, Texas A&M Univ.`; useranswer:=Maplets:-Tools:-Get('Answer'::algebraic, corrections=true, update=true); Set('MMLAnswer'=MathML[Export](Int(decomp2,x)= useranswer)): Set('reply' ="", reply(background)=white, 'reply'(foreground) = white): end proc: ParFracEvalInteg := Maplet(onstartup = RunWindow(MAIN), Font[helv10]("helvetica",10), Window[MAIN]( 'title'="Partial Fractions: Evaluating the Integral", 'defaultbutton'='Preview', BoxColumn(halign=none, background=wheat, BoxRow( inset=0, spacing=0, background=wheat, Button['Bnew']("New Integral", 'onclick'=Evaluate(function=NewFunction), background=turquoise), CheckBox[CBCompSq]("Require Completing the Square", background=wheat, visible=false), Button("Specify Function", 'onclick'=Evaluate(function=SpecifyFunction), visible=false, background=turquoise), HorizontalGlue(), Button("Hints", 'onclick'=RunWindow(HINTS), background=wheat), Button("Quit",Shutdown(), background=pink) ), BoxRow(halign=none, background=wheat, inset=0, spacing=0, BoxColumn(halign=none, background=wheat, BoxRow( border=true, inset=0, spacing=0, background=wheat, caption="Goal: Compute an Integral using a Partial Fraction Expansion:", MathMLViewer['MMLintegral'](value=MathML[Export](Int(f(x),x) = " "),height=100, width=500) ), BoxRow( border=false, background=wheat, "Enter the integral:", TextField['Answer'](background=white, width=50) ), BoxRow( border=true, inset=0, background=wheat, caption="Preview appears here:", MathMLViewer['MMLAnswer'](value=MathML[Export](Int(f(x),x) = " "), height=150, width=500) ) ), BoxColumn(halign=none, background=wheat, VerticalGlue(), Button['Expand']("Expand", Evaluate(function=Expand_Integral), background=wheat, enabled=true), VerticalGlue(), Button['Preview']("Preview",Evaluate(function=Preview), background=wheat, enabled=true), VerticalGlue(), Button['BCheck']("Check", Evaluate(function=Check_Answer), background=wheat, enabled=true), Button['BShow']("Show", Evaluate(function=Show_Answer), background=wheat, enabled=true), VerticalGlue() ) ), BoxRow( background=wheat, HorizontalGlue(), TextField['reply'](background=white, width=50), HorizontalGlue(), HorizontalGlue() ), BoxRow('background'="#DDFFFF", 'inset'=0, 'spacing'=0, Label("Programmers: Rechard and Smith", 'font'=helv10), HorizontalGlue(), Label("Copyright 2006, D.B. Meade and P.B. Yasskin", 'font'=helv10), HorizontalGlue(), Label("v. 1.2a Sept 2006", 'font'=helv10) ) )), Window[HINTS]( 'title'="Hints", BoxColumn(background=wheat, halign=none, BoxRow(background=wheat, "Click on the form of the term:" ), BoxRow(background=wheat, HorizontalGlue(), Button['Second'](" . . A\n---------\n(x-a)^n", Evaluate(function=Type_One), background=wheat, enabled=true), Button['Fourth'](" . . . B x\n-------------\n(x^2+c)^m", Evaluate(function=Type_Two), background=wheat, enabled=true), Button['Sixth'](" . . . C\n-------------\n(x^2+c)^m", Evaluate(function=Type_Three), background=wheat, enabled=true), HorizontalGlue() ), BoxRow(background=wheat, TextBox['HintBox']("",background=white, height=4,width=50) ) ) ) ): Maplets[Display](ParFracEvalInteg);