
(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 (/ (* z -0.5) t)) (t_2 (* 0.5 (/ x t))))
(if (<= y -3.8e-160)
t_2
(if (<= y -1.05e-168)
t_1
(if (<= y -8.8e-293) t_2 (if (<= y 3.2e-5) t_1 (/ (* y 0.5) t)))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * -0.5) / t;
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -3.8e-160) {
tmp = t_2;
} else if (y <= -1.05e-168) {
tmp = t_1;
} else if (y <= -8.8e-293) {
tmp = t_2;
} else if (y <= 3.2e-5) {
tmp = t_1;
} 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 = (z * (-0.5d0)) / t
t_2 = 0.5d0 * (x / t)
if (y <= (-3.8d-160)) then
tmp = t_2
else if (y <= (-1.05d-168)) then
tmp = t_1
else if (y <= (-8.8d-293)) then
tmp = t_2
else if (y <= 3.2d-5) then
tmp = t_1
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 = (z * -0.5) / t;
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -3.8e-160) {
tmp = t_2;
} else if (y <= -1.05e-168) {
tmp = t_1;
} else if (y <= -8.8e-293) {
tmp = t_2;
} else if (y <= 3.2e-5) {
tmp = t_1;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * -0.5) / t t_2 = 0.5 * (x / t) tmp = 0 if y <= -3.8e-160: tmp = t_2 elif y <= -1.05e-168: tmp = t_1 elif y <= -8.8e-293: tmp = t_2 elif y <= 3.2e-5: tmp = t_1 else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * -0.5) / t) t_2 = Float64(0.5 * Float64(x / t)) tmp = 0.0 if (y <= -3.8e-160) tmp = t_2; elseif (y <= -1.05e-168) tmp = t_1; elseif (y <= -8.8e-293) tmp = t_2; elseif (y <= 3.2e-5) tmp = t_1; else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * -0.5) / t; t_2 = 0.5 * (x / t); tmp = 0.0; if (y <= -3.8e-160) tmp = t_2; elseif (y <= -1.05e-168) tmp = t_1; elseif (y <= -8.8e-293) tmp = t_2; elseif (y <= 3.2e-5) tmp = t_1; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.8e-160], t$95$2, If[LessEqual[y, -1.05e-168], t$95$1, If[LessEqual[y, -8.8e-293], t$95$2, If[LessEqual[y, 3.2e-5], t$95$1, N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z \cdot -0.5}{t}\\
t_2 := 0.5 \cdot \frac{x}{t}\\
\mathbf{if}\;y \leq -3.8 \cdot 10^{-160}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{-168}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{-293}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-5}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < -3.7999999999999998e-160 or -1.04999999999999997e-168 < y < -8.8e-293Initial program 100.0%
Taylor expanded in x around inf 39.7%
if -3.7999999999999998e-160 < y < -1.04999999999999997e-168 or -8.8e-293 < y < 3.19999999999999986e-5Initial program 100.0%
Taylor expanded in z around inf 53.9%
*-commutative53.9%
associate-*l/53.9%
Simplified53.9%
if 3.19999999999999986e-5 < y Initial program 100.0%
Taylor expanded in y around inf 59.3%
associate-*r/59.3%
Simplified59.3%
Final simplification47.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4e+147) (not (<= z 3.1e+134))) (/ (* z -0.5) t) (* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4e+147) || !(z <= 3.1e+134)) {
tmp = (z * -0.5) / 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 ((z <= (-4d+147)) .or. (.not. (z <= 3.1d+134))) then
tmp = (z * (-0.5d0)) / 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 ((z <= -4e+147) || !(z <= 3.1e+134)) {
tmp = (z * -0.5) / t;
} else {
tmp = 0.5 * ((x + y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4e+147) or not (z <= 3.1e+134): tmp = (z * -0.5) / t else: tmp = 0.5 * ((x + y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4e+147) || !(z <= 3.1e+134)) tmp = Float64(Float64(z * -0.5) / 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 ((z <= -4e+147) || ~((z <= 3.1e+134))) tmp = (z * -0.5) / t; else tmp = 0.5 * ((x + y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4e+147], N[Not[LessEqual[z, 3.1e+134]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(0.5 * N[(N[(x + y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+147} \lor \neg \left(z \leq 3.1 \cdot 10^{+134}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if z < -3.9999999999999999e147 or 3.09999999999999982e134 < z Initial program 100.0%
Taylor expanded in z around inf 78.8%
*-commutative78.8%
associate-*l/78.8%
Simplified78.8%
if -3.9999999999999999e147 < z < 3.09999999999999982e134Initial program 100.0%
Taylor expanded in z around 0 82.5%
+-commutative82.5%
Simplified82.5%
Final simplification81.6%
(FPCore (x y z t) :precision binary64 (if (<= y 5000.0) (* (- x z) (/ 0.5 t)) (* 0.5 (/ (+ x y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 5000.0) {
tmp = (x - z) * (0.5 / 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 <= 5000.0d0) then
tmp = (x - z) * (0.5d0 / 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 <= 5000.0) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = 0.5 * ((x + y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 5000.0: tmp = (x - z) * (0.5 / t) else: tmp = 0.5 * ((x + y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 5000.0) tmp = Float64(Float64(x - z) * Float64(0.5 / 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 <= 5000.0) tmp = (x - z) * (0.5 / t); else tmp = 0.5 * ((x + y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 5000.0], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x + y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5000:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x + y}{t}\\
\end{array}
\end{array}
if y < 5e3Initial program 100.0%
Taylor expanded in y around 0 77.4%
*-commutative77.4%
associate-*l/77.4%
associate-/l*77.1%
Simplified77.1%
if 5e3 < y Initial program 100.0%
Taylor expanded in z around 0 81.9%
+-commutative81.9%
Simplified81.9%
Final simplification78.2%
(FPCore (x y z t) :precision binary64 (if (<= y 1.95e-13) (* (- x z) (/ 0.5 t)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.95e-13) {
tmp = (x - z) * (0.5 / 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 (y <= 1.95d-13) then
tmp = (x - z) * (0.5d0 / 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 (y <= 1.95e-13) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (0.5 * (y - z)) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.95e-13: tmp = (x - z) * (0.5 / t) else: tmp = (0.5 * (y - z)) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.95e-13) tmp = Float64(Float64(x - z) * Float64(0.5 / 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 (y <= 1.95e-13) tmp = (x - z) * (0.5 / t); else tmp = (0.5 * (y - z)) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.95e-13], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.95 \cdot 10^{-13}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if y < 1.95000000000000002e-13Initial program 100.0%
Taylor expanded in y around 0 77.5%
*-commutative77.5%
associate-*l/77.5%
associate-/l*77.2%
Simplified77.2%
if 1.95000000000000002e-13 < y Initial program 100.0%
Taylor expanded in x around 0 79.1%
associate-*r/79.1%
Simplified79.1%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (if (<= y 9.6e-13) (* 0.5 (/ x t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 9.6e-13) {
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 (y <= 9.6d-13) 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 (y <= 9.6e-13) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 9.6e-13: tmp = 0.5 * (x / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 9.6e-13) 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 (y <= 9.6e-13) tmp = 0.5 * (x / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 9.6e-13], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.6 \cdot 10^{-13}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 9.5999999999999995e-13Initial program 100.0%
Taylor expanded in x around inf 44.5%
if 9.5999999999999995e-13 < y Initial program 100.0%
Taylor expanded in y around inf 56.9%
associate-*r/56.9%
Simplified56.9%
Final simplification47.6%
(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.3%
Final simplification40.3%
herbie shell --seed 2024055
(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)))