
(FPCore (x y z t) :precision binary64 (+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))
double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * 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 = (x / y) + ((2.0d0 + ((z * 2.0d0) * (1.0d0 - t))) / (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
def code(x, y, z, t): return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z))
function code(x, y, z, t) return Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(z * 2.0) * Float64(1.0 - t))) / Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(z * 2.0), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))
double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * 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 = (x / y) + ((2.0d0 + ((z * 2.0d0) * (1.0d0 - t))) / (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
def code(x, y, z, t): return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z))
function code(x, y, z, t) return Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(z * 2.0) * Float64(1.0 - t))) / Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(z * 2.0), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= (+ (/ (+ (* (- 1.0 t) (* z 2.0)) 2.0) (* t z)) (/ x y)) INFINITY) (+ (/ (fma (fma -2.0 t 2.0) z 2.0) (* t z)) (/ x y)) (+ -2.0 (/ x y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((((((1.0 - t) * (z * 2.0)) + 2.0) / (t * z)) + (x / y)) <= ((double) INFINITY)) {
tmp = (fma(fma(-2.0, t, 2.0), z, 2.0) / (t * z)) + (x / y);
} else {
tmp = -2.0 + (x / y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(Float64(Float64(1.0 - t) * Float64(z * 2.0)) + 2.0) / Float64(t * z)) + Float64(x / y)) <= Inf) tmp = Float64(Float64(fma(fma(-2.0, t, 2.0), z, 2.0) / Float64(t * z)) + Float64(x / y)); else tmp = Float64(-2.0 + Float64(x / y)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(N[(N[(N[(1.0 - t), $MachinePrecision] * N[(z * 2.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision] + N[(x / y), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(N[(-2.0 * t + 2.0), $MachinePrecision] * z + 2.0), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision] + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(-2.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 - t\right) \cdot \left(z \cdot 2\right) + 2}{t \cdot z} + \frac{x}{y} \leq \infty:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(-2, t, 2\right), z, 2\right)}{t \cdot z} + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;-2 + \frac{x}{y}\\
\end{array}
\end{array}
if (+.f64 (/.f64 x y) (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z))) < +inf.0Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
if +inf.0 < (+.f64 (/.f64 x y) (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z))) Initial program 0.0%
Taylor expanded in t around inf
Applied rewrites100.0%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (+ (* (- 1.0 t) (* z 2.0)) 2.0) (* t z)))
(t_2 (+ -2.0 (/ x y))))
(if (<= t_1 -5e+306)
(/ (/ 2.0 t) z)
(if (<= t_1 -1e+118)
(- (/ 2.0 t) 2.0)
(if (<= t_1 1e+126) t_2 (if (<= t_1 INFINITY) (/ (/ 2.0 z) t) t_2))))))
double code(double x, double y, double z, double t) {
double t_1 = (((1.0 - t) * (z * 2.0)) + 2.0) / (t * z);
double t_2 = -2.0 + (x / y);
double tmp;
if (t_1 <= -5e+306) {
tmp = (2.0 / t) / z;
} else if (t_1 <= -1e+118) {
tmp = (2.0 / t) - 2.0;
} else if (t_1 <= 1e+126) {
tmp = t_2;
} else if (t_1 <= ((double) INFINITY)) {
tmp = (2.0 / z) / t;
} else {
tmp = t_2;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (((1.0 - t) * (z * 2.0)) + 2.0) / (t * z);
double t_2 = -2.0 + (x / y);
double tmp;
if (t_1 <= -5e+306) {
tmp = (2.0 / t) / z;
} else if (t_1 <= -1e+118) {
tmp = (2.0 / t) - 2.0;
} else if (t_1 <= 1e+126) {
tmp = t_2;
} else if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = (2.0 / z) / t;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = (((1.0 - t) * (z * 2.0)) + 2.0) / (t * z) t_2 = -2.0 + (x / y) tmp = 0 if t_1 <= -5e+306: tmp = (2.0 / t) / z elif t_1 <= -1e+118: tmp = (2.0 / t) - 2.0 elif t_1 <= 1e+126: tmp = t_2 elif t_1 <= math.inf: tmp = (2.0 / z) / t else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(Float64(Float64(1.0 - t) * Float64(z * 2.0)) + 2.0) / Float64(t * z)) t_2 = Float64(-2.0 + Float64(x / y)) tmp = 0.0 if (t_1 <= -5e+306) tmp = Float64(Float64(2.0 / t) / z); elseif (t_1 <= -1e+118) tmp = Float64(Float64(2.0 / t) - 2.0); elseif (t_1 <= 1e+126) tmp = t_2; elseif (t_1 <= Inf) tmp = Float64(Float64(2.0 / z) / t); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (((1.0 - t) * (z * 2.0)) + 2.0) / (t * z); t_2 = -2.0 + (x / y); tmp = 0.0; if (t_1 <= -5e+306) tmp = (2.0 / t) / z; elseif (t_1 <= -1e+118) tmp = (2.0 / t) - 2.0; elseif (t_1 <= 1e+126) tmp = t_2; elseif (t_1 <= Inf) tmp = (2.0 / z) / t; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[(1.0 - t), $MachinePrecision] * N[(z * 2.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+306], N[(N[(2.0 / t), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$1, -1e+118], N[(N[(2.0 / t), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[t$95$1, 1e+126], t$95$2, If[LessEqual[t$95$1, Infinity], N[(N[(2.0 / z), $MachinePrecision] / t), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\left(1 - t\right) \cdot \left(z \cdot 2\right) + 2}{t \cdot z}\\
t_2 := -2 + \frac{x}{y}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+306}:\\
\;\;\;\;\frac{\frac{2}{t}}{z}\\
\mathbf{elif}\;t\_1 \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\frac{2}{t} - 2\\
\mathbf{elif}\;t\_1 \leq 10^{+126}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{\frac{2}{z}}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z)) < -4.99999999999999993e306Initial program 95.1%
Taylor expanded in z around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
Applied rewrites96.1%
if -4.99999999999999993e306 < (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z)) < -9.99999999999999967e117Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites78.1%
Taylor expanded in z around inf
Applied rewrites38.9%
if -9.99999999999999967e117 < (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z)) < 9.99999999999999925e125 or +inf.0 < (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z)) Initial program 77.9%
Taylor expanded in t around inf
Applied rewrites79.3%
if 9.99999999999999925e125 < (/.f64 (+.f64 #s(literal 2 binary64) (*.f64 (*.f64 z #s(literal 2 binary64)) (-.f64 #s(literal 1 binary64) t))) (*.f64 t z)) < +inf.0Initial program 98.0%
Taylor expanded in z around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6456.4
Applied rewrites56.4%
Applied rewrites56.5%
Final simplification69.3%
(FPCore (x y z t) :precision binary64 (- (/ (+ (/ 2.0 z) 2.0) t) (- 2.0 (/ x y))))
double code(double x, double y, double z, double t) {
return (((2.0 / z) + 2.0) / t) - (2.0 - (x / y));
}
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 = (((2.0d0 / z) + 2.0d0) / t) - (2.0d0 - (x / y))
end function
public static double code(double x, double y, double z, double t) {
return (((2.0 / z) + 2.0) / t) - (2.0 - (x / y));
}
def code(x, y, z, t): return (((2.0 / z) + 2.0) / t) - (2.0 - (x / y))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(2.0 / z) + 2.0) / t) - Float64(2.0 - Float64(x / y))) end
function tmp = code(x, y, z, t) tmp = (((2.0 / z) + 2.0) / t) - (2.0 - (x / y)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(2.0 / z), $MachinePrecision] + 2.0), $MachinePrecision] / t), $MachinePrecision] - N[(2.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{z} + 2}{t} - \left(2 - \frac{x}{y}\right)
\end{array}
herbie shell --seed 2024230
(FPCore (x y z t)
:name "Data.HashTable.ST.Basic:computeOverhead from hashtables-1.2.0.2"
:precision binary64
:alt
(! :herbie-platform default (- (/ (+ (/ 2 z) 2) t) (- 2 (/ x y))))
(+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))