FastMath test5

Percentage Accurate: 99.9% → 100.0%
Time: 1.6s
Alternatives: 2
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \end{array} \]
(FPCore (d1)
 :precision binary64
 (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
real(8) function code(d1)
    real(8), intent (in) :: d1
    code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1):
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1)
end
function tmp = code(d1)
	tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}

\\
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 2 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \end{array} \]
(FPCore (d1)
 :precision binary64
 (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
real(8) function code(d1)
    real(8), intent (in) :: d1
    code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1):
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1)
end
function tmp = code(d1)
	tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}

\\
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1
\end{array}

Alternative 1: 100.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ {d1}^{10} \end{array} \]
(FPCore (d1) :precision binary64 (pow d1 10.0))
double code(double d1) {
	return pow(d1, 10.0);
}
real(8) function code(d1)
    real(8), intent (in) :: d1
    code = d1 ** 10.0d0
end function
public static double code(double d1) {
	return Math.pow(d1, 10.0);
}
def code(d1):
	return math.pow(d1, 10.0)
function code(d1)
	return d1 ^ 10.0
end
function tmp = code(d1)
	tmp = d1 ^ 10.0;
end
code[d1_] := N[Power[d1, 10.0], $MachinePrecision]
\begin{array}{l}

\\
{d1}^{10}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
  2. Step-by-step derivation
    1. *-commutative99.9%

      \[\leadsto \color{blue}{\left(\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right)} \cdot d1 \]
    2. associate-*l*99.9%

      \[\leadsto \color{blue}{\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)} \]
    3. associate-*l*99.9%

      \[\leadsto \color{blue}{\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(\left(d1 \cdot d1\right) \cdot d1\right)\right)} \cdot \left(d1 \cdot d1\right) \]
    4. associate-*r*99.9%

      \[\leadsto \left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \color{blue}{\left(d1 \cdot \left(d1 \cdot d1\right)\right)}\right) \cdot \left(d1 \cdot d1\right) \]
    5. associate-*l*99.9%

      \[\leadsto \color{blue}{\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot d1\right)\right)} \]
    6. cube-unmult99.9%

      \[\leadsto \left(\left(\color{blue}{{d1}^{3}} \cdot d1\right) \cdot d1\right) \cdot \left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot d1\right)\right) \]
    7. pow-plus99.9%

      \[\leadsto \left(\color{blue}{{d1}^{\left(3 + 1\right)}} \cdot d1\right) \cdot \left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot d1\right)\right) \]
    8. pow-plus99.9%

      \[\leadsto \color{blue}{{d1}^{\left(\left(3 + 1\right) + 1\right)}} \cdot \left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot d1\right)\right) \]
    9. associate-*l*99.9%

      \[\leadsto {d1}^{\left(\left(3 + 1\right) + 1\right)} \cdot \color{blue}{\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right)} \]
    10. cube-unmult99.9%

      \[\leadsto {d1}^{\left(\left(3 + 1\right) + 1\right)} \cdot \left(\left(\color{blue}{{d1}^{3}} \cdot d1\right) \cdot d1\right) \]
    11. pow-plus100.0%

      \[\leadsto {d1}^{\left(\left(3 + 1\right) + 1\right)} \cdot \left(\color{blue}{{d1}^{\left(3 + 1\right)}} \cdot d1\right) \]
    12. pow-plus99.9%

      \[\leadsto {d1}^{\left(\left(3 + 1\right) + 1\right)} \cdot \color{blue}{{d1}^{\left(\left(3 + 1\right) + 1\right)}} \]
    13. pow-sqr100.0%

      \[\leadsto \color{blue}{{d1}^{\left(2 \cdot \left(\left(3 + 1\right) + 1\right)\right)}} \]
    14. metadata-eval100.0%

      \[\leadsto {d1}^{\left(2 \cdot \left(\color{blue}{4} + 1\right)\right)} \]
    15. metadata-eval100.0%

      \[\leadsto {d1}^{\left(2 \cdot \color{blue}{5}\right)} \]
    16. metadata-eval100.0%

      \[\leadsto {d1}^{\color{blue}{10}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{{d1}^{10}} \]
  4. Final simplification100.0%

    \[\leadsto {d1}^{10} \]

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(\left(d1 \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)\right)\right)\right)\right) \end{array} \]
(FPCore (d1)
 :precision binary64
 (* d1 (* d1 (* d1 (* (* d1 d1) (* d1 (* d1 (* d1 (* d1 d1)))))))))
double code(double d1) {
	return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))));
}
real(8) function code(d1)
    real(8), intent (in) :: d1
    code = d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))))
end function
public static double code(double d1) {
	return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))));
}
def code(d1):
	return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))))
function code(d1)
	return Float64(d1 * Float64(d1 * Float64(d1 * Float64(Float64(d1 * d1) * Float64(d1 * Float64(d1 * Float64(d1 * Float64(d1 * d1))))))))
end
function tmp = code(d1)
	tmp = d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))));
end
code[d1_] := N[(d1 * N[(d1 * N[(d1 * N[(N[(d1 * d1), $MachinePrecision] * N[(d1 * N[(d1 * N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(\left(d1 \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
  2. Final simplification99.9%

    \[\leadsto d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(\left(d1 \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)\right)\right)\right)\right) \]

Developer target: 100.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ {d1}^{10} \end{array} \]
(FPCore (d1) :precision binary64 (pow d1 10.0))
double code(double d1) {
	return pow(d1, 10.0);
}
real(8) function code(d1)
    real(8), intent (in) :: d1
    code = d1 ** 10.0d0
end function
public static double code(double d1) {
	return Math.pow(d1, 10.0);
}
def code(d1):
	return math.pow(d1, 10.0)
function code(d1)
	return d1 ^ 10.0
end
function tmp = code(d1)
	tmp = d1 ^ 10.0;
end
code[d1_] := N[Power[d1, 10.0], $MachinePrecision]
\begin{array}{l}

\\
{d1}^{10}
\end{array}

Reproduce

?
herbie shell --seed 2023200 
(FPCore (d1)
  :name "FastMath test5"
  :precision binary64

  :herbie-target
  (pow d1 10.0)

  (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))