
(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 (+ x y)))))
double code(double x, double y, double z) {
return x + (y + (z * (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 = x + (y + (z * (x + y)))
end function
public static double code(double x, double y, double z) {
return x + (y + (z * (x + y)));
}
def code(x, y, z): return x + (y + (z * (x + y)))
function code(x, y, z) return Float64(x + Float64(y + Float64(z * Float64(x + y)))) end
function tmp = code(x, y, z) tmp = x + (y + (z * (x + y))); end
code[x_, y_, z_] := N[(x + N[(y + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y + z \cdot \left(x + y\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z -8.4e-193)
y
(if (<= z -1e-263)
x
(if (<= z 5.5e-99) y (if (<= z 0.0064) x (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -8.4e-193) {
tmp = y;
} else if (z <= -1e-263) {
tmp = x;
} else if (z <= 5.5e-99) {
tmp = y;
} else if (z <= 0.0064) {
tmp = x;
} 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 <= (-8.4d-193)) then
tmp = y
else if (z <= (-1d-263)) then
tmp = x
else if (z <= 5.5d-99) then
tmp = y
else if (z <= 0.0064d0) then
tmp = x
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 <= -8.4e-193) {
tmp = y;
} else if (z <= -1e-263) {
tmp = x;
} else if (z <= 5.5e-99) {
tmp = y;
} else if (z <= 0.0064) {
tmp = x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= -8.4e-193: tmp = y elif z <= -1e-263: tmp = x elif z <= 5.5e-99: tmp = y elif z <= 0.0064: tmp = x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= -8.4e-193) tmp = y; elseif (z <= -1e-263) tmp = x; elseif (z <= 5.5e-99) tmp = y; elseif (z <= 0.0064) tmp = x; 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 <= -8.4e-193) tmp = y; elseif (z <= -1e-263) tmp = x; elseif (z <= 5.5e-99) tmp = y; elseif (z <= 0.0064) tmp = x; 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, -8.4e-193], y, If[LessEqual[z, -1e-263], x, If[LessEqual[z, 5.5e-99], y, If[LessEqual[z, 0.0064], x, N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -8.4 \cdot 10^{-193}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq -1 \cdot 10^{-263}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-99}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 0.0064:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 0.00640000000000000031 < z Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in94.7%
Applied egg-rr94.7%
Taylor expanded in z around inf 92.2%
Taylor expanded in y around 0 49.1%
*-commutative49.1%
Simplified49.1%
if -1 < z < -8.3999999999999997e-193 or -1e-263 < z < 5.49999999999999991e-99Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 47.7%
Taylor expanded in z around 0 47.0%
if -8.3999999999999997e-193 < z < -1e-263 or 5.49999999999999991e-99 < z < 0.00640000000000000031Initial program 99.8%
Taylor expanded in x around inf 51.4%
Taylor expanded in z around 0 45.5%
Final simplification47.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.8e-6) (not (<= z 7.5e-13))) (* x (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-6) || !(z <= 7.5e-13)) {
tmp = x * (z + 1.0);
} 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 <= (-5.8d-6)) .or. (.not. (z <= 7.5d-13))) then
tmp = x * (z + 1.0d0)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-6) || !(z <= 7.5e-13)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.8e-6) or not (z <= 7.5e-13): tmp = x * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.8e-6) || !(z <= 7.5e-13)) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.8e-6) || ~((z <= 7.5e-13))) tmp = x * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.8e-6], N[Not[LessEqual[z, 7.5e-13]], $MachinePrecision]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{-6} \lor \neg \left(z \leq 7.5 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -5.8000000000000004e-6 or 7.5000000000000004e-13 < z Initial program 99.9%
Taylor expanded in x around inf 53.3%
if -5.8000000000000004e-6 < z < 7.5000000000000004e-13Initial program 100.0%
Taylor expanded in z around 0 99.0%
+-commutative99.0%
Simplified99.0%
Final simplification74.2%
(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 99.9%
Taylor expanded in z around 0 95.8%
+-commutative95.8%
Simplified95.8%
Final simplification96.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 12.2))) (* x z) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 12.2)) {
tmp = x * 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 <= 12.2d0))) then
tmp = x * 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 <= 12.2)) {
tmp = x * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 12.2): tmp = x * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 12.2)) tmp = Float64(x * 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 <= 12.2))) tmp = x * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 12.2]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 12.2\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 12.199999999999999 < z Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in94.6%
Applied egg-rr94.6%
Taylor expanded in z around inf 92.8%
Taylor expanded in y around 0 49.4%
*-commutative49.4%
Simplified49.4%
if -1 < z < 12.199999999999999Initial program 99.9%
Taylor expanded in z around 0 95.8%
+-commutative95.8%
Simplified95.8%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (<= y 7e-108) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 7e-108) {
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 <= 7d-108) 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 <= 7e-108) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 7e-108: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 7e-108) 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 <= 7e-108) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 7e-108], 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 7 \cdot 10^{-108}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 6.9999999999999997e-108Initial program 99.9%
Taylor expanded in x around inf 61.4%
if 6.9999999999999997e-108 < y Initial program 100.0%
Taylor expanded in x around 0 72.7%
Final simplification65.1%
(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 (if (<= y 4.1e-91) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.1e-91) {
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 <= 4.1d-91) 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 <= 4.1e-91) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.1e-91: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.1e-91) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.1e-91) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.1e-91], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.1 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.10000000000000024e-91Initial program 99.9%
Taylor expanded in x around inf 60.9%
Taylor expanded in z around 0 29.9%
if 4.10000000000000024e-91 < y Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in97.5%
Applied egg-rr97.5%
Taylor expanded in z around inf 81.6%
Taylor expanded in z around 0 44.6%
Final simplification34.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 x around inf 52.0%
Taylor expanded in z around 0 25.7%
Final simplification25.7%
herbie shell --seed 2024095
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))