
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (* z -0.5) t)) (t_2 (* 0.5 (/ x t))))
(if (<= y -3.1e-164)
t_2
(if (<= y -1.1e-297)
t_1
(if (<= y 4e-209) t_2 (if (<= y 7.2e+70) t_1 (/ (* y 0.5) t)))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * -0.5) / t;
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -3.1e-164) {
tmp = t_2;
} else if (y <= -1.1e-297) {
tmp = t_1;
} else if (y <= 4e-209) {
tmp = t_2;
} else if (y <= 7.2e+70) {
tmp = t_1;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (z * (-0.5d0)) / t
t_2 = 0.5d0 * (x / t)
if (y <= (-3.1d-164)) then
tmp = t_2
else if (y <= (-1.1d-297)) then
tmp = t_1
else if (y <= 4d-209) then
tmp = t_2
else if (y <= 7.2d+70) then
tmp = t_1
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * -0.5) / t;
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -3.1e-164) {
tmp = t_2;
} else if (y <= -1.1e-297) {
tmp = t_1;
} else if (y <= 4e-209) {
tmp = t_2;
} else if (y <= 7.2e+70) {
tmp = t_1;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * -0.5) / t t_2 = 0.5 * (x / t) tmp = 0 if y <= -3.1e-164: tmp = t_2 elif y <= -1.1e-297: tmp = t_1 elif y <= 4e-209: tmp = t_2 elif y <= 7.2e+70: tmp = t_1 else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * -0.5) / t) t_2 = Float64(0.5 * Float64(x / t)) tmp = 0.0 if (y <= -3.1e-164) tmp = t_2; elseif (y <= -1.1e-297) tmp = t_1; elseif (y <= 4e-209) tmp = t_2; elseif (y <= 7.2e+70) tmp = t_1; else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * -0.5) / t; t_2 = 0.5 * (x / t); tmp = 0.0; if (y <= -3.1e-164) tmp = t_2; elseif (y <= -1.1e-297) tmp = t_1; elseif (y <= 4e-209) tmp = t_2; elseif (y <= 7.2e+70) tmp = t_1; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.1e-164], t$95$2, If[LessEqual[y, -1.1e-297], t$95$1, If[LessEqual[y, 4e-209], t$95$2, If[LessEqual[y, 7.2e+70], t$95$1, N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z \cdot -0.5}{t}\\
t_2 := 0.5 \cdot \frac{x}{t}\\
\mathbf{if}\;y \leq -3.1 \cdot 10^{-164}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq -1.1 \cdot 10^{-297}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-209}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+70}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < -3.1000000000000001e-164 or -1.0999999999999999e-297 < y < 4.0000000000000002e-209Initial program 100.0%
Taylor expanded in x around inf 38.8%
if -3.1000000000000001e-164 < y < -1.0999999999999999e-297 or 4.0000000000000002e-209 < y < 7.1999999999999999e70Initial program 100.0%
Taylor expanded in z around inf 47.0%
*-commutative47.0%
associate-*l/47.0%
Simplified47.0%
if 7.1999999999999999e70 < y Initial program 100.0%
Taylor expanded in y around inf 72.9%
associate-*r/72.9%
Simplified72.9%
Final simplification48.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.7e+162) (not (<= z 9e+85))) (/ (* z -0.5) t) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.7e+162) || !(z <= 9e+85)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-2.7d+162)) .or. (.not. (z <= 9d+85))) then
tmp = (z * (-0.5d0)) / t
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.7e+162) || !(z <= 9e+85)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.7e+162) or not (z <= 9e+85): tmp = (z * -0.5) / t else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.7e+162) || !(z <= 9e+85)) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.7e+162) || ~((z <= 9e+85))) tmp = (z * -0.5) / t; else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.7e+162], N[Not[LessEqual[z, 9e+85]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+162} \lor \neg \left(z \leq 9 \cdot 10^{+85}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if z < -2.7000000000000002e162 or 9.00000000000000013e85 < z Initial program 100.0%
Taylor expanded in z around inf 82.3%
*-commutative82.3%
associate-*l/82.3%
Simplified82.3%
if -2.7000000000000002e162 < z < 9.00000000000000013e85Initial program 100.0%
Taylor expanded in z around 0 84.9%
associate-*r/84.9%
associate-*l/84.8%
*-commutative84.8%
+-commutative84.8%
Simplified84.8%
Final simplification84.2%
(FPCore (x y z t) :precision binary64 (if (<= y 2.9e-56) (* (- x z) (/ 0.5 t)) (if (<= y 7.8e+117) (/ (* 0.5 (- y z)) t) (* (+ x y) (/ 0.5 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.9e-56) {
tmp = (x - z) * (0.5 / t);
} else if (y <= 7.8e+117) {
tmp = (0.5 * (y - z)) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 2.9d-56) then
tmp = (x - z) * (0.5d0 / t)
else if (y <= 7.8d+117) then
tmp = (0.5d0 * (y - z)) / t
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.9e-56) {
tmp = (x - z) * (0.5 / t);
} else if (y <= 7.8e+117) {
tmp = (0.5 * (y - z)) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.9e-56: tmp = (x - z) * (0.5 / t) elif y <= 7.8e+117: tmp = (0.5 * (y - z)) / t else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.9e-56) tmp = Float64(Float64(x - z) * Float64(0.5 / t)); elseif (y <= 7.8e+117) tmp = Float64(Float64(0.5 * Float64(y - z)) / t); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.9e-56) tmp = (x - z) * (0.5 / t); elseif (y <= 7.8e+117) tmp = (0.5 * (y - z)) / t; else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.9e-56], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.8e+117], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-56}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+117}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 2.89999999999999991e-56Initial program 100.0%
Taylor expanded in y around 0 74.5%
*-commutative74.5%
associate-*l/74.5%
associate-/l*74.3%
Simplified74.3%
if 2.89999999999999991e-56 < y < 7.79999999999999981e117Initial program 99.9%
Taylor expanded in x around 0 72.4%
associate-*r/72.4%
Simplified72.4%
if 7.79999999999999981e117 < y Initial program 100.0%
Taylor expanded in z around 0 97.0%
associate-*r/97.0%
associate-*l/96.9%
*-commutative96.9%
+-commutative96.9%
Simplified96.9%
Final simplification78.2%
(FPCore (x y z t) :precision binary64 (if (<= y 7.2e+70) (* (- x z) (/ 0.5 t)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.2e+70) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 7.2d+70) then
tmp = (x - z) * (0.5d0 / t)
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.2e+70) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 7.2e+70: tmp = (x - z) * (0.5 / t) else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 7.2e+70) tmp = Float64(Float64(x - z) * Float64(0.5 / t)); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 7.2e+70) tmp = (x - z) * (0.5 / t); else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 7.2e+70], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+70}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 7.1999999999999999e70Initial program 100.0%
Taylor expanded in y around 0 75.4%
*-commutative75.4%
associate-*l/75.4%
associate-/l*75.2%
Simplified75.2%
if 7.1999999999999999e70 < y Initial program 100.0%
Taylor expanded in z around 0 92.8%
associate-*r/92.8%
associate-*l/92.7%
*-commutative92.7%
+-commutative92.7%
Simplified92.7%
Final simplification79.0%
(FPCore (x y z t) :precision binary64 (if (<= y 1.9e-56) (* 0.5 (/ x t)) (* y (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-56) {
tmp = 0.5 * (x / t);
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.9d-56) then
tmp = 0.5d0 * (x / t)
else
tmp = y * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-56) {
tmp = 0.5 * (x / t);
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.9e-56: tmp = 0.5 * (x / t) else: tmp = y * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.9e-56) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(y * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.9e-56) tmp = 0.5 * (x / t); else tmp = y * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.9e-56], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 1.9000000000000001e-56Initial program 100.0%
Taylor expanded in x around inf 43.2%
if 1.9000000000000001e-56 < y Initial program 100.0%
div-sub94.9%
div-inv94.7%
*-commutative94.7%
associate-/r*94.7%
metadata-eval94.7%
div-inv94.7%
*-commutative94.7%
associate-/r*94.7%
metadata-eval94.7%
Applied egg-rr94.7%
Taylor expanded in y around inf 59.5%
associate-*r/59.5%
associate-*l/59.4%
*-commutative59.4%
Simplified59.4%
Final simplification48.2%
(FPCore (x y z t) :precision binary64 (if (<= y 1.9e-56) (* 0.5 (/ x t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-56) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.9d-56) then
tmp = 0.5d0 * (x / t)
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-56) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.9e-56: tmp = 0.5 * (x / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.9e-56) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.9e-56) tmp = 0.5 * (x / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.9e-56], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 1.9000000000000001e-56Initial program 100.0%
Taylor expanded in x around inf 43.2%
if 1.9000000000000001e-56 < y Initial program 100.0%
Taylor expanded in y around inf 59.5%
associate-*r/59.5%
Simplified59.5%
Final simplification48.2%
(FPCore (x y z t) :precision binary64 (* 0.5 (/ x t)))
double code(double x, double y, double z, double t) {
return 0.5 * (x / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 0.5d0 * (x / t)
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (x / t);
}
def code(x, y, z, t): return 0.5 * (x / t)
function code(x, y, z, t) return Float64(0.5 * Float64(x / t)) end
function tmp = code(x, y, z, t) tmp = 0.5 * (x / t); end
code[x_, y_, z_, t_] := N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{x}{t}
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 40.7%
Final simplification40.7%
herbie shell --seed 2024053
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, B"
:precision binary64
(/ (- (+ x y) z) (* t 2.0)))