
(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 18 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
(let* ((t_1 (+ (/ (- t a) (- b y)) (/ (* (/ y (- b y)) x) z))))
(if (<= z -3400000000000.0)
t_1
(if (<= z 13500.0)
(/ (+ (* (- t a) z) (* y x)) (+ (* (- b y) z) y))
t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((t - a) / (b - y)) + (((y / (b - y)) * x) / z);
double tmp;
if (z <= -3400000000000.0) {
tmp = t_1;
} else if (z <= 13500.0) {
tmp = (((t - a) * z) + (y * x)) / (((b - y) * z) + y);
} else {
tmp = t_1;
}
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) :: tmp
t_1 = ((t - a) / (b - y)) + (((y / (b - y)) * x) / z)
if (z <= (-3400000000000.0d0)) then
tmp = t_1
else if (z <= 13500.0d0) then
tmp = (((t - a) * z) + (y * x)) / (((b - y) * z) + y)
else
tmp = t_1
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 = ((t - a) / (b - y)) + (((y / (b - y)) * x) / z);
double tmp;
if (z <= -3400000000000.0) {
tmp = t_1;
} else if (z <= 13500.0) {
tmp = (((t - a) * z) + (y * x)) / (((b - y) * z) + y);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = ((t - a) / (b - y)) + (((y / (b - y)) * x) / z) tmp = 0 if z <= -3400000000000.0: tmp = t_1 elif z <= 13500.0: tmp = (((t - a) * z) + (y * x)) / (((b - y) * z) + y) else: tmp = t_1 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(t - a) / Float64(b - y)) + Float64(Float64(Float64(y / Float64(b - y)) * x) / z)) tmp = 0.0 if (z <= -3400000000000.0) tmp = t_1; elseif (z <= 13500.0) tmp = Float64(Float64(Float64(Float64(t - a) * z) + Float64(y * x)) / Float64(Float64(Float64(b - y) * z) + y)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = ((t - a) / (b - y)) + (((y / (b - y)) * x) / z); tmp = 0.0; if (z <= -3400000000000.0) tmp = t_1; elseif (z <= 13500.0) tmp = (((t - a) * z) + (y * x)) / (((b - y) * z) + y); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(t - a), $MachinePrecision] / N[(b - y), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y / N[(b - y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3400000000000.0], t$95$1, If[LessEqual[z, 13500.0], N[(N[(N[(N[(t - a), $MachinePrecision] * z), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(b - y), $MachinePrecision] * z), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{t - a}{b - y} + \frac{\frac{y}{b - y} \cdot x}{z}\\
\mathbf{if}\;z \leq -3400000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 13500:\\
\;\;\;\;\frac{\left(t - a\right) \cdot z + y \cdot x}{\left(b - y\right) \cdot z + y}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.4e12 or 13500 < z Initial program 47.2%
Taylor expanded in y around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6418.0
Applied rewrites18.0%
Taylor expanded in z around -inf
associate--l+N/A
div-subN/A
lower-+.f64N/A
Applied rewrites91.5%
Taylor expanded in x around inf
Applied rewrites99.8%
if -3.4e12 < z < 13500Initial program 82.3%
Final simplification91.0%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ (fma t z (* y x)) (fma (- b y) z y)))
(t_2 (/ (- t a) (- b y))))
(if (<= z -3.4e+20)
(+ (/ (- x) z) t_2)
(if (<= z -4.2e-69)
t_1
(if (<= z 5.5e-154)
(fma (- (+ (/ t y) x) (/ a y)) z x)
(if (<= z 12000000000000.0) t_1 t_2))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, z, (y * x)) / fma((b - y), z, y);
double t_2 = (t - a) / (b - y);
double tmp;
if (z <= -3.4e+20) {
tmp = (-x / z) + t_2;
} else if (z <= -4.2e-69) {
tmp = t_1;
} else if (z <= 5.5e-154) {
tmp = fma((((t / y) + x) - (a / y)), z, x);
} else if (z <= 12000000000000.0) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(fma(t, z, Float64(y * x)) / fma(Float64(b - y), z, y)) t_2 = Float64(Float64(t - a) / Float64(b - y)) tmp = 0.0 if (z <= -3.4e+20) tmp = Float64(Float64(Float64(-x) / z) + t_2); elseif (z <= -4.2e-69) tmp = t_1; elseif (z <= 5.5e-154) tmp = fma(Float64(Float64(Float64(t / y) + x) - Float64(a / y)), z, x); elseif (z <= 12000000000000.0) tmp = t_1; else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision] / N[(N[(b - y), $MachinePrecision] * z + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t - a), $MachinePrecision] / N[(b - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.4e+20], N[(N[((-x) / z), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[z, -4.2e-69], t$95$1, If[LessEqual[z, 5.5e-154], N[(N[(N[(N[(t / y), $MachinePrecision] + x), $MachinePrecision] - N[(a / y), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[z, 12000000000000.0], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\mathsf{fma}\left(t, z, y \cdot x\right)}{\mathsf{fma}\left(b - y, z, y\right)}\\
t_2 := \frac{t - a}{b - y}\\
\mathbf{if}\;z \leq -3.4 \cdot 10^{+20}:\\
\;\;\;\;\frac{-x}{z} + t\_2\\
\mathbf{elif}\;z \leq -4.2 \cdot 10^{-69}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-154}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{t}{y} + x\right) - \frac{a}{y}, z, x\right)\\
\mathbf{elif}\;z \leq 12000000000000:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if z < -3.4e20Initial program 41.8%
Taylor expanded in y around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6418.7
Applied rewrites18.7%
Taylor expanded in z around -inf
associate--l+N/A
div-subN/A
lower-+.f64N/A
Applied rewrites88.9%
Taylor expanded in y around inf
Applied rewrites85.8%
if -3.4e20 < z < -4.1999999999999999e-69 or 5.50000000000000002e-154 < z < 1.2e13Initial program 86.6%
Taylor expanded in a around 0
lower-/.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6458.9
Applied rewrites58.9%
if -4.1999999999999999e-69 < z < 5.50000000000000002e-154Initial program 86.5%
Taylor expanded in b around 0
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6465.3
Applied rewrites65.3%
Taylor expanded in z around 0
Applied rewrites69.2%
if 1.2e13 < z Initial program 44.8%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f64N/A
lower--.f6481.3
Applied rewrites81.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 2024230
(FPCore (x y z t a b)
:name "Development.Shake.Progress:decay from shake-0.15.5"
:precision binary64
: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)))))