
(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 6 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 1.5) (/ x (/ 0.1111111111111111 (* x 0.3333333333333333))) (* -3.0 (* x x))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x / (0.1111111111111111 / (x * 0.3333333333333333));
} else {
tmp = -3.0 * (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x / (0.1111111111111111d0 / (x * 0.3333333333333333d0))
else
tmp = (-3.0d0) * (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x / (0.1111111111111111 / (x * 0.3333333333333333));
} else {
tmp = -3.0 * (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x / (0.1111111111111111 / (x * 0.3333333333333333)) else: tmp = -3.0 * (x * x) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x / Float64(0.1111111111111111 / Float64(x * 0.3333333333333333))); else tmp = Float64(-3.0 * Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x / (0.1111111111111111 / (x * 0.3333333333333333)); else tmp = -3.0 * (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x / N[(0.1111111111111111 / N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;\frac{x}{\frac{0.1111111111111111}{x \cdot 0.3333333333333333}}\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < 1.5Initial 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-rr67.5%
Taylor expanded in x around 0 67.5%
*-commutative67.5%
Simplified67.5%
clear-num67.5%
un-div-inv67.6%
*-un-lft-identity67.6%
*-commutative67.6%
times-frac67.6%
metadata-eval67.6%
Applied egg-rr67.6%
Taylor expanded in x around 0 85.8%
clear-num85.7%
un-div-inv85.7%
div-inv85.8%
metadata-eval85.8%
Applied egg-rr85.8%
if 1.5 < x 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-rr0.3%
Taylor expanded in x around 0 0.5%
*-commutative0.5%
Simplified0.5%
clear-num0.5%
un-div-inv0.5%
*-un-lft-identity0.5%
*-commutative0.5%
times-frac0.5%
metadata-eval0.5%
Applied egg-rr0.5%
Taylor expanded in x around 0 0.3%
clear-num0.3%
un-div-inv0.3%
div-inv0.3%
metadata-eval0.3%
Applied egg-rr0.3%
clear-num0.3%
associate-/l*0.3%
metadata-eval0.3%
*-commutative0.3%
frac-2neg0.3%
associate-/r*0.3%
metadata-eval0.3%
distribute-frac-neg20.3%
*-un-lft-identity0.3%
metadata-eval0.3%
frac-2neg0.3%
div-inv0.3%
times-frac0.3%
metadata-eval0.3%
add-sqr-sqrt0.0%
sqrt-unprod53.6%
sqr-neg53.6%
sqrt-unprod53.6%
add-sqr-sqrt53.6%
Applied egg-rr53.6%
pow153.6%
inv-pow53.6%
pow-div53.6%
metadata-eval53.6%
pow253.6%
Applied egg-rr53.6%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (* -3.0 (* x x))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = -3.0 * (x * 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 = (-3.0d0) * (x * 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 = -3.0 * (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = -3.0 * (x * x) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(-3.0 * Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = -3.0 * (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < 1.5Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 85.8%
if 1.5 < x 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-rr0.3%
Taylor expanded in x around 0 0.5%
*-commutative0.5%
Simplified0.5%
clear-num0.5%
un-div-inv0.5%
*-un-lft-identity0.5%
*-commutative0.5%
times-frac0.5%
metadata-eval0.5%
Applied egg-rr0.5%
Taylor expanded in x around 0 0.3%
clear-num0.3%
un-div-inv0.3%
div-inv0.3%
metadata-eval0.3%
Applied egg-rr0.3%
clear-num0.3%
associate-/l*0.3%
metadata-eval0.3%
*-commutative0.3%
frac-2neg0.3%
associate-/r*0.3%
metadata-eval0.3%
distribute-frac-neg20.3%
*-un-lft-identity0.3%
metadata-eval0.3%
frac-2neg0.3%
div-inv0.3%
times-frac0.3%
metadata-eval0.3%
add-sqr-sqrt0.0%
sqrt-unprod53.6%
sqr-neg53.6%
sqrt-unprod53.6%
add-sqr-sqrt53.6%
Applied egg-rr53.6%
pow153.6%
inv-pow53.6%
pow-div53.6%
metadata-eval53.6%
pow253.6%
Applied egg-rr53.6%
Final simplification76.9%
(FPCore (x) :precision binary64 (* -3.0 (* x x)))
double code(double x) {
return -3.0 * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-3.0d0) * (x * x)
end function
public static double code(double x) {
return -3.0 * (x * x);
}
def code(x): return -3.0 * (x * x)
function code(x) return Float64(-3.0 * Float64(x * x)) end
function tmp = code(x) tmp = -3.0 * (x * x); end
code[x_] := N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-3 \cdot \left(x \cdot x\right)
\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-rr48.8%
Taylor expanded in x around 0 49.0%
*-commutative49.0%
Simplified49.0%
clear-num48.9%
un-div-inv49.0%
*-un-lft-identity49.0%
*-commutative49.0%
times-frac49.0%
metadata-eval49.0%
Applied egg-rr49.0%
Taylor expanded in x around 0 62.1%
clear-num62.1%
un-div-inv62.1%
div-inv62.1%
metadata-eval62.1%
Applied egg-rr62.1%
clear-num62.1%
associate-/l*62.1%
metadata-eval62.1%
*-commutative62.1%
frac-2neg62.1%
associate-/r*62.1%
metadata-eval62.1%
distribute-frac-neg262.1%
*-un-lft-identity62.1%
metadata-eval62.1%
frac-2neg62.1%
div-inv62.1%
times-frac62.1%
metadata-eval62.1%
add-sqr-sqrt41.4%
sqrt-unprod66.4%
sqr-neg66.4%
sqrt-unprod25.0%
add-sqr-sqrt42.4%
Applied egg-rr42.4%
pow142.4%
inv-pow42.4%
pow-div42.4%
metadata-eval42.4%
pow242.4%
Applied egg-rr42.4%
(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-rr48.8%
Taylor expanded in x around 0 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in x around inf 3.0%
(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-rr48.8%
Taylor expanded in x around 0 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in x around inf 1.6%
associate-*r/1.6%
metadata-eval1.6%
Simplified1.6%
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 2024107
(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))))