
(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(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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (+ (* x -4.5) -6.75)))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = (x * -4.5) + -6.75;
}
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)) + (-6.75d0)
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) + -6.75;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = (x * -4.5) + -6.75 return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(Float64(x * -4.5) + -6.75); 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) + -6.75; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * -4.5), $MachinePrecision] + -6.75), $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 + -6.75\\
\end{array}
\end{array}
if x < 1.5Initial program 99.8%
*-commutative99.8%
Simplified99.8%
flip--99.8%
clear-num99.8%
associate-*l/99.7%
*-un-lft-identity99.7%
pow299.7%
clear-num99.7%
flip--99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 76.5%
div-inv76.6%
unpow276.6%
metadata-eval76.6%
associate-*l*76.6%
Applied egg-rr76.6%
if 1.5 < x Initial program 99.9%
*-commutative99.9%
Simplified99.9%
associate-*r*99.9%
flip--98.4%
associate-*l/98.4%
associate-*l/88.8%
*-commutative88.8%
sub-neg88.8%
metadata-eval88.8%
swap-sqr88.8%
distribute-rgt-neg-in88.8%
pow288.8%
metadata-eval88.8%
metadata-eval88.8%
Applied egg-rr88.8%
Taylor expanded in x around 0 0.4%
*-commutative0.4%
Simplified0.4%
Taylor expanded in x around inf 0.4%
sub-neg0.4%
add-sqr-sqrt0.4%
sqrt-prod0.4%
unpow20.4%
unpow20.4%
sqr-neg0.4%
sqrt-unprod0.0%
add-sqr-sqrt7.6%
distribute-rgt-neg-out7.6%
distribute-neg-in7.6%
*-un-lft-identity7.6%
distribute-lft-neg-in7.6%
metadata-eval7.6%
*-commutative7.6%
fma-def7.6%
Applied egg-rr7.6%
fma-udef7.6%
distribute-lft-in7.6%
neg-mul-17.6%
distribute-rgt-neg-in7.6%
metadata-eval7.6%
metadata-eval7.6%
Simplified7.6%
Final simplification58.6%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (* x (* x -3.0))))
double code(double x) {
double tmp;
if (x <= 1.5) {
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 <= 1.5d0) 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 <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x * (x * -3.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = x * (x * -3.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) 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 <= 1.5) tmp = x * (x * 3.0); else tmp = x * (x * -3.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], 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 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot -3\right)\\
\end{array}
\end{array}
if x < 1.5Initial program 99.8%
*-commutative99.8%
Simplified99.8%
flip--99.8%
clear-num99.8%
associate-*l/99.7%
*-un-lft-identity99.7%
pow299.7%
clear-num99.7%
flip--99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 76.5%
div-inv76.6%
unpow276.6%
metadata-eval76.6%
associate-*l*76.6%
Applied egg-rr76.6%
if 1.5 < x Initial program 99.9%
*-commutative99.9%
Simplified99.9%
flip--98.4%
clear-num98.3%
associate-*l/98.3%
*-un-lft-identity98.3%
pow298.3%
clear-num98.3%
flip--99.8%
sub-neg99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Applied egg-rr99.8%
unpow299.8%
div-inv99.8%
times-frac99.9%
+-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 0.3%
frac-2neg0.3%
neg-sub00.3%
div-sub0.3%
metadata-eval0.3%
metadata-eval0.3%
add-sqr-sqrt0.3%
sqrt-prod0.3%
unpow20.3%
unpow20.3%
sqr-neg0.3%
sqrt-unprod0.0%
add-sqr-sqrt51.6%
neg-sub051.6%
div-sub51.6%
metadata-eval51.6%
metadata-eval51.6%
add-sqr-sqrt51.6%
sqrt-prod51.6%
unpow251.6%
unpow251.6%
sqr-neg51.6%
sqrt-unprod0.0%
add-sqr-sqrt0.3%
frac-2neg0.3%
Applied egg-rr51.6%
+-lft-identity51.6%
Simplified51.6%
Final simplification70.1%
(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%
*-commutative99.8%
Simplified99.8%
flip--99.4%
clear-num99.4%
associate-*l/99.3%
*-un-lft-identity99.3%
pow299.3%
clear-num99.3%
flip--99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 56.6%
div-inv56.6%
unpow256.6%
metadata-eval56.6%
associate-*l*56.6%
Applied egg-rr56.6%
Final simplification56.6%
(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%
*-commutative99.8%
Simplified99.8%
associate-*r*99.8%
flip--99.4%
associate-*l/99.4%
associate-*l/93.4%
*-commutative93.4%
sub-neg93.4%
metadata-eval93.4%
swap-sqr93.4%
distribute-rgt-neg-in93.4%
pow293.4%
metadata-eval93.4%
metadata-eval93.4%
Applied egg-rr93.4%
Taylor expanded in x around 0 43.2%
*-commutative43.2%
Simplified43.2%
Taylor expanded in x around inf 2.9%
*-commutative2.9%
Simplified2.9%
Final simplification2.9%
(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%
*-commutative99.8%
Simplified99.8%
associate-*r*99.8%
flip--99.4%
associate-*l/99.4%
associate-*l/93.4%
*-commutative93.4%
sub-neg93.4%
metadata-eval93.4%
swap-sqr93.4%
distribute-rgt-neg-in93.4%
pow293.4%
metadata-eval93.4%
metadata-eval93.4%
Applied egg-rr93.4%
Taylor expanded in x around 0 43.2%
*-commutative43.2%
Simplified43.2%
Taylor expanded in x around inf 1.4%
Taylor expanded in x around 0 2.4%
Final simplification2.4%
(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 2023336
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))