| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 1481.00 |
(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+37)
(+ (- x (/ y (* z 3.0))) (/ (* (/ t 3.0) (/ 1.0 z)) y))
(if (<= (* z 3.0) 2e+18)
(+ 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+37) {
tmp = (x - (y / (z * 3.0))) + (((t / 3.0) * (1.0 / z)) / y);
} else if ((z * 3.0) <= 2e+18) {
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+37) tmp = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(Float64(Float64(t / 3.0) * Float64(1.0 / z)) / y)); elseif (Float64(z * 3.0) <= 2e+18) tmp = Float64(x + Float64(Float64(Float64(y - Float64(t / y)) / 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+37], N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t / 3.0), $MachinePrecision] * N[(1.0 / z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 2e+18], N[(x + N[(N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] / -3.0), $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^{+37}:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{3} \cdot \frac{1}{z}}{y}\\
\mathbf{elif}\;z \cdot 3 \leq 2 \cdot 10^{+18}:\\
\;\;\;\;x + \frac{\frac{y - \frac{t}{y}}{z}}{-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 | 95.0% |
|---|---|
| Target | 97.5% |
| Herbie | 99.0% |
if (*.f64 z 3) < -4.99999999999999989e37Initial program 99.4
Simplified98.2
[Start]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-/r* [=>]98.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{t}{z \cdot 3}}{y}}
\] |
Applied egg-rr98.3
[Start]98.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y}
\] |
|---|---|
associate-/l/ [<=]98.3 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{\frac{\frac{t}{3}}{z}}}{y}
\] |
div-inv [=>]98.3 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{\frac{t}{3} \cdot \frac{1}{z}}}{y}
\] |
if -4.99999999999999989e37 < (*.f64 z 3) < 2e18Initial program 88.3
Simplified99.3
[Start]88.3 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]88.3 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]88.3 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]88.3 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]88.3 | \[ 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/ [=>]88.3 | \[ 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/ [<=]88.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/ [=>]88.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 [=>]99.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-- [=>]99.3 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]99.3 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]99.3 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]99.3 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr99.3
[Start]99.3 | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
*-commutative [=>]99.3 | \[ x + \color{blue}{\left(y - \frac{t}{y}\right) \cdot \frac{-0.3333333333333333}{z}}
\] |
associate-*r/ [=>]99.3 | \[ x + \color{blue}{\frac{\left(y - \frac{t}{y}\right) \cdot -0.3333333333333333}{z}}
\] |
associate-/l* [=>]99.3 | \[ x + \color{blue}{\frac{y - \frac{t}{y}}{\frac{z}{-0.3333333333333333}}}
\] |
div-inv [=>]99.4 | \[ x + \frac{y - \frac{t}{y}}{\color{blue}{z \cdot \frac{1}{-0.3333333333333333}}}
\] |
associate-/r* [=>]99.3 | \[ x + \color{blue}{\frac{\frac{y - \frac{t}{y}}{z}}{\frac{1}{-0.3333333333333333}}}
\] |
metadata-eval [=>]99.3 | \[ x + \frac{\frac{y - \frac{t}{y}}{z}}{\color{blue}{-3}}
\] |
if 2e18 < (*.f64 z 3) Initial program 99.4
Simplified99.4
[Start]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
sub-neg [=>]99.4 | \[ \color{blue}{\left(x + \left(-\frac{y}{z \cdot 3}\right)\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
+-commutative [=>]99.4 | \[ \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) + x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
neg-mul-1 [=>]99.4 | \[ \left(\color{blue}{-1 \cdot \frac{y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
associate-*r/ [=>]99.4 | \[ \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
*-commutative [=>]99.4 | \[ \left(\frac{-1 \cdot y}{\color{blue}{3 \cdot z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
times-frac [=>]99.4 | \[ \left(\color{blue}{\frac{-1}{3} \cdot \frac{y}{z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
fma-def [=>]99.4 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3}, \frac{y}{z}, x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
metadata-eval [=>]99.4 | \[ \mathsf{fma}\left(\color{blue}{-0.3333333333333333}, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
*-commutative [=>]99.4 | \[ \mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\color{blue}{y \cdot \left(z \cdot 3\right)}}
\] |
Final simplification99.0
| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 1481.00 |
| Alternative 2 | |
|---|---|
| Error | 99.0% |
| Cost | 1480.00 |
| Alternative 3 | |
|---|---|
| Error | 99.0% |
| Cost | 1480.00 |
| Alternative 4 | |
|---|---|
| Error | 96.8% |
| Cost | 969.00 |
| Alternative 5 | |
|---|---|
| Error | 96.8% |
| Cost | 969.00 |
| Alternative 6 | |
|---|---|
| Error | 49.7% |
| Cost | 850.00 |
| Alternative 7 | |
|---|---|
| Error | 49.8% |
| Cost | 848.00 |
| Alternative 8 | |
|---|---|
| Error | 49.8% |
| Cost | 848.00 |
| Alternative 9 | |
|---|---|
| Error | 49.8% |
| Cost | 848.00 |
| Alternative 10 | |
|---|---|
| Error | 49.8% |
| Cost | 848.00 |
| Alternative 11 | |
|---|---|
| Error | 49.8% |
| Cost | 848.00 |
| Alternative 12 | |
|---|---|
| Error | 82.0% |
| Cost | 841.00 |
| Alternative 13 | |
|---|---|
| Error | 87.4% |
| Cost | 840.00 |
| Alternative 14 | |
|---|---|
| Error | 87.9% |
| Cost | 840.00 |
| Alternative 15 | |
|---|---|
| Error | 88.0% |
| Cost | 840.00 |
| Alternative 16 | |
|---|---|
| Error | 91.3% |
| Cost | 840.00 |
| Alternative 17 | |
|---|---|
| Error | 91.2% |
| Cost | 840.00 |
| Alternative 18 | |
|---|---|
| Error | 91.3% |
| Cost | 840.00 |
| Alternative 19 | |
|---|---|
| Error | 91.2% |
| Cost | 840.00 |
| Alternative 20 | |
|---|---|
| Error | 72.4% |
| Cost | 448.00 |
| Alternative 21 | |
|---|---|
| Error | 72.4% |
| Cost | 448.00 |
| Alternative 22 | |
|---|---|
| Error | 72.5% |
| Cost | 448.00 |
| Alternative 23 | |
|---|---|
| Error | 41.7% |
| Cost | 64.00 |
herbie shell --seed 2023104
(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))))