
(FPCore (x) :precision binary64 (- (* 0.954929658551372 x) (* 0.12900613773279798 (* (* x x) x))))
double code(double x) {
return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.954929658551372d0 * x) - (0.12900613773279798d0 * ((x * x) * x))
end function
public static double code(double x) {
return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
def code(x): return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x))
function code(x) return Float64(Float64(0.954929658551372 * x) - Float64(0.12900613773279798 * Float64(Float64(x * x) * x))) end
function tmp = code(x) tmp = (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x)); end
code[x_] := N[(N[(0.954929658551372 * x), $MachinePrecision] - N[(0.12900613773279798 * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (* 0.954929658551372 x) (* 0.12900613773279798 (* (* x x) x))))
double code(double x) {
return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.954929658551372d0 * x) - (0.12900613773279798d0 * ((x * x) * x))
end function
public static double code(double x) {
return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
def code(x): return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x))
function code(x) return Float64(Float64(0.954929658551372 * x) - Float64(0.12900613773279798 * Float64(Float64(x * x) * x))) end
function tmp = code(x) tmp = (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x)); end
code[x_] := N[(N[(0.954929658551372 * x), $MachinePrecision] - N[(0.12900613773279798 * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right)
\end{array}
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (fma (pow x_m 1.5) (* (pow x_m 1.5) -0.12900613773279798) (* x_m 0.954929658551372))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * fma(pow(x_m, 1.5), (pow(x_m, 1.5) * -0.12900613773279798), (x_m * 0.954929658551372));
}
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * fma((x_m ^ 1.5), Float64((x_m ^ 1.5) * -0.12900613773279798), Float64(x_m * 0.954929658551372))) end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[Power[x$95$m, 1.5], $MachinePrecision] * N[(N[Power[x$95$m, 1.5], $MachinePrecision] * -0.12900613773279798), $MachinePrecision] + N[(x$95$m * 0.954929658551372), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \mathsf{fma}\left({x_m}^{1.5}, {x_m}^{1.5} \cdot -0.12900613773279798, x_m \cdot 0.954929658551372\right)
\end{array}
Initial program 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
add-sqr-sqrt72.6%
associate-*l*72.6%
fma-def72.6%
pow372.6%
sqrt-pow154.3%
metadata-eval54.3%
pow354.3%
sqrt-pow154.6%
metadata-eval54.6%
*-commutative54.6%
Applied egg-rr54.6%
Final simplification54.6%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (fma (* -0.12900613773279798 (pow x_m 2.0)) x_m (* x_m 0.954929658551372))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * fma((-0.12900613773279798 * pow(x_m, 2.0)), x_m, (x_m * 0.954929658551372));
}
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * fma(Float64(-0.12900613773279798 * (x_m ^ 2.0)), x_m, Float64(x_m * 0.954929658551372))) end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(-0.12900613773279798 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x$95$m + N[(x$95$m * 0.954929658551372), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \mathsf{fma}\left(-0.12900613773279798 \cdot {x_m}^{2}, x_m, x_m \cdot 0.954929658551372\right)
\end{array}
Initial program 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
*-commutative99.5%
associate-*r*99.8%
fma-def99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
Final simplification99.8%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (* x_m (- 0.954929658551372 (* (pow x_m 2.0) 0.12900613773279798)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (x_m * (0.954929658551372 - (pow(x_m, 2.0) * 0.12900613773279798)));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * (x_m * (0.954929658551372d0 - ((x_m ** 2.0d0) * 0.12900613773279798d0)))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * (x_m * (0.954929658551372 - (Math.pow(x_m, 2.0) * 0.12900613773279798)));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (x_m * (0.954929658551372 - (math.pow(x_m, 2.0) * 0.12900613773279798)))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(x_m * Float64(0.954929658551372 - Float64((x_m ^ 2.0) * 0.12900613773279798)))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (x_m * (0.954929658551372 - ((x_m ^ 2.0) * 0.12900613773279798))); end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(x$95$m * N[(0.954929658551372 - N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.12900613773279798), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m \cdot \left(0.954929658551372 - {x_m}^{2} \cdot 0.12900613773279798\right)\right)
\end{array}
Initial program 99.5%
associate-*r*99.8%
distribute-rgt-out--99.8%
pow299.8%
Applied egg-rr99.8%
Final simplification99.8%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (* x_m (fma (* x_m -0.12900613773279798) x_m 0.954929658551372))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (x_m * fma((x_m * -0.12900613773279798), x_m, 0.954929658551372));
}
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(x_m * fma(Float64(x_m * -0.12900613773279798), x_m, 0.954929658551372))) end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(x$95$m * N[(N[(x$95$m * -0.12900613773279798), $MachinePrecision] * x$95$m + 0.954929658551372), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m \cdot \mathsf{fma}\left(x_m \cdot -0.12900613773279798, x_m, 0.954929658551372\right)\right)
\end{array}
Initial program 99.5%
associate-*r*99.8%
distribute-rgt-out--99.8%
pow299.8%
Applied egg-rr99.8%
sub-neg99.8%
+-commutative99.8%
distribute-lft-neg-in99.8%
metadata-eval99.8%
unpow299.8%
associate-*r*99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (- (* x_m 0.954929658551372) (* 0.12900613773279798 (* x_m (* x_m x_m))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * ((x_m * 0.954929658551372) - (0.12900613773279798 * (x_m * (x_m * x_m))));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * ((x_m * 0.954929658551372d0) - (0.12900613773279798d0 * (x_m * (x_m * x_m))))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * ((x_m * 0.954929658551372) - (0.12900613773279798 * (x_m * (x_m * x_m))));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * ((x_m * 0.954929658551372) - (0.12900613773279798 * (x_m * (x_m * x_m))))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(x_m * 0.954929658551372) - Float64(0.12900613773279798 * Float64(x_m * Float64(x_m * x_m))))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * ((x_m * 0.954929658551372) - (0.12900613773279798 * (x_m * (x_m * x_m)))); end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(x$95$m * 0.954929658551372), $MachinePrecision] - N[(0.12900613773279798 * N[(x$95$m * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m \cdot 0.954929658551372 - 0.12900613773279798 \cdot \left(x_m \cdot \left(x_m \cdot x_m\right)\right)\right)
\end{array}
Initial program 99.5%
Final simplification99.5%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (* x_m 0.954929658551372)))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (x_m * 0.954929658551372);
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * (x_m * 0.954929658551372d0)
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * (x_m * 0.954929658551372);
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (x_m * 0.954929658551372)
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(x_m * 0.954929658551372)) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (x_m * 0.954929658551372); end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(x$95$m * 0.954929658551372), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m \cdot 0.954929658551372\right)
\end{array}
Initial program 99.5%
Taylor expanded in x around 0 57.0%
*-commutative57.0%
Simplified57.0%
Final simplification57.0%
herbie shell --seed 2023315
(FPCore (x)
:name "Rosa's Benchmark"
:precision binary64
(- (* 0.954929658551372 x) (* 0.12900613773279798 (* (* x x) x))))