
(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 (+ z (fma x 3.0 (* y 2.0))))
double code(double x, double y, double z) {
return z + fma(x, 3.0, (y * 2.0));
}
function code(x, y, z) return Float64(z + fma(x, 3.0, Float64(y * 2.0))) end
code[x_, y_, z_] := N[(z + N[(x * 3.0 + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \mathsf{fma}\left(x, 3, y \cdot 2\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
associate-+r+99.9%
*-lft-identity99.9%
metadata-eval99.9%
count-299.9%
distribute-rgt-out99.9%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* y 2.0))))
(if (<= x -1.05e+76)
(* x 3.0)
(if (<= x -2.15e-186)
t_0
(if (<= x 2.2e-200) z (if (<= x 9.5e+81) t_0 (* x 3.0)))))))
double code(double x, double y, double z) {
double t_0 = x + (y * 2.0);
double tmp;
if (x <= -1.05e+76) {
tmp = x * 3.0;
} else if (x <= -2.15e-186) {
tmp = t_0;
} else if (x <= 2.2e-200) {
tmp = z;
} else if (x <= 9.5e+81) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x + (y * 2.0d0)
if (x <= (-1.05d+76)) then
tmp = x * 3.0d0
else if (x <= (-2.15d-186)) then
tmp = t_0
else if (x <= 2.2d-200) then
tmp = z
else if (x <= 9.5d+81) then
tmp = t_0
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y * 2.0);
double tmp;
if (x <= -1.05e+76) {
tmp = x * 3.0;
} else if (x <= -2.15e-186) {
tmp = t_0;
} else if (x <= 2.2e-200) {
tmp = z;
} else if (x <= 9.5e+81) {
tmp = t_0;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y * 2.0) tmp = 0 if x <= -1.05e+76: tmp = x * 3.0 elif x <= -2.15e-186: tmp = t_0 elif x <= 2.2e-200: tmp = z elif x <= 9.5e+81: tmp = t_0 else: tmp = x * 3.0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y * 2.0)) tmp = 0.0 if (x <= -1.05e+76) tmp = Float64(x * 3.0); elseif (x <= -2.15e-186) tmp = t_0; elseif (x <= 2.2e-200) tmp = z; elseif (x <= 9.5e+81) tmp = t_0; else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y * 2.0); tmp = 0.0; if (x <= -1.05e+76) tmp = x * 3.0; elseif (x <= -2.15e-186) tmp = t_0; elseif (x <= 2.2e-200) tmp = z; elseif (x <= 9.5e+81) tmp = t_0; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.05e+76], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -2.15e-186], t$95$0, If[LessEqual[x, 2.2e-200], z, If[LessEqual[x, 9.5e+81], t$95$0, N[(x * 3.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + y \cdot 2\\
\mathbf{if}\;x \leq -1.05 \cdot 10^{+76}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq -2.15 \cdot 10^{-186}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-200}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.05000000000000003e76 or 9.50000000000000083e81 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define99.8%
metadata-eval99.8%
metadata-eval99.8%
count-299.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in x around inf 89.9%
Taylor expanded in x around inf 89.8%
Taylor expanded in z around 0 70.9%
if -1.05000000000000003e76 < x < -2.14999999999999995e-186 or 2.20000000000000013e-200 < x < 9.50000000000000083e81Initial program 99.9%
associate-+l+99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around 0 67.1%
Taylor expanded in x around 0 55.0%
if -2.14999999999999995e-186 < x < 2.20000000000000013e-200Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
associate-+r+100.0%
associate-+r+100.0%
*-lft-identity100.0%
metadata-eval100.0%
count-2100.0%
distribute-rgt-out100.0%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 62.0%
Final simplification61.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e+55) (not (<= y 3e+76))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e+55) || !(y <= 3e+76)) {
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 <= (-2.8d+55)) .or. (.not. (y <= 3d+76))) 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 <= -2.8e+55) || !(y <= 3e+76)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e+55) or not (y <= 3e+76): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e+55) || !(y <= 3e+76)) 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 <= -2.8e+55) || ~((y <= 3e+76))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e+55], N[Not[LessEqual[y, 3e+76]], $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 -2.8 \cdot 10^{+55} \lor \neg \left(y \leq 3 \cdot 10^{+76}\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -2.8000000000000001e55 or 2.9999999999999998e76 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
associate-+r+100.0%
associate-+r+100.0%
*-lft-identity100.0%
metadata-eval100.0%
count-2100.0%
distribute-rgt-out100.0%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 89.5%
if -2.8000000000000001e55 < y < 2.9999999999999998e76Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
associate-+r+99.9%
*-lft-identity99.9%
metadata-eval99.9%
count-299.9%
distribute-rgt-out99.9%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 89.9%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.05e+155) (not (<= x 2.6e+82))) (* x 3.0) (+ z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.05e+155) || !(x <= 2.6e+82)) {
tmp = x * 3.0;
} else {
tmp = z + (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 ((x <= (-4.05d+155)) .or. (.not. (x <= 2.6d+82))) then
tmp = x * 3.0d0
else
tmp = z + (y * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.05e+155) || !(x <= 2.6e+82)) {
tmp = x * 3.0;
} else {
tmp = z + (y * 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.05e+155) or not (x <= 2.6e+82): tmp = x * 3.0 else: tmp = z + (y * 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.05e+155) || !(x <= 2.6e+82)) tmp = Float64(x * 3.0); else tmp = Float64(z + Float64(y * 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.05e+155) || ~((x <= 2.6e+82))) tmp = x * 3.0; else tmp = z + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.05e+155], N[Not[LessEqual[x, 2.6e+82]], $MachinePrecision]], N[(x * 3.0), $MachinePrecision], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.05 \cdot 10^{+155} \lor \neg \left(x \leq 2.6 \cdot 10^{+82}\right):\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot 2\\
\end{array}
\end{array}
if x < -4.05000000000000014e155 or 2.5999999999999998e82 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define99.8%
metadata-eval99.8%
metadata-eval99.8%
count-299.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in x around inf 91.1%
Taylor expanded in x around inf 91.0%
Taylor expanded in z around 0 78.7%
if -4.05000000000000014e155 < x < 2.5999999999999998e82Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
associate-+r+99.9%
*-lft-identity99.9%
metadata-eval99.9%
count-299.9%
distribute-rgt-out99.9%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 86.7%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-10) (not (<= x 6.2e+31))) (* x 3.0) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-10) || !(x <= 6.2e+31)) {
tmp = x * 3.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 ((x <= (-8.2d-10)) .or. (.not. (x <= 6.2d+31))) then
tmp = x * 3.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-10) || !(x <= 6.2e+31)) {
tmp = x * 3.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-10) or not (x <= 6.2e+31): tmp = x * 3.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-10) || !(x <= 6.2e+31)) tmp = Float64(x * 3.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-10) || ~((x <= 6.2e+31))) tmp = x * 3.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-10], N[Not[LessEqual[x, 6.2e+31]], $MachinePrecision]], N[(x * 3.0), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-10} \lor \neg \left(x \leq 6.2 \cdot 10^{+31}\right):\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.1999999999999996e-10 or 6.2000000000000004e31 < x Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
associate-+r+99.9%
*-lft-identity99.9%
metadata-eval99.9%
count-299.9%
distribute-rgt-out99.9%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 80.9%
Taylor expanded in x around inf 80.8%
Taylor expanded in z around 0 62.3%
if -8.1999999999999996e-10 < x < 6.2000000000000004e31Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
associate-+r+100.0%
associate-+r+100.0%
*-lft-identity100.0%
metadata-eval100.0%
count-2100.0%
distribute-rgt-out100.0%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 46.3%
Final simplification53.6%
(FPCore (x y z) :precision binary64 (+ (* 2.0 (+ x y)) (+ z x)))
double code(double x, double y, double z) {
return (2.0 * (x + y)) + (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 = (2.0d0 * (x + y)) + (z + x)
end function
public static double code(double x, double y, double z) {
return (2.0 * (x + y)) + (z + x);
}
def code(x, y, z): return (2.0 * (x + y)) + (z + x)
function code(x, y, z) return Float64(Float64(2.0 * Float64(x + y)) + Float64(z + x)) end
function tmp = code(x, y, z) tmp = (2.0 * (x + y)) + (z + x); end
code[x_, y_, z_] := N[(N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x + y\right) + \left(z + x\right)
\end{array}
Initial program 99.9%
associate-+l+99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(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%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
associate-+r+99.9%
*-lft-identity99.9%
metadata-eval99.9%
count-299.9%
distribute-rgt-out99.9%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 33.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
associate-+l+99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around 0 66.4%
Taylor expanded in x around 0 40.4%
Taylor expanded in x around inf 7.6%
herbie shell --seed 2024185
(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))