
(FPCore (x y z t a b) :precision binary64 (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
def code(x, y, z, t, a, b): return ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * Float64(t - a))) / Float64(y + Float64(z * Float64(b - y)))) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * (t - a))) / (y + (z * (b - y))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
def code(x, y, z, t, a, b): return ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * Float64(t - a))) / Float64(y + Float64(z * Float64(b - y)))) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * (t - a))) / (y + (z * (b - y))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\end{array}
(FPCore (x y z t a b) :precision binary64 (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
def code(x, y, z, t, a, b): return ((x * y) + (z * (t - a))) / (y + (z * (b - y)))
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * Float64(t - a))) / Float64(y + Float64(z * Float64(b - y)))) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * (t - a))) / (y + (z * (b - y))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\end{array}
Initial program 69.6%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ y (* z (- b y)))) (t_2 (/ (* x y) t_1))) (if (<= y -1.05e-14) t_2 (if (<= y 1.7e+39) (/ (* z (- t a)) t_1) t_2))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y + (z * (b - y));
double t_2 = (x * y) / t_1;
double tmp;
if (y <= -1.05e-14) {
tmp = t_2;
} else if (y <= 1.7e+39) {
tmp = (z * (t - a)) / t_1;
} else {
tmp = t_2;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = y + (z * (b - y))
t_2 = (x * y) / t_1
if (y <= (-1.05d-14)) then
tmp = t_2
else if (y <= 1.7d+39) then
tmp = (z * (t - a)) / t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y + (z * (b - y));
double t_2 = (x * y) / t_1;
double tmp;
if (y <= -1.05e-14) {
tmp = t_2;
} else if (y <= 1.7e+39) {
tmp = (z * (t - a)) / t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = y + (z * (b - y)) t_2 = (x * y) / t_1 tmp = 0 if y <= -1.05e-14: tmp = t_2 elif y <= 1.7e+39: tmp = (z * (t - a)) / t_1 else: tmp = t_2 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(y + Float64(z * Float64(b - y))) t_2 = Float64(Float64(x * y) / t_1) tmp = 0.0 if (y <= -1.05e-14) tmp = t_2; elseif (y <= 1.7e+39) tmp = Float64(Float64(z * Float64(t - a)) / t_1); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = y + (z * (b - y)); t_2 = (x * y) / t_1; tmp = 0.0; if (y <= -1.05e-14) tmp = t_2; elseif (y <= 1.7e+39) tmp = (z * (t - a)) / t_1; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[y, -1.05e-14], t$95$2, If[LessEqual[y, 1.7e+39], N[(N[(z * N[(t - a), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y + z \cdot \left(b - y\right)\\
t_2 := \frac{x \cdot y}{t\_1}\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{-14}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+39}:\\
\;\;\;\;\frac{z \cdot \left(t - a\right)}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if y < -1.0499999999999999e-14 or 1.6999999999999999e39 < y Initial program 51.9%
Taylor expanded in x around 0
Applied rewrites35.6%
if -1.0499999999999999e-14 < y < 1.6999999999999999e39Initial program 82.6%
Taylor expanded in x around 0
Applied rewrites67.8%
(FPCore (x y z t a b) :precision binary64 (/ (* x y) (+ y (* z (- b y)))))
double code(double x, double y, double z, double t, double a, double b) {
return (x * y) / (y + (z * (b - y)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (x * y) / (y + (z * (b - y)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x * y) / (y + (z * (b - y)));
}
def code(x, y, z, t, a, b): return (x * y) / (y + (z * (b - y)))
function code(x, y, z, t, a, b) return Float64(Float64(x * y) / Float64(y + Float64(z * Float64(b - y)))) end
function tmp = code(x, y, z, t, a, b) tmp = (x * y) / (y + (z * (b - y))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * y), $MachinePrecision] / N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{y + z \cdot \left(b - y\right)}
\end{array}
Initial program 69.6%
Taylor expanded in x around 0
Applied rewrites27.9%
(FPCore (x y z t a b) :precision binary64 (* z (- t a)))
double code(double x, double y, double z, double t, double a, double b) {
return z * (t - a);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = z * (t - a)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return z * (t - a);
}
def code(x, y, z, t, a, b): return z * (t - a)
function code(x, y, z, t, a, b) return Float64(z * Float64(t - a)) end
function tmp = code(x, y, z, t, a, b) tmp = z * (t - a); end
code[x_, y_, z_, t_, a_, b_] := N[(z * N[(t - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(t - a\right)
\end{array}
Initial program 69.6%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites5.1%
(FPCore (x y z t a b) :precision binary64 (* x y))
double code(double x, double y, double z, double t, double a, double b) {
return x * y;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * y
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * y;
}
def code(x, y, z, t, a, b): return x * y
function code(x, y, z, t, a, b) return Float64(x * y) end
function tmp = code(x, y, z, t, a, b) tmp = x * y; end
code[x_, y_, z_, t_, a_, b_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 69.6%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites4.0%
(FPCore (x y z t a b) :precision binary64 (- t a))
double code(double x, double y, double z, double t, double a, double b) {
return t - a;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = t - a
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return t - a;
}
def code(x, y, z, t, a, b): return t - a
function code(x, y, z, t, a, b) return Float64(t - a) end
function tmp = code(x, y, z, t, a, b) tmp = t - a; end
code[x_, y_, z_, t_, a_, b_] := N[(t - a), $MachinePrecision]
\begin{array}{l}
\\
t - a
\end{array}
Initial program 69.6%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around -inf
Applied rewrites3.3%
(FPCore (x y z t a b) :precision binary64 (- (/ (+ (* z t) (* y x)) (+ y (* z (- b y)))) (/ a (+ (- b y) (/ y z)))))
double code(double x, double y, double z, double t, double a, double b) {
return (((z * t) + (y * x)) / (y + (z * (b - y)))) - (a / ((b - y) + (y / z)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (((z * t) + (y * x)) / (y + (z * (b - y)))) - (a / ((b - y) + (y / z)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (((z * t) + (y * x)) / (y + (z * (b - y)))) - (a / ((b - y) + (y / z)));
}
def code(x, y, z, t, a, b): return (((z * t) + (y * x)) / (y + (z * (b - y)))) - (a / ((b - y) + (y / z)))
function code(x, y, z, t, a, b) return Float64(Float64(Float64(Float64(z * t) + Float64(y * x)) / Float64(y + Float64(z * Float64(b - y)))) - Float64(a / Float64(Float64(b - y) + Float64(y / z)))) end
function tmp = code(x, y, z, t, a, b) tmp = (((z * t) + (y * x)) / (y + (z * (b - y)))) - (a / ((b - y) + (y / z))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(z * t), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] / N[(y + N[(z * N[(b - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[(b - y), $MachinePrecision] + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{z \cdot t + y \cdot x}{y + z \cdot \left(b - y\right)} - \frac{a}{\left(b - y\right) + \frac{y}{z}}
\end{array}
herbie shell --seed 2024321
(FPCore (x y z t a b)
:name "Development.Shake.Progress:decay from shake-0.15.5"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- (/ (+ (* z t) (* y x)) (+ y (* z (- b y)))) (/ a (+ (- b y) (/ y z)))))
(/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))