
(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 7 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) -1e+238)
(* y z)
(if (<= (+ z 1.0) -5e+42)
(* x z)
(if (<= (+ z 1.0) -2000.0)
(* y z)
(if (<= (+ z 1.0) 5000000000000.0)
(+ x y)
(if (<= (+ z 1.0) 1e+103) (* y z) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -1e+238) {
tmp = y * z;
} else if ((z + 1.0) <= -5e+42) {
tmp = x * z;
} else if ((z + 1.0) <= -2000.0) {
tmp = y * z;
} else if ((z + 1.0) <= 5000000000000.0) {
tmp = x + y;
} else if ((z + 1.0) <= 1e+103) {
tmp = y * z;
} else {
tmp = x * 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) <= (-1d+238)) then
tmp = y * z
else if ((z + 1.0d0) <= (-5d+42)) then
tmp = x * z
else if ((z + 1.0d0) <= (-2000.0d0)) then
tmp = y * z
else if ((z + 1.0d0) <= 5000000000000.0d0) then
tmp = x + y
else if ((z + 1.0d0) <= 1d+103) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -1e+238) {
tmp = y * z;
} else if ((z + 1.0) <= -5e+42) {
tmp = x * z;
} else if ((z + 1.0) <= -2000.0) {
tmp = y * z;
} else if ((z + 1.0) <= 5000000000000.0) {
tmp = x + y;
} else if ((z + 1.0) <= 1e+103) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -1e+238: tmp = y * z elif (z + 1.0) <= -5e+42: tmp = x * z elif (z + 1.0) <= -2000.0: tmp = y * z elif (z + 1.0) <= 5000000000000.0: tmp = x + y elif (z + 1.0) <= 1e+103: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -1e+238) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= -5e+42) tmp = Float64(x * z); elseif (Float64(z + 1.0) <= -2000.0) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= 5000000000000.0) tmp = Float64(x + y); elseif (Float64(z + 1.0) <= 1e+103) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= -1e+238) tmp = y * z; elseif ((z + 1.0) <= -5e+42) tmp = x * z; elseif ((z + 1.0) <= -2000.0) tmp = y * z; elseif ((z + 1.0) <= 5000000000000.0) tmp = x + y; elseif ((z + 1.0) <= 1e+103) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -1e+238], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], -5e+42], N[(x * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], -2000.0], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 5000000000000.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1e+103], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -1 \cdot 10^{+238}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq -5 \cdot 10^{+42}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z + 1 \leq -2000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq 5000000000000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z + 1 \leq 10^{+103}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -1e238 or -5.00000000000000007e42 < (+.f64 z #s(literal 1 binary64)) < -2e3 or 5e12 < (+.f64 z #s(literal 1 binary64)) < 1e103Initial program 100.0%
Taylor expanded in x around 0 54.3%
Taylor expanded in z around inf 52.6%
*-commutative52.6%
Simplified52.6%
if -1e238 < (+.f64 z #s(literal 1 binary64)) < -5.00000000000000007e42 or 1e103 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf 56.7%
Taylor expanded in z around inf 56.7%
if -2e3 < (+.f64 z #s(literal 1 binary64)) < 5e12Initial program 100.0%
Taylor expanded in z around 0 96.1%
+-commutative96.1%
Simplified96.1%
Final simplification76.5%
(FPCore (x y z)
:precision binary64
(if (<= z -7.2e+236)
(* y z)
(if (<= z -1.5e+41)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 6.4e-215)
x
(if (<= z 1.0) y (if (<= z 3e+107) (* y z) (* x z))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e+236) {
tmp = y * z;
} else if (z <= -1.5e+41) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 6.4e-215) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} else if (z <= 3e+107) {
tmp = y * z;
} else {
tmp = x * 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 <= (-7.2d+236)) then
tmp = y * z
else if (z <= (-1.5d+41)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 6.4d-215) then
tmp = x
else if (z <= 1.0d0) then
tmp = y
else if (z <= 3d+107) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e+236) {
tmp = y * z;
} else if (z <= -1.5e+41) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 6.4e-215) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} else if (z <= 3e+107) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.2e+236: tmp = y * z elif z <= -1.5e+41: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 6.4e-215: tmp = x elif z <= 1.0: tmp = y elif z <= 3e+107: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.2e+236) tmp = Float64(y * z); elseif (z <= -1.5e+41) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 6.4e-215) tmp = x; elseif (z <= 1.0) tmp = y; elseif (z <= 3e+107) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.2e+236) tmp = y * z; elseif (z <= -1.5e+41) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 6.4e-215) tmp = x; elseif (z <= 1.0) tmp = y; elseif (z <= 3e+107) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.2e+236], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.5e+41], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.4e-215], x, If[LessEqual[z, 1.0], y, If[LessEqual[z, 3e+107], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{+236}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.5 \cdot 10^{+41}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-215}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+107}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -7.1999999999999999e236 or -1.4999999999999999e41 < z < -1 or 1 < z < 3.00000000000000023e107Initial program 100.0%
Taylor expanded in x around 0 53.1%
Taylor expanded in z around inf 50.4%
*-commutative50.4%
Simplified50.4%
if -7.1999999999999999e236 < z < -1.4999999999999999e41 or 3.00000000000000023e107 < z Initial program 100.0%
Taylor expanded in x around inf 56.7%
Taylor expanded in z around inf 56.7%
if -1 < z < 6.4000000000000003e-215Initial program 100.0%
Taylor expanded in z around 0 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in y around 0 39.6%
if 6.4000000000000003e-215 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.4%
+-commutative97.4%
Simplified97.4%
Taylor expanded in y around inf 48.2%
Final simplification48.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 1e-208) x (if (<= z 0.7) y (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 1e-208) {
tmp = x;
} else if (z <= 0.7) {
tmp = y;
} else {
tmp = x * 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 <= 1d-208) then
tmp = x
else if (z <= 0.7d0) then
tmp = y
else
tmp = x * 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 <= 1e-208) {
tmp = x;
} else if (z <= 0.7) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 1e-208: tmp = x elif z <= 0.7: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 1e-208) tmp = x; elseif (z <= 0.7) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= 1e-208) tmp = x; elseif (z <= 0.7) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 1e-208], x, If[LessEqual[z, 0.7], y, N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 10^{-208}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.7:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 0.69999999999999996 < z Initial program 100.0%
Taylor expanded in x around inf 57.1%
Taylor expanded in z around inf 56.0%
if -1 < z < 1.0000000000000001e-208Initial program 100.0%
Taylor expanded in z around 0 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in y around 0 39.6%
if 1.0000000000000001e-208 < z < 0.69999999999999996Initial program 100.0%
Taylor expanded in z around 0 97.4%
+-commutative97.4%
Simplified97.4%
Taylor expanded in y around inf 48.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-263) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-263) {
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) <= (-1d-263)) 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) <= -1e-263) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -1e-263: 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) <= -1e-263) 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) <= -1e-263) 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], -1e-263], 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 -1 \cdot 10^{-263}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1e-263Initial program 100.0%
Taylor expanded in x around inf 50.7%
if -1e-263 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 54.2%
(FPCore (x y z) :precision binary64 (if (<= y 1.4e-71) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.4e-71) {
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.4d-71) 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.4e-71) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.4e-71: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.4e-71) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.4e-71) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.4e-71], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.4 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.4e-71Initial program 100.0%
Taylor expanded in z around 0 51.0%
+-commutative51.0%
Simplified51.0%
Taylor expanded in y around 0 30.6%
if 1.4e-71 < y Initial program 100.0%
Taylor expanded in z around 0 52.8%
+-commutative52.8%
Simplified52.8%
Taylor expanded in y around inf 46.9%
(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 51.5%
+-commutative51.5%
Simplified51.5%
Taylor expanded in y around 0 23.3%
herbie shell --seed 2024128
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))