| Alternative 1 | |
|---|---|
| Error | 0.87% |
| Cost | 2513 |
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- x (/ (* x z) y))) (t_1 (/ (* x (- y z)) y)))
(if (<= t_1 (- INFINITY))
(/ (- y z) (/ y x))
(if (<= t_1 -2e+18)
t_0
(if (<= t_1 2e-121)
(fma x (/ (- z) y) x)
(if (<= t_1 1e+258) t_0 (- x (/ x (/ y z)))))))))double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
double t_0 = x - ((x * z) / y);
double t_1 = (x * (y - z)) / y;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = (y - z) / (y / x);
} else if (t_1 <= -2e+18) {
tmp = t_0;
} else if (t_1 <= 2e-121) {
tmp = fma(x, (-z / y), x);
} else if (t_1 <= 1e+258) {
tmp = t_0;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function code(x, y, z) t_0 = Float64(x - Float64(Float64(x * z) / y)) t_1 = Float64(Float64(x * Float64(y - z)) / y) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(y - z) / Float64(y / x)); elseif (t_1 <= -2e+18) tmp = t_0; elseif (t_1 <= 2e-121) tmp = fma(x, Float64(Float64(-z) / y), x); elseif (t_1 <= 1e+258) tmp = t_0; else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(y - z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e+18], t$95$0, If[LessEqual[t$95$1, 2e-121], N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 1e+258], t$95$0, N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := x - \frac{x \cdot z}{y}\\
t_1 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{y - z}{\frac{y}{x}}\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{+18}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-121}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\
\mathbf{elif}\;t_1 \leq 10^{+258}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
| Original | 19.84% |
|---|---|
| Target | 4.91% |
| Herbie | 0.81% |
if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0Initial program 100
Simplified0.21
[Start]100 | \[ \frac{x \cdot \left(y - z\right)}{y}
\] |
|---|---|
*-commutative [=>]100 | \[ \frac{\color{blue}{\left(y - z\right) \cdot x}}{y}
\] |
associate-/l* [=>]0.21 | \[ \color{blue}{\frac{y - z}{\frac{y}{x}}}
\] |
if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2e18 or 2e-121 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000006e258Initial program 0.49
Simplified8.36
[Start]0.49 | \[ \frac{x \cdot \left(y - z\right)}{y}
\] |
|---|---|
associate-*r/ [<=]8.96 | \[ \color{blue}{x \cdot \frac{y - z}{y}}
\] |
div-sub [=>]8.95 | \[ x \cdot \color{blue}{\left(\frac{y}{y} - \frac{z}{y}\right)}
\] |
distribute-rgt-out-- [<=]8.94 | \[ \color{blue}{\frac{y}{y} \cdot x - \frac{z}{y} \cdot x}
\] |
*-inverses [=>]8.94 | \[ \color{blue}{1} \cdot x - \frac{z}{y} \cdot x
\] |
*-lft-identity [=>]8.94 | \[ \color{blue}{x} - \frac{z}{y} \cdot x
\] |
associate-*l/ [=>]0.36 | \[ x - \color{blue}{\frac{z \cdot x}{y}}
\] |
*-commutative [<=]0.36 | \[ x - \frac{\color{blue}{x \cdot z}}{y}
\] |
associate-/l* [=>]8.36 | \[ x - \color{blue}{\frac{x}{\frac{y}{z}}}
\] |
Taylor expanded in x around 0 0.36
if -2e18 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2e-121Initial program 12.21
Simplified0.15
[Start]12.21 | \[ \frac{x \cdot \left(y - z\right)}{y}
\] |
|---|---|
*-commutative [=>]12.21 | \[ \frac{\color{blue}{\left(y - z\right) \cdot x}}{y}
\] |
associate-*l/ [<=]0.17 | \[ \color{blue}{\frac{y - z}{y} \cdot x}
\] |
div-sub [=>]0.17 | \[ \color{blue}{\left(\frac{y}{y} - \frac{z}{y}\right)} \cdot x
\] |
sub-neg [=>]0.17 | \[ \color{blue}{\left(\frac{y}{y} + \left(-\frac{z}{y}\right)\right)} \cdot x
\] |
+-commutative [=>]0.17 | \[ \color{blue}{\left(\left(-\frac{z}{y}\right) + \frac{y}{y}\right)} \cdot x
\] |
*-inverses [=>]0.17 | \[ \left(\left(-\frac{z}{y}\right) + \color{blue}{1}\right) \cdot x
\] |
distribute-lft1-in [<=]0.15 | \[ \color{blue}{\left(-\frac{z}{y}\right) \cdot x + x}
\] |
*-commutative [=>]0.15 | \[ \color{blue}{x \cdot \left(-\frac{z}{y}\right)} + x
\] |
fma-def [=>]0.15 | \[ \color{blue}{\mathsf{fma}\left(x, -\frac{z}{y}, x\right)}
\] |
distribute-neg-frac [=>]0.15 | \[ \mathsf{fma}\left(x, \color{blue}{\frac{-z}{y}}, x\right)
\] |
if 1.00000000000000006e258 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 76.22
Simplified5.83
[Start]76.22 | \[ \frac{x \cdot \left(y - z\right)}{y}
\] |
|---|---|
associate-*r/ [<=]5.95 | \[ \color{blue}{x \cdot \frac{y - z}{y}}
\] |
div-sub [=>]5.95 | \[ x \cdot \color{blue}{\left(\frac{y}{y} - \frac{z}{y}\right)}
\] |
distribute-rgt-out-- [<=]5.94 | \[ \color{blue}{\frac{y}{y} \cdot x - \frac{z}{y} \cdot x}
\] |
*-inverses [=>]5.94 | \[ \color{blue}{1} \cdot x - \frac{z}{y} \cdot x
\] |
*-lft-identity [=>]5.94 | \[ \color{blue}{x} - \frac{z}{y} \cdot x
\] |
associate-*l/ [=>]26.21 | \[ x - \color{blue}{\frac{z \cdot x}{y}}
\] |
*-commutative [<=]26.21 | \[ x - \frac{\color{blue}{x \cdot z}}{y}
\] |
associate-/l* [=>]5.83 | \[ x - \color{blue}{\frac{x}{\frac{y}{z}}}
\] |
Final simplification0.81
| Alternative 1 | |
|---|---|
| Error | 0.87% |
| Cost | 2513 |
| Alternative 2 | |
|---|---|
| Error | 0.86% |
| Cost | 2513 |
| Alternative 3 | |
|---|---|
| Error | 5.05% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Error | 12.3% |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Error | 29.81% |
| Cost | 649 |
| Alternative 6 | |
|---|---|
| Error | 29.84% |
| Cost | 648 |
| Alternative 7 | |
|---|---|
| Error | 39.63% |
| Cost | 64 |
herbie shell --seed 2023115
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))