
(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 8 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 -3.55e+56) (not (<= z 3.5e+71))) (* 0.5 (/ (- x z) t)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.55e+56) || !(z <= 3.5e+71)) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (x + 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 ((z <= (-3.55d+56)) .or. (.not. (z <= 3.5d+71))) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = (x + 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 ((z <= -3.55e+56) || !(z <= 3.5e+71)) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.55e+56) or not (z <= 3.5e+71): tmp = 0.5 * ((x - z) / t) else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.55e+56) || !(z <= 3.5e+71)) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.55e+56) || ~((z <= 3.5e+71))) tmp = 0.5 * ((x - z) / t); else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.55e+56], N[Not[LessEqual[z, 3.5e+71]], $MachinePrecision]], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.55 \cdot 10^{+56} \lor \neg \left(z \leq 3.5 \cdot 10^{+71}\right):\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if z < -3.55e56 or 3.4999999999999999e71 < z Initial program 100.0%
Taylor expanded in y around 0 87.6%
if -3.55e56 < z < 3.4999999999999999e71Initial program 100.0%
Taylor expanded in z around 0 93.1%
associate-*r/93.1%
associate-*l/92.8%
*-commutative92.8%
+-commutative92.8%
Simplified92.8%
Final simplification90.6%
(FPCore (x y z t) :precision binary64 (if (<= (+ x y) 1e-156) (* 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) <= 1e-156) {
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) <= 1d-156) 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) <= 1e-156) {
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) <= 1e-156: 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) <= 1e-156) 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) <= 1e-156) 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], 1e-156], 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 10^{-156}:\\
\;\;\;\;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) < 1.00000000000000004e-156Initial program 100.0%
Taylor expanded in y around 0 68.6%
if 1.00000000000000004e-156 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 73.3%
associate-*r/73.3%
*-commutative73.3%
associate-*r/73.1%
Simplified73.1%
Final simplification70.8%
(FPCore (x y z t) :precision binary64 (if (<= y -3.6e-307) (* 0.5 (/ x t)) (if (<= y 7e+52) (* (/ z t) -0.5) (* y (/ 0.5 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.6e-307) {
tmp = 0.5 * (x / t);
} else if (y <= 7e+52) {
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 (y <= (-3.6d-307)) then
tmp = 0.5d0 * (x / t)
else if (y <= 7d+52) 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 (y <= -3.6e-307) {
tmp = 0.5 * (x / t);
} else if (y <= 7e+52) {
tmp = (z / t) * -0.5;
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3.6e-307: tmp = 0.5 * (x / t) elif y <= 7e+52: tmp = (z / t) * -0.5 else: tmp = y * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3.6e-307) tmp = Float64(0.5 * Float64(x / t)); elseif (y <= 7e+52) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(y * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -3.6e-307) tmp = 0.5 * (x / t); elseif (y <= 7e+52) tmp = (z / t) * -0.5; else tmp = y * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.6e-307], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7e+52], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-307}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+52}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < -3.60000000000000007e-307Initial program 100.0%
Taylor expanded in x around inf 34.1%
if -3.60000000000000007e-307 < y < 7e52Initial program 100.0%
Taylor expanded in z around inf 57.6%
*-commutative57.6%
Simplified57.6%
if 7e52 < y Initial program 100.0%
Taylor expanded in z around 0 89.4%
associate-*r/89.4%
associate-*l/89.1%
*-commutative89.1%
+-commutative89.1%
Simplified89.1%
Taylor expanded in y around inf 70.4%
associate-*r/70.4%
associate-*l/70.2%
*-commutative70.2%
Simplified70.2%
Final simplification49.1%
(FPCore (x y z t) :precision binary64 (if (<= y -2.3e-306) (* 0.5 (/ x t)) (if (<= y 8e+52) (* (/ z t) -0.5) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.3e-306) {
tmp = 0.5 * (x / t);
} else if (y <= 8e+52) {
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 (y <= (-2.3d-306)) then
tmp = 0.5d0 * (x / t)
else if (y <= 8d+52) 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 (y <= -2.3e-306) {
tmp = 0.5 * (x / t);
} else if (y <= 8e+52) {
tmp = (z / t) * -0.5;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -2.3e-306: tmp = 0.5 * (x / t) elif y <= 8e+52: tmp = (z / t) * -0.5 else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -2.3e-306) tmp = Float64(0.5 * Float64(x / t)); elseif (y <= 8e+52) 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 (y <= -2.3e-306) tmp = 0.5 * (x / t); elseif (y <= 8e+52) tmp = (z / t) * -0.5; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.3e-306], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e+52], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-306}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+52}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < -2.29999999999999989e-306Initial program 100.0%
Taylor expanded in x around inf 34.1%
if -2.29999999999999989e-306 < y < 7.9999999999999999e52Initial program 100.0%
Taylor expanded in z around inf 57.6%
*-commutative57.6%
Simplified57.6%
if 7.9999999999999999e52 < y Initial program 100.0%
Taylor expanded in y around inf 70.4%
associate-*r/70.4%
Simplified70.4%
Final simplification49.2%
(FPCore (x y z t) :precision binary64 (if (<= y 5.8e+82) (* 0.5 (/ (- x z) t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5.8e+82) {
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 <= 5.8d+82) 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 <= 5.8e+82) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 5.8e+82: 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 <= 5.8e+82) 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 <= 5.8e+82) 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, 5.8e+82], 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 5.8 \cdot 10^{+82}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 5.8000000000000003e82Initial program 100.0%
Taylor expanded in y around 0 75.0%
if 5.8000000000000003e82 < y Initial program 100.0%
Taylor expanded in y around inf 76.2%
associate-*r/76.2%
Simplified76.2%
Final simplification75.2%
(FPCore (x y z t) :precision binary64 (if (<= x -0.0008) (* 0.5 (/ x t)) (* y (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.0008) {
tmp = 0.5 * (x / 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 (x <= (-0.0008d0)) then
tmp = 0.5d0 * (x / 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 (x <= -0.0008) {
tmp = 0.5 * (x / t);
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -0.0008: tmp = 0.5 * (x / t) else: tmp = y * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -0.0008) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(y * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -0.0008) tmp = 0.5 * (x / t); else tmp = y * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.0008], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0008:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if x < -8.00000000000000038e-4Initial program 100.0%
Taylor expanded in x around inf 65.4%
if -8.00000000000000038e-4 < x Initial program 100.0%
Taylor expanded in z around 0 62.2%
associate-*r/62.2%
associate-*l/62.0%
*-commutative62.0%
+-commutative62.0%
Simplified62.0%
Taylor expanded in y around inf 42.2%
associate-*r/42.2%
associate-*l/42.1%
*-commutative42.1%
Simplified42.1%
Final simplification46.4%
(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 32.3%
Final simplification32.3%
herbie shell --seed 2023310
(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)))