
(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 -8.4e+157) (not (<= z 4.7e+119))) (/ (* z -0.5) t) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.4e+157) || !(z <= 4.7e+119)) {
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 <= (-8.4d+157)) .or. (.not. (z <= 4.7d+119))) 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 <= -8.4e+157) || !(z <= 4.7e+119)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8.4e+157) or not (z <= 4.7e+119): 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 <= -8.4e+157) || !(z <= 4.7e+119)) 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 <= -8.4e+157) || ~((z <= 4.7e+119))) 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, -8.4e+157], N[Not[LessEqual[z, 4.7e+119]], $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 -8.4 \cdot 10^{+157} \lor \neg \left(z \leq 4.7 \cdot 10^{+119}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -8.4e157 or 4.70000000000000008e119 < z Initial program 100.0%
Taylor expanded in z around inf 76.4%
associate-*r/76.4%
Simplified76.4%
if -8.4e157 < z < 4.70000000000000008e119Initial program 100.0%
Taylor expanded in z around 0 86.7%
+-commutative86.7%
Simplified86.7%
Final simplification84.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.4e+158) (not (<= z 1.7e+119))) (/ (* z -0.5) t) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.4e+158) || !(z <= 1.7e+119)) {
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 <= (-1.4d+158)) .or. (.not. (z <= 1.7d+119))) 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 <= -1.4e+158) || !(z <= 1.7e+119)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.4e+158) or not (z <= 1.7e+119): 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 <= -1.4e+158) || !(z <= 1.7e+119)) 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 <= -1.4e+158) || ~((z <= 1.7e+119))) 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, -1.4e+158], N[Not[LessEqual[z, 1.7e+119]], $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 -1.4 \cdot 10^{+158} \lor \neg \left(z \leq 1.7 \cdot 10^{+119}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if z < -1.40000000000000001e158 or 1.70000000000000007e119 < z Initial program 100.0%
Taylor expanded in z around inf 76.4%
associate-*r/76.4%
Simplified76.4%
if -1.40000000000000001e158 < z < 1.70000000000000007e119Initial program 100.0%
Taylor expanded in z around 0 86.7%
+-commutative86.7%
Simplified86.7%
clear-num86.5%
associate-/r/86.5%
*-commutative86.5%
associate-/r*86.5%
metadata-eval86.5%
Applied egg-rr86.5%
Final simplification84.3%
(FPCore (x y z t) :precision binary64 (if (<= x -2.8e+90) (* 0.5 (/ x t)) (if (<= x -8.5e-62) (/ (* z -0.5) t) (* 0.5 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.8e+90) {
tmp = 0.5 * (x / t);
} else if (x <= -8.5e-62) {
tmp = (z * -0.5) / t;
} else {
tmp = 0.5 * (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 (x <= (-2.8d+90)) then
tmp = 0.5d0 * (x / t)
else if (x <= (-8.5d-62)) then
tmp = (z * (-0.5d0)) / t
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.8e+90) {
tmp = 0.5 * (x / t);
} else if (x <= -8.5e-62) {
tmp = (z * -0.5) / t;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -2.8e+90: tmp = 0.5 * (x / t) elif x <= -8.5e-62: tmp = (z * -0.5) / t else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -2.8e+90) tmp = Float64(0.5 * Float64(x / t)); elseif (x <= -8.5e-62) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -2.8e+90) tmp = 0.5 * (x / t); elseif (x <= -8.5e-62) tmp = (z * -0.5) / t; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -2.8e+90], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -8.5e-62], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+90}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-62}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -2.8e90Initial program 100.0%
Taylor expanded in x around inf 79.8%
if -2.8e90 < x < -8.4999999999999995e-62Initial program 100.0%
Taylor expanded in z around inf 37.8%
associate-*r/37.8%
Simplified37.8%
if -8.4999999999999995e-62 < x Initial program 100.0%
Taylor expanded in y around inf 40.6%
Final simplification46.9%
(FPCore (x y z t) :precision binary64 (if (<= x -0.084) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.084) {
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 <= (-0.084d0)) 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 <= -0.084) {
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 <= -0.084: 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 <= -0.084) 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 <= -0.084) 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, -0.084], 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 -0.084:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if x < -0.0840000000000000052Initial program 100.0%
Taylor expanded in x around inf 83.5%
if -0.0840000000000000052 < x Initial program 100.0%
Taylor expanded in x around 0 71.4%
(FPCore (x y z t) :precision binary64 (if (<= y 7e-33) (/ (- x z) (* t 2.0)) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7e-33) {
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 <= 7d-33) 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 <= 7e-33) {
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 <= 7e-33: 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 <= 7e-33) 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 <= 7e-33) 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, 7e-33], 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 7 \cdot 10^{-33}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if y < 6.9999999999999997e-33Initial program 100.0%
Taylor expanded in x around inf 76.2%
if 6.9999999999999997e-33 < y Initial program 100.0%
Taylor expanded in z around 0 74.6%
+-commutative74.6%
Simplified74.6%
Final simplification75.8%
(FPCore (x y z t) :precision binary64 (if (<= x -0.082) (* 0.5 (/ x t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.082) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (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 (x <= (-0.082d0)) then
tmp = 0.5d0 * (x / t)
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.082) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -0.082: tmp = 0.5 * (x / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -0.082) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -0.082) tmp = 0.5 * (x / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.082], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.082:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -0.0820000000000000034Initial program 100.0%
Taylor expanded in x around inf 65.9%
if -0.0820000000000000034 < x Initial program 100.0%
Taylor expanded in y around inf 41.6%
(FPCore (x y z t) :precision binary64 (* (/ 0.5 t) (+ x (- y z))))
double code(double x, double y, double z, double t) {
return (0.5 / t) * (x + (y - 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) * (x + (y - z))
end function
public static double code(double x, double y, double z, double t) {
return (0.5 / t) * (x + (y - z));
}
def code(x, y, z, t): return (0.5 / t) * (x + (y - z))
function code(x, y, z, t) return Float64(Float64(0.5 / t) * Float64(x + Float64(y - z))) end
function tmp = code(x, y, z, t) tmp = (0.5 / t) * (x + (y - z)); end
code[x_, y_, z_, t_] := N[(N[(0.5 / t), $MachinePrecision] * N[(x + N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{t} \cdot \left(x + \left(y - z\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 98.4%
associate-*r/98.4%
associate-*l/98.3%
associate-*r/98.3%
associate-*l/98.2%
distribute-lft-in99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.7%
(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 43.1%
herbie shell --seed 2024110
(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)))