
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
(FPCore (x) :precision binary64 (if (<= x 4.6e-14) (* x (* x 3.0)) (* x (* x -3.0))))
double code(double x) {
double tmp;
if (x <= 4.6e-14) {
tmp = x * (x * 3.0);
} else {
tmp = x * (x * -3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 4.6d-14) then
tmp = x * (x * 3.0d0)
else
tmp = x * (x * (-3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 4.6e-14) {
tmp = x * (x * 3.0);
} else {
tmp = x * (x * -3.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 4.6e-14: tmp = x * (x * 3.0) else: tmp = x * (x * -3.0) return tmp
function code(x) tmp = 0.0 if (x <= 4.6e-14) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(x * Float64(x * -3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.6e-14) tmp = x * (x * 3.0); else tmp = x * (x * -3.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.6e-14], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.6 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot -3\right)\\
\end{array}
\end{array}
if x < 4.59999999999999996e-14Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 85.6%
if 4.59999999999999996e-14 < x Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
*-commutative99.7%
flip--99.7%
*-commutative99.7%
metadata-eval99.7%
cancel-sign-sub-inv99.7%
*-commutative99.7%
associate-*l/99.7%
Applied egg-rr6.5%
Taylor expanded in x around 0 6.7%
*-commutative6.7%
Simplified6.7%
clear-num6.7%
un-div-inv6.7%
*-un-lft-identity6.7%
*-commutative6.7%
times-frac6.7%
metadata-eval6.7%
Applied egg-rr6.7%
associate-/r*6.7%
Simplified6.7%
Taylor expanded in x around inf 6.7%
expm1-log1p-u6.7%
expm1-undefine2.5%
div-inv2.5%
metadata-eval2.5%
div-inv2.5%
Applied egg-rr2.5%
log1p-undefine2.5%
rem-exp-log2.5%
+-commutative2.5%
associate--l+6.7%
metadata-eval6.7%
+-commutative6.7%
+-lft-identity6.7%
*-commutative6.7%
associate-/l*6.7%
metadata-eval6.7%
times-frac6.7%
*-lft-identity6.7%
+-commutative6.7%
distribute-lft-in6.7%
associate-*r/6.7%
metadata-eval6.7%
metadata-eval6.7%
Simplified6.7%
Taylor expanded in x around 0 5.0%
add-sqr-sqrt5.0%
sqrt-prod5.0%
sqr-neg5.0%
sqrt-unprod0.0%
add-sqr-sqrt39.8%
distribute-neg-frac239.8%
div-inv39.8%
distribute-lft-neg-in39.8%
metadata-eval39.8%
Applied egg-rr39.8%
un-div-inv39.8%
associate-/r/39.8%
div-inv39.8%
metadata-eval39.8%
Applied egg-rr39.8%
Final simplification73.4%
(FPCore (x) :precision binary64 (* x (* x 3.0)))
double code(double x) {
return x * (x * 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 3.0d0)
end function
public static double code(double x) {
return x * (x * 3.0);
}
def code(x): return x * (x * 3.0)
function code(x) return Float64(x * Float64(x * 3.0)) end
function tmp = code(x) tmp = x * (x * 3.0); end
code[x_] := N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 3\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 64.2%
Final simplification64.2%
(FPCore (x) :precision binary64 (* x 4.5))
double code(double x) {
return x * 4.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 4.5d0
end function
public static double code(double x) {
return x * 4.5;
}
def code(x): return x * 4.5
function code(x) return Float64(x * 4.5) end
function tmp = code(x) tmp = x * 4.5; end
code[x_] := N[(x * 4.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 4.5
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
*-commutative99.8%
flip--99.8%
*-commutative99.8%
metadata-eval99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
associate-*l/99.8%
Applied egg-rr53.6%
Taylor expanded in x around 0 53.7%
*-commutative53.7%
Simplified53.7%
Taylor expanded in x around inf 3.5%
(FPCore (x) :precision binary64 -6.75)
double code(double x) {
return -6.75;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -6.75d0
end function
public static double code(double x) {
return -6.75;
}
def code(x): return -6.75
function code(x) return -6.75 end
function tmp = code(x) tmp = -6.75; end
code[x_] := -6.75
\begin{array}{l}
\\
-6.75
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
*-commutative99.8%
flip--99.8%
*-commutative99.8%
metadata-eval99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
associate-*l/99.8%
Applied egg-rr53.6%
Taylor expanded in x around 0 53.7%
*-commutative53.7%
Simplified53.7%
Taylor expanded in x around inf 1.7%
associate-*r/1.7%
metadata-eval1.7%
Simplified1.7%
Taylor expanded in x around 0 2.7%
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
herbie shell --seed 2024105
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:alt
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))