
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z -2.3e-148)
y
(if (<= z 1.15e-305)
x
(if (<= z 1.4e-107) y (if (<= z 8.5e-6) x (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -2.3e-148) {
tmp = y;
} else if (z <= 1.15e-305) {
tmp = x;
} else if (z <= 1.4e-107) {
tmp = y;
} else if (z <= 8.5e-6) {
tmp = x;
} 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 <= (-1.0d0)) then
tmp = x * z
else if (z <= (-2.3d-148)) then
tmp = y
else if (z <= 1.15d-305) then
tmp = x
else if (z <= 1.4d-107) then
tmp = y
else if (z <= 8.5d-6) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -2.3e-148) {
tmp = y;
} else if (z <= 1.15e-305) {
tmp = x;
} else if (z <= 1.4e-107) {
tmp = y;
} else if (z <= 8.5e-6) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= -2.3e-148: tmp = y elif z <= 1.15e-305: tmp = x elif z <= 1.4e-107: tmp = y elif z <= 8.5e-6: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= -2.3e-148) tmp = y; elseif (z <= 1.15e-305) tmp = x; elseif (z <= 1.4e-107) tmp = y; elseif (z <= 8.5e-6) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= -2.3e-148) tmp = y; elseif (z <= 1.15e-305) tmp = x; elseif (z <= 1.4e-107) tmp = y; elseif (z <= 8.5e-6) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, -2.3e-148], y, If[LessEqual[z, 1.15e-305], x, If[LessEqual[z, 1.4e-107], y, If[LessEqual[z, 8.5e-6], x, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-148}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-305}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-107}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1Initial program 100.0%
Taylor expanded in z around inf 97.6%
Taylor expanded in x around inf 51.1%
*-commutative51.1%
Simplified51.1%
if -1 < z < -2.29999999999999997e-148 or 1.15e-305 < z < 1.3999999999999999e-107Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in y around inf 41.3%
if -2.29999999999999997e-148 < z < 1.15e-305 or 1.3999999999999999e-107 < z < 8.4999999999999999e-6Initial program 99.9%
Taylor expanded in z around 0 97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in y around 0 44.3%
if 8.4999999999999999e-6 < z Initial program 100.0%
Taylor expanded in z around inf 92.5%
Taylor expanded in x around 0 48.9%
Final simplification46.3%
(FPCore (x y z)
:precision binary64
(if (<= z -17.0)
(* y z)
(if (<= z -4.8e-146)
y
(if (<= z 6.7e-302)
x
(if (<= z 9.8e-107) y (if (<= z 8.5e-6) x (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -17.0) {
tmp = y * z;
} else if (z <= -4.8e-146) {
tmp = y;
} else if (z <= 6.7e-302) {
tmp = x;
} else if (z <= 9.8e-107) {
tmp = y;
} else if (z <= 8.5e-6) {
tmp = x;
} 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 <= (-17.0d0)) then
tmp = y * z
else if (z <= (-4.8d-146)) then
tmp = y
else if (z <= 6.7d-302) then
tmp = x
else if (z <= 9.8d-107) then
tmp = y
else if (z <= 8.5d-6) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -17.0) {
tmp = y * z;
} else if (z <= -4.8e-146) {
tmp = y;
} else if (z <= 6.7e-302) {
tmp = x;
} else if (z <= 9.8e-107) {
tmp = y;
} else if (z <= 8.5e-6) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -17.0: tmp = y * z elif z <= -4.8e-146: tmp = y elif z <= 6.7e-302: tmp = x elif z <= 9.8e-107: tmp = y elif z <= 8.5e-6: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -17.0) tmp = Float64(y * z); elseif (z <= -4.8e-146) tmp = y; elseif (z <= 6.7e-302) tmp = x; elseif (z <= 9.8e-107) tmp = y; elseif (z <= 8.5e-6) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -17.0) tmp = y * z; elseif (z <= -4.8e-146) tmp = y; elseif (z <= 6.7e-302) tmp = x; elseif (z <= 9.8e-107) tmp = y; elseif (z <= 8.5e-6) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -17.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -4.8e-146], y, If[LessEqual[z, 6.7e-302], x, If[LessEqual[z, 9.8e-107], y, If[LessEqual[z, 8.5e-6], x, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -17:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-146}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 6.7 \cdot 10^{-302}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{-107}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -17 or 8.4999999999999999e-6 < z Initial program 100.0%
Taylor expanded in z around inf 95.5%
Taylor expanded in x around 0 49.5%
if -17 < z < -4.8000000000000003e-146 or 6.70000000000000042e-302 < z < 9.79999999999999959e-107Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Taylor expanded in y around inf 40.9%
if -4.8000000000000003e-146 < z < 6.70000000000000042e-302 or 9.79999999999999959e-107 < z < 8.4999999999999999e-6Initial program 99.9%
Taylor expanded in z around 0 97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in y around 0 44.3%
(FPCore (x y z) :precision binary64 (if (<= (+ z 1.0) 0.99998) (* x (+ z 1.0)) (if (<= (+ z 1.0) 800.0) (+ x y) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= 0.99998) {
tmp = x * (z + 1.0);
} else if ((z + 1.0) <= 800.0) {
tmp = x + y;
} 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 + 1.0d0) <= 0.99998d0) then
tmp = x * (z + 1.0d0)
else if ((z + 1.0d0) <= 800.0d0) then
tmp = x + y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= 0.99998) {
tmp = x * (z + 1.0);
} else if ((z + 1.0) <= 800.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= 0.99998: tmp = x * (z + 1.0) elif (z + 1.0) <= 800.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= 0.99998) tmp = Float64(x * Float64(z + 1.0)); elseif (Float64(z + 1.0) <= 800.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= 0.99998) tmp = x * (z + 1.0); elseif ((z + 1.0) <= 800.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], 0.99998], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 800.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq 0.99998:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{elif}\;z + 1 \leq 800:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < 0.99997999999999998Initial program 100.0%
Taylor expanded in x around inf 53.0%
if 0.99997999999999998 < (+.f64 z #s(literal 1 binary64)) < 800Initial program 100.0%
Taylor expanded in z around 0 97.4%
+-commutative97.4%
Simplified97.4%
if 800 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf 95.9%
Taylor expanded in x around 0 50.6%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 920.0) (+ x y) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 920.0) {
tmp = x + y;
} 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 <= (-1.0d0)) then
tmp = x * z
else if (z <= 920.0d0) then
tmp = x + y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 920.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 920.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 920.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= 920.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 920.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 920:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1Initial program 100.0%
Taylor expanded in z around inf 97.6%
Taylor expanded in x around inf 51.1%
*-commutative51.1%
Simplified51.1%
if -1 < z < 920Initial program 100.0%
Taylor expanded in z around 0 97.0%
+-commutative97.0%
Simplified97.0%
if 920 < z Initial program 100.0%
Taylor expanded in z around inf 95.9%
Taylor expanded in x around 0 50.6%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-295) (+ x (* x z)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-295) {
tmp = x + (x * z);
} else {
tmp = y * (z + 1.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 + y) <= (-2d-295)) then
tmp = x + (x * z)
else
tmp = y * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-295) {
tmp = x + (x * z);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-295: tmp = x + (x * z) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-295) tmp = Float64(x + Float64(x * z)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-295) tmp = x + (x * z); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-295], N[(x + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-295}:\\
\;\;\;\;x + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2.00000000000000012e-295Initial program 100.0%
Taylor expanded in x around inf 49.9%
distribute-lft-in49.9%
*-rgt-identity49.9%
Applied egg-rr49.9%
if -2.00000000000000012e-295 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 44.6%
Final simplification47.3%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-295) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-295) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.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 + y) <= (-2d-295)) then
tmp = x * (z + 1.0d0)
else
tmp = y * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-295) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-295: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-295) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-295) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-295], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-295}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2.00000000000000012e-295Initial program 100.0%
Taylor expanded in x around inf 49.9%
if -2.00000000000000012e-295 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 44.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e-35) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e-35) {
tmp = x;
} else {
tmp = 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.35d-35) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e-35) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.35e-35: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.35e-35) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.35e-35) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.35e-35], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.3499999999999999e-35Initial program 100.0%
Taylor expanded in z around 0 50.9%
+-commutative50.9%
Simplified50.9%
Taylor expanded in y around 0 31.4%
if 1.3499999999999999e-35 < y Initial program 100.0%
Taylor expanded in z around 0 49.4%
+-commutative49.4%
Simplified49.4%
Taylor expanded in y around inf 32.6%
(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 100.0%
Taylor expanded in z around 0 50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in y around 0 27.7%
herbie shell --seed 2024139
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))