
(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 (* 0.5 (/ x t))) (t_2 (* (/ z t) -0.5)))
(if (<= x -1.3e+91)
t_1
(if (<= x -3.8e+35)
t_2
(if (<= x -2.3e-11)
t_1
(if (or (<= x -1.72e-156)
(and (not (<= x -2.7e-183)) (<= x 1.1e-242)))
t_2
(* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
double t_1 = 0.5 * (x / t);
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -1.3e+91) {
tmp = t_1;
} else if (x <= -3.8e+35) {
tmp = t_2;
} else if (x <= -2.3e-11) {
tmp = t_1;
} else if ((x <= -1.72e-156) || (!(x <= -2.7e-183) && (x <= 1.1e-242))) {
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 = 0.5d0 * (x / t)
t_2 = (z / t) * (-0.5d0)
if (x <= (-1.3d+91)) then
tmp = t_1
else if (x <= (-3.8d+35)) then
tmp = t_2
else if (x <= (-2.3d-11)) then
tmp = t_1
else if ((x <= (-1.72d-156)) .or. (.not. (x <= (-2.7d-183))) .and. (x <= 1.1d-242)) 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 = 0.5 * (x / t);
double t_2 = (z / t) * -0.5;
double tmp;
if (x <= -1.3e+91) {
tmp = t_1;
} else if (x <= -3.8e+35) {
tmp = t_2;
} else if (x <= -2.3e-11) {
tmp = t_1;
} else if ((x <= -1.72e-156) || (!(x <= -2.7e-183) && (x <= 1.1e-242))) {
tmp = t_2;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = 0.5 * (x / t) t_2 = (z / t) * -0.5 tmp = 0 if x <= -1.3e+91: tmp = t_1 elif x <= -3.8e+35: tmp = t_2 elif x <= -2.3e-11: tmp = t_1 elif (x <= -1.72e-156) or (not (x <= -2.7e-183) and (x <= 1.1e-242)): tmp = t_2 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) t_1 = Float64(0.5 * Float64(x / t)) t_2 = Float64(Float64(z / t) * -0.5) tmp = 0.0 if (x <= -1.3e+91) tmp = t_1; elseif (x <= -3.8e+35) tmp = t_2; elseif (x <= -2.3e-11) tmp = t_1; elseif ((x <= -1.72e-156) || (!(x <= -2.7e-183) && (x <= 1.1e-242))) 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 = 0.5 * (x / t); t_2 = (z / t) * -0.5; tmp = 0.0; if (x <= -1.3e+91) tmp = t_1; elseif (x <= -3.8e+35) tmp = t_2; elseif (x <= -2.3e-11) tmp = t_1; elseif ((x <= -1.72e-156) || (~((x <= -2.7e-183)) && (x <= 1.1e-242))) tmp = t_2; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, -1.3e+91], t$95$1, If[LessEqual[x, -3.8e+35], t$95$2, If[LessEqual[x, -2.3e-11], t$95$1, If[Or[LessEqual[x, -1.72e-156], And[N[Not[LessEqual[x, -2.7e-183]], $MachinePrecision], LessEqual[x, 1.1e-242]]], t$95$2, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 0.5 \cdot \frac{x}{t}\\
t_2 := \frac{z}{t} \cdot -0.5\\
\mathbf{if}\;x \leq -1.3 \cdot 10^{+91}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{+35}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.72 \cdot 10^{-156} \lor \neg \left(x \leq -2.7 \cdot 10^{-183}\right) \land x \leq 1.1 \cdot 10^{-242}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.3e91 or -3.8e35 < x < -2.30000000000000014e-11Initial program 100.0%
Taylor expanded in x around inf 74.0%
if -1.3e91 < x < -3.8e35 or -2.30000000000000014e-11 < x < -1.7199999999999999e-156 or -2.70000000000000008e-183 < x < 1.10000000000000001e-242Initial program 100.0%
Taylor expanded in z around inf 50.4%
*-commutative50.4%
Simplified50.4%
if -1.7199999999999999e-156 < x < -2.70000000000000008e-183 or 1.10000000000000001e-242 < x Initial program 100.0%
Taylor expanded in y around inf 39.4%
Final simplification51.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.4e+184) (not (<= z 3.5e+124))) (* (/ z t) -0.5) (* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.4e+184) || !(z <= 3.5e+124)) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * ((x + 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 <= (-3.4d+184)) .or. (.not. (z <= 3.5d+124))) then
tmp = (z / t) * (-0.5d0)
else
tmp = 0.5d0 * ((x + y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.4e+184) || !(z <= 3.5e+124)) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * ((x + y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.4e+184) or not (z <= 3.5e+124): tmp = (z / t) * -0.5 else: tmp = 0.5 * ((x + y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.4e+184) || !(z <= 3.5e+124)) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(0.5 * Float64(Float64(x + y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.4e+184) || ~((z <= 3.5e+124))) tmp = (z / t) * -0.5; else tmp = 0.5 * ((x + y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.4e+184], N[Not[LessEqual[z, 3.5e+124]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(N[(x + y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{+184} \lor \neg \left(z \leq 3.5 \cdot 10^{+124}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if z < -3.4000000000000002e184 or 3.5000000000000001e124 < z Initial program 100.0%
Taylor expanded in z around inf 80.6%
*-commutative80.6%
Simplified80.6%
if -3.4000000000000002e184 < z < 3.5000000000000001e124Initial program 100.0%
Taylor expanded in z around 0 83.3%
+-commutative83.3%
Simplified83.3%
Final simplification82.5%
(FPCore (x y z t) :precision binary64 (if (<= (+ x y) 2e-259) (* 0.5 (/ (- x z) t)) (* (- y z) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= 2e-259) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y - z) * (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 + y) <= 2d-259) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = (y - z) * (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 + y) <= 2e-259) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y - z) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x + y) <= 2e-259: tmp = 0.5 * ((x - z) / t) else: tmp = (y - z) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= 2e-259) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(y - z) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x + y) <= 2e-259) tmp = 0.5 * ((x - z) / t); else tmp = (y - z) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], 2e-259], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq 2 \cdot 10^{-259}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < 2.0000000000000001e-259Initial program 100.0%
Taylor expanded in y around 0 77.7%
if 2.0000000000000001e-259 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 73.4%
associate-*r/73.4%
associate-*l/73.2%
*-commutative73.2%
Simplified73.2%
Final simplification75.5%
(FPCore (x y z t) :precision binary64 (if (<= y 5.7e-59) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5.7e-59) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * ((x + 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 <= 5.7d-59) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = 0.5d0 * ((x + y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5.7e-59) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * ((x + y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 5.7e-59: tmp = 0.5 * ((x - z) / t) else: tmp = 0.5 * ((x + y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 5.7e-59) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(0.5 * Float64(Float64(x + y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 5.7e-59) tmp = 0.5 * ((x - z) / t); else tmp = 0.5 * ((x + y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 5.7e-59], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x + y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.7 \cdot 10^{-59}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if y < 5.7e-59Initial program 100.0%
Taylor expanded in y around 0 81.6%
if 5.7e-59 < y Initial program 100.0%
Taylor expanded in z around 0 80.0%
+-commutative80.0%
Simplified80.0%
Final simplification81.1%
(FPCore (x y z t) :precision binary64 (if (<= y 9.2e-8) (* 0.5 (/ x t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 9.2e-8) {
tmp = 0.5 * (x / 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 <= 9.2d-8) then
tmp = 0.5d0 * (x / 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 <= 9.2e-8) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 9.2e-8: tmp = 0.5 * (x / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 9.2e-8) tmp = Float64(0.5 * Float64(x / 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 <= 9.2e-8) tmp = 0.5 * (x / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 9.2e-8], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.2 \cdot 10^{-8}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 9.2000000000000003e-8Initial program 100.0%
Taylor expanded in x around inf 43.3%
if 9.2000000000000003e-8 < y Initial program 100.0%
Taylor expanded in y around inf 68.2%
Final simplification50.3%
(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.6%
Final simplification36.6%
herbie shell --seed 2023271
(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)))