
(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%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.02e+65) (not (<= z 7.5e+84))) (* z (/ -0.5 t)) (/ x (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.02e+65) || !(z <= 7.5e+84)) {
tmp = z * (-0.5 / t);
} else {
tmp = x / (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 <= (-1.02d+65)) .or. (.not. (z <= 7.5d+84))) then
tmp = z * ((-0.5d0) / t)
else
tmp = x / (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 <= -1.02e+65) || !(z <= 7.5e+84)) {
tmp = z * (-0.5 / t);
} else {
tmp = x / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.02e+65) or not (z <= 7.5e+84): tmp = z * (-0.5 / t) else: tmp = x / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.02e+65) || !(z <= 7.5e+84)) tmp = Float64(z * Float64(-0.5 / t)); else tmp = Float64(x / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.02e+65) || ~((z <= 7.5e+84))) tmp = z * (-0.5 / t); else tmp = x / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.02e+65], N[Not[LessEqual[z, 7.5e+84]], $MachinePrecision]], N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+65} \lor \neg \left(z \leq 7.5 \cdot 10^{+84}\right):\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\end{array}
\end{array}
if z < -1.02000000000000005e65 or 7.5000000000000001e84 < z Initial program 100.0%
Taylor expanded in x around 0 94.9%
distribute-lft-out94.9%
Simplified94.9%
Taylor expanded in z around inf 72.2%
associate-*r/72.2%
*-commutative72.2%
associate-*r/72.1%
Simplified72.1%
if -1.02000000000000005e65 < z < 7.5000000000000001e84Initial program 100.0%
Taylor expanded in x around inf 51.3%
Final simplification59.3%
(FPCore (x y z t) :precision binary64 (if (<= x -2.6e+96) (/ x (* t 2.0)) (if (<= x -1.4e-188) (/ (* z -0.5) t) (/ y (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.6e+96) {
tmp = x / (t * 2.0);
} else if (x <= -1.4e-188) {
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 (x <= (-2.6d+96)) then
tmp = x / (t * 2.0d0)
else if (x <= (-1.4d-188)) 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 (x <= -2.6e+96) {
tmp = x / (t * 2.0);
} else if (x <= -1.4e-188) {
tmp = (z * -0.5) / t;
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -2.6e+96: tmp = x / (t * 2.0) elif x <= -1.4e-188: tmp = (z * -0.5) / t else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -2.6e+96) tmp = Float64(x / Float64(t * 2.0)); elseif (x <= -1.4e-188) 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 (x <= -2.6e+96) tmp = x / (t * 2.0); elseif (x <= -1.4e-188) tmp = (z * -0.5) / t; else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -2.6e+96], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.4e-188], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+96}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{-188}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -2.6e96Initial program 100.0%
Taylor expanded in x around inf 66.5%
if -2.6e96 < x < -1.4000000000000001e-188Initial program 100.0%
Taylor expanded in z around inf 56.1%
*-commutative56.1%
associate-*l/56.1%
Simplified56.1%
if -1.4000000000000001e-188 < x Initial program 100.0%
Taylor expanded in y around inf 46.5%
(FPCore (x y z t) :precision binary64 (if (<= x -7.2e+95) (/ x (* t 2.0)) (if (<= x -2.7e-189) (* z (/ -0.5 t)) (/ y (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -7.2e+95) {
tmp = x / (t * 2.0);
} else if (x <= -2.7e-189) {
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 (x <= (-7.2d+95)) then
tmp = x / (t * 2.0d0)
else if (x <= (-2.7d-189)) 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 (x <= -7.2e+95) {
tmp = x / (t * 2.0);
} else if (x <= -2.7e-189) {
tmp = z * (-0.5 / t);
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -7.2e+95: tmp = x / (t * 2.0) elif x <= -2.7e-189: tmp = z * (-0.5 / t) else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -7.2e+95) tmp = Float64(x / Float64(t * 2.0)); elseif (x <= -2.7e-189) tmp = Float64(z * Float64(-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 (x <= -7.2e+95) tmp = x / (t * 2.0); elseif (x <= -2.7e-189) tmp = z * (-0.5 / t); else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -7.2e+95], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.7e-189], N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+95}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-189}:\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -7.19999999999999955e95Initial program 100.0%
Taylor expanded in x around inf 66.5%
if -7.19999999999999955e95 < x < -2.6999999999999999e-189Initial program 100.0%
Taylor expanded in x around 0 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 56.1%
associate-*r/56.1%
*-commutative56.1%
associate-*r/56.0%
Simplified56.0%
if -2.6999999999999999e-189 < x Initial program 100.0%
Taylor expanded in y around inf 46.5%
(FPCore (x y z t) :precision binary64 (if (<= x -3.8e-26) (/ (- x z) (* t 2.0)) (* (- y z) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.8e-26) {
tmp = (x - z) / (t * 2.0);
} 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 <= (-3.8d-26)) then
tmp = (x - z) / (t * 2.0d0)
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 <= -3.8e-26) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.8e-26: tmp = (x - z) / (t * 2.0) else: tmp = (y - z) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.8e-26) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); 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 <= -3.8e-26) tmp = (x - z) / (t * 2.0); else tmp = (y - z) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.8e-26], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-26}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if x < -3.80000000000000015e-26Initial program 100.0%
Taylor expanded in y around 0 75.9%
if -3.80000000000000015e-26 < x Initial program 100.0%
Taylor expanded in x around 0 78.1%
*-commutative78.1%
associate-*l/78.5%
associate-*r/78.4%
Simplified78.4%
(FPCore (x y z t) :precision binary64 (if (<= x -3.5e-26) (/ (+ x y) (* t 2.0)) (* (- y z) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.5e-26) {
tmp = (x + y) / (t * 2.0);
} 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 <= (-3.5d-26)) then
tmp = (x + y) / (t * 2.0d0)
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 <= -3.5e-26) {
tmp = (x + y) / (t * 2.0);
} else {
tmp = (y - z) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.5e-26: tmp = (x + y) / (t * 2.0) else: tmp = (y - z) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.5e-26) tmp = Float64(Float64(x + y) / Float64(t * 2.0)); 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 <= -3.5e-26) tmp = (x + y) / (t * 2.0); else tmp = (y - z) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.5e-26], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-26}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if x < -3.49999999999999985e-26Initial program 100.0%
Taylor expanded in z around 0 84.4%
+-commutative84.4%
Simplified84.4%
if -3.49999999999999985e-26 < x Initial program 100.0%
Taylor expanded in x around 0 78.1%
*-commutative78.1%
associate-*l/78.5%
associate-*r/78.4%
Simplified78.4%
Final simplification80.2%
(FPCore (x y z t) :precision binary64 (if (<= x -3.6e+107) (/ x (* t 2.0)) (* (- y z) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.6e+107) {
tmp = x / (t * 2.0);
} 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 <= (-3.6d+107)) then
tmp = x / (t * 2.0d0)
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 <= -3.6e+107) {
tmp = x / (t * 2.0);
} else {
tmp = (y - z) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.6e+107: tmp = x / (t * 2.0) else: tmp = (y - z) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.6e+107) tmp = Float64(x / Float64(t * 2.0)); 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 <= -3.6e+107) tmp = x / (t * 2.0); else tmp = (y - z) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.6e+107], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+107}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if x < -3.5999999999999998e107Initial program 100.0%
Taylor expanded in x around inf 71.7%
if -3.5999999999999998e107 < x Initial program 100.0%
Taylor expanded in x around 0 76.0%
*-commutative76.0%
associate-*l/76.4%
associate-*r/76.2%
Simplified76.2%
(FPCore (x y z t) :precision binary64 (* z (/ -0.5 t)))
double code(double x, double y, double z, double t) {
return z * (-0.5 / 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 = z * ((-0.5d0) / t)
end function
public static double code(double x, double y, double z, double t) {
return z * (-0.5 / t);
}
def code(x, y, z, t): return z * (-0.5 / t)
function code(x, y, z, t) return Float64(z * Float64(-0.5 / t)) end
function tmp = code(x, y, z, t) tmp = z * (-0.5 / t); end
code[x_, y_, z_, t_] := N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{-0.5}{t}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 96.2%
distribute-lft-out96.2%
Simplified96.2%
Taylor expanded in z around inf 35.9%
associate-*r/35.9%
*-commutative35.9%
associate-*r/35.9%
Simplified35.9%
herbie shell --seed 2024180
(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)))