| Alternative 1 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 980 |
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z) :precision binary64 (if (<= z -4.5e+34) (- (* y (/ x z)) x) (if (<= z 1650000.0) (/ (fma x (- y z) x) z) (- (/ x (/ z y)) x))))
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 <= -4.5e+34) {
tmp = (y * (x / z)) - x;
} else if (z <= 1650000.0) {
tmp = fma(x, (y - z), x) / z;
} else {
tmp = (x / (z / y)) - x;
}
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 <= -4.5e+34) tmp = Float64(Float64(y * Float64(x / z)) - x); elseif (z <= 1650000.0) tmp = Float64(fma(x, Float64(y - z), x) / z); else tmp = Float64(Float64(x / Float64(z / y)) - x); 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, -4.5e+34], N[(N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[z, 1650000.0], N[(N[(x * N[(y - z), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+34}:\\
\;\;\;\;y \cdot \frac{x}{z} - x\\
\mathbf{elif}\;z \leq 1650000:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}} - x\\
\end{array}
| Original | 84.1% |
|---|---|
| Target | 99.2% |
| Herbie | 98.3% |
if z < -4.5e34Initial program 72.1%
Simplified90.5%
[Start]72.1 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
associate-*r/ [<=]99.9 | \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}}
\] |
+-commutative [=>]99.9 | \[ x \cdot \frac{\color{blue}{1 + \left(y - z\right)}}{z}
\] |
associate-+r- [=>]99.9 | \[ x \cdot \frac{\color{blue}{\left(1 + y\right) - z}}{z}
\] |
div-sub [=>]99.9 | \[ x \cdot \color{blue}{\left(\frac{1 + y}{z} - \frac{z}{z}\right)}
\] |
*-inverses [=>]99.9 | \[ x \cdot \left(\frac{1 + y}{z} - \color{blue}{1}\right)
\] |
distribute-rgt-out-- [<=]99.9 | \[ \color{blue}{\frac{1 + y}{z} \cdot x - 1 \cdot x}
\] |
*-lft-identity [=>]99.9 | \[ \frac{1 + y}{z} \cdot x - \color{blue}{x}
\] |
*-commutative [=>]99.9 | \[ \color{blue}{x \cdot \frac{1 + y}{z}} - x
\] |
associate-*r/ [=>]90.5 | \[ \color{blue}{\frac{x \cdot \left(1 + y\right)}{z}} - x
\] |
*-commutative [=>]90.5 | \[ \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} - x
\] |
+-commutative [=>]90.5 | \[ \frac{\color{blue}{\left(y + 1\right)} \cdot x}{z} - x
\] |
distribute-lft1-in [<=]90.5 | \[ \frac{\color{blue}{y \cdot x + x}}{z} - x
\] |
*-commutative [=>]90.5 | \[ \frac{\color{blue}{x \cdot y} + x}{z} - x
\] |
fma-def [=>]90.5 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, x\right)}}{z} - x
\] |
Taylor expanded in y around inf 90.5%
Simplified95.1%
[Start]90.5 | \[ \frac{y \cdot x}{z} - x
\] |
|---|---|
*-lft-identity [<=]90.5 | \[ \frac{\color{blue}{1 \cdot \left(y \cdot x\right)}}{z} - x
\] |
associate-*l/ [<=]90.5 | \[ \color{blue}{\frac{1}{z} \cdot \left(y \cdot x\right)} - x
\] |
*-commutative [=>]90.5 | \[ \frac{1}{z} \cdot \color{blue}{\left(x \cdot y\right)} - x
\] |
associate-*r* [=>]95.1 | \[ \color{blue}{\left(\frac{1}{z} \cdot x\right) \cdot y} - x
\] |
*-commutative [=>]95.1 | \[ \color{blue}{y \cdot \left(\frac{1}{z} \cdot x\right)} - x
\] |
associate-*l/ [=>]95.1 | \[ y \cdot \color{blue}{\frac{1 \cdot x}{z}} - x
\] |
metadata-eval [<=]95.1 | \[ y \cdot \frac{\color{blue}{\left(--1\right)} \cdot x}{z} - x
\] |
distribute-lft-neg-in [<=]95.1 | \[ y \cdot \frac{\color{blue}{--1 \cdot x}}{z} - x
\] |
mul-1-neg [=>]95.1 | \[ y \cdot \frac{-\color{blue}{\left(-x\right)}}{z} - x
\] |
remove-double-neg [=>]95.1 | \[ y \cdot \frac{\color{blue}{x}}{z} - x
\] |
if -4.5e34 < z < 1.65e6Initial program 99.5%
Simplified99.5%
[Start]99.5 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
distribute-lft-in [=>]99.5 | \[ \frac{\color{blue}{x \cdot \left(y - z\right) + x \cdot 1}}{z}
\] |
*-rgt-identity [=>]99.5 | \[ \frac{x \cdot \left(y - z\right) + \color{blue}{x}}{z}
\] |
fma-def [=>]99.5 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y - z, x\right)}}{z}
\] |
if 1.65e6 < z Initial program 72.6%
Simplified90.6%
[Start]72.6 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
associate-*r/ [<=]99.9 | \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}}
\] |
+-commutative [=>]99.9 | \[ x \cdot \frac{\color{blue}{1 + \left(y - z\right)}}{z}
\] |
associate-+r- [=>]99.9 | \[ x \cdot \frac{\color{blue}{\left(1 + y\right) - z}}{z}
\] |
div-sub [=>]99.9 | \[ x \cdot \color{blue}{\left(\frac{1 + y}{z} - \frac{z}{z}\right)}
\] |
*-inverses [=>]99.9 | \[ x \cdot \left(\frac{1 + y}{z} - \color{blue}{1}\right)
\] |
distribute-rgt-out-- [<=]99.9 | \[ \color{blue}{\frac{1 + y}{z} \cdot x - 1 \cdot x}
\] |
*-lft-identity [=>]99.9 | \[ \frac{1 + y}{z} \cdot x - \color{blue}{x}
\] |
*-commutative [=>]99.9 | \[ \color{blue}{x \cdot \frac{1 + y}{z}} - x
\] |
associate-*r/ [=>]90.6 | \[ \color{blue}{\frac{x \cdot \left(1 + y\right)}{z}} - x
\] |
*-commutative [=>]90.6 | \[ \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} - x
\] |
+-commutative [=>]90.6 | \[ \frac{\color{blue}{\left(y + 1\right)} \cdot x}{z} - x
\] |
distribute-lft1-in [<=]90.6 | \[ \frac{\color{blue}{y \cdot x + x}}{z} - x
\] |
*-commutative [=>]90.6 | \[ \frac{\color{blue}{x \cdot y} + x}{z} - x
\] |
fma-def [=>]90.6 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, x\right)}}{z} - x
\] |
Taylor expanded in y around inf 90.3%
Simplified95.7%
[Start]90.3 | \[ \frac{y \cdot x}{z} - x
\] |
|---|---|
*-lft-identity [<=]90.3 | \[ \frac{\color{blue}{1 \cdot \left(y \cdot x\right)}}{z} - x
\] |
associate-*l/ [<=]90.2 | \[ \color{blue}{\frac{1}{z} \cdot \left(y \cdot x\right)} - x
\] |
*-commutative [=>]90.2 | \[ \frac{1}{z} \cdot \color{blue}{\left(x \cdot y\right)} - x
\] |
associate-*r* [=>]95.6 | \[ \color{blue}{\left(\frac{1}{z} \cdot x\right) \cdot y} - x
\] |
*-commutative [=>]95.6 | \[ \color{blue}{y \cdot \left(\frac{1}{z} \cdot x\right)} - x
\] |
associate-*l/ [=>]95.7 | \[ y \cdot \color{blue}{\frac{1 \cdot x}{z}} - x
\] |
metadata-eval [<=]95.7 | \[ y \cdot \frac{\color{blue}{\left(--1\right)} \cdot x}{z} - x
\] |
distribute-lft-neg-in [<=]95.7 | \[ y \cdot \frac{\color{blue}{--1 \cdot x}}{z} - x
\] |
mul-1-neg [=>]95.7 | \[ y \cdot \frac{-\color{blue}{\left(-x\right)}}{z} - x
\] |
remove-double-neg [=>]95.7 | \[ y \cdot \frac{\color{blue}{x}}{z} - x
\] |
Taylor expanded in y around 0 90.3%
Simplified99.6%
[Start]90.3 | \[ \frac{y \cdot x}{z} - x
\] |
|---|---|
*-commutative [=>]90.3 | \[ \frac{\color{blue}{x \cdot y}}{z} - x
\] |
associate-/l* [=>]99.6 | \[ \color{blue}{\frac{x}{\frac{z}{y}}} - x
\] |
Final simplification98.3%
| Alternative 1 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 980 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 840 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.6% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 69.8% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 48.2% |
| Cost | 128 |
herbie shell --seed 2023140
(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))