
(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 (* (+ 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 -4e+78)
t_0
(if (<= z -4.9e+55)
(* y z)
(if (<= z -3.8e+34)
t_0
(if (<= z -1.0)
(* y z)
(if (<= z 2.85e-5)
(+ x y)
(if (or (<= z 1.26e+270) (not (<= z 4.1e+278)))
t_0
(* y z)))))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -4e+78) {
tmp = t_0;
} else if (z <= -4.9e+55) {
tmp = y * z;
} else if (z <= -3.8e+34) {
tmp = t_0;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 2.85e-5) {
tmp = x + y;
} else if ((z <= 1.26e+270) || !(z <= 4.1e+278)) {
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 <= (-4d+78)) then
tmp = t_0
else if (z <= (-4.9d+55)) then
tmp = y * z
else if (z <= (-3.8d+34)) then
tmp = t_0
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 2.85d-5) then
tmp = x + y
else if ((z <= 1.26d+270) .or. (.not. (z <= 4.1d+278))) 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 <= -4e+78) {
tmp = t_0;
} else if (z <= -4.9e+55) {
tmp = y * z;
} else if (z <= -3.8e+34) {
tmp = t_0;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 2.85e-5) {
tmp = x + y;
} else if ((z <= 1.26e+270) || !(z <= 4.1e+278)) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -4e+78: tmp = t_0 elif z <= -4.9e+55: tmp = y * z elif z <= -3.8e+34: tmp = t_0 elif z <= -1.0: tmp = y * z elif z <= 2.85e-5: tmp = x + y elif (z <= 1.26e+270) or not (z <= 4.1e+278): 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 (z <= -4e+78) tmp = t_0; elseif (z <= -4.9e+55) tmp = Float64(y * z); elseif (z <= -3.8e+34) tmp = t_0; elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 2.85e-5) tmp = Float64(x + y); elseif ((z <= 1.26e+270) || !(z <= 4.1e+278)) 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 <= -4e+78) tmp = t_0; elseif (z <= -4.9e+55) tmp = y * z; elseif (z <= -3.8e+34) tmp = t_0; elseif (z <= -1.0) tmp = y * z; elseif (z <= 2.85e-5) tmp = x + y; elseif ((z <= 1.26e+270) || ~((z <= 4.1e+278))) 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[z, -4e+78], t$95$0, If[LessEqual[z, -4.9e+55], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.8e+34], t$95$0, If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.85e-5], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.26e+270], N[Not[LessEqual[z, 4.1e+278]], $MachinePrecision]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -4 \cdot 10^{+78}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.9 \cdot 10^{+55}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -3.8 \cdot 10^{+34}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.85 \cdot 10^{-5}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.26 \cdot 10^{+270} \lor \neg \left(z \leq 4.1 \cdot 10^{+278}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.00000000000000003e78 or -4.90000000000000015e55 < z < -3.8000000000000001e34 or 2.8500000000000002e-5 < z < 1.2600000000000001e270 or 4.10000000000000015e278 < z Initial program 100.0%
Taylor expanded in x around inf 54.1%
if -4.00000000000000003e78 < z < -4.90000000000000015e55 or -3.8000000000000001e34 < z < -1 or 1.2600000000000001e270 < z < 4.10000000000000015e278Initial program 99.9%
Taylor expanded in x around 0 49.5%
+-commutative49.5%
distribute-lft-in49.5%
*-rgt-identity49.5%
Applied egg-rr49.5%
Taylor expanded in z around inf 40.3%
if -1 < z < 2.8500000000000002e-5Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification73.3%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* y z)
(if (<= z -1.45e-140)
y
(if (<= z -1.65e-178)
x
(if (<= z 5.5e-286)
y
(if (<= z 2e-118) 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 <= -1.45e-140) {
tmp = y;
} else if (z <= -1.65e-178) {
tmp = x;
} else if (z <= 5.5e-286) {
tmp = y;
} else if (z <= 2e-118) {
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 <= (-1.45d-140)) then
tmp = y
else if (z <= (-1.65d-178)) then
tmp = x
else if (z <= 5.5d-286) then
tmp = y
else if (z <= 2d-118) 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 <= -1.45e-140) {
tmp = y;
} else if (z <= -1.65e-178) {
tmp = x;
} else if (z <= 5.5e-286) {
tmp = y;
} else if (z <= 2e-118) {
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 <= -1.45e-140: tmp = y elif z <= -1.65e-178: tmp = x elif z <= 5.5e-286: tmp = y elif z <= 2e-118: 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 <= -1.45e-140) tmp = y; elseif (z <= -1.65e-178) tmp = x; elseif (z <= 5.5e-286) tmp = y; elseif (z <= 2e-118) 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 <= -1.45e-140) tmp = y; elseif (z <= -1.65e-178) tmp = x; elseif (z <= 5.5e-286) tmp = y; elseif (z <= 2e-118) 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, -1.45e-140], y, If[LessEqual[z, -1.65e-178], x, If[LessEqual[z, 5.5e-286], y, If[LessEqual[z, 2e-118], 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 -1.45 \cdot 10^{-140}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq -1.65 \cdot 10^{-178}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-286}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-118}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in x around 0 54.9%
+-commutative54.9%
distribute-lft-in54.9%
*-rgt-identity54.9%
Applied egg-rr54.9%
Taylor expanded in z around inf 53.0%
if -1 < z < -1.44999999999999999e-140 or -1.6500000000000001e-178 < z < 5.4999999999999998e-286 or 1.99999999999999997e-118 < z < 1Initial program 100.0%
Taylor expanded in x around 0 42.6%
Taylor expanded in z around 0 40.5%
if -1.44999999999999999e-140 < z < -1.6500000000000001e-178 or 5.4999999999999998e-286 < z < 1.99999999999999997e-118Initial program 100.0%
Taylor expanded in x around inf 47.4%
Taylor expanded in z around 0 47.4%
Final simplification48.4%
(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 97.4%
+-commutative97.4%
Simplified97.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.2%
+-commutative97.2%
Simplified97.2%
Final simplification97.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 102.0))) (* y z) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 102.0)) {
tmp = y * z;
} 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 <= 102.0d0))) then
tmp = y * z
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 <= 102.0)) {
tmp = y * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 102.0): tmp = y * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 102.0)) tmp = Float64(y * z); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 102.0))) tmp = y * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 102.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 102\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 102 < z Initial program 100.0%
Taylor expanded in x around 0 54.9%
+-commutative54.9%
distribute-lft-in54.9%
*-rgt-identity54.9%
Applied egg-rr54.9%
Taylor expanded in z around inf 53.0%
if -1 < z < 102Initial program 100.0%
Taylor expanded in z around 0 97.2%
+-commutative97.2%
Simplified97.2%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-44) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e-44) {
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 <= (-1.05d-44)) 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 <= -1.05e-44) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e-44: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e-44) 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 <= -1.05e-44) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-44], 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 \leq -1.05 \cdot 10^{-44}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -1.05000000000000001e-44Initial program 100.0%
Taylor expanded in x around inf 79.6%
if -1.05000000000000001e-44 < x Initial program 100.0%
Taylor expanded in x around 0 61.2%
Final simplification66.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-44) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e-44) {
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 (x <= (-1.05d-44)) 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 (x <= -1.05e-44) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e-44: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e-44) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e-44) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-44], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.05000000000000001e-44Initial program 100.0%
Taylor expanded in x around inf 79.6%
Taylor expanded in z around 0 31.3%
if -1.05000000000000001e-44 < x Initial program 100.0%
Taylor expanded in x around 0 61.2%
Taylor expanded in z around 0 27.3%
Final simplification28.4%
(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 x around inf 53.8%
Taylor expanded in z around 0 26.2%
Final simplification26.2%
herbie shell --seed 2023334
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))