
(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 4 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*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
(FPCore (x) :precision binary64 (if (<= x -1.5) (* (* x -2.0) (* x x)) (if (<= x 1.5) (* x (* x 3.0)) (/ (* x x) (/ -0.5 x)))))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (x * -2.0) * (x * x);
} else if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = (x * x) / (-0.5 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.5d0)) then
tmp = (x * (-2.0d0)) * (x * x)
else if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = (x * x) / ((-0.5d0) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (x * -2.0) * (x * x);
} else if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = (x * x) / (-0.5 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.5: tmp = (x * -2.0) * (x * x) elif x <= 1.5: tmp = x * (x * 3.0) else: tmp = (x * x) / (-0.5 / x) return tmp
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(Float64(x * -2.0) * Float64(x * x)); elseif (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(Float64(x * x) / Float64(-0.5 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.5) tmp = (x * -2.0) * (x * x); elseif (x <= 1.5) tmp = x * (x * 3.0); else tmp = (x * x) / (-0.5 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.5], N[(N[(x * -2.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] / N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\left(x \cdot -2\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{\frac{-0.5}{x}}\\
\end{array}
\end{array}
if x < -1.5Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6497.1%
Simplified97.1%
if -1.5 < x < 1.5Initial program 99.7%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0
Simplified99.0%
if 1.5 < x Initial program 99.8%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
distribute-rgt-inN/A
fma-defineN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-outN/A
fmm-undefN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8%
Applied egg-rr99.8%
flip--N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
*-commutativeN/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6499.8%
Applied egg-rr99.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6498.7%
Simplified98.7%
associate-/r*N/A
associate-/r/N/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6498.7%
Applied egg-rr98.7%
Final simplification98.5%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* x -2.0) (* x x)))) (if (<= x -1.5) t_0 (if (<= x 1.5) (* x (* x 3.0)) t_0))))
double code(double x) {
double t_0 = (x * -2.0) * (x * x);
double tmp;
if (x <= -1.5) {
tmp = t_0;
} else if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x * (-2.0d0)) * (x * x)
if (x <= (-1.5d0)) then
tmp = t_0
else if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * -2.0) * (x * x);
double tmp;
if (x <= -1.5) {
tmp = t_0;
} else if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (x * -2.0) * (x * x) tmp = 0 if x <= -1.5: tmp = t_0 elif x <= 1.5: tmp = x * (x * 3.0) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(x * -2.0) * Float64(x * x)) tmp = 0.0 if (x <= -1.5) tmp = t_0; elseif (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (x * -2.0) * (x * x); tmp = 0.0; if (x <= -1.5) tmp = t_0; elseif (x <= 1.5) tmp = x * (x * 3.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x * -2.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5], t$95$0, If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot -2\right) \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.5 or 1.5 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6497.9%
Simplified97.9%
if -1.5 < x < 1.5Initial program 99.7%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0
Simplified99.0%
Final simplification98.5%
(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*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0
Simplified63.1%
(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 2024161
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:alt
(! :herbie-platform default (* x (* x (- 3 (* x 2)))))
(* (* x x) (- 3.0 (* x 2.0))))