
(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 8 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 (* (+ z 1.0) (+ x y)))
double code(double x, double y, double z) {
return (z + 1.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 = (z + 1.0d0) * (x + y)
end function
public static double code(double x, double y, double z) {
return (z + 1.0) * (x + y);
}
def code(x, y, z): return (z + 1.0) * (x + y)
function code(x, y, z) return Float64(Float64(z + 1.0) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (z + 1.0) * (x + y); end
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(z + 1\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z 1.0))))
(if (<= (+ z 1.0) -4e+79)
(* y z)
(if (<= (+ z 1.0) 1.0)
t_0
(if (<= (+ z 1.0) 1.000005)
(+ x y)
(if (<= (+ z 1.0) 2e+172) t_0 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if ((z + 1.0) <= -4e+79) {
tmp = y * z;
} else if ((z + 1.0) <= 1.0) {
tmp = t_0;
} else if ((z + 1.0) <= 1.000005) {
tmp = x + y;
} else if ((z + 1.0) <= 2e+172) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (z + 1.0d0)
if ((z + 1.0d0) <= (-4d+79)) then
tmp = y * z
else if ((z + 1.0d0) <= 1.0d0) then
tmp = t_0
else if ((z + 1.0d0) <= 1.000005d0) then
tmp = x + y
else if ((z + 1.0d0) <= 2d+172) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if ((z + 1.0) <= -4e+79) {
tmp = y * z;
} else if ((z + 1.0) <= 1.0) {
tmp = t_0;
} else if ((z + 1.0) <= 1.000005) {
tmp = x + y;
} else if ((z + 1.0) <= 2e+172) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if (z + 1.0) <= -4e+79: tmp = y * z elif (z + 1.0) <= 1.0: tmp = t_0 elif (z + 1.0) <= 1.000005: tmp = x + y elif (z + 1.0) <= 2e+172: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (Float64(z + 1.0) <= -4e+79) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= 1.0) tmp = t_0; elseif (Float64(z + 1.0) <= 1.000005) tmp = Float64(x + y); elseif (Float64(z + 1.0) <= 2e+172) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if ((z + 1.0) <= -4e+79) tmp = y * z; elseif ((z + 1.0) <= 1.0) tmp = t_0; elseif ((z + 1.0) <= 1.000005) tmp = x + y; elseif ((z + 1.0) <= 2e+172) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z + 1.0), $MachinePrecision], -4e+79], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.0], t$95$0, If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.000005], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 2e+172], t$95$0, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z + 1 \leq -4 \cdot 10^{+79}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z + 1 \leq 1.000005:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z + 1 \leq 2 \cdot 10^{+172}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -3.99999999999999987e79 or 2.0000000000000002e172 < (+.f64 z #s(literal 1 binary64)) Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 50.5%
if -3.99999999999999987e79 < (+.f64 z #s(literal 1 binary64)) < 1 or 1.00000500000000003 < (+.f64 z #s(literal 1 binary64)) < 2.0000000000000002e172Initial program 100.0%
Taylor expanded in x around inf 46.6%
if 1 < (+.f64 z #s(literal 1 binary64)) < 1.00000500000000003Initial program 99.5%
Taylor expanded in z around 0 77.1%
+-commutative77.1%
Simplified77.1%
Final simplification48.6%
(FPCore (x y z)
:precision binary64
(if (<= z -1.65e+63)
(* y z)
(if (<= z -1.0)
(* x z)
(if (<= z -2.3e-191)
x
(if (<= z 4.0) y (if (<= z 9.5e+177) (* x z) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.65e+63) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= -2.3e-191) {
tmp = x;
} else if (z <= 4.0) {
tmp = y;
} else if (z <= 9.5e+177) {
tmp = x * z;
} 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.65d+63)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= (-2.3d-191)) then
tmp = x
else if (z <= 4.0d0) then
tmp = y
else if (z <= 9.5d+177) then
tmp = x * z
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.65e+63) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= -2.3e-191) {
tmp = x;
} else if (z <= 4.0) {
tmp = y;
} else if (z <= 9.5e+177) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.65e+63: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= -2.3e-191: tmp = x elif z <= 4.0: tmp = y elif z <= 9.5e+177: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.65e+63) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= -2.3e-191) tmp = x; elseif (z <= 4.0) tmp = y; elseif (z <= 9.5e+177) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.65e+63) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= -2.3e-191) tmp = x; elseif (z <= 4.0) tmp = y; elseif (z <= 9.5e+177) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.65e+63], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, -2.3e-191], x, If[LessEqual[z, 4.0], y, If[LessEqual[z, 9.5e+177], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-191}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{+177}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.6500000000000001e63 or 9.49999999999999996e177 < z Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 50.5%
if -1.6500000000000001e63 < z < -1 or 4 < z < 9.49999999999999996e177Initial program 99.9%
Taylor expanded in z around inf 95.2%
Taylor expanded in x around inf 50.4%
*-commutative50.4%
Simplified50.4%
if -1 < z < -2.30000000000000011e-191Initial program 100.0%
Taylor expanded in z around 0 95.3%
+-commutative95.3%
Simplified95.3%
Taylor expanded in y around 0 31.4%
if -2.30000000000000011e-191 < z < 4Initial program 100.0%
Taylor expanded in z around 0 97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in y around inf 49.4%
Final simplification47.3%
(FPCore (x y z)
:precision binary64
(if (<= z -4.8e+60)
(* y z)
(if (<= z -1.0)
(* x z)
(if (<= z 5000.0) (+ x y) (if (<= z 1.3e+184) (* x z) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+60) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 5000.0) {
tmp = x + y;
} else if (z <= 1.3e+184) {
tmp = x * z;
} 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 <= (-4.8d+60)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= 5000.0d0) then
tmp = x + y
else if (z <= 1.3d+184) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+60) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 5000.0) {
tmp = x + y;
} else if (z <= 1.3e+184) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e+60: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= 5000.0: tmp = x + y elif z <= 1.3e+184: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e+60) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= 5000.0) tmp = Float64(x + y); elseif (z <= 1.3e+184) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.8e+60) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= 5000.0) tmp = x + y; elseif (z <= 1.3e+184) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e+60], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 5000.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.3e+184], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+60}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 5000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+184}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.8e60 or 1.29999999999999997e184 < z Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 50.5%
if -4.8e60 < z < -1 or 5e3 < z < 1.29999999999999997e184Initial program 99.9%
Taylor expanded in z around inf 97.9%
Taylor expanded in x around inf 52.4%
*-commutative52.4%
Simplified52.4%
if -1 < z < 5e3Initial program 100.0%
Taylor expanded in z around 0 95.2%
+-commutative95.2%
Simplified95.2%
Final simplification73.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z -9.2e-198) x (if (<= z 1.0) y (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= -9.2e-198) {
tmp = x;
} else if (z <= 1.0) {
tmp = 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 = y * z
else if (z <= (-9.2d-198)) then
tmp = x
else if (z <= 1.0d0) then
tmp = 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 = y * z;
} else if (z <= -9.2e-198) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= -9.2e-198: tmp = x elif z <= 1.0: tmp = y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= -9.2e-198) tmp = x; elseif (z <= 1.0) tmp = 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 = y * z; elseif (z <= -9.2e-198) tmp = x; elseif (z <= 1.0) tmp = y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -9.2e-198], x, If[LessEqual[z, 1.0], y, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -9.2 \cdot 10^{-198}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 99.9%
Taylor expanded in z around inf 98.1%
Taylor expanded in x around 0 51.0%
if -1 < z < -9.20000000000000053e-198Initial program 100.0%
Taylor expanded in z around 0 95.3%
+-commutative95.3%
Simplified95.3%
Taylor expanded in y around 0 31.4%
if -9.20000000000000053e-198 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in y around inf 49.4%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-282) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-282) {
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-282)) 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-282) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-282: 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-282) 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-282) 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-282], 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^{-282}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2e-282Initial program 99.9%
Taylor expanded in x around inf 48.0%
if -2e-282 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 54.6%
(FPCore (x y z) :precision binary64 (if (<= y 3e-39) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e-39) {
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 <= 3d-39) 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 <= 3e-39) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e-39: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e-39) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e-39) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e-39], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-39}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.00000000000000028e-39Initial program 100.0%
Taylor expanded in z around 0 49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in y around 0 29.0%
if 3.00000000000000028e-39 < y Initial program 100.0%
Taylor expanded in z around 0 49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in y around inf 44.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 49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in y around 0 22.8%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))