
(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%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.8e+113) (not (<= z 1.22e+64))) (/ (* z -0.5) t) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+113) || !(z <= 1.22e+64)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) / (t * 2.0);
}
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.8d+113)) .or. (.not. (z <= 1.22d+64))) then
tmp = (z * (-0.5d0)) / t
else
tmp = (x + y) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+113) || !(z <= 1.22e+64)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.8e+113) or not (z <= 1.22e+64): tmp = (z * -0.5) / t else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.8e+113) || !(z <= 1.22e+64)) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(x + y) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.8e+113) || ~((z <= 1.22e+64))) tmp = (z * -0.5) / t; else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.8e+113], N[Not[LessEqual[z, 1.22e+64]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+113} \lor \neg \left(z \leq 1.22 \cdot 10^{+64}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -2.79999999999999998e113 or 1.21999999999999994e64 < z Initial program 100.0%
Taylor expanded in z around inf 81.8%
associate-*r/82.9%
Simplified82.9%
if -2.79999999999999998e113 < z < 1.21999999999999994e64Initial program 100.0%
Taylor expanded in z around 0 87.4%
+-commutative87.4%
Simplified87.4%
Final simplification86.0%
(FPCore (x y z t) :precision binary64 (if (<= x -1.26e+53) (/ x (* t 2.0)) (if (<= x 2.9e-178) (/ (* z -0.5) t) (/ y (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.26e+53) {
tmp = x / (t * 2.0);
} else if (x <= 2.9e-178) {
tmp = (z * -0.5) / t;
} else {
tmp = y / (t * 2.0);
}
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 (x <= (-1.26d+53)) then
tmp = x / (t * 2.0d0)
else if (x <= 2.9d-178) then
tmp = (z * (-0.5d0)) / t
else
tmp = y / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.26e+53) {
tmp = x / (t * 2.0);
} else if (x <= 2.9e-178) {
tmp = (z * -0.5) / t;
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.26e+53: tmp = x / (t * 2.0) elif x <= 2.9e-178: tmp = (z * -0.5) / t else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.26e+53) tmp = Float64(x / Float64(t * 2.0)); elseif (x <= 2.9e-178) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.26e+53) tmp = x / (t * 2.0); elseif (x <= 2.9e-178) tmp = (z * -0.5) / t; else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.26e+53], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.9e-178], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.26 \cdot 10^{+53}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{-178}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -1.25999999999999999e53Initial program 99.9%
Taylor expanded in x around inf 69.4%
if -1.25999999999999999e53 < x < 2.8999999999999998e-178Initial program 100.0%
Taylor expanded in z around inf 50.6%
associate-*r/51.4%
Simplified51.4%
if 2.8999999999999998e-178 < x Initial program 100.0%
Taylor expanded in y around inf 41.6%
Final simplification50.7%
(FPCore (x y z t) :precision binary64 (if (<= y 3e-8) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3e-8) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
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 <= 3d-8) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (y - z) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3e-8) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 3e-8: tmp = (x - z) / (t * 2.0) else: tmp = (y - z) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 3e-8) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(y - z) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 3e-8) tmp = (x - z) / (t * 2.0); else tmp = (y - z) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 3e-8], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-8}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if y < 2.99999999999999973e-8Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 2.99999999999999973e-8 < y Initial program 99.9%
Taylor expanded in x around 0 84.4%
(FPCore (x y z t) :precision binary64 (if (<= y 7.4e+25) (/ (- x z) (* t 2.0)) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.4e+25) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (x + y) / (t * 2.0);
}
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.4d+25) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (x + y) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.4e+25) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 7.4e+25: tmp = (x - z) / (t * 2.0) else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 7.4e+25) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(x + y) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 7.4e+25) tmp = (x - z) / (t * 2.0); else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 7.4e+25], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.4 \cdot 10^{+25}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if y < 7.3999999999999998e25Initial program 100.0%
Taylor expanded in y around 0 74.6%
if 7.3999999999999998e25 < y Initial program 99.9%
Taylor expanded in z around 0 82.6%
+-commutative82.6%
Simplified82.6%
Final simplification76.3%
(FPCore (x y z t) :precision binary64 (if (<= y 5.4e-8) (/ x (* t 2.0)) (/ y (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5.4e-8) {
tmp = x / (t * 2.0);
} else {
tmp = y / (t * 2.0);
}
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 <= 5.4d-8) then
tmp = x / (t * 2.0d0)
else
tmp = y / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5.4e-8) {
tmp = x / (t * 2.0);
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 5.4e-8: tmp = x / (t * 2.0) else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 5.4e-8) tmp = Float64(x / Float64(t * 2.0)); else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 5.4e-8) tmp = x / (t * 2.0); else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 5.4e-8], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.4 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if y < 5.40000000000000005e-8Initial program 100.0%
Taylor expanded in x around inf 39.7%
if 5.40000000000000005e-8 < y Initial program 99.9%
Taylor expanded in y around inf 62.0%
(FPCore (x y z t) :precision binary64 (if (<= y 4.2e-8) (/ x (* t 2.0)) (* y (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4.2e-8) {
tmp = x / (t * 2.0);
} 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 <= 4.2d-8) then
tmp = x / (t * 2.0d0)
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 <= 4.2e-8) {
tmp = x / (t * 2.0);
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 4.2e-8: tmp = x / (t * 2.0) else: tmp = y * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 4.2e-8) tmp = Float64(x / Float64(t * 2.0)); 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 <= 4.2e-8) tmp = x / (t * 2.0); else tmp = y * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 4.2e-8], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 4.19999999999999989e-8Initial program 100.0%
Taylor expanded in x around inf 39.7%
if 4.19999999999999989e-8 < y Initial program 99.9%
clear-num99.7%
inv-pow99.7%
associate--l+99.7%
Applied egg-rr99.7%
unpow-199.7%
associate-/l*99.6%
associate-+r-99.6%
+-commutative99.6%
associate-+r-99.6%
Simplified99.6%
Taylor expanded in y around inf 62.0%
associate-*r/62.0%
Simplified62.0%
*-commutative62.0%
associate-/l*61.8%
Applied egg-rr61.8%
(FPCore (x y z t) :precision binary64 (* y (/ 0.5 t)))
double code(double x, double y, double z, double t) {
return y * (0.5 / 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 = y * (0.5d0 / t)
end function
public static double code(double x, double y, double z, double t) {
return y * (0.5 / t);
}
def code(x, y, z, t): return y * (0.5 / t)
function code(x, y, z, t) return Float64(y * Float64(0.5 / t)) end
function tmp = code(x, y, z, t) tmp = y * (0.5 / t); end
code[x_, y_, z_, t_] := N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{0.5}{t}
\end{array}
Initial program 100.0%
clear-num99.4%
inv-pow99.4%
associate--l+99.4%
Applied egg-rr99.4%
unpow-199.4%
associate-/l*99.3%
associate-+r-99.3%
+-commutative99.3%
associate-+r-99.3%
Simplified99.3%
Taylor expanded in y around inf 39.4%
associate-*r/39.4%
Simplified39.4%
*-commutative39.4%
associate-/l*39.3%
Applied egg-rr39.3%
herbie shell --seed 2024132
(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)))