@Override
    public boolean equals(Object o) {
        if (!(o instanceof Polynomial)) {
            return false;
        }
        Polynomial other = (Polynomial) o;

        Set<Integer> a = this.terms.keySet();
        Set<Integer> b = other.terms.keySet();
        if (!(a.equals(b))) {
            return false;
        }
        for (int power : a) {
            double coeff_a = this.terms.get(power);
            double coeff_b = other.terms.get(power);
            if (coeff_a != coeff_b) {
                return false;
            }
        }
        return true;
    }