| Alternative 1 | |
|---|---|
| Error | 31.75% |
| Cost | 984 |
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z) :precision binary64 (if (<= z -1.5e+42) (- (* (/ y z) x) x) (if (<= z 5e-37) (- (/ (fma x y x) z) x) (* x (/ (+ y (- 1.0 z)) z)))))
double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+42) {
tmp = ((y / z) * x) - x;
} else if (z <= 5e-37) {
tmp = (fma(x, y, x) / z) - x;
} else {
tmp = x * ((y + (1.0 - z)) / z);
}
return tmp;
}
function code(x, y, z) return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) end
function code(x, y, z) tmp = 0.0 if (z <= -1.5e+42) tmp = Float64(Float64(Float64(y / z) * x) - x); elseif (z <= 5e-37) tmp = Float64(Float64(fma(x, y, x) / z) - x); else tmp = Float64(x * Float64(Float64(y + Float64(1.0 - z)) / z)); end return tmp end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -1.5e+42], N[(N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[z, 5e-37], N[(N[(N[(x * y + x), $MachinePrecision] / z), $MachinePrecision] - x), $MachinePrecision], N[(x * N[(N[(y + N[(1.0 - z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+42}:\\
\;\;\;\;\frac{y}{z} \cdot x - x\\
\mathbf{elif}\;z \leq 5 \cdot 10^{-37}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y + \left(1 - z\right)}{z}\\
\end{array}
| Original | 15.7% |
|---|---|
| Target | 0.65% |
| Herbie | 0.23% |
if z < -1.50000000000000014e42Initial program 30.13
Simplified9.95
[Start]30.13 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
associate-*r/ [<=]0.1 | \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}}
\] |
+-commutative [=>]0.1 | \[ x \cdot \frac{\color{blue}{1 + \left(y - z\right)}}{z}
\] |
associate-+r- [=>]0.1 | \[ x \cdot \frac{\color{blue}{\left(1 + y\right) - z}}{z}
\] |
div-sub [=>]0.09 | \[ x \cdot \color{blue}{\left(\frac{1 + y}{z} - \frac{z}{z}\right)}
\] |
*-inverses [=>]0.09 | \[ x \cdot \left(\frac{1 + y}{z} - \color{blue}{1}\right)
\] |
distribute-rgt-out-- [<=]0.08 | \[ \color{blue}{\frac{1 + y}{z} \cdot x - 1 \cdot x}
\] |
*-lft-identity [=>]0.08 | \[ \frac{1 + y}{z} \cdot x - \color{blue}{x}
\] |
*-commutative [=>]0.08 | \[ \color{blue}{x \cdot \frac{1 + y}{z}} - x
\] |
associate-*r/ [=>]9.95 | \[ \color{blue}{\frac{x \cdot \left(1 + y\right)}{z}} - x
\] |
*-commutative [=>]9.95 | \[ \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} - x
\] |
+-commutative [=>]9.95 | \[ \frac{\color{blue}{\left(y + 1\right)} \cdot x}{z} - x
\] |
distribute-lft1-in [<=]9.95 | \[ \frac{\color{blue}{y \cdot x + x}}{z} - x
\] |
*-commutative [=>]9.95 | \[ \frac{\color{blue}{x \cdot y} + x}{z} - x
\] |
fma-def [=>]9.95 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, x\right)}}{z} - x
\] |
Taylor expanded in y around inf 9.95
Simplified0.08
[Start]9.95 | \[ \frac{y \cdot x}{z} - x
\] |
|---|---|
associate-*l/ [<=]0.08 | \[ \color{blue}{\frac{y}{z} \cdot x} - x
\] |
if -1.50000000000000014e42 < z < 4.9999999999999997e-37Initial program 0.51
Simplified0.36
[Start]0.51 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
associate-*r/ [<=]13.35 | \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}}
\] |
+-commutative [=>]13.35 | \[ x \cdot \frac{\color{blue}{1 + \left(y - z\right)}}{z}
\] |
associate-+r- [=>]13.35 | \[ x \cdot \frac{\color{blue}{\left(1 + y\right) - z}}{z}
\] |
div-sub [=>]13.34 | \[ x \cdot \color{blue}{\left(\frac{1 + y}{z} - \frac{z}{z}\right)}
\] |
*-inverses [=>]13.34 | \[ x \cdot \left(\frac{1 + y}{z} - \color{blue}{1}\right)
\] |
distribute-rgt-out-- [<=]13.34 | \[ \color{blue}{\frac{1 + y}{z} \cdot x - 1 \cdot x}
\] |
*-lft-identity [=>]13.34 | \[ \frac{1 + y}{z} \cdot x - \color{blue}{x}
\] |
*-commutative [=>]13.34 | \[ \color{blue}{x \cdot \frac{1 + y}{z}} - x
\] |
associate-*r/ [=>]0.37 | \[ \color{blue}{\frac{x \cdot \left(1 + y\right)}{z}} - x
\] |
*-commutative [=>]0.37 | \[ \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} - x
\] |
+-commutative [=>]0.37 | \[ \frac{\color{blue}{\left(y + 1\right)} \cdot x}{z} - x
\] |
distribute-lft1-in [<=]0.37 | \[ \frac{\color{blue}{y \cdot x + x}}{z} - x
\] |
*-commutative [=>]0.37 | \[ \frac{\color{blue}{x \cdot y} + x}{z} - x
\] |
fma-def [=>]0.36 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, x\right)}}{z} - x
\] |
if 4.9999999999999997e-37 < z Initial program 23.02
Applied egg-rr0.18
Final simplification0.23
| Alternative 1 | |
|---|---|
| Error | 31.75% |
| Cost | 984 |
| Alternative 2 | |
|---|---|
| Error | 17.94% |
| Cost | 849 |
| Alternative 3 | |
|---|---|
| Error | 17.97% |
| Cost | 848 |
| Alternative 4 | |
|---|---|
| Error | 0.24% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Error | 0.18% |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Error | 14.18% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 1.46% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 1.45% |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Error | 30.61% |
| Cost | 456 |
| Alternative 10 | |
|---|---|
| Error | 52.75% |
| Cost | 128 |
herbie shell --seed 2023102
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))
(/ (* x (+ (- y z) 1.0)) z))