
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
(FPCore (x y z) :precision binary64 (fma 3.0 x (fma y 2.0 z)))
double code(double x, double y, double z) {
return fma(3.0, x, fma(y, 2.0, z));
}
function code(x, y, z) return fma(3.0, x, fma(y, 2.0, z)) end
code[x_, y_, z_] := N[(3.0 * x + N[(y * 2.0 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x, \mathsf{fma}\left(y, 2, z\right)\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
flip-+N/A
div-invN/A
+-commutativeN/A
lower-fma.f64N/A
difference-of-squaresN/A
lift-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64N/A
Applied egg-rr57.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6450.9
Simplified50.9%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -4.8e+83)
(* 3.0 x)
(if (<= x -7.4e-196)
(* y 2.0)
(if (<= x -1.25e-296)
(+ y z)
(if (<= x 3.2e-116)
(* y 2.0)
(if (<= x 3.1e+115) (+ y z) (* 3.0 x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+83) {
tmp = 3.0 * x;
} else if (x <= -7.4e-196) {
tmp = y * 2.0;
} else if (x <= -1.25e-296) {
tmp = y + z;
} else if (x <= 3.2e-116) {
tmp = y * 2.0;
} else if (x <= 3.1e+115) {
tmp = y + z;
} else {
tmp = 3.0 * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-4.8d+83)) then
tmp = 3.0d0 * x
else if (x <= (-7.4d-196)) then
tmp = y * 2.0d0
else if (x <= (-1.25d-296)) then
tmp = y + z
else if (x <= 3.2d-116) then
tmp = y * 2.0d0
else if (x <= 3.1d+115) then
tmp = y + z
else
tmp = 3.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+83) {
tmp = 3.0 * x;
} else if (x <= -7.4e-196) {
tmp = y * 2.0;
} else if (x <= -1.25e-296) {
tmp = y + z;
} else if (x <= 3.2e-116) {
tmp = y * 2.0;
} else if (x <= 3.1e+115) {
tmp = y + z;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e+83: tmp = 3.0 * x elif x <= -7.4e-196: tmp = y * 2.0 elif x <= -1.25e-296: tmp = y + z elif x <= 3.2e-116: tmp = y * 2.0 elif x <= 3.1e+115: tmp = y + z else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+83) tmp = Float64(3.0 * x); elseif (x <= -7.4e-196) tmp = Float64(y * 2.0); elseif (x <= -1.25e-296) tmp = Float64(y + z); elseif (x <= 3.2e-116) tmp = Float64(y * 2.0); elseif (x <= 3.1e+115) tmp = Float64(y + z); else tmp = Float64(3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e+83) tmp = 3.0 * x; elseif (x <= -7.4e-196) tmp = y * 2.0; elseif (x <= -1.25e-296) tmp = y + z; elseif (x <= 3.2e-116) tmp = y * 2.0; elseif (x <= 3.1e+115) tmp = y + z; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+83], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, -7.4e-196], N[(y * 2.0), $MachinePrecision], If[LessEqual[x, -1.25e-296], N[(y + z), $MachinePrecision], If[LessEqual[x, 3.2e-116], N[(y * 2.0), $MachinePrecision], If[LessEqual[x, 3.1e+115], N[(y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+83}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq -7.4 \cdot 10^{-196}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-296}:\\
\;\;\;\;y + z\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-116}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+115}:\\
\;\;\;\;y + z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -4.79999999999999982e83 or 3.10000000000000005e115 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6470.1
Simplified70.1%
if -4.79999999999999982e83 < x < -7.4000000000000002e-196 or -1.25000000000000008e-296 < x < 3.20000000000000009e-116Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6457.6
Simplified57.6%
if -7.4000000000000002e-196 < x < -1.25000000000000008e-296 or 3.20000000000000009e-116 < x < 3.10000000000000005e115Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
flip-+N/A
div-invN/A
+-commutativeN/A
lower-fma.f64N/A
difference-of-squaresN/A
lift-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64N/A
Applied egg-rr75.4%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6474.9
Simplified74.9%
Taylor expanded in x around 0
lower-+.f6467.8
Simplified67.8%
Final simplification64.5%
(FPCore (x y z) :precision binary64 (if (<= y -3.3e+59) (fma 2.0 y z) (if (<= y 3.5) (fma x 3.0 z) (fma 2.0 (+ x y) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e+59) {
tmp = fma(2.0, y, z);
} else if (y <= 3.5) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, (x + y), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -3.3e+59) tmp = fma(2.0, y, z); elseif (y <= 3.5) tmp = fma(x, 3.0, z); else tmp = fma(2.0, Float64(x + y), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -3.3e+59], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 3.5], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+59}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 3.5:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\end{array}
\end{array}
if y < -3.2999999999999999e59Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6495.7
Simplified95.7%
if -3.2999999999999999e59 < y < 3.5Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6490.7
Simplified90.7%
if 3.5 < y Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6484.6
Simplified84.6%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -5.1e+60) (fma 2.0 y z) (if (<= y 1.95e+163) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.1e+60) {
tmp = fma(2.0, y, z);
} else if (y <= 1.95e+163) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -5.1e+60) tmp = fma(2.0, y, z); elseif (y <= 1.95e+163) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -5.1e+60], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 1.95e+163], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.1 \cdot 10^{+60}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+163}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -5.09999999999999996e60 or 1.95000000000000012e163 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6495.2
Simplified95.2%
if -5.09999999999999996e60 < y < 1.95000000000000012e163Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6485.3
Simplified85.3%
(FPCore (x y z) :precision binary64 (if (<= x -9.5e+135) (* 3.0 x) (if (<= x 2.7e+115) (fma 2.0 y z) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+135) {
tmp = 3.0 * x;
} else if (x <= 2.7e+115) {
tmp = fma(2.0, y, z);
} else {
tmp = 3.0 * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -9.5e+135) tmp = Float64(3.0 * x); elseif (x <= 2.7e+115) tmp = fma(2.0, y, z); else tmp = Float64(3.0 * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -9.5e+135], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 2.7e+115], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+135}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -9.50000000000000036e135 or 2.70000000000000004e115 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6473.1
Simplified73.1%
if -9.50000000000000036e135 < x < 2.70000000000000004e115Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.5
Simplified87.5%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (<= z -7e+26) (+ y z) (if (<= z 1.26e+37) (* y 2.0) (+ y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e+26) {
tmp = y + z;
} else if (z <= 1.26e+37) {
tmp = y * 2.0;
} else {
tmp = y + z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-7d+26)) then
tmp = y + z
else if (z <= 1.26d+37) then
tmp = y * 2.0d0
else
tmp = y + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7e+26) {
tmp = y + z;
} else if (z <= 1.26e+37) {
tmp = y * 2.0;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e+26: tmp = y + z elif z <= 1.26e+37: tmp = y * 2.0 else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e+26) tmp = Float64(y + z); elseif (z <= 1.26e+37) tmp = Float64(y * 2.0); else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e+26) tmp = y + z; elseif (z <= 1.26e+37) tmp = y * 2.0; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e+26], N[(y + z), $MachinePrecision], If[LessEqual[z, 1.26e+37], N[(y * 2.0), $MachinePrecision], N[(y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+26}:\\
\;\;\;\;y + z\\
\mathbf{elif}\;z \leq 1.26 \cdot 10^{+37}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if z < -6.9999999999999998e26 or 1.26e37 < z Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
flip-+N/A
div-invN/A
+-commutativeN/A
lower-fma.f64N/A
difference-of-squaresN/A
lift-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64N/A
Applied egg-rr56.4%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6463.0
Simplified63.0%
Taylor expanded in x around 0
lower-+.f6465.5
Simplified65.5%
if -6.9999999999999998e26 < z < 1.26e37Initial program 99.8%
Taylor expanded in y around inf
lower-*.f6453.0
Simplified53.0%
Final simplification59.1%
(FPCore (x y z) :precision binary64 (fma 2.0 (+ x y) (+ x z)))
double code(double x, double y, double z) {
return fma(2.0, (x + y), (x + z));
}
function code(x, y, z) return fma(2.0, Float64(x + y), Float64(x + z)) end
code[x_, y_, z_] := N[(2.0 * N[(x + y), $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, x + y, x + z\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
count-2N/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f6499.9
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (+ y z))
double code(double x, double y, double z) {
return y + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + z
end function
public static double code(double x, double y, double z) {
return y + z;
}
def code(x, y, z): return y + z
function code(x, y, z) return Float64(y + z) end
function tmp = code(x, y, z) tmp = y + z; end
code[x_, y_, z_] := N[(y + z), $MachinePrecision]
\begin{array}{l}
\\
y + z
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
flip-+N/A
div-invN/A
+-commutativeN/A
lower-fma.f64N/A
difference-of-squaresN/A
lift-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64N/A
Applied egg-rr57.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6450.9
Simplified50.9%
Taylor expanded in x around 0
lower-+.f6440.3
Simplified40.3%
herbie shell --seed 2024212
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))