
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z 1.0))))
(if (<= z -3.7e-11)
t_0
(if (<= z 120.0)
(+ x y)
(if (or (<= z 1e+191) (not (<= z 9.2e+252))) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -3.7e-11) {
tmp = t_0;
} else if (z <= 120.0) {
tmp = x + y;
} else if ((z <= 1e+191) || !(z <= 9.2e+252)) {
tmp = y * z;
} else {
tmp = t_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 * (z + 1.0d0)
if (z <= (-3.7d-11)) then
tmp = t_0
else if (z <= 120.0d0) then
tmp = x + y
else if ((z <= 1d+191) .or. (.not. (z <= 9.2d+252))) then
tmp = y * z
else
tmp = t_0
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 <= -3.7e-11) {
tmp = t_0;
} else if (z <= 120.0) {
tmp = x + y;
} else if ((z <= 1e+191) || !(z <= 9.2e+252)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -3.7e-11: tmp = t_0 elif z <= 120.0: tmp = x + y elif (z <= 1e+191) or not (z <= 9.2e+252): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (z <= -3.7e-11) tmp = t_0; elseif (z <= 120.0) tmp = Float64(x + y); elseif ((z <= 1e+191) || !(z <= 9.2e+252)) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if (z <= -3.7e-11) tmp = t_0; elseif (z <= 120.0) tmp = x + y; elseif ((z <= 1e+191) || ~((z <= 9.2e+252))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.7e-11], t$95$0, If[LessEqual[z, 120.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1e+191], N[Not[LessEqual[z, 9.2e+252]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -3.7 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 120:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 10^{+191} \lor \neg \left(z \leq 9.2 \cdot 10^{+252}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.7000000000000001e-11 or 1.00000000000000007e191 < z < 9.1999999999999999e252Initial program 100.0%
Taylor expanded in x around inf 55.0%
if -3.7000000000000001e-11 < z < 120Initial program 100.0%
Taylor expanded in z around 0 99.3%
+-commutative99.3%
Simplified99.3%
if 120 < z < 1.00000000000000007e191 or 9.1999999999999999e252 < z Initial program 99.9%
Taylor expanded in z around inf 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in y around inf 57.6%
Final simplification74.7%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z 17.0)
(+ x y)
(if (or (<= z 1.5e+195) (not (<= z 1.08e+253))) (* y z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 17.0) {
tmp = x + y;
} else if ((z <= 1.5e+195) || !(z <= 1.08e+253)) {
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)) then
tmp = x * z
else if (z <= 17.0d0) then
tmp = x + y
else if ((z <= 1.5d+195) .or. (.not. (z <= 1.08d+253))) 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) {
tmp = x * z;
} else if (z <= 17.0) {
tmp = x + y;
} else if ((z <= 1.5e+195) || !(z <= 1.08e+253)) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 17.0: tmp = x + y elif (z <= 1.5e+195) or not (z <= 1.08e+253): tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 17.0) tmp = Float64(x + y); elseif ((z <= 1.5e+195) || !(z <= 1.08e+253)) 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) tmp = x * z; elseif (z <= 17.0) tmp = x + y; elseif ((z <= 1.5e+195) || ~((z <= 1.08e+253))) tmp = y * z; 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, 17.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.5e+195], N[Not[LessEqual[z, 1.08e+253]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 17:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+195} \lor \neg \left(z \leq 1.08 \cdot 10^{+253}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.5e195 < z < 1.08000000000000004e253Initial program 100.0%
Taylor expanded in z around inf 98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 81.0%
Taylor expanded in y around 0 54.4%
if -1 < z < 17Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
if 17 < z < 1.5e195 or 1.08000000000000004e253 < z Initial program 99.9%
Taylor expanded in z around inf 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in y around inf 57.6%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (or (<= y 2.85e-70) (and (not (<= y 5.8e-14)) (<= y 1.9e+19))) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= 2.85e-70) || (!(y <= 5.8e-14) && (y <= 1.9e+19))) {
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 ((y <= 2.85d-70) .or. (.not. (y <= 5.8d-14)) .and. (y <= 1.9d+19)) 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 ((y <= 2.85e-70) || (!(y <= 5.8e-14) && (y <= 1.9e+19))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 2.85e-70) or (not (y <= 5.8e-14) and (y <= 1.9e+19)): tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 2.85e-70) || (!(y <= 5.8e-14) && (y <= 1.9e+19))) 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 ((y <= 2.85e-70) || (~((y <= 5.8e-14)) && (y <= 1.9e+19))) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 2.85e-70], And[N[Not[LessEqual[y, 5.8e-14]], $MachinePrecision], LessEqual[y, 1.9e+19]]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.85 \cdot 10^{-70} \lor \neg \left(y \leq 5.8 \cdot 10^{-14}\right) \land y \leq 1.9 \cdot 10^{+19}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 2.85000000000000014e-70 or 5.8000000000000005e-14 < y < 1.9e19Initial program 100.0%
Taylor expanded in x around inf 60.2%
if 2.85000000000000014e-70 < y < 5.8000000000000005e-14 or 1.9e19 < y Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = 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 ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * (x + y)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * (x + y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(z * Float64(x + y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = z * (x + y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.6%
+-commutative98.6%
Simplified98.6%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y 1.7e-68) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.7e-68) {
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 (y <= 1.7d-68) 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 (y <= 1.7e-68) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.7e-68: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.7e-68) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.7e-68) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.7e-68], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{-68}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < 1.70000000000000009e-68Initial program 100.0%
Taylor expanded in z around inf 52.7%
+-commutative52.7%
Simplified52.7%
Taylor expanded in x around inf 46.7%
Taylor expanded in y around 0 30.6%
if 1.70000000000000009e-68 < y Initial program 100.0%
Taylor expanded in z around inf 66.9%
+-commutative66.9%
Simplified66.9%
Taylor expanded in y around inf 47.0%
Final simplification35.8%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return 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 * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 57.2%
+-commutative57.2%
Simplified57.2%
Taylor expanded in x around inf 48.0%
Taylor expanded in y around 0 28.8%
Final simplification28.8%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))