def count_horner_compensated6(): print("horner.compensated_k(..., 6) (312n + 818, n >= 5):") for degree in range(5, 9 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated_k(x, coeffs, 6) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == horner_expected_total(6, degree) assert parent.fma_count == horner_expected_fma(6, degree) print(" degree {}: {}".format(degree, parent.display))
def count_horner_compensated5(): print("horner.compensated_k(..., 5) (152n + 350, n >= 4):") for degree in range(4, 8 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated_k(x, coeffs, 5) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == horner_expected_total(5, degree) assert parent.fma_count == horner_expected_fma(5, degree) print(" degree {}: {}".format(degree, parent.display))
def count_horner_compensated3(): print("horner.compensated3() (32n + 46, n >= 2):") for degree in range(2, 6 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated3(x, coeffs) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == horner_expected_total(3, degree) assert parent.fma_count == horner_expected_fma(3, degree) print(" degree {}: {}".format(degree, parent.display)) print("horner.compensated_k(..., 3) (32n + 46, n >= 2):") for degree in range(2, 6 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated_k(x, coeffs, 3) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == horner_expected_total(3, degree) assert parent.fma_count == horner_expected_fma(3, degree) print(" degree {}: {}".format(degree, parent.display))
def count_horner_compensated(): print("horner.compensated() (11n + 1):") for degree in range(1, 5 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated(x, coeffs) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == 11 * degree + 1 print(" degree {}: {}".format(degree, parent.display)) # NOTE: This is **the same** as ``horner.compensated()`` but uses # a different algorithm. print("horner.compensated_k(..., 2) (12n + 10):") for degree in range(1, 5 + 1): parent = operation_count.Computation() x = operation_count.Float(2.0, parent) coeffs = (operation_count.Float(1.0, parent), ) * (degree + 1) p = horner.compensated_k(x, coeffs, 2) assert p.value == 2.0**(degree + 1) - 1 assert parent.count == horner_expected_total(2, degree) assert parent.fma_count == horner_expected_fma(2, degree) print(" degree {}: {}".format(degree, parent.display))