
(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%
(FPCore (x y z t) :precision binary64 (if (or (<= z -7.2e+137) (not (<= z 5.1e+206))) (/ (* z -0.5) t) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7.2e+137) || !(z <= 5.1e+206)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) / (t * 2.0);
}
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 <= (-7.2d+137)) .or. (.not. (z <= 5.1d+206))) then
tmp = (z * (-0.5d0)) / t
else
tmp = (x + y) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7.2e+137) || !(z <= 5.1e+206)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -7.2e+137) or not (z <= 5.1e+206): tmp = (z * -0.5) / t else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -7.2e+137) || !(z <= 5.1e+206)) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(x + y) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -7.2e+137) || ~((z <= 5.1e+206))) tmp = (z * -0.5) / t; else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -7.2e+137], N[Not[LessEqual[z, 5.1e+206]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{+137} \lor \neg \left(z \leq 5.1 \cdot 10^{+206}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -7.1999999999999999e137 or 5.1000000000000003e206 < z Initial program 100.0%
Taylor expanded in z around inf 82.4%
*-commutative82.4%
associate-*l/82.4%
Simplified82.4%
if -7.1999999999999999e137 < z < 5.1000000000000003e206Initial program 100.0%
Taylor expanded in z around 0 88.0%
+-commutative88.0%
Simplified88.0%
Final simplification87.0%
(FPCore (x y z t) :precision binary64 (if (<= x -9e+90) (/ (+ x y) (* t 2.0)) (if (<= x -56000000.0) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -9e+90) {
tmp = (x + y) / (t * 2.0);
} else if (x <= -56000000.0) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
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 <= (-9d+90)) then
tmp = (x + y) / (t * 2.0d0)
else if (x <= (-56000000.0d0)) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (y - z) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -9e+90) {
tmp = (x + y) / (t * 2.0);
} else if (x <= -56000000.0) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -9e+90: tmp = (x + y) / (t * 2.0) elif x <= -56000000.0: tmp = (x - z) / (t * 2.0) else: tmp = (y - z) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -9e+90) tmp = Float64(Float64(x + y) / Float64(t * 2.0)); elseif (x <= -56000000.0) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(y - z) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -9e+90) tmp = (x + y) / (t * 2.0); elseif (x <= -56000000.0) tmp = (x - z) / (t * 2.0); else tmp = (y - z) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -9e+90], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -56000000.0], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+90}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\mathbf{elif}\;x \leq -56000000:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if x < -9e90Initial program 100.0%
Taylor expanded in z around 0 97.2%
+-commutative97.2%
Simplified97.2%
if -9e90 < x < -5.6e7Initial program 100.0%
Taylor expanded in y around 0 89.8%
if -5.6e7 < x Initial program 100.0%
Taylor expanded in x around 0 72.3%
Final simplification78.9%
(FPCore (x y z t) :precision binary64 (if (<= y 4e-77) (/ x (* t 2.0)) (if (<= y 6e+75) (/ (* z -0.5) t) (/ y (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4e-77) {
tmp = x / (t * 2.0);
} else if (y <= 6e+75) {
tmp = (z * -0.5) / t;
} else {
tmp = y / (t * 2.0);
}
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 <= 4d-77) then
tmp = x / (t * 2.0d0)
else if (y <= 6d+75) then
tmp = (z * (-0.5d0)) / t
else
tmp = y / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4e-77) {
tmp = x / (t * 2.0);
} else if (y <= 6e+75) {
tmp = (z * -0.5) / t;
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 4e-77: tmp = x / (t * 2.0) elif y <= 6e+75: tmp = (z * -0.5) / t else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 4e-77) tmp = Float64(x / Float64(t * 2.0)); elseif (y <= 6e+75) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 4e-77) tmp = x / (t * 2.0); elseif (y <= 6e+75) tmp = (z * -0.5) / t; else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 4e-77], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6e+75], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{-77}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+75}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if y < 3.9999999999999997e-77Initial program 100.0%
Taylor expanded in x around inf 54.0%
if 3.9999999999999997e-77 < y < 6e75Initial program 99.9%
Taylor expanded in z around inf 38.1%
*-commutative38.1%
associate-*l/38.1%
Simplified38.1%
if 6e75 < y Initial program 100.0%
Taylor expanded in y around inf 82.8%
(FPCore (x y z t) :precision binary64 (if (<= y 6.0) (/ (- x z) (* t 2.0)) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.0) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (x + y) / (t * 2.0);
}
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 <= 6.0d0) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (x + y) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.0) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 6.0: tmp = (x - z) / (t * 2.0) else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 6.0) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(x + y) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 6.0) tmp = (x - z) / (t * 2.0); else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 6.0], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if y < 6Initial program 100.0%
Taylor expanded in y around 0 81.9%
if 6 < y Initial program 100.0%
Taylor expanded in z around 0 89.2%
+-commutative89.2%
Simplified89.2%
Final simplification83.9%
(FPCore (x y z t) :precision binary64 (if (<= x -760000000.0) (/ x (* t 2.0)) (/ y (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -760000000.0) {
tmp = x / (t * 2.0);
} else {
tmp = y / (t * 2.0);
}
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 <= (-760000000.0d0)) then
tmp = x / (t * 2.0d0)
else
tmp = y / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -760000000.0) {
tmp = x / (t * 2.0);
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -760000000.0: tmp = x / (t * 2.0) else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -760000000.0) tmp = Float64(x / Float64(t * 2.0)); else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -760000000.0) tmp = x / (t * 2.0); else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -760000000.0], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -760000000:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -7.6e8Initial program 100.0%
Taylor expanded in x around inf 77.4%
if -7.6e8 < x Initial program 100.0%
Taylor expanded in y around inf 41.7%
(FPCore (x y z t) :precision binary64 (/ x (* t 2.0)))
double code(double x, double y, double z, double t) {
return x / (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 / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return x / (t * 2.0);
}
def code(x, y, z, t): return x / (t * 2.0)
function code(x, y, z, t) return Float64(x / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = x / (t * 2.0); end
code[x_, y_, z_, t_] := N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{t \cdot 2}
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 46.3%
herbie shell --seed 2024185
(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)))