Solver Factoring using the AC method (Factor by Grouping)
Algebra
->
Algebra
->
Polynomials-and-rational-expressions
-> Solver Factoring using the AC method (Factor by Grouping)
Log On
Ad:
Algebrator™
solves your algebra problems and provides step-by-step explanations!
Ad:
Algebra Solved!™
: algebra software solves algebra homework problems with step-by-step help!
Algebra: Polynomials, rational expressions and equations
Solvers
Lessons
Problems, free tutors
Quiz
In Depth
Source code of 'Factoring using the AC method (Factor by Grouping)'
This Solver (Factoring using the AC method (Factor by Grouping))
was created by by
jim_thompson5910(13794)
:
View Source
,
Show
,
Put on YOUR site
About jim_thompson5910
:
==section input Here is another way to factor quadratics. This solver will show you how to factor any quadratic by grouping. Enter integer (whole number) coefficients of the quadratic in the form {{{ax^2+bx+c}}} where c must not equal zero. For instance, to factor the quadratic {{{2x^2+8x+6}}}, let a=2, b=8, and c=6. a=*[input a=2] b=*[input b=8] c=*[input c=6] Now enter the variable of the quadratic *[input variable=x] note: I have not fully tested this solver (there might be a special case I have overlooked), so check your answer by foiling. If you come across an error, in either the answer or the step-by-step guide, please tell me about it. ==section solution perl my $count=0, $ac=$a*$c, @f, $max=0, $half=0, $size=0, $ab=0, $sum, @factor, $check=0, $flag=0, @foil, $opp, @gcf, @reduce, @negf, $ldiv=0, $rdiv=0, $finish, $path=0, $temp, $temp1, $temp2, $temp3, $counter=0, $divide=1, $opposite=1, $counter2=0, $temporary1=55, $temporary2=55, $reserve=1; $ab=abs($ac); sub clean {$string=$_[0]; $string=~s/\+\-/\-/g; $string=~s/\-\-/\+/g; $string=~s/(\D)1$variable/\1$variable/g; $string=~s/(\D)1\*$variable/\1$variable/g; $string=~s/^1$variable/$variable/g; $string=~s/^1\*$variable/$variable/g; return $string; } if($a==0) {print " {{{$b*$variable+$c}}} is not a quadratic since a=0. So quadratic factoring cannot be used. "; return undef;} for ($count=1; $count<=$ab; $count++) {$mod=$ab%$count; if($mod == 0) { $f[$half]=$count; $half++; } } for($count=0; $count<=$half; $count++) {$negf[$count]=(-1)*($f[$count]);} $size=@f; if($c==0) { for($count=1;$count<abs($a*$b);$count++) { if(($a%$count==0)&&($b%$count==0)) {$gcf[0]=$count;}} print " Notice how each term in the expression {{{$a*$variable^2+$b*$variable}}}"; if($gcf[0]>1) { print " has a common factor of $gcf[0]$variable. We can simply factor out an $gcf[0]$variable like this:"; if($gcf[0]!=0) {$temp=$a/$gcf[0]; $temp1=$b/$gcf[0];} print " {{{$gcf[0]$variable($temp*$variable+$temp1)}}} "; } if($gcf[0]==1) { print " has a common factor of $variable. We can simply factor out an $variable like this:"; print " {{{$variable($a*$variable+$b)}}} "; } return undef; } if($a<0) { $a=0-$a; $b=0-$b; $c=0-$c; $neg=1; print " Factor out a negative 1 {{{-($a*$variable^2+$b*$variable+$c)}}} Now lets concentrate on the quadratic {{{$a*$variable^2+$b*$variable+$c}}} inside the parenthesis and ignore the -1 outside the parenthesis (we'll place it back in later) "; } if($a==0) { #print "now lets focus on the quadratic in the parenthesis {{{$a*$variable^2+$b*$variable+$c}}}"; #solve("factoring-quadratics", $a, $b, $c); $temp=solve("factoring-quadratics", $a, $b, $c); if($neg==1) {print " Remember we factored out a negative 1, so lets reintroduce it back in -$temp Notice if we foil we get {{{-($a*$variable^2+$b*$variable+$c)}}}"; $a=0-$a; $b=0-$b; $c=0-$c; print " and if we distribute the negative we get {{{$a*$variable^2+$b*$variable+$c}}} again. This verifies our answer. ";} $path=5; } if($path==0) { $temp=clean("$a*$variable^2+$b*$variable+$c"); $original=$temp; print "In order to factor {{{$temp}}}, first multiply the leading coefficient $a and the last term $c to get $ac. Now we need to ask ourselves: What two numbers multiply to $ac and add to $b? Lets find out by listing all of the possible factors of $ac Factors: "; for ($count=0; $count<$size; $count++) { print "$f[$count],"; } print " "; for ($count=0; $count<$size; $count++) { print "$negf[$count],"; } print " List the negative factors as well. This will allow us to find all possible combinations"; print " "; print "These factors pair up to multiply to $ac. "; if($c>0) {for($count=0;$count<$size/2;$count++) { print "$f[$count]*$f[$size-$count-1]=$ac "; } } if($c>0) { for($count=0;$count<$size/2;$count++) { print "($negf[$count])*($negf[$size-$count-1])=$ac "; } print "note: remember two negative numbers multiplied together make a positive number "; } if($c<0) { for($count=0;$count<$size/2;$count++) { $opp=(-1)*($negf[$size-$count-1]); print "($negf[$count])*($opp)=$ac "; } } print " Now which of these pairs add to $b? Lets make a table of all of the pairs of factors we multiplied and see which two numbers add to $b "; print "<TABLE>"; print "<TR><TD>First Number</TD><TD>|</TD><TD>Second Number</TD><TD>|</TD><TD>Sum</TD></TR>"; if($c>0) { for($count=0;$count<$size/2;$count++) { $sum=$f[$count]+$f[$size-$count-1]; print "<TR><TD>$f[$count]</TD><TD>|</TD><TD>$f[$size-$count-1]</TD>|</TD><TD>|</TD><TD>$f[$count]+$f[$size-$count-1]=$sum</TD></TR>"; if($sum==$b) {$factor[$check]=$f[$count]; $check++; $factor[$check]=$f[$size-$count-1]; } } } if($c>0) { for($count=0;$count<$size/2;$count++) { $sum=$negf[$count]+$negf[$size-$count-1]; print "<TR><TD>$negf[$count]</TD><TD>|</TD><TD>$negf[$size-$count-1]</TD>|</TD><TD>|</TD><TD>$negf[$count]+($negf[$size-$count-1])=$sum</TD></TR>"; if($sum==$b) {$factor[$check]=$negf[$count]; $check++; $factor[$check]=$negf[$size-$count-1]; } } } if($c<0) { for($count=0;$count<$size/2;$count++) { $sum=$f[$count]+$negf[$size-$count-1]; print "<TR><TD>$f[$count]</TD><TD>|</TD><TD>$negf[$size-$count-1]</TD>|</TD><TD>|</TD><TD>$f[$count]+($negf[$size-$count-1])=$sum</TD></TR>"; if($sum==$b) {$factor[$check]=$f[$count]; $check++; $factor[$check]=$negf[$size-$count-1]; } } } if($c<0) { for($count=0;$count<$size/2;$count++) { $sum=$negf[$count]+$f[$size-$count-1]; print "<TR><TD>$negf[$count]</TD><TD>|</TD><TD>$f[$size-$count-1]</TD>|</TD><TD>|</TD><TD>($negf[$count])+$f[$size-$count-1]=$sum</TD></TR>"; if($sum==$b) {$factor[$check]=$negf[$count]; $check++; $factor[$check]=$f[$size-$count-1]; } } } print "</TABLE>"; $gcf[0]=1; $gcf[1]=1; for($count=2;$count<abs($a*$factor[1]);$count++) { if(($factor[0]%$count==0)&&($a%$count==0)) {$gcf[0]=$count;} if(($factor[1]%$count==0)&&($a%$count==0)) {$gcf[1]=$count;} } if($check>0) { $foil[0]=$a*$a; $foil[1]=$a*$factor[1]; $foil[2]=$a*$factor[0]; $foil[3]=$factor[0]*$factor[1]; $foil[4]=$foil[1]+$foil[2]; $divide=$foil[3]/$c; $reduce[0]=$a/$gcf[0]; $reduce[1]=$factor[0]/$gcf[0]; $reduce[2]=$a/$gcf[1]; $reduce[3]=$factor[1]/$gcf[1]; print " We can see from the table that $factor[0] and $factor[1] add to $b. So the two numbers that multiply to $ac and add to $b are: $factor[0] and $factor[1]"; } $temp=$factor[0]; $temp1=$factor[1]; $temp2=$a; $temp3=$a; for($count=2;$count<=abs($divide);$count++) { if($divide%$count==0) {$opposite=abs($divide/$count);} if(($factor[0]%$count==0)&&($a%$count==0)) {$reserve=$count; $temp=$factor[0]/$count; $temp2=$a/$count;} if(($factor[1]%$opposite==0)&&($a%$opposite==0)) {$temp1=$factor[1]/$opposite; $temp3=$a/$opposite;} if((($temp*$temp1==$c)&&((($temp2*$temp1)+($temp3*$temp))==$b))&&($opposite!=1)) { $count=abs($divide); $path=3; } } if($path!=3) { for($count=2;$count<=abs($foil[3]);$count++) { if(($factor[0]%$count==0)&&($a%$count==0)) {$temp=$factor[0]/$count; $temp2=$a/$count;} if(($temp*$factor[1])==$c) { $count=abs($foil[3]); $path=1; $counter++; } }} if($path!=3) { for($count=2;$count<=abs($foil[3]);$count++) { if(($factor[1]%$count==0)&&($a%$count==0)) {$temp1=$factor[1]/$count; $temp3=$a/$count;} if((($temp1*$factor[0]==$c)&&($path==1))) { $count=abs($foil[3]); $path=4; $counter++; } if($temp1*$factor[0]==$c) { #$rdiv=$count; $count=abs($foil[3]); if(($path!=1)&&($path!=4)) {$path=2; $counter++;} } }} if($check>0) {$temporary1=$temp; $temporary2=$temp1; $ldiv=$factor[0]/$temporary1; $rdiv=$factor[1]/$temporary2;} if(($a==1)&&($check>0)) {$path=5;} $gcf[0]=1; $gcf[1]=1; if($check>0) { $temp=clean("$a*$variable^2+$b*$variable+$c"); $temp1=clean("$factor[0]$variable+$factor[1]$variable"); $temp2=clean("$a*$variable^2+highlight($factor[0]$variable+$factor[1]$variable)+$c"); print " So the original quadratic {{{$original}}} breaks down to this (just replace {{{$b*$variable}}} with the two numbers that multiply to $ac and add to $b, which are: $factor[0] and $factor[1]) {{{$temp2}}} Replace {{{$b*$variable}}} with {{{$temp1}}}"; # {{{($a*$variable+$factor[0])($temp3*$variable+$temp1)}}}"; for($count=2;$count<abs($a*$factor[0]);$count++) { if(($factor[0]%$count==0)&&($a%$count==0)) {$gcf[0]=$count;}} #for($count=2;$count<abs($a*$factor[0]);$count++) #{ if(($factor[1]%$count==0)&&($c%$count==0)) # {$gcf[1]=$count;}} $reduce[1]=$factor[0]/$gcf[0]; $gcf[1]=$c/$reduce[1]; $reduce[0]=$a/$gcf[0]; $reduce[3]=$c/$gcf[1]; $reduce[2]=$factor[1]/$gcf[1]; if(($reduce[0]+$reduce[1])==($reduce[2]+$reduce[3])) { $temp1=clean("$a*$variable^2+$factor[0]$variable"); $temp2=clean("$factor[1]$variable+$c"); $temp3=clean("$reduce[0]$variable+$reduce[1]"); $temp4=clean("$reduce[2]$variable+$reduce[3]"); $gcf_temp=clean("$gcf[0]$variable+$gcf[1]"); #Notice if we let {{{y=$reduce[0]$variable+$reduce[1]}}} we would get #{{{$gcf[0]$variabley+$gcf[1]y=($gcf[0]$variable+$gcf[1])y}}}. Since we have that common term {{{y}}}, we are able #to combine {{{$gcf[0]$variable}}} and {{{$gcf[1]}}} print " Group the first two terms together and the last two terms together like this: {{{($temp1)+($temp2)}}} Factor a $gcf[0]$variable out of the first group and factor a $gcf[1] out of the second group. {{{$gcf[0]$variable($temp3)+$gcf[1]($temp4)}}} Now since we have a common term {{{$temp3}}} we can combine the two terms. {{{($gcf_temp)($temp3)}}} Combine like terms. "; if($neg==1) { print " Remember we factored out a negative 1 to start the problem, so lets reintroduce it back in. So our answer is --------------------------------------------------------------------------------------------------- Answer: So the quadratic {{{-($a*$variable^2+$b*$variable+$c)}}} factors to {{{-($gcf[0]$variable+$gcf[1])($reduce[0]$variable+$reduce[1])}}} "; if(($gcf[0]==$reduce[0])&&($gcf[1]==$reduce[1])) {print " which can also be written as {{{-($gcf[0]$variable+$gcf[1])^2}}} since the factors repeat themselves ";} else {print " ";} print " Notice how {{{-($gcf[0]$variable+$gcf[1])($reduce[0]$variable+$reduce[1])}}} foils back to {{{-($a*$variable^2+$b*$variable+$c)}}}. Notice how if we distribute the negative we get:"; $a=0-$a; $b=0-$b; $c=0-$c; print " {{{$a*$variable^2+$b*$variable+$c}}} This verifies our answer."; return undef;} print " Answer: So the quadratic {{{$original}}} factors to {{{($gcf_temp)($temp3)}}} "; if($gcf_temp eq $temp3) {print "which can also be written as {{{($gcf_temp)^2}}} since the factors repeat themselves ";} else {print " ";} print " Notice how {{{($gcf_temp)($temp3)}}} foils back to our original problem {{{$original}}}. This verifies our answer. "; } } if($check==0) { print " None of these factors add to $b. So the quadratic {{{$original}}} cannot be factored."; #In order to solve for $variable, we need to use the quadratic formula."; } print " --------------------------------------------------------------------------------------------------- "; } ==section output ==section check angle=40 angle1=50