private static Algebra constructAlgebra(ArrayList<AlgebraicParticle> l, Algebra old) {
		Boolean s /*sign*/ = null;
		Integer e /*exponent*/ = null;
		if(old instanceof AlgebraicParticle) {
			AlgebraicParticle a =  (AlgebraicParticle) old;
			s = a.sign();
			e = a.exponent();
		}
		
		
		if(old instanceof Equation) return new Equation(l.get(0), l.get(1));
		//if expression, or it's a mixed number but the fraction was replaced with something other than a fraction
		if(old instanceof Expression || old instanceof MixedNumber && !(l.get(1) instanceof Fraction)) {
			return new Expression(s, l, e);
		}
		if(old instanceof Term) return new Term(s, l, e);
		if(old instanceof Fraction) return new Fraction(s, l.get(0), l.get(1), e);
		if(old instanceof MixedNumber) return new MixedNumber(s, (Number) l.get(0), (Fraction) l.get(1), e);
		if(old instanceof Root) return new Root(s, ((Root)old).getNthRoot(), l.get(0), e);
		throw new RuntimeException("None of the above matched. Must have been sent a variable or number or something.");
	}