
(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 9 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 -2.1e+96) (not (<= z 9.5e+108))) (/ (* z -0.5) t) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.1e+96) || !(z <= 9.5e+108)) {
tmp = (z * -0.5) / 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 <= (-2.1d+96)) .or. (.not. (z <= 9.5d+108))) then
tmp = (z * (-0.5d0)) / 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 <= -2.1e+96) || !(z <= 9.5e+108)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.1e+96) or not (z <= 9.5e+108): tmp = (z * -0.5) / t else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.1e+96) || !(z <= 9.5e+108)) tmp = Float64(Float64(z * -0.5) / 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 <= -2.1e+96) || ~((z <= 9.5e+108))) tmp = (z * -0.5) / t; else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.1e+96], N[Not[LessEqual[z, 9.5e+108]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+96} \lor \neg \left(z \leq 9.5 \cdot 10^{+108}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if z < -2.1000000000000001e96 or 9.50000000000000097e108 < z Initial program 100.0%
Taylor expanded in z around inf 80.8%
*-commutative80.8%
associate-*l/80.8%
Simplified80.8%
if -2.1000000000000001e96 < z < 9.50000000000000097e108Initial program 100.0%
Taylor expanded in z around 0 87.2%
associate-*r/87.2%
associate-*l/86.9%
*-commutative86.9%
+-commutative86.9%
Simplified86.9%
Final simplification84.9%
(FPCore (x y z t) :precision binary64 (if (<= y -1.65e-266) (* 0.5 (/ x t)) (if (<= y 2.7e+42) (/ (* z -0.5) t) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.65e-266) {
tmp = 0.5 * (x / t);
} else if (y <= 2.7e+42) {
tmp = (z * -0.5) / 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 <= (-1.65d-266)) then
tmp = 0.5d0 * (x / t)
else if (y <= 2.7d+42) then
tmp = (z * (-0.5d0)) / 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 <= -1.65e-266) {
tmp = 0.5 * (x / t);
} else if (y <= 2.7e+42) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.65e-266: tmp = 0.5 * (x / t) elif y <= 2.7e+42: tmp = (z * -0.5) / t else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.65e-266) tmp = Float64(0.5 * Float64(x / t)); elseif (y <= 2.7e+42) tmp = Float64(Float64(z * -0.5) / 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 <= -1.65e-266) tmp = 0.5 * (x / t); elseif (y <= 2.7e+42) tmp = (z * -0.5) / t; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.65e-266], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.7e+42], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-266}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+42}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < -1.6500000000000001e-266Initial program 100.0%
Taylor expanded in x around inf 36.4%
if -1.6500000000000001e-266 < y < 2.7000000000000001e42Initial program 100.0%
Taylor expanded in z around inf 55.5%
*-commutative55.5%
associate-*l/55.5%
Simplified55.5%
if 2.7000000000000001e42 < y Initial program 100.0%
Taylor expanded in y around inf 71.0%
associate-*r/71.0%
Simplified71.0%
Final simplification49.2%
(FPCore (x y z t) :precision binary64 (if (<= y 6e-19) (* (/ 0.5 t) (- x z)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6e-19) {
tmp = (0.5 / t) * (x - z);
} 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 <= 6d-19) then
tmp = (0.5d0 / t) * (x - z)
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 <= 6e-19) {
tmp = (0.5 / t) * (x - z);
} else {
tmp = (0.5 * (y - z)) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 6e-19: tmp = (0.5 / t) * (x - z) else: tmp = (0.5 * (y - z)) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 6e-19) tmp = Float64(Float64(0.5 / t) * Float64(x - z)); 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 <= 6e-19) tmp = (0.5 / t) * (x - z); else tmp = (0.5 * (y - z)) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 6e-19], N[(N[(0.5 / t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-19}:\\
\;\;\;\;\frac{0.5}{t} \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if y < 5.99999999999999985e-19Initial program 100.0%
Taylor expanded in y around 0 77.7%
*-commutative77.7%
associate-*l/77.7%
associate-/l*77.4%
Simplified77.4%
if 5.99999999999999985e-19 < y Initial program 100.0%
Taylor expanded in x around 0 78.6%
associate-*r/78.6%
Simplified78.6%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (if (<= y 2.75e+42) (* (/ 0.5 t) (- x z)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.75e+42) {
tmp = (0.5 / t) * (x - z);
} 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 (y <= 2.75d+42) then
tmp = (0.5d0 / t) * (x - z)
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 (y <= 2.75e+42) {
tmp = (0.5 / t) * (x - z);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.75e+42: tmp = (0.5 / t) * (x - z) else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.75e+42) tmp = Float64(Float64(0.5 / t) * Float64(x - z)); 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 (y <= 2.75e+42) tmp = (0.5 / t) * (x - z); else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.75e+42], N[(N[(0.5 / t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.75 \cdot 10^{+42}:\\
\;\;\;\;\frac{0.5}{t} \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 2.75000000000000001e42Initial program 100.0%
Taylor expanded in y around 0 77.6%
*-commutative77.6%
associate-*l/77.6%
associate-/l*77.3%
Simplified77.3%
if 2.75000000000000001e42 < y Initial program 100.0%
Taylor expanded in z around 0 88.4%
associate-*r/88.4%
associate-*l/88.0%
*-commutative88.0%
+-commutative88.0%
Simplified88.0%
Final simplification79.6%
(FPCore (x y z t) :precision binary64 (if (<= y 1.65e-15) (* 0.5 (/ x t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.65e-15) {
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 <= 1.65d-15) 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 <= 1.65e-15) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.65e-15: tmp = 0.5 * (x / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.65e-15) 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 <= 1.65e-15) tmp = 0.5 * (x / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.65e-15], 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 1.65 \cdot 10^{-15}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 1.65e-15Initial program 100.0%
Taylor expanded in x around inf 38.4%
if 1.65e-15 < y Initial program 100.0%
Taylor expanded in y around inf 65.8%
associate-*r/65.8%
Simplified65.8%
Final simplification45.5%
(FPCore (x y z t) :precision binary64 (if (<= y 1.65e-15) (* 0.5 (/ x t)) (* y (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.65e-15) {
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 <= 1.65d-15) 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 <= 1.65e-15) {
tmp = 0.5 * (x / t);
} else {
tmp = y * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.65e-15: tmp = 0.5 * (x / t) else: tmp = y * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.65e-15) 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 (y <= 1.65e-15) tmp = 0.5 * (x / t); else tmp = y * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.65e-15], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-15}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 1.65e-15Initial program 100.0%
Taylor expanded in x around inf 38.4%
if 1.65e-15 < y Initial program 100.0%
clear-num99.6%
inv-pow99.6%
associate--l+99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 65.8%
*-commutative65.8%
associate-*l/65.8%
associate-*r/65.6%
Simplified65.6%
(FPCore (x y z t) :precision binary64 (* (/ 0.5 t) (+ y (- x z))))
double code(double x, double y, double z, double t) {
return (0.5 / t) * (y + (x - z));
}
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 / t) * (y + (x - z))
end function
public static double code(double x, double y, double z, double t) {
return (0.5 / t) * (y + (x - z));
}
def code(x, y, z, t): return (0.5 / t) * (y + (x - z))
function code(x, y, z, t) return Float64(Float64(0.5 / t) * Float64(y + Float64(x - z))) end
function tmp = code(x, y, z, t) tmp = (0.5 / t) * (y + (x - z)); end
code[x_, y_, z_, t_] := N[(N[(0.5 / t), $MachinePrecision] * N[(y + N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{t} \cdot \left(y + \left(x - z\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 94.9%
associate-*r/94.9%
associate-*l/94.8%
associate-*r/94.8%
associate-*l/94.5%
distribute-lft-in99.6%
associate-+r-99.6%
+-commutative99.6%
associate--l+99.6%
Simplified99.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 34.9%
herbie shell --seed 2024106
(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)))