
(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 9 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
(if (<= x -4.7e+20)
(/ 0.5 (/ t x))
(if (or (<= x -3.3e-125) (and (not (<= x -2.9e-209)) (<= x 1.55e-280)))
(* (/ z t) -0.5)
(* 0.5 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.7e+20) {
tmp = 0.5 / (t / x);
} else if ((x <= -3.3e-125) || (!(x <= -2.9e-209) && (x <= 1.55e-280))) {
tmp = (z / t) * -0.5;
} 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 (x <= (-4.7d+20)) then
tmp = 0.5d0 / (t / x)
else if ((x <= (-3.3d-125)) .or. (.not. (x <= (-2.9d-209))) .and. (x <= 1.55d-280)) then
tmp = (z / t) * (-0.5d0)
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 (x <= -4.7e+20) {
tmp = 0.5 / (t / x);
} else if ((x <= -3.3e-125) || (!(x <= -2.9e-209) && (x <= 1.55e-280))) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -4.7e+20: tmp = 0.5 / (t / x) elif (x <= -3.3e-125) or (not (x <= -2.9e-209) and (x <= 1.55e-280)): tmp = (z / t) * -0.5 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -4.7e+20) tmp = Float64(0.5 / Float64(t / x)); elseif ((x <= -3.3e-125) || (!(x <= -2.9e-209) && (x <= 1.55e-280))) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -4.7e+20) tmp = 0.5 / (t / x); elseif ((x <= -3.3e-125) || (~((x <= -2.9e-209)) && (x <= 1.55e-280))) tmp = (z / t) * -0.5; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -4.7e+20], N[(0.5 / N[(t / x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -3.3e-125], And[N[Not[LessEqual[x, -2.9e-209]], $MachinePrecision], LessEqual[x, 1.55e-280]]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{+20}:\\
\;\;\;\;\frac{0.5}{\frac{t}{x}}\\
\mathbf{elif}\;x \leq -3.3 \cdot 10^{-125} \lor \neg \left(x \leq -2.9 \cdot 10^{-209}\right) \land x \leq 1.55 \cdot 10^{-280}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -4.7e20Initial program 100.0%
Taylor expanded in x around inf 60.8%
associate-*r/60.8%
associate-/l*60.7%
Simplified60.7%
if -4.7e20 < x < -3.3000000000000001e-125 or -2.90000000000000026e-209 < x < 1.55000000000000011e-280Initial program 100.0%
Taylor expanded in z around inf 58.6%
*-commutative58.6%
Simplified58.6%
if -3.3000000000000001e-125 < x < -2.90000000000000026e-209 or 1.55000000000000011e-280 < x Initial program 99.9%
Taylor expanded in y around inf 39.2%
Final simplification48.9%
(FPCore (x y z t)
:precision binary64
(if (<= x -6e+20)
(/ (* x 0.5) t)
(if (or (<= x -8.5e-124) (and (not (<= x -4.4e-209)) (<= x 1.02e-280)))
(* (/ z t) -0.5)
(* 0.5 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -6e+20) {
tmp = (x * 0.5) / t;
} else if ((x <= -8.5e-124) || (!(x <= -4.4e-209) && (x <= 1.02e-280))) {
tmp = (z / t) * -0.5;
} 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 (x <= (-6d+20)) then
tmp = (x * 0.5d0) / t
else if ((x <= (-8.5d-124)) .or. (.not. (x <= (-4.4d-209))) .and. (x <= 1.02d-280)) then
tmp = (z / t) * (-0.5d0)
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 (x <= -6e+20) {
tmp = (x * 0.5) / t;
} else if ((x <= -8.5e-124) || (!(x <= -4.4e-209) && (x <= 1.02e-280))) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -6e+20: tmp = (x * 0.5) / t elif (x <= -8.5e-124) or (not (x <= -4.4e-209) and (x <= 1.02e-280)): tmp = (z / t) * -0.5 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -6e+20) tmp = Float64(Float64(x * 0.5) / t); elseif ((x <= -8.5e-124) || (!(x <= -4.4e-209) && (x <= 1.02e-280))) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -6e+20) tmp = (x * 0.5) / t; elseif ((x <= -8.5e-124) || (~((x <= -4.4e-209)) && (x <= 1.02e-280))) tmp = (z / t) * -0.5; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -6e+20], N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision], If[Or[LessEqual[x, -8.5e-124], And[N[Not[LessEqual[x, -4.4e-209]], $MachinePrecision], LessEqual[x, 1.02e-280]]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+20}:\\
\;\;\;\;\frac{x \cdot 0.5}{t}\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-124} \lor \neg \left(x \leq -4.4 \cdot 10^{-209}\right) \land x \leq 1.02 \cdot 10^{-280}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -6e20Initial program 100.0%
Taylor expanded in x around inf 60.8%
associate-*r/60.8%
Simplified60.8%
if -6e20 < x < -8.5000000000000002e-124 or -4.40000000000000019e-209 < x < 1.02000000000000005e-280Initial program 100.0%
Taylor expanded in z around inf 57.9%
*-commutative57.9%
Simplified57.9%
if -8.5000000000000002e-124 < x < -4.40000000000000019e-209 or 1.02000000000000005e-280 < x Initial program 99.9%
Taylor expanded in y around inf 39.0%
Final simplification48.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.25e+46) (not (<= z 1.55e+53))) (* (/ z t) -0.5) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e+46) || !(z <= 1.55e+53)) {
tmp = (z / t) * -0.5;
} 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 ((z <= (-2.25d+46)) .or. (.not. (z <= 1.55d+53))) then
tmp = (z / t) * (-0.5d0)
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 ((z <= -2.25e+46) || !(z <= 1.55e+53)) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.25e+46) or not (z <= 1.55e+53): tmp = (z / t) * -0.5 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.25e+46) || !(z <= 1.55e+53)) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.25e+46) || ~((z <= 1.55e+53))) tmp = (z / t) * -0.5; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.25e+46], N[Not[LessEqual[z, 1.55e+53]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{+46} \lor \neg \left(z \leq 1.55 \cdot 10^{+53}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -2.25000000000000005e46 or 1.5500000000000001e53 < z Initial program 99.9%
Taylor expanded in z around inf 74.7%
*-commutative74.7%
Simplified74.7%
if -2.25000000000000005e46 < z < 1.5500000000000001e53Initial program 100.0%
Taylor expanded in y around inf 50.9%
Final simplification60.8%
(FPCore (x y z t) :precision binary64 (if (<= y 1.25e+121) (* 0.5 (/ (- x z) t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.25e+121) {
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 <= 1.25d+121) 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 <= 1.25e+121) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.25e+121: 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 <= 1.25e+121) 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 <= 1.25e+121) 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, 1.25e+121], 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 1.25 \cdot 10^{+121}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 1.25000000000000002e121Initial program 100.0%
Taylor expanded in y around 0 75.8%
if 1.25000000000000002e121 < y Initial program 100.0%
Taylor expanded in y around inf 82.3%
Final simplification76.9%
(FPCore (x y z t) :precision binary64 (if (<= y 1.65e-56) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (- y z) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.65e-56) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * ((y - z) / 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.65d-56) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = 0.5d0 * ((y - z) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.65e-56) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * ((y - z) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.65e-56: tmp = 0.5 * ((x - z) / t) else: tmp = 0.5 * ((y - z) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.65e-56) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(0.5 * Float64(Float64(y - z) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.65e-56) tmp = 0.5 * ((x - z) / t); else tmp = 0.5 * ((y - z) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.65e-56], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y - z}{t}\\
\end{array}
\end{array}
if y < 1.64999999999999992e-56Initial program 100.0%
Taylor expanded in y around 0 76.7%
if 1.64999999999999992e-56 < y Initial program 99.9%
Taylor expanded in x around 0 80.9%
Final simplification77.9%
(FPCore (x y z t) :precision binary64 (* (/ 0.5 t) (+ x (- y z))))
double code(double x, double y, double z, double t) {
return (0.5 / t) * (x + (y - z));
}
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 / t) * (x + (y - z))
end function
public static double code(double x, double y, double z, double t) {
return (0.5 / t) * (x + (y - z));
}
def code(x, y, z, t): return (0.5 / t) * (x + (y - z))
function code(x, y, z, t) return Float64(Float64(0.5 / t) * Float64(x + Float64(y - z))) end
function tmp = code(x, y, z, t) tmp = (0.5 / t) * (x + (y - z)); end
code[x_, y_, z_, t_] := N[(N[(0.5 / t), $MachinePrecision] * N[(x + N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{t} \cdot \left(x + \left(y - z\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 96.8%
associate-*r/96.8%
associate-*l/96.7%
associate-*r/96.7%
associate-*l/96.6%
distribute-lft-in99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z t) :precision binary64 (* 0.5 (/ y t)))
double code(double x, double y, double z, double t) {
return 0.5 * (y / 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 * (y / t)
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (y / t);
}
def code(x, y, z, t): return 0.5 * (y / t)
function code(x, y, z, t) return Float64(0.5 * Float64(y / t)) end
function tmp = code(x, y, z, t) tmp = 0.5 * (y / t); end
code[x_, y_, z_, t_] := N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{y}{t}
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 38.2%
Final simplification38.2%
(FPCore (x y z t) :precision binary64 (* x 0.0))
double code(double x, double y, double z, double t) {
return x * 0.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 * 0.0d0
end function
public static double code(double x, double y, double z, double t) {
return x * 0.0;
}
def code(x, y, z, t): return x * 0.0
function code(x, y, z, t) return Float64(x * 0.0) end
function tmp = code(x, y, z, t) tmp = x * 0.0; end
code[x_, y_, z_, t_] := N[(x * 0.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 34.2%
associate-*r/34.2%
Simplified34.2%
expm1-log1p-u20.8%
expm1-udef14.3%
associate-*l/14.3%
*-commutative14.3%
clear-num14.3%
div-inv14.3%
metadata-eval14.3%
*-commutative14.3%
count-214.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
clear-num0.0%
flip-+2.3%
Applied egg-rr2.3%
Simplified3.5%
Final simplification3.5%
herbie shell --seed 2023274
(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)))