| Alternative 1 | |
|---|---|
| Error | 13.05% |
| Cost | 6352 |
(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))))
(if (<= t_1 (- INFINITY))
(+ (/ (/ b c) z) (- (* (/ x z) (/ (* 9.0 y) c)) (* 4.0 (/ (* t a) c))))
(if (<= t_1 -2e-126)
t_1
(if (<= t_1 700000000.0)
(/ (+ (* a (* t -4.0)) (/ (fma x (* 9.0 y) b) z)) c)
(if (<= t_1 2e+306) t_1 (* t (/ (* a -4.0) c))))))))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 tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = ((b / c) / z) + (((x / z) * ((9.0 * y) / c)) - (4.0 * ((t * a) / c)));
} else if (t_1 <= -2e-126) {
tmp = t_1;
} else if (t_1 <= 700000000.0) {
tmp = ((a * (t * -4.0)) + (fma(x, (9.0 * y), b) / z)) / c;
} else if (t_1 <= 2e+306) {
tmp = t_1;
} else {
tmp = t * ((a * -4.0) / c);
}
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)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64(b / c) / z) + Float64(Float64(Float64(x / z) * Float64(Float64(9.0 * y) / c)) - Float64(4.0 * Float64(Float64(t * a) / c)))); elseif (t_1 <= -2e-126) tmp = t_1; elseif (t_1 <= 700000000.0) tmp = Float64(Float64(Float64(a * Float64(t * -4.0)) + Float64(fma(x, Float64(9.0 * y), b) / z)) / c); elseif (t_1 <= 2e+306) tmp = t_1; else tmp = Float64(t * Float64(Float64(a * -4.0) / c)); 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]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(b / c), $MachinePrecision] / z), $MachinePrecision] + N[(N[(N[(x / z), $MachinePrecision] * N[(N[(9.0 * y), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] - N[(4.0 * N[(N[(t * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e-126], t$95$1, If[LessEqual[t$95$1, 700000000.0], N[(N[(N[(a * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x * N[(9.0 * y), $MachinePrecision] + b), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[t$95$1, 2e+306], t$95$1, N[(t * N[(N[(a * -4.0), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]]]]
\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}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{\frac{b}{c}}{z} + \left(\frac{x}{z} \cdot \frac{9 \cdot y}{c} - 4 \cdot \frac{t \cdot a}{c}\right)\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-126}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 700000000:\\
\;\;\;\;\frac{a \cdot \left(t \cdot -4\right) + \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}}{c}\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+306}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t \cdot \frac{a \cdot -4}{c}\\
\end{array}
| Original | 32.17% |
|---|---|
| Target | 22.92% |
| Herbie | 10.02% |
if (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -inf.0Initial program 100
Taylor expanded in x around 0 46.79
Simplified28.61
[Start]46.79 | \[ \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+ [=>]46.79 | \[ \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* [=>]53.66 | \[ \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 [<=]53.66 | \[ \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/ [=>]53.98 | \[ \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* [=>]53.98 | \[ \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 [<=]53.98 | \[ \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)
\] |
times-frac [=>]28.61 | \[ \frac{\frac{b}{c}}{z} + \left(\color{blue}{\frac{x}{z} \cdot \frac{9 \cdot y}{c}} - 4 \cdot \frac{a \cdot t}{c}\right)
\] |
if -inf.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -1.9999999999999999e-126 or 7e8 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 2.00000000000000003e306Initial program 1.03
if -1.9999999999999999e-126 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 7e8Initial program 25.89
Simplified1.48
[Start]25.89 | \[ \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.01 | \[ \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}}
\] |
if 2.00000000000000003e306 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) Initial program 98.96
Simplified87.83
[Start]98.96 | \[ \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- [=>]98.96 | \[ \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* [=>]98.82 | \[ \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 [=>]98.82 | \[ \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 [=>]98.82 | \[ \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- [<=]98.82 | \[ \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 [<=]98.82 | \[ \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 [=>]98.82 | \[ \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 [=>]98.82 | \[ \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 [=>]98.82 | \[ \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* [=>]87.98 | \[ \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 [=>]87.98 | \[ \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 [=>]87.97 | \[ \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 [<=]87.97 | \[ \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* [=>]87.83 | \[ \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 [=>]87.83 | \[ \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 [=>]87.83 | \[ \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 [=>]87.83 | \[ \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}
\] |
Taylor expanded in t around inf 46.45
Simplified39.07
[Start]46.45 | \[ -4 \cdot \frac{a \cdot t}{c}
\] |
|---|---|
associate-/l* [=>]37.65 | \[ -4 \cdot \color{blue}{\frac{a}{\frac{c}{t}}}
\] |
associate-*r/ [=>]37.65 | \[ \color{blue}{\frac{-4 \cdot a}{\frac{c}{t}}}
\] |
*-commutative [<=]37.65 | \[ \frac{\color{blue}{a \cdot -4}}{\frac{c}{t}}
\] |
associate-/r/ [=>]39.07 | \[ \color{blue}{\frac{a \cdot -4}{c} \cdot t}
\] |
*-commutative [=>]39.07 | \[ \frac{\color{blue}{-4 \cdot a}}{c} \cdot t
\] |
Final simplification10.02
| Alternative 1 | |
|---|---|
| Error | 13.05% |
| Cost | 6352 |
| Alternative 2 | |
|---|---|
| Error | 11.2% |
| Cost | 6352 |
| Alternative 3 | |
|---|---|
| Error | 10.1% |
| Cost | 6352 |
| Alternative 4 | |
|---|---|
| Error | 31.84% |
| Cost | 1884 |
| Alternative 5 | |
|---|---|
| Error | 31.44% |
| Cost | 1620 |
| Alternative 6 | |
|---|---|
| Error | 22.16% |
| Cost | 1481 |
| Alternative 7 | |
|---|---|
| Error | 54.3% |
| Cost | 1372 |
| Alternative 8 | |
|---|---|
| Error | 54.34% |
| Cost | 1372 |
| Alternative 9 | |
|---|---|
| Error | 56.59% |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Error | 40.43% |
| Cost | 1232 |
| Alternative 11 | |
|---|---|
| Error | 30.35% |
| Cost | 1225 |
| Alternative 12 | |
|---|---|
| Error | 56.07% |
| Cost | 977 |
| Alternative 13 | |
|---|---|
| Error | 56.07% |
| Cost | 976 |
| Alternative 14 | |
|---|---|
| Error | 56.05% |
| Cost | 976 |
| Alternative 15 | |
|---|---|
| Error | 56.03% |
| Cost | 976 |
| Alternative 16 | |
|---|---|
| Error | 30.37% |
| Cost | 969 |
| Alternative 17 | |
|---|---|
| Error | 67.69% |
| Cost | 452 |
| Alternative 18 | |
|---|---|
| Error | 68.85% |
| Cost | 320 |
herbie shell --seed 2023121
(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)))