| Alternative 1 | |
|---|---|
| Error | 29.8 |
| Cost | 1504 |
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t)
:precision binary64
(if (<= (* z 3.0) -5e-61)
(+ (- x (/ y (* z 3.0))) (/ t (* 3.0 (* z y))))
(if (<= (* z 3.0) 1e+21)
(+ x (/ (- y (/ t y)) (* z -3.0)))
(+ (fma -0.3333333333333333 (/ y z) x) (/ t (* (* z 3.0) y))))))double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
double code(double x, double y, double z, double t) {
double tmp;
if ((z * 3.0) <= -5e-61) {
tmp = (x - (y / (z * 3.0))) + (t / (3.0 * (z * y)));
} else if ((z * 3.0) <= 1e+21) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else {
tmp = fma(-0.3333333333333333, (y / z), x) + (t / ((z * 3.0) * y));
}
return tmp;
}
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))) end
function code(x, y, z, t) tmp = 0.0 if (Float64(z * 3.0) <= -5e-61) tmp = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(3.0 * Float64(z * y)))); elseif (Float64(z * 3.0) <= 1e+21) tmp = Float64(x + Float64(Float64(y - Float64(t / y)) / Float64(z * -3.0))); else tmp = Float64(fma(-0.3333333333333333, Float64(y / z), x) + Float64(t / Float64(Float64(z * 3.0) * y))); end return tmp end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(z * 3.0), $MachinePrecision], -5e-61], N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(3.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 1e+21], N[(x + N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;z \cdot 3 \leq -5 \cdot 10^{-61}:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{3 \cdot \left(z \cdot y\right)}\\
\mathbf{elif}\;z \cdot 3 \leq 10^{+21}:\\
\;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\end{array}
| Original | 3.3 |
|---|---|
| Target | 1.5 |
| Herbie | 0.4 |
if (*.f64 z 3) < -4.9999999999999999e-61Initial program 0.5
Taylor expanded in t around 0 0.5
Simplified0.5
[Start]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
metadata-eval [<=]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{1}{3}} \cdot \frac{t}{y \cdot z}
\] |
times-frac [<=]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{1 \cdot t}{3 \cdot \left(y \cdot z\right)}}
\] |
*-lft-identity [=>]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{t}}{3 \cdot \left(y \cdot z\right)}
\] |
remove-double-neg [<=]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{-\left(-t\right)}}{3 \cdot \left(y \cdot z\right)}
\] |
remove-double-neg [=>]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{t}}{3 \cdot \left(y \cdot z\right)}
\] |
*-commutative [=>]0.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{\left(y \cdot z\right) \cdot 3}}
\] |
if -4.9999999999999999e-61 < (*.f64 z 3) < 1e21Initial program 10.2
Simplified0.3
[Start]10.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]10.2 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]10.2 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]10.2 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]10.2 | \[ x + \color{blue}{\left(-1 \cdot \frac{y}{z \cdot 3} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
associate-*r/ [=>]10.2 | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*l/ [<=]10.2 | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*r/ [=>]10.2 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1 \cdot t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
times-frac [=>]0.3 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]0.3 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]0.3 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]0.3 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]0.3 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr0.3
if 1e21 < (*.f64 z 3) Initial program 0.3
Simplified0.3
[Start]0.3 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
sub-neg [=>]0.3 | \[ \color{blue}{\left(x + \left(-\frac{y}{z \cdot 3}\right)\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
+-commutative [=>]0.3 | \[ \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) + x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
neg-mul-1 [=>]0.3 | \[ \left(\color{blue}{-1 \cdot \frac{y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
associate-*r/ [=>]0.3 | \[ \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
*-commutative [=>]0.3 | \[ \left(\frac{-1 \cdot y}{\color{blue}{3 \cdot z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
times-frac [=>]0.3 | \[ \left(\color{blue}{\frac{-1}{3} \cdot \frac{y}{z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
fma-def [=>]0.3 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3}, \frac{y}{z}, x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
metadata-eval [=>]0.3 | \[ \mathsf{fma}\left(\color{blue}{-0.3333333333333333}, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
*-commutative [=>]0.3 | \[ \mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\color{blue}{y \cdot \left(z \cdot 3\right)}}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 29.8 |
| Cost | 1504 |
| Alternative 2 | |
|---|---|
| Error | 35.0 |
| Cost | 1244 |
| Alternative 3 | |
|---|---|
| Error | 29.0 |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Error | 18.3 |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Error | 18.3 |
| Cost | 1240 |
| Alternative 6 | |
|---|---|
| Error | 0.4 |
| Cost | 1225 |
| Alternative 7 | |
|---|---|
| Error | 0.5 |
| Cost | 1224 |
| Alternative 8 | |
|---|---|
| Error | 2.3 |
| Cost | 969 |
| Alternative 9 | |
|---|---|
| Error | 2.3 |
| Cost | 969 |
| Alternative 10 | |
|---|---|
| Error | 2.4 |
| Cost | 969 |
| Alternative 11 | |
|---|---|
| Error | 2.4 |
| Cost | 968 |
| Alternative 12 | |
|---|---|
| Error | 2.5 |
| Cost | 968 |
| Alternative 13 | |
|---|---|
| Error | 11.9 |
| Cost | 841 |
| Alternative 14 | |
|---|---|
| Error | 8.4 |
| Cost | 841 |
| Alternative 15 | |
|---|---|
| Error | 5.8 |
| Cost | 841 |
| Alternative 16 | |
|---|---|
| Error | 28.4 |
| Cost | 584 |
| Alternative 17 | |
|---|---|
| Error | 37.4 |
| Cost | 64 |
herbie shell --seed 2022354
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, H"
:precision binary64
:herbie-target
(+ (- x (/ y (* z 3.0))) (/ (/ t (* z 3.0)) y))
(+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))