
(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.02e+213)
(* y z)
(if (<= z -4.1e+193)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 1.15e-6)
(+ x y)
(if (<= z 1.1e+145) (* x (+ z 1.0)) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.02e+213) {
tmp = y * z;
} else if (z <= -4.1e+193) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1.15e-6) {
tmp = x + y;
} else if (z <= 1.1e+145) {
tmp = x * (z + 1.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) :: tmp
if (z <= (-1.02d+213)) then
tmp = y * z
else if (z <= (-4.1d+193)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 1.15d-6) then
tmp = x + y
else if (z <= 1.1d+145) then
tmp = x * (z + 1.0d0)
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.02e+213) {
tmp = y * z;
} else if (z <= -4.1e+193) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1.15e-6) {
tmp = x + y;
} else if (z <= 1.1e+145) {
tmp = x * (z + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.02e+213: tmp = y * z elif z <= -4.1e+193: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 1.15e-6: tmp = x + y elif z <= 1.1e+145: tmp = x * (z + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.02e+213) tmp = Float64(y * z); elseif (z <= -4.1e+193) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 1.15e-6) tmp = Float64(x + y); elseif (z <= 1.1e+145) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.02e+213) tmp = y * z; elseif (z <= -4.1e+193) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 1.15e-6) tmp = x + y; elseif (z <= 1.1e+145) tmp = x * (z + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.02e+213], N[(y * z), $MachinePrecision], If[LessEqual[z, -4.1e+193], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.15e-6], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.1e+145], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+213}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4.1 \cdot 10^{+193}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-6}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+145}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.02e213 or -4.0999999999999997e193 < z < -1 or 1.10000000000000004e145 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
+-commutative98.3%
Simplified98.3%
distribute-lft-in95.8%
Applied egg-rr95.8%
Taylor expanded in y around inf 44.5%
*-commutative44.5%
Simplified44.5%
if -1.02e213 < z < -4.0999999999999997e193Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in80.0%
Applied egg-rr80.0%
Taylor expanded in y around 0 80.0%
*-commutative80.0%
Simplified80.0%
if -1 < z < 1.15e-6Initial program 100.0%
Taylor expanded in z around 0 98.9%
+-commutative98.9%
Simplified98.9%
if 1.15e-6 < z < 1.10000000000000004e145Initial program 100.0%
Taylor expanded in x around inf 63.6%
Final simplification75.8%
(FPCore (x y z)
:precision binary64
(if (<= z -1.4e+213)
(* y z)
(if (<= z -1.95e+193)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 260.0) (+ x y) (if (<= z 1.45e+148) (* x z) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+213) {
tmp = y * z;
} else if (z <= -1.95e+193) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 260.0) {
tmp = x + y;
} else if (z <= 1.45e+148) {
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.4d+213)) then
tmp = y * z
else if (z <= (-1.95d+193)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 260.0d0) then
tmp = x + y
else if (z <= 1.45d+148) 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.4e+213) {
tmp = y * z;
} else if (z <= -1.95e+193) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 260.0) {
tmp = x + y;
} else if (z <= 1.45e+148) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+213: tmp = y * z elif z <= -1.95e+193: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 260.0: tmp = x + y elif z <= 1.45e+148: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+213) tmp = Float64(y * z); elseif (z <= -1.95e+193) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 260.0) tmp = Float64(x + y); elseif (z <= 1.45e+148) 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.4e+213) tmp = y * z; elseif (z <= -1.95e+193) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 260.0) tmp = x + y; elseif (z <= 1.45e+148) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+213], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.95e+193], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 260.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.45e+148], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+213}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.95 \cdot 10^{+193}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 260:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+148}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.39999999999999995e213 or -1.95e193 < z < -1 or 1.45e148 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
+-commutative98.3%
Simplified98.3%
distribute-lft-in95.8%
Applied egg-rr95.8%
Taylor expanded in y around inf 44.5%
*-commutative44.5%
Simplified44.5%
if -1.39999999999999995e213 < z < -1.95e193 or 260 < z < 1.45e148Initial program 100.0%
Taylor expanded in z around inf 96.1%
+-commutative96.1%
Simplified96.1%
distribute-lft-in93.7%
Applied egg-rr93.7%
Taylor expanded in y around 0 61.3%
*-commutative61.3%
Simplified61.3%
if -1 < z < 260Initial program 100.0%
Taylor expanded in z around 0 97.3%
+-commutative97.3%
Simplified97.3%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (or (<= y 7.5e-105) (and (not (<= y 13500.0)) (<= y 4.6e+57))) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= 7.5e-105) || (!(y <= 13500.0) && (y <= 4.6e+57))) {
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 <= 7.5d-105) .or. (.not. (y <= 13500.0d0)) .and. (y <= 4.6d+57)) 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 <= 7.5e-105) || (!(y <= 13500.0) && (y <= 4.6e+57))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 7.5e-105) or (not (y <= 13500.0) and (y <= 4.6e+57)): tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 7.5e-105) || (!(y <= 13500.0) && (y <= 4.6e+57))) 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 <= 7.5e-105) || (~((y <= 13500.0)) && (y <= 4.6e+57))) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 7.5e-105], And[N[Not[LessEqual[y, 13500.0]], $MachinePrecision], LessEqual[y, 4.6e+57]]], 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.5 \cdot 10^{-105} \lor \neg \left(y \leq 13500\right) \land y \leq 4.6 \cdot 10^{+57}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 7.5000000000000006e-105 or 13500 < y < 4.5999999999999998e57Initial program 100.0%
Taylor expanded in x around inf 67.3%
if 7.5000000000000006e-105 < y < 13500 or 4.5999999999999998e57 < y Initial program 100.0%
Taylor expanded in x around 0 72.0%
Final simplification68.7%
(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 96.9%
+-commutative96.9%
Simplified96.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification97.4%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e+71) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+71) {
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 (x <= (-2.8d+71)) 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 (x <= -2.8e+71) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8e+71: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8e+71) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.8e+71) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8e+71], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+71}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.80000000000000002e71Initial program 100.0%
Taylor expanded in z around inf 51.4%
+-commutative51.4%
Simplified51.4%
distribute-lft-in51.4%
Applied egg-rr51.4%
Taylor expanded in y around 0 45.8%
*-commutative45.8%
Simplified45.8%
if -2.80000000000000002e71 < x Initial program 100.0%
Taylor expanded in z around inf 48.1%
+-commutative48.1%
Simplified48.1%
distribute-lft-in46.7%
Applied egg-rr46.7%
Taylor expanded in y around inf 24.0%
*-commutative24.0%
Simplified24.0%
Final simplification28.4%
(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 48.8%
+-commutative48.8%
Simplified48.8%
distribute-lft-in47.6%
Applied egg-rr47.6%
Taylor expanded in y around 0 32.7%
*-commutative32.7%
Simplified32.7%
Final simplification32.7%
herbie shell --seed 2024100
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))