
(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 x 3.0 (fma y 2.0 z)))
double code(double x, double y, double z) {
return fma(x, 3.0, fma(y, 2.0, z));
}
function code(x, y, z) return fma(x, 3.0, fma(y, 2.0, z)) end
code[x_, y_, z_] := N[(x * 3.0 + N[(y * 2.0 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
count-299.9%
associate-+l+99.9%
associate-+r+99.9%
distribute-rgt1-in99.9%
*-commutative99.9%
fma-def100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -7.6e+85)
(* y 2.0)
(if (<= y 2.8e-298)
(+ x z)
(if (<= y 1.32e-164)
(* x 3.0)
(if (<= y 6e-88)
(+ x z)
(if (<= y 1.65e-62)
(* x 3.0)
(if (<= y 1.1e+18) (+ x z) (* y 2.0))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.6e+85) {
tmp = y * 2.0;
} else if (y <= 2.8e-298) {
tmp = x + z;
} else if (y <= 1.32e-164) {
tmp = x * 3.0;
} else if (y <= 6e-88) {
tmp = x + z;
} else if (y <= 1.65e-62) {
tmp = x * 3.0;
} else if (y <= 1.1e+18) {
tmp = x + z;
} else {
tmp = y * 2.0;
}
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 (y <= (-7.6d+85)) then
tmp = y * 2.0d0
else if (y <= 2.8d-298) then
tmp = x + z
else if (y <= 1.32d-164) then
tmp = x * 3.0d0
else if (y <= 6d-88) then
tmp = x + z
else if (y <= 1.65d-62) then
tmp = x * 3.0d0
else if (y <= 1.1d+18) then
tmp = x + z
else
tmp = y * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.6e+85) {
tmp = y * 2.0;
} else if (y <= 2.8e-298) {
tmp = x + z;
} else if (y <= 1.32e-164) {
tmp = x * 3.0;
} else if (y <= 6e-88) {
tmp = x + z;
} else if (y <= 1.65e-62) {
tmp = x * 3.0;
} else if (y <= 1.1e+18) {
tmp = x + z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.6e+85: tmp = y * 2.0 elif y <= 2.8e-298: tmp = x + z elif y <= 1.32e-164: tmp = x * 3.0 elif y <= 6e-88: tmp = x + z elif y <= 1.65e-62: tmp = x * 3.0 elif y <= 1.1e+18: tmp = x + z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.6e+85) tmp = Float64(y * 2.0); elseif (y <= 2.8e-298) tmp = Float64(x + z); elseif (y <= 1.32e-164) tmp = Float64(x * 3.0); elseif (y <= 6e-88) tmp = Float64(x + z); elseif (y <= 1.65e-62) tmp = Float64(x * 3.0); elseif (y <= 1.1e+18) tmp = Float64(x + z); else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.6e+85) tmp = y * 2.0; elseif (y <= 2.8e-298) tmp = x + z; elseif (y <= 1.32e-164) tmp = x * 3.0; elseif (y <= 6e-88) tmp = x + z; elseif (y <= 1.65e-62) tmp = x * 3.0; elseif (y <= 1.1e+18) tmp = x + z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.6e+85], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 2.8e-298], N[(x + z), $MachinePrecision], If[LessEqual[y, 1.32e-164], N[(x * 3.0), $MachinePrecision], If[LessEqual[y, 6e-88], N[(x + z), $MachinePrecision], If[LessEqual[y, 1.65e-62], N[(x * 3.0), $MachinePrecision], If[LessEqual[y, 1.1e+18], N[(x + z), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{+85}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-298}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{-164}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-88}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-62}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+18}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -7.59999999999999984e85 or 1.1e18 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 71.6%
if -7.59999999999999984e85 < y < 2.79999999999999992e-298 or 1.3199999999999999e-164 < y < 5.9999999999999999e-88 or 1.65000000000000002e-62 < y < 1.1e18Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 87.4%
flip-+33.0%
div-inv32.9%
swap-sqr32.9%
metadata-eval32.9%
pow232.9%
+-commutative32.9%
add-log-exp16.9%
*-commutative16.9%
exp-lft-sqr16.9%
log-prod16.9%
add-log-exp16.9%
add-log-exp32.9%
+-commutative32.9%
Applied egg-rr32.9%
un-div-inv33.0%
metadata-eval33.0%
swap-sqr33.0%
count-233.0%
count-233.0%
unpow233.0%
flip-+87.4%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified62.0%
if 2.79999999999999992e-298 < y < 1.3199999999999999e-164 or 5.9999999999999999e-88 < y < 1.65000000000000002e-62Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 79.8%
Final simplification67.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e+28) (not (<= y 1.9e-44))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e+28) || !(y <= 1.9e-44)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
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 ((y <= (-5d+28)) .or. (.not. (y <= 1.9d-44))) then
tmp = z + (y * 2.0d0)
else
tmp = z + (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5e+28) || !(y <= 1.9e-44)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e+28) or not (y <= 1.9e-44): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e+28) || !(y <= 1.9e-44)) tmp = Float64(z + Float64(y * 2.0)); else tmp = Float64(z + Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5e+28) || ~((y <= 1.9e-44))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e+28], N[Not[LessEqual[y, 1.9e-44]], $MachinePrecision]], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+28} \lor \neg \left(y \leq 1.9 \cdot 10^{-44}\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -4.99999999999999957e28 or 1.9e-44 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around 0 86.1%
if -4.99999999999999957e28 < y < 1.9e-44Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 95.5%
Taylor expanded in x around 0 95.5%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (<= x -4.8e+201) (* x 3.0) (if (<= x 3.2e+91) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+201) {
tmp = x * 3.0;
} else if (x <= 3.2e+91) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
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+201)) then
tmp = x * 3.0d0
else if (x <= 3.2d+91) then
tmp = z + (y * 2.0d0)
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+201) {
tmp = x * 3.0;
} else if (x <= 3.2e+91) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e+201: tmp = x * 3.0 elif x <= 3.2e+91: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+201) tmp = Float64(x * 3.0); elseif (x <= 3.2e+91) tmp = Float64(z + Float64(y * 2.0)); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e+201) tmp = x * 3.0; elseif (x <= 3.2e+91) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+201], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 3.2e+91], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+201}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+91}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -4.79999999999999985e201 or 3.19999999999999989e91 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 77.8%
if -4.79999999999999985e201 < x < 3.19999999999999989e91Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 86.2%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (+ x (+ z (* 2.0 (+ x y)))))
double code(double x, double y, double z) {
return x + (z + (2.0 * (x + y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (z + (2.0d0 * (x + y)))
end function
public static double code(double x, double y, double z) {
return x + (z + (2.0 * (x + y)));
}
def code(x, y, z): return x + (z + (2.0 * (x + y)))
function code(x, y, z) return Float64(x + Float64(z + Float64(2.0 * Float64(x + y)))) end
function tmp = code(x, y, z) tmp = x + (z + (2.0 * (x + y))); end
code[x_, y_, z_] := N[(x + N[(z + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z + 2 \cdot \left(x + y\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -3.3e+47) z (if (<= z 2.5e+60) (* y 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e+47) {
tmp = z;
} else if (z <= 2.5e+60) {
tmp = y * 2.0;
} else {
tmp = 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 <= (-3.3d+47)) then
tmp = z
else if (z <= 2.5d+60) then
tmp = y * 2.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e+47) {
tmp = z;
} else if (z <= 2.5e+60) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e+47: tmp = z elif z <= 2.5e+60: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e+47) tmp = z; elseif (z <= 2.5e+60) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.3e+47) tmp = z; elseif (z <= 2.5e+60) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e+47], z, If[LessEqual[z, 2.5e+60], N[(y * 2.0), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+47}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+60}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.2999999999999999e47 or 2.49999999999999987e60 < z Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 70.2%
if -3.2999999999999999e47 < z < 2.49999999999999987e60Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 50.4%
Final simplification58.7%
(FPCore (x y z) :precision binary64 2.0)
double code(double x, double y, double z) {
return 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 2.0d0
end function
public static double code(double x, double y, double z) {
return 2.0;
}
def code(x, y, z): return 2.0
function code(x, y, z) return 2.0 end
function tmp = code(x, y, z) tmp = 2.0; end
code[x_, y_, z_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 65.6%
flip-+24.4%
div-inv24.4%
swap-sqr24.3%
metadata-eval24.3%
pow224.3%
+-commutative24.3%
add-log-exp10.5%
*-commutative10.5%
exp-lft-sqr10.5%
log-prod10.5%
add-log-exp10.4%
add-log-exp24.3%
+-commutative24.3%
Applied egg-rr24.3%
un-div-inv24.4%
metadata-eval24.4%
swap-sqr24.4%
count-224.4%
count-224.4%
unpow224.4%
flip-+65.6%
flip-+0.0%
flip3-+0.0%
frac-add0.0%
Applied egg-rr0.0%
Simplified3.2%
Final simplification3.2%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 36.3%
Final simplification36.3%
herbie shell --seed 2023195
(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))