
(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 10 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 -5.6e+99)
(* y 2.0)
(if (<= y 6.5e-237)
z
(if (<= y 3.2e-133) (* x 3.0) (if (<= y 9e+78) z (* y 2.0))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.6e+99) {
tmp = y * 2.0;
} else if (y <= 6.5e-237) {
tmp = z;
} else if (y <= 3.2e-133) {
tmp = x * 3.0;
} else if (y <= 9e+78) {
tmp = 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 <= (-5.6d+99)) then
tmp = y * 2.0d0
else if (y <= 6.5d-237) then
tmp = z
else if (y <= 3.2d-133) then
tmp = x * 3.0d0
else if (y <= 9d+78) then
tmp = 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 <= -5.6e+99) {
tmp = y * 2.0;
} else if (y <= 6.5e-237) {
tmp = z;
} else if (y <= 3.2e-133) {
tmp = x * 3.0;
} else if (y <= 9e+78) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.6e+99: tmp = y * 2.0 elif y <= 6.5e-237: tmp = z elif y <= 3.2e-133: tmp = x * 3.0 elif y <= 9e+78: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.6e+99) tmp = Float64(y * 2.0); elseif (y <= 6.5e-237) tmp = z; elseif (y <= 3.2e-133) tmp = Float64(x * 3.0); elseif (y <= 9e+78) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.6e+99) tmp = y * 2.0; elseif (y <= 6.5e-237) tmp = z; elseif (y <= 3.2e-133) tmp = x * 3.0; elseif (y <= 9e+78) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.6e+99], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 6.5e-237], z, If[LessEqual[y, 3.2e-133], N[(x * 3.0), $MachinePrecision], If[LessEqual[y, 9e+78], z, N[(y * 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{+99}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-237}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-133}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+78}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -5.6e99 or 8.9999999999999999e78 < 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.4%
if -5.6e99 < y < 6.5000000000000001e-237 or 3.20000000000000013e-133 < y < 8.9999999999999999e78Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 53.5%
if 6.5000000000000001e-237 < y < 3.20000000000000013e-133Initial program 99.7%
+-commutative99.7%
associate-+l+99.7%
+-commutative99.7%
count-299.7%
Simplified99.7%
Taylor expanded in x around inf 72.9%
Final simplification61.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+17) (+ z (* y 2.0)) (if (<= y 5.4e+71) (+ z (* x 3.0)) (+ x (* 2.0 (+ x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+17) {
tmp = z + (y * 2.0);
} else if (y <= 5.4e+71) {
tmp = z + (x * 3.0);
} else {
tmp = x + (2.0 * (x + y));
}
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 <= (-1.95d+17)) then
tmp = z + (y * 2.0d0)
else if (y <= 5.4d+71) then
tmp = z + (x * 3.0d0)
else
tmp = x + (2.0d0 * (x + y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+17) {
tmp = z + (y * 2.0);
} else if (y <= 5.4e+71) {
tmp = z + (x * 3.0);
} else {
tmp = x + (2.0 * (x + y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+17: tmp = z + (y * 2.0) elif y <= 5.4e+71: tmp = z + (x * 3.0) else: tmp = x + (2.0 * (x + y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+17) tmp = Float64(z + Float64(y * 2.0)); elseif (y <= 5.4e+71) tmp = Float64(z + Float64(x * 3.0)); else tmp = Float64(x + Float64(2.0 * Float64(x + y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.95e+17) tmp = z + (y * 2.0); elseif (y <= 5.4e+71) tmp = z + (x * 3.0); else tmp = x + (2.0 * (x + y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+17], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.4e+71], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+17}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+71}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.95e17Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 84.5%
if -1.95e17 < y < 5.39999999999999993e71Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 89.1%
Taylor expanded in x around 0 89.1%
if 5.39999999999999993e71 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around 0 90.7%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (+ (* x 2.0) (+ (* y 2.0) (+ x z))))
double code(double x, double y, double z) {
return (x * 2.0) + ((y * 2.0) + (x + z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 2.0d0) + ((y * 2.0d0) + (x + z))
end function
public static double code(double x, double y, double z) {
return (x * 2.0) + ((y * 2.0) + (x + z));
}
def code(x, y, z): return (x * 2.0) + ((y * 2.0) + (x + z))
function code(x, y, z) return Float64(Float64(x * 2.0) + Float64(Float64(y * 2.0) + Float64(x + z))) end
function tmp = code(x, y, z) tmp = (x * 2.0) + ((y * 2.0) + (x + z)); end
code[x_, y_, z_] := N[(N[(x * 2.0), $MachinePrecision] + N[(N[(y * 2.0), $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2 + \left(y \cdot 2 + \left(x + z\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.7e+20) (not (<= y 3.5e+86))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.7e+20) || !(y <= 3.5e+86)) {
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 <= (-4.7d+20)) .or. (.not. (y <= 3.5d+86))) 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 <= -4.7e+20) || !(y <= 3.5e+86)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.7e+20) or not (y <= 3.5e+86): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.7e+20) || !(y <= 3.5e+86)) 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 <= -4.7e+20) || ~((y <= 3.5e+86))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.7e+20], N[Not[LessEqual[y, 3.5e+86]], $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 -4.7 \cdot 10^{+20} \lor \neg \left(y \leq 3.5 \cdot 10^{+86}\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -4.7e20 or 3.50000000000000019e86 < y Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 83.9%
if -4.7e20 < y < 3.50000000000000019e86Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 89.2%
Taylor expanded in x around 0 89.2%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e+161) (* x 3.0) (if (<= x 2.05e+154) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+161) {
tmp = x * 3.0;
} else if (x <= 2.05e+154) {
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 <= (-1.05d+161)) then
tmp = x * 3.0d0
else if (x <= 2.05d+154) 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 <= -1.05e+161) {
tmp = x * 3.0;
} else if (x <= 2.05e+154) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e+161: tmp = x * 3.0 elif x <= 2.05e+154: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e+161) tmp = Float64(x * 3.0); elseif (x <= 2.05e+154) 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 <= -1.05e+161) tmp = x * 3.0; elseif (x <= 2.05e+154) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e+161], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 2.05e+154], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+161}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{+154}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.05e161 or 2.05e154 < x Initial program 99.7%
+-commutative99.7%
associate-+l+99.7%
+-commutative99.7%
count-299.7%
Simplified99.7%
Taylor expanded in x around inf 81.7%
if -1.05e161 < x < 2.05e154Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 83.5%
Final simplification83.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 (<= y -1.38e+101) (* y 2.0) (if (<= y 4.5e+79) z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.38e+101) {
tmp = y * 2.0;
} else if (y <= 4.5e+79) {
tmp = 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 <= (-1.38d+101)) then
tmp = y * 2.0d0
else if (y <= 4.5d+79) then
tmp = 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 <= -1.38e+101) {
tmp = y * 2.0;
} else if (y <= 4.5e+79) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.38e+101: tmp = y * 2.0 elif y <= 4.5e+79: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.38e+101) tmp = Float64(y * 2.0); elseif (y <= 4.5e+79) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.38e+101) tmp = y * 2.0; elseif (y <= 4.5e+79) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.38e+101], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 4.5e+79], z, N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.38 \cdot 10^{+101}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+79}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -1.38e101 or 4.49999999999999994e79 < 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.4%
if -1.38e101 < y < 4.49999999999999994e79Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 49.6%
Final simplification56.7%
(FPCore (x y z) :precision binary64 -28.0)
double code(double x, double y, double z) {
return -28.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -28.0d0
end function
public static double code(double x, double y, double z) {
return -28.0;
}
def code(x, y, z): return -28.0
function code(x, y, z) return -28.0 end
function tmp = code(x, y, z) tmp = -28.0; end
code[x_, y_, z_] := -28.0
\begin{array}{l}
\\
-28
\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 66.8%
Taylor expanded in x around 0 66.8%
flip3-+20.4%
div-inv20.3%
unpow-prod-down20.3%
metadata-eval20.3%
*-commutative20.3%
*-commutative20.3%
swap-sqr20.3%
metadata-eval20.3%
distribute-rgt-out--20.3%
*-commutative20.3%
Applied egg-rr20.3%
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.8%
Final simplification36.8%
herbie shell --seed 2023181
(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))