
(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 8 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 (* x 2.0)))))
double code(double x) {
return x * ((x * 3.0) - (x * (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * ((x * 3.0d0) - (x * (x * 2.0d0)))
end function
public static double code(double x) {
return x * ((x * 3.0) - (x * (x * 2.0)));
}
def code(x): return x * ((x * 3.0) - (x * (x * 2.0)))
function code(x) return Float64(x * Float64(Float64(x * 3.0) - Float64(x * Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * ((x * 3.0) - (x * (x * 2.0))); end
code[x_] := N[(x * N[(N[(x * 3.0), $MachinePrecision] - N[(x * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 3 - x \cdot \left(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%
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%
(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.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6499.2%
Simplified99.2%
if -1.5 < x < 1.5Initial program 99.6%
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.7%
Simplified99.7%
Taylor expanded in x around 0
Simplified97.1%
Final simplification98.2%
(FPCore (x) :precision binary64 (let* ((t_0 (* x (/ x (/ -0.5 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 * (x / (-0.5 / 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 * (x / ((-0.5d0) / 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 * (x / (-0.5 / 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 * (x / (-0.5 / 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(x * Float64(x / Float64(-0.5 / 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 * (x / (-0.5 / 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[(x * N[(x / N[(-0.5 / x), $MachinePrecision]), $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 := x \cdot \frac{x}{\frac{-0.5}{x}}\\
\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.9%
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.9%
Simplified99.9%
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.9%
Applied egg-rr99.9%
distribute-lft-out--N/A
*-commutativeN/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
/-rgt-identityN/A
metadata-evalN/A
clear-numN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
metadata-evalN/A
remove-double-negN/A
frac-2negN/A
/-lowering-/.f64N/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f6499.9%
Applied egg-rr99.9%
Taylor expanded in x around inf
/-lowering-/.f6499.2%
Simplified99.2%
if -1.5 < x < 1.5Initial program 99.6%
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.7%
Simplified99.7%
Taylor expanded in x around 0
Simplified97.1%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (/ x (/ -0.3333333333333333 x))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x / (-0.3333333333333333 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = x / ((-0.3333333333333333d0) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x / (-0.3333333333333333 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = x / (-0.3333333333333333 / x) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(x / Float64(-0.3333333333333333 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = x / (-0.3333333333333333 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(-0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{-0.3333333333333333}{x}}\\
\end{array}
\end{array}
if 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
Simplified85.0%
if 1.5 < x Initial program 99.9%
Taylor expanded in x around 0
Simplified0.2%
metadata-evalN/A
div-invN/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f640.2%
Applied egg-rr0.2%
frac-2negN/A
div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
remove-double-negN/A
div-invN/A
remove-double-negN/A
/-lowering-/.f64N/A
metadata-eval61.8%
Applied egg-rr61.8%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (- -6.75 (* x 4.5))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = -6.75 - (x * 4.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = (-6.75d0) - (x * 4.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = -6.75 - (x * 4.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = -6.75 - (x * 4.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(-6.75 - Float64(x * 4.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = -6.75 - (x * 4.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(-6.75 - N[(x * 4.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;-6.75 - x \cdot 4.5\\
\end{array}
\end{array}
if 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
Simplified85.0%
if 1.5 < x Initial program 99.9%
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.9%
Simplified99.9%
Applied egg-rr0.2%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6460.7%
Simplified60.7%
Taylor expanded in x around inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
+-commutativeN/A
sub-negN/A
--lowering--.f64N/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f646.8%
Simplified6.8%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (* x -4.5)))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x * -4.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = x * (-4.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x * -4.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = x * -4.5 return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(x * -4.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = x * -4.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x * -4.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot -4.5\\
\end{array}
\end{array}
if 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
Simplified85.0%
if 1.5 < x Initial program 99.9%
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.9%
Simplified99.9%
Applied egg-rr0.2%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6460.7%
Simplified60.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f646.8%
Simplified6.8%
(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 (* 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*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%
Applied egg-rr48.6%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6478.5%
Simplified78.5%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f646.2%
Simplified6.2%
(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 2024160
(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))))