
(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
(if (<= x -1.3e+72)
(* x (/ 0.5 t))
(if (or (<= x -1.25e-183)
(and (not (<= x -8.8e-262))
(or (<= x -1.25e-296)
(and (not (<= x 2.1e-286)) (<= x 1.62e-236)))))
(* (/ z t) -0.5)
(/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.3e+72) {
tmp = x * (0.5 / t);
} else if ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236))))) {
tmp = (z / t) * -0.5;
} 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 (x <= (-1.3d+72)) then
tmp = x * (0.5d0 / t)
else if ((x <= (-1.25d-183)) .or. (.not. (x <= (-8.8d-262))) .and. (x <= (-1.25d-296)) .or. (.not. (x <= 2.1d-286)) .and. (x <= 1.62d-236)) then
tmp = (z / t) * (-0.5d0)
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 (x <= -1.3e+72) {
tmp = x * (0.5 / t);
} else if ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236))))) {
tmp = (z / t) * -0.5;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.3e+72: tmp = x * (0.5 / t) elif (x <= -1.25e-183) or (not (x <= -8.8e-262) and ((x <= -1.25e-296) or (not (x <= 2.1e-286) and (x <= 1.62e-236)))): tmp = (z / t) * -0.5 else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.3e+72) tmp = Float64(x * Float64(0.5 / t)); elseif ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236))))) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.3e+72) tmp = x * (0.5 / t); elseif ((x <= -1.25e-183) || (~((x <= -8.8e-262)) && ((x <= -1.25e-296) || (~((x <= 2.1e-286)) && (x <= 1.62e-236))))) tmp = (z / t) * -0.5; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.3e+72], N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -1.25e-183], And[N[Not[LessEqual[x, -8.8e-262]], $MachinePrecision], Or[LessEqual[x, -1.25e-296], And[N[Not[LessEqual[x, 2.1e-286]], $MachinePrecision], LessEqual[x, 1.62e-236]]]]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+72}:\\
\;\;\;\;x \cdot \frac{0.5}{t}\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-183} \lor \neg \left(x \leq -8.8 \cdot 10^{-262}\right) \land \left(x \leq -1.25 \cdot 10^{-296} \lor \neg \left(x \leq 2.1 \cdot 10^{-286}\right) \land x \leq 1.62 \cdot 10^{-236}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -1.29999999999999991e72Initial program 99.9%
Taylor expanded in x around 0 83.5%
div-sub81.6%
distribute-lft-out81.6%
div-sub83.5%
Simplified83.5%
Taylor expanded in x around inf 64.4%
associate-*r/65.8%
*-commutative65.8%
associate-*r/65.7%
Simplified65.7%
if -1.29999999999999991e72 < x < -1.2500000000000001e-183 or -8.79999999999999954e-262 < x < -1.25000000000000008e-296 or 2.09999999999999988e-286 < x < 1.62e-236Initial program 100.0%
Taylor expanded in z around inf 61.6%
*-commutative61.6%
Simplified61.6%
if -1.2500000000000001e-183 < x < -8.79999999999999954e-262 or -1.25000000000000008e-296 < x < 2.09999999999999988e-286 or 1.62e-236 < x Initial program 100.0%
Taylor expanded in y around inf 46.2%
associate-*r/46.2%
Simplified46.2%
Final simplification54.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -950000000000.0) (not (<= z 3.8e+115))) (* (/ z t) -0.5) (* 0.5 (/ x t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -950000000000.0) || !(z <= 3.8e+115)) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (x / 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 <= (-950000000000.0d0)) .or. (.not. (z <= 3.8d+115))) then
tmp = (z / t) * (-0.5d0)
else
tmp = 0.5d0 * (x / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -950000000000.0) || !(z <= 3.8e+115)) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (x / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -950000000000.0) or not (z <= 3.8e+115): tmp = (z / t) * -0.5 else: tmp = 0.5 * (x / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -950000000000.0) || !(z <= 3.8e+115)) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(0.5 * Float64(x / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -950000000000.0) || ~((z <= 3.8e+115))) tmp = (z / t) * -0.5; else tmp = 0.5 * (x / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -950000000000.0], N[Not[LessEqual[z, 3.8e+115]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -950000000000 \lor \neg \left(z \leq 3.8 \cdot 10^{+115}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\end{array}
\end{array}
if z < -9.5e11 or 3.8000000000000001e115 < z Initial program 100.0%
Taylor expanded in z around inf 76.9%
*-commutative76.9%
Simplified76.9%
if -9.5e11 < z < 3.8000000000000001e115Initial program 100.0%
Taylor expanded in x around inf 49.5%
Final simplification60.9%
(FPCore (x y z t) :precision binary64 (if (<= y 2.6e+43) (* 0.5 (/ (- x z) t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.6e+43) {
tmp = 0.5 * ((x - z) / t);
} 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 <= 2.6d+43) then
tmp = 0.5d0 * ((x - z) / t)
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 <= 2.6e+43) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.6e+43: tmp = 0.5 * ((x - z) / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.6e+43) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.6e+43) tmp = 0.5 * ((x - z) / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.6e+43], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 2.60000000000000021e43Initial program 100.0%
Taylor expanded in y around 0 78.5%
if 2.60000000000000021e43 < y Initial program 100.0%
Taylor expanded in y around inf 63.2%
associate-*r/63.2%
Simplified63.2%
Final simplification74.5%
(FPCore (x y z t) :precision binary64 (if (<= x -2.1e+15) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (- y z) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.1e+15) {
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 <= (-2.1d+15)) 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 <= -2.1e+15) {
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 <= -2.1e+15: 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 (x <= -2.1e+15) 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 <= -2.1e+15) 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[x, -2.1e+15], 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 \leq -2.1 \cdot 10^{+15}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y - z}{t}\\
\end{array}
\end{array}
if x < -2.1e15Initial program 99.9%
Taylor expanded in y around 0 87.7%
if -2.1e15 < x Initial program 100.0%
Taylor expanded in x around 0 77.3%
Final simplification79.7%
(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 36.4%
Final simplification36.4%
(FPCore (x y z t) :precision binary64 (* x (/ 0.5 t)))
double code(double x, double y, double z, double t) {
return x * (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 = x * (0.5d0 / t)
end function
public static double code(double x, double y, double z, double t) {
return x * (0.5 / t);
}
def code(x, y, z, t): return x * (0.5 / t)
function code(x, y, z, t) return Float64(x * Float64(0.5 / t)) end
function tmp = code(x, y, z, t) tmp = x * (0.5 / t); end
code[x_, y_, z_, t_] := N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{0.5}{t}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 95.4%
div-sub93.0%
distribute-lft-out93.0%
div-sub95.4%
Simplified95.4%
Taylor expanded in x around inf 36.4%
associate-*r/36.6%
*-commutative36.6%
associate-*r/36.6%
Simplified36.6%
Final simplification36.6%
herbie shell --seed 2023320
(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)))