
(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 -0.5) t)))
(if (<= x -5.8e+82)
t_1
(if (<= x -1.3e+53)
t_2
(if (<= x -2.2e+17) t_1 (if (<= x -9e-218) t_2 (/ (* y 0.5) t)))))))
double code(double x, double y, double z, double t) {
double t_1 = 0.5 * (x / t);
double t_2 = (z * -0.5) / t;
double tmp;
if (x <= -5.8e+82) {
tmp = t_1;
} else if (x <= -1.3e+53) {
tmp = t_2;
} else if (x <= -2.2e+17) {
tmp = t_1;
} else if (x <= -9e-218) {
tmp = t_2;
} 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = 0.5d0 * (x / t)
t_2 = (z * (-0.5d0)) / t
if (x <= (-5.8d+82)) then
tmp = t_1
else if (x <= (-1.3d+53)) then
tmp = t_2
else if (x <= (-2.2d+17)) then
tmp = t_1
else if (x <= (-9d-218)) then
tmp = t_2
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 t_1 = 0.5 * (x / t);
double t_2 = (z * -0.5) / t;
double tmp;
if (x <= -5.8e+82) {
tmp = t_1;
} else if (x <= -1.3e+53) {
tmp = t_2;
} else if (x <= -2.2e+17) {
tmp = t_1;
} else if (x <= -9e-218) {
tmp = t_2;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): t_1 = 0.5 * (x / t) t_2 = (z * -0.5) / t tmp = 0 if x <= -5.8e+82: tmp = t_1 elif x <= -1.3e+53: tmp = t_2 elif x <= -2.2e+17: tmp = t_1 elif x <= -9e-218: tmp = t_2 else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) t_1 = Float64(0.5 * Float64(x / t)) t_2 = Float64(Float64(z * -0.5) / t) tmp = 0.0 if (x <= -5.8e+82) tmp = t_1; elseif (x <= -1.3e+53) tmp = t_2; elseif (x <= -2.2e+17) tmp = t_1; elseif (x <= -9e-218) tmp = t_2; else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = 0.5 * (x / t); t_2 = (z * -0.5) / t; tmp = 0.0; if (x <= -5.8e+82) tmp = t_1; elseif (x <= -1.3e+53) tmp = t_2; elseif (x <= -2.2e+17) tmp = t_1; elseif (x <= -9e-218) tmp = t_2; else tmp = (y * 0.5) / 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 * -0.5), $MachinePrecision] / t), $MachinePrecision]}, If[LessEqual[x, -5.8e+82], t$95$1, If[LessEqual[x, -1.3e+53], t$95$2, If[LessEqual[x, -2.2e+17], t$95$1, If[LessEqual[x, -9e-218], t$95$2, N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 0.5 \cdot \frac{x}{t}\\
t_2 := \frac{z \cdot -0.5}{t}\\
\mathbf{if}\;x \leq -5.8 \cdot 10^{+82}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+53}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-218}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -5.8000000000000003e82 or -1.29999999999999999e53 < x < -2.2e17Initial program 100.0%
Taylor expanded in x around inf 78.8%
if -5.8000000000000003e82 < x < -1.29999999999999999e53 or -2.2e17 < x < -8.99999999999999953e-218Initial program 100.0%
Taylor expanded in z around inf 52.2%
*-commutative52.2%
associate-*l/52.2%
Simplified52.2%
if -8.99999999999999953e-218 < x Initial program 100.0%
Taylor expanded in y around inf 44.2%
associate-*r/44.2%
Simplified44.2%
Final simplification53.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y 0.00031) (and (not (<= y 1.35e+45)) (<= y 1.55e+105))) (* 0.5 (/ (- x z) t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= 0.00031) || (!(y <= 1.35e+45) && (y <= 1.55e+105))) {
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 <= 0.00031d0) .or. (.not. (y <= 1.35d+45)) .and. (y <= 1.55d+105)) 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 <= 0.00031) || (!(y <= 1.35e+45) && (y <= 1.55e+105))) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= 0.00031) or (not (y <= 1.35e+45) and (y <= 1.55e+105)): 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 <= 0.00031) || (!(y <= 1.35e+45) && (y <= 1.55e+105))) 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 <= 0.00031) || (~((y <= 1.35e+45)) && (y <= 1.55e+105))) tmp = 0.5 * ((x - z) / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, 0.00031], And[N[Not[LessEqual[y, 1.35e+45]], $MachinePrecision], LessEqual[y, 1.55e+105]]], 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 0.00031 \lor \neg \left(y \leq 1.35 \cdot 10^{+45}\right) \land y \leq 1.55 \cdot 10^{+105}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 3.1e-4 or 1.34999999999999992e45 < y < 1.55000000000000002e105Initial program 100.0%
Taylor expanded in y around 0 77.2%
if 3.1e-4 < y < 1.34999999999999992e45 or 1.55000000000000002e105 < y Initial program 99.9%
Taylor expanded in y around inf 68.2%
associate-*r/68.2%
Simplified68.2%
Final simplification75.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.6e-6) (not (<= z 2.4e+126))) (* 0.5 (/ (- x z) t)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.6e-6) || !(z <= 2.4e+126)) {
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 <= (-5.6d-6)) .or. (.not. (z <= 2.4d+126))) 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 <= -5.6e-6) || !(z <= 2.4e+126)) {
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 <= -5.6e-6) or not (z <= 2.4e+126): 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 <= -5.6e-6) || !(z <= 2.4e+126)) 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 <= -5.6e-6) || ~((z <= 2.4e+126))) 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, -5.6e-6], N[Not[LessEqual[z, 2.4e+126]], $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 -5.6 \cdot 10^{-6} \lor \neg \left(z \leq 2.4 \cdot 10^{+126}\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 < -5.59999999999999975e-6 or 2.40000000000000012e126 < z Initial program 100.0%
Taylor expanded in y around 0 84.7%
if -5.59999999999999975e-6 < z < 2.40000000000000012e126Initial program 100.0%
Taylor expanded in z around 0 92.7%
associate-*r/92.7%
associate-*l/92.4%
*-commutative92.4%
+-commutative92.4%
Simplified92.4%
Final simplification89.5%
(FPCore (x y z t) :precision binary64 (if (<= (+ x y) -5e-134) (* 0.5 (/ (- x z) t)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -5e-134) {
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 + y) <= (-5d-134)) 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 + y) <= -5e-134) {
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 + y) <= -5e-134: 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 (Float64(x + y) <= -5e-134) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(0.5 * Float64(y - z)) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x + y) <= -5e-134) 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[N[(x + y), $MachinePrecision], -5e-134], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -5 \cdot 10^{-134}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < -5.0000000000000003e-134Initial program 100.0%
Taylor expanded in y around 0 66.9%
if -5.0000000000000003e-134 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 74.9%
associate-*r/74.9%
Simplified74.9%
Final simplification71.3%
(FPCore (x y z t) :precision binary64 (if (<= x -6e-39) (* 0.5 (/ x t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -6e-39) {
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 <= (-6d-39)) 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 <= -6e-39) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -6e-39: tmp = 0.5 * (x / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -6e-39) tmp = Float64(0.5 * Float64(x / 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 (x <= -6e-39) tmp = 0.5 * (x / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -6e-39], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-39}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -6.00000000000000055e-39Initial program 100.0%
Taylor expanded in x around inf 65.8%
if -6.00000000000000055e-39 < x Initial program 100.0%
Taylor expanded in y around inf 44.5%
associate-*r/44.5%
Simplified44.5%
Final simplification50.2%
(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 40.2%
Final simplification40.2%
herbie shell --seed 2024075
(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)))