
(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 7 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 (* t -2.0))) (t_2 (* 0.5 (/ x t))))
(if (<= y -1.7e-165)
t_2
(if (<= y -6.4e-299)
t_1
(if (<= y 5.2e-209) t_2 (if (<= y 2.1e+72) t_1 (* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
double t_1 = z / (t * -2.0);
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -1.7e-165) {
tmp = t_2;
} else if (y <= -6.4e-299) {
tmp = t_1;
} else if (y <= 5.2e-209) {
tmp = t_2;
} else if (y <= 2.1e+72) {
tmp = t_1;
} else {
tmp = 0.5 * (y / 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 / (t * (-2.0d0))
t_2 = 0.5d0 * (x / t)
if (y <= (-1.7d-165)) then
tmp = t_2
else if (y <= (-6.4d-299)) then
tmp = t_1
else if (y <= 5.2d-209) then
tmp = t_2
else if (y <= 2.1d+72) then
tmp = t_1
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z / (t * -2.0);
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -1.7e-165) {
tmp = t_2;
} else if (y <= -6.4e-299) {
tmp = t_1;
} else if (y <= 5.2e-209) {
tmp = t_2;
} else if (y <= 2.1e+72) {
tmp = t_1;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = z / (t * -2.0) t_2 = 0.5 * (x / t) tmp = 0 if y <= -1.7e-165: tmp = t_2 elif y <= -6.4e-299: tmp = t_1 elif y <= 5.2e-209: tmp = t_2 elif y <= 2.1e+72: tmp = t_1 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) t_1 = Float64(z / Float64(t * -2.0)) t_2 = Float64(0.5 * Float64(x / t)) tmp = 0.0 if (y <= -1.7e-165) tmp = t_2; elseif (y <= -6.4e-299) tmp = t_1; elseif (y <= 5.2e-209) tmp = t_2; elseif (y <= 2.1e+72) tmp = t_1; else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z / (t * -2.0); t_2 = 0.5 * (x / t); tmp = 0.0; if (y <= -1.7e-165) tmp = t_2; elseif (y <= -6.4e-299) tmp = t_1; elseif (y <= 5.2e-209) tmp = t_2; elseif (y <= 2.1e+72) tmp = t_1; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z / N[(t * -2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e-165], t$95$2, If[LessEqual[y, -6.4e-299], t$95$1, If[LessEqual[y, 5.2e-209], t$95$2, If[LessEqual[y, 2.1e+72], t$95$1, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z}{t \cdot -2}\\
t_2 := 0.5 \cdot \frac{x}{t}\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{-165}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq -6.4 \cdot 10^{-299}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-209}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+72}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < -1.7e-165 or -6.40000000000000016e-299 < y < 5.19999999999999969e-209Initial program 100.0%
Taylor expanded in x around inf 38.3%
if -1.7e-165 < y < -6.40000000000000016e-299 or 5.19999999999999969e-209 < y < 2.1000000000000001e72Initial program 100.0%
Taylor expanded in z around inf 46.4%
associate-*r/46.4%
associate-*l/46.2%
metadata-eval46.2%
associate-/r*46.2%
*-commutative46.2%
associate-*l/46.4%
metadata-eval46.4%
distribute-lft-neg-in46.4%
neg-mul-146.4%
remove-double-neg46.4%
Simplified46.4%
if 2.1000000000000001e72 < y Initial program 100.0%
Taylor expanded in y around inf 72.9%
Final simplification48.2%
(FPCore (x y z t) :precision binary64 (if (<= y 2.9e-56) (* 0.5 (/ (- x z) 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 = 0.5 * ((x - z) / 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 = 0.5d0 * ((x - z) / 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 = 0.5 * ((x - z) / 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 = 0.5 * ((x - z) / 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(0.5 * Float64(Float64(x - z) / t)); elseif (y <= 7.8e+117) tmp = Float64(Float64(0.5 * Float64(y - z)) / t); else tmp = Float64(Float64(Float64(x + y) * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.9e-56) tmp = 0.5 * ((x - z) / 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[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.8e+117], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+117}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x + y\right) \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 2.89999999999999991e-56Initial program 100.0%
Taylor expanded in y around 0 74.5%
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%
+-commutative97.0%
Simplified97.0%
Final simplification78.4%
(FPCore (x y z t) :precision binary64 (if (<= y 9e+72) (* 0.5 (/ (- x z) t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 9e+72) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / 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 <= 9d+72) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 9e+72) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 9e+72: tmp = 0.5 * ((x - z) / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 9e+72) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 9e+72) tmp = 0.5 * ((x - z) / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 9e+72], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{+72}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 8.9999999999999997e72Initial program 100.0%
Taylor expanded in y around 0 75.4%
if 8.9999999999999997e72 < y Initial program 100.0%
Taylor expanded in y around inf 72.9%
Final simplification74.9%
(FPCore (x y z t) :precision binary64 (if (<= y 7.2e+70) (* 0.5 (/ (- x z) t)) (/ (* (+ x y) 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.2e+70) {
tmp = 0.5 * ((x - 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 <= 7.2d+70) then
tmp = 0.5d0 * ((x - 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 <= 7.2e+70) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = ((x + y) * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 7.2e+70: tmp = 0.5 * ((x - z) / 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(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(Float64(x + y) * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 7.2e+70) tmp = 0.5 * ((x - z) / 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[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x + y\right) \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 7.1999999999999999e70Initial program 100.0%
Taylor expanded in y around 0 75.4%
if 7.1999999999999999e70 < y Initial program 100.0%
Taylor expanded in z around 0 92.8%
associate-*r/92.8%
+-commutative92.8%
Simplified92.8%
Final simplification79.2%
(FPCore (x y z t) :precision binary64 (if (<= y 2.9e-56) (* 0.5 (/ x t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.9e-56) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / 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 = 0.5d0 * (x / t)
else
tmp = 0.5d0 * (y / 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 = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.9e-56: tmp = 0.5 * (x / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.9e-56) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.9e-56) tmp = 0.5 * (x / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.9e-56], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 2.89999999999999991e-56Initial program 100.0%
Taylor expanded in x around inf 43.2%
if 2.89999999999999991e-56 < y Initial program 100.0%
Taylor expanded in y around inf 59.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)))