Algebra.js
function(symbol, factors) { 
                try {
                    var remove_square = function(x) {
                        return core.Utils.block('POSITIVE_MULTIPLIERS', function() {
                            return Symbol.unwrapPARENS(math.sqrt(math.abs(x)));
                        }, true);
                    }; 
                    var separated = core.Utils.separate(symbol.clone());
                    var obj_array = [];
                    //get the unique variables
                    for(var x in separated) {
                        if(x !== 'constants') {
                            obj_array.push(separated[x]);
                        }
                    }
                    obj_array.sort(function(a, b) {
                        return b.power - a.power;
                    });

                    //if we have the same number of variables as unique variables then we can apply the difference of squares
                    if(obj_array.length === 2) { 
                        var a, b;
                        a = obj_array.pop();
                        b = obj_array.pop();
                        if(a.isComposite() && b.power.equals(2)) {
                            //remove the square from b
                            b = remove_square(b);
                            var f = __.Factor.factor(_.add(a, separated.constants));
                            if(f.power.equals(2)) {
                                f.toLinear();
                                factors.add(_.subtract(f.clone(), b.clone()));
                                factors.add(_.add(f, b));
                                symbol = new Symbol(1);
                            }
                        }
                        else {
                            a = a.powSimp();
                            b = b.powSimp();
                            
                            if((a.group === S || a.fname === '') && a.power.equals(2) && (b.group === S || b.fname === '') && b.power.equals(2)) {
                                if(a.multiplier.lessThan(0)) {
                                    var t = b; b = a; a = t;
                                }
                                if(a.multiplier.greaterThan(0)) {
                                    a = remove_square(a);
                                    b = remove_square(b);
                                }
                                factors.add(_.subtract(a.clone(), b.clone()));
                                factors.add(_.add(a, b));
                                symbol = new Symbol(1);
                            }
                        }
                    }
                }
                catch(e){;}
                
                return symbol;
            }
function(symbol, factors) { 
                try {
                    var remove_square = function(x) {
                        return core.Utils.block('POSITIVE_MULTIPLIERS', function() {
                            return Symbol.unwrapPARENS(math.sqrt(math.abs(x)));
                        }, true);
                    }; 
                    var separated = core.Utils.separate(symbol.clone());
                    var obj_array = [];
                    //get the unique variables
                    for(var x in separated) {
                        if(x !== 'constants') {
                            obj_array.push(separated[x]);
                        }
                    }
                    obj_array.sort(function(a, b) {
                        return b.power - a.power;
                    });

                    //if we have the same number of variables as unique variables then we can apply the difference of squares
                    if(obj_array.length === 2) { 
                        var a, b;
                        a = obj_array.pop();
                        b = obj_array.pop();
                        if(a.isComposite() && b.power.equals(2)) {
                            //remove the square from b
                            b = remove_square(b);
                            var f = __.Factor.factor(_.add(a, separated.constants));
                            if(f.power.equals(2)) {
                                f.toLinear();
                                factors.add(_.subtract(f.clone(), b.clone()));
                                factors.add(_.add(f, b));
                                symbol = new Symbol(1);
                            }
                        }
                        else {
                            a = a.powSimp();
                            b = b.powSimp();
                            
                            if((a.group === S || a.fname === '') && a.power.equals(2) && (b.group === S || b.fname === '') && b.power.equals(2)) {
                                if(a.multiplier.lessThan(0)) {
                                    var t = b; b = a; a = t;
                                }
                                if(a.multiplier.greaterThan(0)) {
                                    a = remove_square(a);
                                    b = remove_square(b);
                                }
                                factors.add(_.subtract(a.clone(), b.clone()));
                                factors.add(_.add(a, b));
                                symbol = new Symbol(1);
                            }
                        }
                    }
                }
                catch(e){;}
                
                return symbol;
            }
function ( symbol , factors ) { try { var remove_square = function ( x ) { return core . Utils . block ( 'POSITIVE_MULTIPLIERS' , function ( ) { return Symbol . unwrapPARENS ( math . sqrt ( math . abs ( x ) ) ) ; } , true ) ; } ; var separated = core . Utils . separate ( symbol . clone ( ) ) ; var obj_array = [ ] ; //get the unique variables
 for ( var x in separated ) { if ( x !== 'constants' ) { obj_array . push ( separated [ x ] ) ; } } obj_array . sort ( function ( a , b ) { return b . power - a . power ; } ) ; //if we have the same number of variables as unique variables then we can apply the difference of squares
 if ( obj_array . length === 2 ) { var a , b ; a = obj_array . pop ( ) ; b = obj_array . pop ( ) ; if ( a . isComposite ( ) && b . power . equals ( 2 ) ) { //remove the square from b
 b = remove_square ( b ) ; var f = __ . Factor . factor ( _ . add ( a , separated . constants ) ) ; if ( f . power . equals ( 2 ) ) { f . toLinear ( ) ; factors . add ( _ . subtract ( f . clone ( ) , b . clone ( ) ) ) ; factors . add ( _ . add ( f , b ) ) ; symbol = new Symbol ( 1 ) ; } } else { a = a . powSimp ( ) ; b = b . powSimp ( ) ; if ( ( a . group === S || a . fname === '' ) && a . power . equals ( 2 ) && ( b . group === S || b . fname === '' ) && b . power . equals ( 2 ) ) { if ( a . multiplier . lessThan ( 0 ) ) { var t = b ; b = a ; a = t ; } if ( a . multiplier . greaterThan ( 0 ) ) { a = remove_square ( a ) ; b = remove_square ( b ) ; } factors . add ( _ . subtract ( a . clone ( ) , b . clone ( ) ) ) ; factors . add ( _ . add ( a , b ) ) ; symbol = new Symbol ( 1 ) ; } } } } catch ( e ) { ; } return symbol ; }
difference of squares factorization
difference of squares factorization