
(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%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ x (* t 2.0))) (t_2 (* -0.5 (/ z t))))
(if (<= x -1.35e+140)
t_1
(if (<= x -1.2e+114)
t_2
(if (<= x -6.2e+75) t_1 (if (<= x 3.5e-200) t_2 (/ y (* t 2.0))))))))
double code(double x, double y, double z, double t) {
double t_1 = x / (t * 2.0);
double t_2 = -0.5 * (z / t);
double tmp;
if (x <= -1.35e+140) {
tmp = t_1;
} else if (x <= -1.2e+114) {
tmp = t_2;
} else if (x <= -6.2e+75) {
tmp = t_1;
} else if (x <= 3.5e-200) {
tmp = t_2;
} 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = x / (t * 2.0d0)
t_2 = (-0.5d0) * (z / t)
if (x <= (-1.35d+140)) then
tmp = t_1
else if (x <= (-1.2d+114)) then
tmp = t_2
else if (x <= (-6.2d+75)) then
tmp = t_1
else if (x <= 3.5d-200) then
tmp = t_2
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 t_1 = x / (t * 2.0);
double t_2 = -0.5 * (z / t);
double tmp;
if (x <= -1.35e+140) {
tmp = t_1;
} else if (x <= -1.2e+114) {
tmp = t_2;
} else if (x <= -6.2e+75) {
tmp = t_1;
} else if (x <= 3.5e-200) {
tmp = t_2;
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): t_1 = x / (t * 2.0) t_2 = -0.5 * (z / t) tmp = 0 if x <= -1.35e+140: tmp = t_1 elif x <= -1.2e+114: tmp = t_2 elif x <= -6.2e+75: tmp = t_1 elif x <= 3.5e-200: tmp = t_2 else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) t_1 = Float64(x / Float64(t * 2.0)) t_2 = Float64(-0.5 * Float64(z / t)) tmp = 0.0 if (x <= -1.35e+140) tmp = t_1; elseif (x <= -1.2e+114) tmp = t_2; elseif (x <= -6.2e+75) tmp = t_1; elseif (x <= 3.5e-200) tmp = t_2; else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x / (t * 2.0); t_2 = -0.5 * (z / t); tmp = 0.0; if (x <= -1.35e+140) tmp = t_1; elseif (x <= -1.2e+114) tmp = t_2; elseif (x <= -6.2e+75) tmp = t_1; elseif (x <= 3.5e-200) tmp = t_2; else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-0.5 * N[(z / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e+140], t$95$1, If[LessEqual[x, -1.2e+114], t$95$2, If[LessEqual[x, -6.2e+75], t$95$1, If[LessEqual[x, 3.5e-200], t$95$2, N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x}{t \cdot 2}\\
t_2 := -0.5 \cdot \frac{z}{t}\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+140}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{+114}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq -6.2 \cdot 10^{+75}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-200}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -1.35000000000000009e140 or -1.2e114 < x < -6.2000000000000002e75Initial program 100.0%
Taylor expanded in x around inf 78.1%
if -1.35000000000000009e140 < x < -1.2e114 or -6.2000000000000002e75 < x < 3.50000000000000023e-200Initial program 100.0%
Taylor expanded in y around 0 61.6%
Taylor expanded in x around 0 53.5%
if 3.50000000000000023e-200 < x Initial program 100.0%
Taylor expanded in y around inf 27.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2e+40) (not (<= z 1.6e-15))) (/ (- x z) (* t 2.0)) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2e+40) || !(z <= 1.6e-15)) {
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 ((z <= (-2d+40)) .or. (.not. (z <= 1.6d-15))) 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 ((z <= -2e+40) || !(z <= 1.6e-15)) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2e+40) or not (z <= 1.6e-15): 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 ((z <= -2e+40) || !(z <= 1.6e-15)) 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 ((z <= -2e+40) || ~((z <= 1.6e-15))) tmp = (x - z) / (t * 2.0); else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2e+40], N[Not[LessEqual[z, 1.6e-15]], $MachinePrecision]], 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}\;z \leq -2 \cdot 10^{+40} \lor \neg \left(z \leq 1.6 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -2.00000000000000006e40 or 1.6e-15 < z Initial program 100.0%
Taylor expanded in y around 0 86.5%
if -2.00000000000000006e40 < z < 1.6e-15Initial program 100.0%
Taylor expanded in z around 0 95.2%
+-commutative95.2%
Simplified95.2%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.6e+142) (not (<= z 7.8e+108))) (* -0.5 (/ z t)) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.6e+142) || !(z <= 7.8e+108)) {
tmp = -0.5 * (z / 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 <= (-6.6d+142)) .or. (.not. (z <= 7.8d+108))) then
tmp = (-0.5d0) * (z / 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 <= -6.6e+142) || !(z <= 7.8e+108)) {
tmp = -0.5 * (z / t);
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.6e+142) or not (z <= 7.8e+108): tmp = -0.5 * (z / t) else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.6e+142) || !(z <= 7.8e+108)) tmp = Float64(-0.5 * Float64(z / 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 <= -6.6e+142) || ~((z <= 7.8e+108))) tmp = -0.5 * (z / t); else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.6e+142], N[Not[LessEqual[z, 7.8e+108]], $MachinePrecision]], N[(-0.5 * N[(z / t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+142} \lor \neg \left(z \leq 7.8 \cdot 10^{+108}\right):\\
\;\;\;\;-0.5 \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -6.6000000000000004e142 or 7.79999999999999969e108 < z Initial program 100.0%
Taylor expanded in y around 0 93.1%
Taylor expanded in x around 0 83.0%
if -6.6000000000000004e142 < z < 7.79999999999999969e108Initial program 100.0%
Taylor expanded in z around 0 88.0%
+-commutative88.0%
Simplified88.0%
Final simplification86.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.6e+114) (not (<= z 6.3e+72))) (* -0.5 (/ z t)) (/ x (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.6e+114) || !(z <= 6.3e+72)) {
tmp = -0.5 * (z / t);
} else {
tmp = x / (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 <= (-4.6d+114)) .or. (.not. (z <= 6.3d+72))) then
tmp = (-0.5d0) * (z / t)
else
tmp = x / (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 <= -4.6e+114) || !(z <= 6.3e+72)) {
tmp = -0.5 * (z / t);
} else {
tmp = x / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.6e+114) or not (z <= 6.3e+72): tmp = -0.5 * (z / t) else: tmp = x / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.6e+114) || !(z <= 6.3e+72)) tmp = Float64(-0.5 * Float64(z / t)); else tmp = Float64(x / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.6e+114) || ~((z <= 6.3e+72))) tmp = -0.5 * (z / t); else tmp = x / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.6e+114], N[Not[LessEqual[z, 6.3e+72]], $MachinePrecision]], N[(-0.5 * N[(z / t), $MachinePrecision]), $MachinePrecision], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+114} \lor \neg \left(z \leq 6.3 \cdot 10^{+72}\right):\\
\;\;\;\;-0.5 \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\end{array}
\end{array}
if z < -4.6000000000000001e114 or 6.29999999999999963e72 < z Initial program 100.0%
Taylor expanded in y around 0 92.0%
Taylor expanded in x around 0 78.2%
if -4.6000000000000001e114 < z < 6.29999999999999963e72Initial program 100.0%
Taylor expanded in x around inf 52.8%
Final simplification62.2%
(FPCore (x y z t) :precision binary64 (if (<= y 6e-77) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6e-77) {
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 <= 6d-77) 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 <= 6e-77) {
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 <= 6e-77: 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 <= 6e-77) 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 <= 6e-77) 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, 6e-77], 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 6 \cdot 10^{-77}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if y < 6.00000000000000033e-77Initial program 100.0%
Taylor expanded in y around 0 79.3%
if 6.00000000000000033e-77 < y Initial program 100.0%
Taylor expanded in x around 0 69.5%
(FPCore (x y z t) :precision binary64 (* -0.5 (/ z t)))
double code(double x, double y, double z, double t) {
return -0.5 * (z / 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) * (z / t)
end function
public static double code(double x, double y, double z, double t) {
return -0.5 * (z / t);
}
def code(x, y, z, t): return -0.5 * (z / t)
function code(x, y, z, t) return Float64(-0.5 * Float64(z / t)) end
function tmp = code(x, y, z, t) tmp = -0.5 * (z / t); end
code[x_, y_, z_, t_] := N[(-0.5 * N[(z / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{z}{t}
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 72.5%
Taylor expanded in x around 0 36.8%
herbie shell --seed 2024087
(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)))