
(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 (or (<= z -3e+173)
(not
(or (<= z -1.44e+144) (and (not (<= z -4.5e+126)) (<= z 3e+97)))))
(* (/ z t) -0.5)
(* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3e+173) || !((z <= -1.44e+144) || (!(z <= -4.5e+126) && (z <= 3e+97)))) {
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 <= (-3d+173)) .or. (.not. (z <= (-1.44d+144)) .or. (.not. (z <= (-4.5d+126))) .and. (z <= 3d+97))) 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 <= -3e+173) || !((z <= -1.44e+144) || (!(z <= -4.5e+126) && (z <= 3e+97)))) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * ((x + y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3e+173) or not ((z <= -1.44e+144) or (not (z <= -4.5e+126) and (z <= 3e+97))): 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 <= -3e+173) || !((z <= -1.44e+144) || (!(z <= -4.5e+126) && (z <= 3e+97)))) 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 <= -3e+173) || ~(((z <= -1.44e+144) || (~((z <= -4.5e+126)) && (z <= 3e+97))))) 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, -3e+173], N[Not[Or[LessEqual[z, -1.44e+144], And[N[Not[LessEqual[z, -4.5e+126]], $MachinePrecision], LessEqual[z, 3e+97]]]], $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 \cdot 10^{+173} \lor \neg \left(z \leq -1.44 \cdot 10^{+144} \lor \neg \left(z \leq -4.5 \cdot 10^{+126}\right) \land z \leq 3 \cdot 10^{+97}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if z < -2.9999999999999998e173 or -1.44e144 < z < -4.49999999999999974e126 or 2.9999999999999998e97 < z Initial program 100.0%
Taylor expanded in z around inf 79.7%
*-commutative79.7%
Simplified79.7%
if -2.9999999999999998e173 < z < -1.44e144 or -4.49999999999999974e126 < z < 2.9999999999999998e97Initial program 100.0%
Taylor expanded in z around 0 92.6%
+-commutative92.6%
Simplified92.6%
Final simplification89.2%
(FPCore (x y z t) :precision binary64 (if (<= x -1050000.0) (* 0.5 (/ x t)) (if (<= x -2.4e-276) (* (/ z t) -0.5) (* 0.5 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1050000.0) {
tmp = 0.5 * (x / t);
} else if (x <= -2.4e-276) {
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 <= (-1050000.0d0)) then
tmp = 0.5d0 * (x / t)
else if (x <= (-2.4d-276)) 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 <= -1050000.0) {
tmp = 0.5 * (x / t);
} else if (x <= -2.4e-276) {
tmp = (z / t) * -0.5;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1050000.0: tmp = 0.5 * (x / t) elif x <= -2.4e-276: tmp = (z / t) * -0.5 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1050000.0) tmp = Float64(0.5 * Float64(x / t)); elseif (x <= -2.4e-276) 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 <= -1050000.0) tmp = 0.5 * (x / t); elseif (x <= -2.4e-276) tmp = (z / t) * -0.5; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1050000.0], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.4e-276], 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 -1050000:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-276}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.05e6Initial program 100.0%
Taylor expanded in x around inf 68.3%
if -1.05e6 < x < -2.39999999999999983e-276Initial program 100.0%
Taylor expanded in z around inf 56.6%
*-commutative56.6%
Simplified56.6%
if -2.39999999999999983e-276 < x Initial program 100.0%
Taylor expanded in y around inf 39.8%
Final simplification51.9%
(FPCore (x y z t) :precision binary64 (if (<= y 2.3e-11) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.3e-11) {
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 <= 2.3d-11) 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 <= 2.3e-11) {
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 <= 2.3e-11: 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 <= 2.3e-11) 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 <= 2.3e-11) 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, 2.3e-11], 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 2.3 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if y < 2.30000000000000014e-11Initial program 100.0%
Taylor expanded in y around 0 78.1%
if 2.30000000000000014e-11 < y Initial program 99.9%
Taylor expanded in z around 0 80.4%
+-commutative80.4%
Simplified80.4%
Final simplification78.7%
(FPCore (x y z t) :precision binary64 (if (<= y 2.05e-113) (* 0.5 (/ (- x z) t)) (* (- y z) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.05e-113) {
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 (y <= 2.05d-113) 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 (y <= 2.05e-113) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y - z) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.05e-113: 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 (y <= 2.05e-113) 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 (y <= 2.05e-113) 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[y, 2.05e-113], 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}\;y \leq 2.05 \cdot 10^{-113}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 2.05e-113Initial program 100.0%
Taylor expanded in y around 0 78.2%
if 2.05e-113 < y Initial program 99.9%
Taylor expanded in x around 0 73.3%
associate-*r/73.3%
associate-*l/73.2%
*-commutative73.2%
Simplified73.2%
Final simplification76.4%
(FPCore (x y z t) :precision binary64 (if (<= y 1.7e-106) (* 0.5 (/ x t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.7e-106) {
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 <= 1.7d-106) 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 <= 1.7e-106) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.7e-106: tmp = 0.5 * (x / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.7e-106) 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 <= 1.7e-106) tmp = 0.5 * (x / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.7e-106], 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 1.7 \cdot 10^{-106}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 1.69999999999999991e-106Initial program 100.0%
Taylor expanded in x around inf 52.7%
if 1.69999999999999991e-106 < y Initial program 99.9%
Taylor expanded in y around inf 52.0%
Final simplification52.5%
(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 45.0%
Final simplification45.0%
herbie shell --seed 2023293
(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)))