\[\frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
↓
\[\begin{array}{l}
t_1 := \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, x, z\right), 27464.7644705\right), 230661.510616\right), t\right)\\
t_2 := \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(y + a, y, b\right), y, c\right), y, i\right)}\\
t_3 := \frac{t + y \cdot \left(230661.510616 + y \cdot \left(27464.7644705 + y \cdot \left(z + x \cdot y\right)\right)\right)}{i + y \cdot \left(c + y \cdot \left(y \cdot \left(y + a\right) + b\right)\right)}\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{-288}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\frac{1}{\frac{i}{t_1} + \left(\frac{c}{\frac{t_1}{y}} + \frac{y \cdot y}{\frac{t_1}{\mathsf{fma}\left(y, y + a, b\right)}}\right)}\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+304}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\left(x + \frac{z}{y}\right) - \frac{x \cdot a}{y}\\
\end{array}
\]
(FPCore (x y z t a b c i)
:precision binary64
(/
(+ (* (+ (* (+ (* (+ (* x y) z) y) 27464.7644705) y) 230661.510616) y) t)
(+ (* (+ (* (+ (* (+ y a) y) b) y) c) y) i)))
↓
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma y (fma y (fma y (fma y x z) 27464.7644705) 230661.510616) t))
(t_2
(/
(fma (fma (fma (fma x y z) y 27464.7644705) y 230661.510616) y t)
(fma (fma (fma (+ y a) y b) y c) y i)))
(t_3
(/
(+
t
(* y (+ 230661.510616 (* y (+ 27464.7644705 (* y (+ z (* x y))))))))
(+ i (* y (+ c (* y (+ (* y (+ y a)) b))))))))
(if (<= t_3 -2e-288)
t_2
(if (<= t_3 0.0)
(/
1.0
(+
(/ i t_1)
(+ (/ c (/ t_1 y)) (/ (* y y) (/ t_1 (fma y (+ y a) b))))))
(if (<= t_3 2e+304) t_2 (- (+ x (/ z y)) (/ (* x a) y)))))))
\frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
↓
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, x, z\right), 27464.7644705\right), 230661.510616\right), t\right)\\
t_2 := \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(y + a, y, b\right), y, c\right), y, i\right)}\\
t_3 := \frac{t + y \cdot \left(230661.510616 + y \cdot \left(27464.7644705 + y \cdot \left(z + x \cdot y\right)\right)\right)}{i + y \cdot \left(c + y \cdot \left(y \cdot \left(y + a\right) + b\right)\right)}\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{-288}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\frac{1}{\frac{i}{t_1} + \left(\frac{c}{\frac{t_1}{y}} + \frac{y \cdot y}{\frac{t_1}{\mathsf{fma}\left(y, y + a, b\right)}}\right)}\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+304}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\left(x + \frac{z}{y}\right) - \frac{x \cdot a}{y}\\
\end{array}
The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 18 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
if (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) 54929528941/2000000) y) 28832688827/125000) y) t) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 y a) y) b) y) c) y) i)) < -2.00000000000000012e-288 or 0.0 < (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) 54929528941/2000000) y) 28832688827/125000) y) t) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 y a) y) b) y) c) y) i)) < 1.9999999999999999e304
Initial program 96.8%
\[\frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
Simplified96.8%
\[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(y + a, y, b\right), y, c\right), y, i\right)}}
\]
Step-by-step derivation
[Start]96.8%
\[ \frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
fma-def [=>]96.8%
\[ \frac{\color{blue}{\mathsf{fma}\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616, y, t\right)}}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705, y, 230661.510616\right)}, y, t\right)}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x \cdot y + z, y, 27464.7644705\right)}, y, 230661.510616\right), y, t\right)}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\color{blue}{\mathsf{fma}\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c, y, i\right)}}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\left(y + a\right) \cdot y + b, y, c\right)}, y, i\right)}
\]
fma-def [=>]96.8%
\[ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, 27464.7644705\right), y, 230661.510616\right), y, t\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(y + a, y, b\right)}, y, c\right), y, i\right)}
\]
if -2.00000000000000012e-288 < (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) 54929528941/2000000) y) 28832688827/125000) y) t) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 y a) y) b) y) c) y) i)) < 0.0
Initial program 40.3%
\[\frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
Applied egg-rr40.3%
\[\leadsto \color{blue}{{\left(\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, y + a, b\right), c\right), i\right)}{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, y, z\right), 27464.7644705\right), 230661.510616\right), t\right)}\right)}^{-1}}
\]
Step-by-step derivation
[Start]40.3%
\[ \frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
clear-num [=>]40.3%
\[ \color{blue}{\frac{1}{\frac{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}}}
\]
inv-pow [=>]40.3%
\[ \color{blue}{{\left(\frac{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}\right)}^{-1}}
\]
Simplified40.3%
\[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, y + a, b\right), c\right), i\right)}{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, x, z\right), 27464.7644705\right), 230661.510616\right), t\right)}}}
\]
Step-by-step derivation
[Start]40.3%
\[ {\left(\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, y + a, b\right), c\right), i\right)}{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, y, z\right), 27464.7644705\right), 230661.510616\right), t\right)}\right)}^{-1}
\]
unpow-1 [=>]40.3%
\[ \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, y + a, b\right), c\right), i\right)}{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, y, z\right), 27464.7644705\right), 230661.510616\right), t\right)}}}
\]
fma-udef [=>]40.3%
\[ \frac{1}{\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, y + a, b\right), c\right), i\right)}{\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, \color{blue}{x \cdot y + z}, 27464.7644705\right), 230661.510616\right), t\right)}}
\]
if 1.9999999999999999e304 < (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) 54929528941/2000000) y) 28832688827/125000) y) t) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 y a) y) b) y) c) y) i))
Initial program 1.3%
\[\frac{\left(\left(\left(x \cdot y + z\right) \cdot y + 27464.7644705\right) \cdot y + 230661.510616\right) \cdot y + t}{\left(\left(\left(y + a\right) \cdot y + b\right) \cdot y + c\right) \cdot y + i}
\]
herbie shell --seed 2023272
(FPCore (x y z t a b c i)
:name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2"
:precision binary64
(/ (+ (* (+ (* (+ (* (+ (* x y) z) y) 27464.7644705) y) 230661.510616) y) t) (+ (* (+ (* (+ (* (+ y a) y) b) y) c) y) i)))