| Alternative 1 | |
|---|---|
| Error | 7.15% |
| Cost | 6608 |
(FPCore (x y z t a b c) :precision binary64 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
(FPCore (x y z t a b c)
:precision binary64
(let* ((t_1 (/ (+ (+ (* (* x 9.0) y) (* a (* t (* z -4.0)))) b) (* z c)))
(t_2
(+
(/ (/ b c) z)
(+ (/ x (/ (* z c) (* 9.0 y))) (* (/ a (/ c t)) -4.0))))
(t_3 (* x (* 9.0 y))))
(if (<= t_1 -5e+298)
t_2
(if (<= t_1 -2e+56)
(/ (+ (fma t (* z (* a -4.0)) b) t_3) (* z c))
(if (<= t_1 2000000000.0)
(/ (+ (* a (* t -4.0)) (/ (+ b t_3) z)) c)
(if (<= t_1 4e+303) t_1 t_2))))))double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = ((((x * 9.0) * y) + (a * (t * (z * -4.0)))) + b) / (z * c);
double t_2 = ((b / c) / z) + ((x / ((z * c) / (9.0 * y))) + ((a / (c / t)) * -4.0));
double t_3 = x * (9.0 * y);
double tmp;
if (t_1 <= -5e+298) {
tmp = t_2;
} else if (t_1 <= -2e+56) {
tmp = (fma(t, (z * (a * -4.0)), b) + t_3) / (z * c);
} else if (t_1 <= 2000000000.0) {
tmp = ((a * (t * -4.0)) + ((b + t_3) / z)) / c;
} else if (t_1 <= 4e+303) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) end
function code(x, y, z, t, a, b, c) t_1 = Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) + Float64(a * Float64(t * Float64(z * -4.0)))) + b) / Float64(z * c)) t_2 = Float64(Float64(Float64(b / c) / z) + Float64(Float64(x / Float64(Float64(z * c) / Float64(9.0 * y))) + Float64(Float64(a / Float64(c / t)) * -4.0))) t_3 = Float64(x * Float64(9.0 * y)) tmp = 0.0 if (t_1 <= -5e+298) tmp = t_2; elseif (t_1 <= -2e+56) tmp = Float64(Float64(fma(t, Float64(z * Float64(a * -4.0)), b) + t_3) / Float64(z * c)); elseif (t_1 <= 2000000000.0) tmp = Float64(Float64(Float64(a * Float64(t * -4.0)) + Float64(Float64(b + t_3) / z)) / c); elseif (t_1 <= 4e+303) tmp = t_1; else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] + N[(a * N[(t * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(b / c), $MachinePrecision] / z), $MachinePrecision] + N[(N[(x / N[(N[(z * c), $MachinePrecision] / N[(9.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[(c / t), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x * N[(9.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+298], t$95$2, If[LessEqual[t$95$1, -2e+56], N[(N[(N[(t * N[(z * N[(a * -4.0), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] + t$95$3), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2000000000.0], N[(N[(N[(a * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b + t$95$3), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[t$95$1, 4e+303], t$95$1, t$95$2]]]]]]]
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\begin{array}{l}
t_1 := \frac{\left(\left(x \cdot 9\right) \cdot y + a \cdot \left(t \cdot \left(z \cdot -4\right)\right)\right) + b}{z \cdot c}\\
t_2 := \frac{\frac{b}{c}}{z} + \left(\frac{x}{\frac{z \cdot c}{9 \cdot y}} + \frac{a}{\frac{c}{t}} \cdot -4\right)\\
t_3 := x \cdot \left(9 \cdot y\right)\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+298}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{+56}:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, z \cdot \left(a \cdot -4\right), b\right) + t_3}{z \cdot c}\\
\mathbf{elif}\;t_1 \leq 2000000000:\\
\;\;\;\;\frac{a \cdot \left(t \cdot -4\right) + \frac{b + t_3}{z}}{c}\\
\mathbf{elif}\;t_1 \leq 4 \cdot 10^{+303}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
| Original | 31.84% |
|---|---|
| Target | 21.7% |
| Herbie | 8.68% |
if (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -5.0000000000000003e298 or 4e303 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) Initial program 96.52
Simplified82.1
[Start]96.52 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-*l* [=>]96.42 | \[ \frac{\left(\color{blue}{x \cdot \left(9 \cdot y\right)} - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
associate-*l* [=>]82.1 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \color{blue}{\left(z \cdot 4\right) \cdot \left(t \cdot a\right)}\right) + b}{z \cdot c}
\] |
Taylor expanded in x around 0 44.08
Simplified24.31
[Start]44.08 | \[ \left(\frac{b}{c \cdot z} + 9 \cdot \frac{y \cdot x}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}
\] |
|---|---|
associate--l+ [=>]44.08 | \[ \color{blue}{\frac{b}{c \cdot z} + \left(9 \cdot \frac{y \cdot x}{c \cdot z} - 4 \cdot \frac{a \cdot t}{c}\right)}
\] |
associate-/r* [=>]46.19 | \[ \color{blue}{\frac{\frac{b}{c}}{z}} + \left(9 \cdot \frac{y \cdot x}{c \cdot z} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
*-commutative [<=]46.19 | \[ \frac{\frac{b}{c}}{z} + \left(9 \cdot \frac{y \cdot x}{\color{blue}{z \cdot c}} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
associate-*r/ [=>]46.34 | \[ \frac{\frac{b}{c}}{z} + \left(\color{blue}{\frac{9 \cdot \left(y \cdot x\right)}{z \cdot c}} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
associate-*r* [=>]46.43 | \[ \frac{\frac{b}{c}}{z} + \left(\frac{\color{blue}{\left(9 \cdot y\right) \cdot x}}{z \cdot c} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
*-commutative [<=]46.43 | \[ \frac{\frac{b}{c}}{z} + \left(\frac{\color{blue}{x \cdot \left(9 \cdot y\right)}}{z \cdot c} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
associate-/l* [=>]31.56 | \[ \frac{\frac{b}{c}}{z} + \left(\color{blue}{\frac{x}{\frac{z \cdot c}{9 \cdot y}}} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
associate-/l* [=>]24.31 | \[ \frac{\frac{b}{c}}{z} + \left(\frac{x}{\frac{z \cdot c}{9 \cdot y}} - 4 \cdot \color{blue}{\frac{a}{\frac{c}{t}}}\right)
\] |
if -5.0000000000000003e298 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -2.00000000000000018e56Initial program 0.9
Simplified8.21
[Start]0.9 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-+l- [=>]0.9 | \[ \frac{\color{blue}{\left(x \cdot 9\right) \cdot y - \left(\left(\left(z \cdot 4\right) \cdot t\right) \cdot a - b\right)}}{z \cdot c}
\] |
associate-*l* [=>]1.03 | \[ \frac{\color{blue}{x \cdot \left(9 \cdot y\right)} - \left(\left(\left(z \cdot 4\right) \cdot t\right) \cdot a - b\right)}{z \cdot c}
\] |
fma-neg [=>]1.03 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, 9 \cdot y, -\left(\left(\left(z \cdot 4\right) \cdot t\right) \cdot a - b\right)\right)}}{z \cdot c}
\] |
neg-sub0 [=>]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{0 - \left(\left(\left(z \cdot 4\right) \cdot t\right) \cdot a - b\right)}\right)}{z \cdot c}
\] |
associate-+l- [<=]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{\left(0 - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}\right)}{z \cdot c}
\] |
neg-sub0 [<=]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{\left(-\left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right)} + b\right)}{z \cdot c}
\] |
distribute-lft-neg-in [=>]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{\left(-\left(z \cdot 4\right) \cdot t\right) \cdot a} + b\right)}{z \cdot c}
\] |
*-commutative [=>]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{a \cdot \left(-\left(z \cdot 4\right) \cdot t\right)} + b\right)}{z \cdot c}
\] |
distribute-lft-neg-in [=>]1.03 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, a \cdot \color{blue}{\left(\left(-z \cdot 4\right) \cdot t\right)} + b\right)}{z \cdot c}
\] |
associate-*r* [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{\left(a \cdot \left(-z \cdot 4\right)\right) \cdot t} + b\right)}{z \cdot c}
\] |
*-commutative [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{t \cdot \left(a \cdot \left(-z \cdot 4\right)\right)} + b\right)}{z \cdot c}
\] |
fma-def [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \color{blue}{\mathsf{fma}\left(t, a \cdot \left(-z \cdot 4\right), b\right)}\right)}{z \cdot c}
\] |
distribute-rgt-neg-in [<=]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \mathsf{fma}\left(t, \color{blue}{-a \cdot \left(z \cdot 4\right)}, b\right)\right)}{z \cdot c}
\] |
associate-*r* [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \mathsf{fma}\left(t, -\color{blue}{\left(a \cdot z\right) \cdot 4}, b\right)\right)}{z \cdot c}
\] |
distribute-rgt-neg-in [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \mathsf{fma}\left(t, \color{blue}{\left(a \cdot z\right) \cdot \left(-4\right)}, b\right)\right)}{z \cdot c}
\] |
*-commutative [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \mathsf{fma}\left(t, \color{blue}{\left(z \cdot a\right)} \cdot \left(-4\right), b\right)\right)}{z \cdot c}
\] |
metadata-eval [=>]8.21 | \[ \frac{\mathsf{fma}\left(x, 9 \cdot y, \mathsf{fma}\left(t, \left(z \cdot a\right) \cdot \color{blue}{-4}, b\right)\right)}{z \cdot c}
\] |
Applied egg-rr8.21
if -2.00000000000000018e56 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 2e9Initial program 17.93
Simplified1.73
[Start]17.93 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-/r* [=>]2.3 | \[ \color{blue}{\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}}
\] |
Applied egg-rr1.74
if 2e9 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 4e303Initial program 1.24
Final simplification8.68
| Alternative 1 | |
|---|---|
| Error | 7.15% |
| Cost | 6608 |
| Alternative 2 | |
|---|---|
| Error | 9.94% |
| Cost | 6352 |
| Alternative 3 | |
|---|---|
| Error | 39.2% |
| Cost | 1762 |
| Alternative 4 | |
|---|---|
| Error | 24.21% |
| Cost | 1748 |
| Alternative 5 | |
|---|---|
| Error | 34.39% |
| Cost | 1624 |
| Alternative 6 | |
|---|---|
| Error | 34.09% |
| Cost | 1624 |
| Alternative 7 | |
|---|---|
| Error | 34.58% |
| Cost | 1624 |
| Alternative 8 | |
|---|---|
| Error | 36.82% |
| Cost | 1492 |
| Alternative 9 | |
|---|---|
| Error | 16.33% |
| Cost | 1484 |
| Alternative 10 | |
|---|---|
| Error | 54.17% |
| Cost | 1372 |
| Alternative 11 | |
|---|---|
| Error | 33.99% |
| Cost | 1364 |
| Alternative 12 | |
|---|---|
| Error | 40.47% |
| Cost | 1232 |
| Alternative 13 | |
|---|---|
| Error | 55.6% |
| Cost | 976 |
| Alternative 14 | |
|---|---|
| Error | 55.44% |
| Cost | 976 |
| Alternative 15 | |
|---|---|
| Error | 54.07% |
| Cost | 713 |
| Alternative 16 | |
|---|---|
| Error | 54.11% |
| Cost | 712 |
| Alternative 17 | |
|---|---|
| Error | 54.08% |
| Cost | 712 |
| Alternative 18 | |
|---|---|
| Error | 54% |
| Cost | 712 |
| Alternative 19 | |
|---|---|
| Error | 67.77% |
| Cost | 320 |
| Alternative 20 | |
|---|---|
| Error | 68.15% |
| Cost | 320 |
herbie shell --seed 2023115
(FPCore (x y z t a b c)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, J"
:precision binary64
:herbie-target
(if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -1.100156740804105e-171) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 0.0) (/ (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.1708877911747488e-53) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 2.876823679546137e+130) (- (+ (* (* 9.0 (/ y c)) (/ x z)) (/ b (* c z))) (* 4.0 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.3838515042456319e+158) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (- (+ (* 9.0 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4.0 (/ (* a t) c))))))))
(/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))