
(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 (* x (/ 0.5 t))) (t_2 (* (/ z t) -0.5)))
(if (<= x -2.2e+129)
t_1
(if (<= x -1.75e+89)
t_2
(if (<= x -470.0)
t_1
(if (or (<= x -1.25e-145)
(and (not (<= x -4.6e-191)) (<= x 3.3e-257)))
t_2
(* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
double t_1 = x * (0.5 / t);
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -2.2e+129) {
tmp = t_1;
} else if (x <= -1.75e+89) {
tmp = t_2;
} else if (x <= -470.0) {
tmp = t_1;
} else if ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257))) {
tmp = t_2;
} 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 = x * (0.5d0 / t)
t_2 = (z / t) * (-0.5d0)
if (x <= (-2.2d+129)) then
tmp = t_1
else if (x <= (-1.75d+89)) then
tmp = t_2
else if (x <= (-470.0d0)) then
tmp = t_1
else if ((x <= (-1.25d-145)) .or. (.not. (x <= (-4.6d-191))) .and. (x <= 3.3d-257)) then
tmp = t_2
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 = x * (0.5 / t);
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -2.2e+129) {
tmp = t_1;
} else if (x <= -1.75e+89) {
tmp = t_2;
} else if (x <= -470.0) {
tmp = t_1;
} else if ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257))) {
tmp = t_2;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (0.5 / t) t_2 = (z / t) * -0.5 tmp = 0 if x <= -2.2e+129: tmp = t_1 elif x <= -1.75e+89: tmp = t_2 elif x <= -470.0: tmp = t_1 elif (x <= -1.25e-145) or (not (x <= -4.6e-191) and (x <= 3.3e-257)): tmp = t_2 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(0.5 / t)) t_2 = Float64(Float64(z / t) * -0.5) tmp = 0.0 if (x <= -2.2e+129) tmp = t_1; elseif (x <= -1.75e+89) tmp = t_2; elseif (x <= -470.0) tmp = t_1; elseif ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257))) tmp = t_2; else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (0.5 / t); t_2 = (z / t) * -0.5; tmp = 0.0; if (x <= -2.2e+129) tmp = t_1; elseif (x <= -1.75e+89) tmp = t_2; elseif (x <= -470.0) tmp = t_1; elseif ((x <= -1.25e-145) || (~((x <= -4.6e-191)) && (x <= 3.3e-257))) tmp = t_2; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, -2.2e+129], t$95$1, If[LessEqual[x, -1.75e+89], t$95$2, If[LessEqual[x, -470.0], t$95$1, If[Or[LessEqual[x, -1.25e-145], And[N[Not[LessEqual[x, -4.6e-191]], $MachinePrecision], LessEqual[x, 3.3e-257]]], t$95$2, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \frac{0.5}{t}\\
t_2 := \frac{z}{t} \cdot -0.5\\
\mathbf{if}\;x \leq -2.2 \cdot 10^{+129}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.75 \cdot 10^{+89}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq -470:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-145} \lor \neg \left(x \leq -4.6 \cdot 10^{-191}\right) \land x \leq 3.3 \cdot 10^{-257}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -2.1999999999999999e129 or -1.75e89 < x < -470Initial program 99.9%
Taylor expanded in z around 0 92.3%
associate-*r/92.3%
+-commutative92.3%
associate-/l*92.1%
+-commutative92.1%
Simplified92.1%
Taylor expanded in y around 0 78.1%
associate-*r/78.1%
associate-*l/77.9%
*-commutative77.9%
Simplified77.9%
if -2.1999999999999999e129 < x < -1.75e89 or -470 < x < -1.2499999999999999e-145 or -4.60000000000000021e-191 < x < 3.3e-257Initial program 100.0%
Taylor expanded in z around inf 56.6%
*-commutative56.6%
Simplified56.6%
if -1.2499999999999999e-145 < x < -4.60000000000000021e-191 or 3.3e-257 < x Initial program 100.0%
Taylor expanded in y around inf 39.7%
Final simplification52.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (* x 0.5) t)) (t_2 (* (/ z t) -0.5)))
(if (<= x -2.65e+129)
t_1
(if (<= x -8.5e+88)
t_2
(if (<= x -246.0)
t_1
(if (or (<= x -1e-144) (and (not (<= x -1.1e-193)) (<= x 8e-250)))
t_2
(* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) / t;
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -2.65e+129) {
tmp = t_1;
} else if (x <= -8.5e+88) {
tmp = t_2;
} else if (x <= -246.0) {
tmp = t_1;
} else if ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250))) {
tmp = t_2;
} 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 = (x * 0.5d0) / t
t_2 = (z / t) * (-0.5d0)
if (x <= (-2.65d+129)) then
tmp = t_1
else if (x <= (-8.5d+88)) then
tmp = t_2
else if (x <= (-246.0d0)) then
tmp = t_1
else if ((x <= (-1d-144)) .or. (.not. (x <= (-1.1d-193))) .and. (x <= 8d-250)) then
tmp = t_2
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 = (x * 0.5) / t;
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -2.65e+129) {
tmp = t_1;
} else if (x <= -8.5e+88) {
tmp = t_2;
} else if (x <= -246.0) {
tmp = t_1;
} else if ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250))) {
tmp = t_2;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) / t t_2 = (z / t) * -0.5 tmp = 0 if x <= -2.65e+129: tmp = t_1 elif x <= -8.5e+88: tmp = t_2 elif x <= -246.0: tmp = t_1 elif (x <= -1e-144) or (not (x <= -1.1e-193) and (x <= 8e-250)): tmp = t_2 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) / t) t_2 = Float64(Float64(z / t) * -0.5) tmp = 0.0 if (x <= -2.65e+129) tmp = t_1; elseif (x <= -8.5e+88) tmp = t_2; elseif (x <= -246.0) tmp = t_1; elseif ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250))) tmp = t_2; else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * 0.5) / t; t_2 = (z / t) * -0.5; tmp = 0.0; if (x <= -2.65e+129) tmp = t_1; elseif (x <= -8.5e+88) tmp = t_2; elseif (x <= -246.0) tmp = t_1; elseif ((x <= -1e-144) || (~((x <= -1.1e-193)) && (x <= 8e-250))) tmp = t_2; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, -2.65e+129], t$95$1, If[LessEqual[x, -8.5e+88], t$95$2, If[LessEqual[x, -246.0], t$95$1, If[Or[LessEqual[x, -1e-144], And[N[Not[LessEqual[x, -1.1e-193]], $MachinePrecision], LessEqual[x, 8e-250]]], t$95$2, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x \cdot 0.5}{t}\\
t_2 := \frac{z}{t} \cdot -0.5\\
\mathbf{if}\;x \leq -2.65 \cdot 10^{+129}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{+88}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq -246:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-144} \lor \neg \left(x \leq -1.1 \cdot 10^{-193}\right) \land x \leq 8 \cdot 10^{-250}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -2.6499999999999999e129 or -8.5000000000000005e88 < x < -246Initial program 99.9%
Taylor expanded in x around inf 78.1%
associate-*r/78.1%
Simplified78.1%
if -2.6499999999999999e129 < x < -8.5000000000000005e88 or -246 < x < -9.9999999999999995e-145 or -1.09999999999999988e-193 < x < 8.0000000000000004e-250Initial program 100.0%
Taylor expanded in z around inf 56.6%
*-commutative56.6%
Simplified56.6%
if -9.9999999999999995e-145 < x < -1.09999999999999988e-193 or 8.0000000000000004e-250 < x Initial program 100.0%
Taylor expanded in y around inf 39.7%
Final simplification52.5%
(FPCore (x y z t) :precision binary64 (if (<= (+ x y) -2e-237) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (- y z) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -2e-237) {
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 ((x + y) <= (-2d-237)) 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 ((x + y) <= -2e-237) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * ((y - z) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x + y) <= -2e-237: 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 (Float64(x + y) <= -2e-237) 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 ((x + y) <= -2e-237) 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[N[(x + y), $MachinePrecision], -2e-237], 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}\;x + y \leq -2 \cdot 10^{-237}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y - z}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < -2e-237Initial program 100.0%
Taylor expanded in y around 0 69.8%
if -2e-237 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 64.0%
Final simplification67.3%
(FPCore (x y z t) :precision binary64 (if (<= y 4.2e+125) (* 0.5 (/ (- x z) t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4.2e+125) {
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 <= 4.2d+125) 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 <= 4.2e+125) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 4.2e+125: 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 <= 4.2e+125) 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 <= 4.2e+125) 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, 4.2e+125], 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 4.2 \cdot 10^{+125}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 4.2000000000000001e125Initial program 100.0%
Taylor expanded in y around 0 76.2%
if 4.2000000000000001e125 < y Initial program 100.0%
Taylor expanded in y around inf 68.7%
Final simplification75.2%
(FPCore (x y z t) :precision binary64 (if (<= x -1.7e-14) (* x (/ 0.5 t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.7e-14) {
tmp = x * (0.5 / 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 (x <= (-1.7d-14)) then
tmp = x * (0.5d0 / 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 (x <= -1.7e-14) {
tmp = x * (0.5 / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.7e-14: tmp = x * (0.5 / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.7e-14) tmp = Float64(x * Float64(0.5 / 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 (x <= -1.7e-14) tmp = x * (0.5 / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.7e-14], N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.70000000000000001e-14Initial program 100.0%
Taylor expanded in z around 0 84.6%
associate-*r/84.6%
+-commutative84.6%
associate-/l*84.4%
+-commutative84.4%
Simplified84.4%
Taylor expanded in y around 0 69.4%
associate-*r/69.4%
associate-*l/69.2%
*-commutative69.2%
Simplified69.2%
if -1.70000000000000001e-14 < x Initial program 100.0%
Taylor expanded in y around inf 39.1%
Final simplification46.6%
(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 34.2%
Final simplification34.2%
herbie shell --seed 2023195
(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)))