| Alternative 1 | |
|---|---|
| Error | 2.14% |
| Cost | 713 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+37} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z) :precision binary64 (- y (/ (+ y -1.0) (/ z x))))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
return y - ((y + -1.0) / (z / x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y - ((y + (-1.0d0)) / (z / x))
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
public static double code(double x, double y, double z) {
return y - ((y + -1.0) / (z / x));
}
def code(x, y, z): return (x + (y * (z - x))) / z
def code(x, y, z): return y - ((y + -1.0) / (z / x))
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function code(x, y, z) return Float64(y - Float64(Float64(y + -1.0) / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
function tmp = code(x, y, z) tmp = y - ((y + -1.0) / (z / x)); end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(y - N[(N[(y + -1.0), $MachinePrecision] / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x + y \cdot \left(z - x\right)}{z}
y - \frac{y + -1}{\frac{z}{x}}
Results
| Original | 16.29% |
|---|---|
| Target | 0.07% |
| Herbie | 0.22% |
Initial program 16.29
Taylor expanded in x around inf 5.25
Simplified0.22
[Start]5.25 | \[ y + \frac{\left(1 + -1 \cdot y\right) \cdot x}{z}
\] |
|---|---|
associate-/l* [=>]0.22 | \[ y + \color{blue}{\frac{1 + -1 \cdot y}{\frac{z}{x}}}
\] |
+-commutative [=>]0.22 | \[ y + \frac{\color{blue}{-1 \cdot y + 1}}{\frac{z}{x}}
\] |
metadata-eval [<=]0.22 | \[ y + \frac{-1 \cdot y + \color{blue}{-1 \cdot -1}}{\frac{z}{x}}
\] |
distribute-lft-in [<=]0.22 | \[ y + \frac{\color{blue}{-1 \cdot \left(y + -1\right)}}{\frac{z}{x}}
\] |
metadata-eval [<=]0.22 | \[ y + \frac{-1 \cdot \left(y + \color{blue}{\left(-1\right)}\right)}{\frac{z}{x}}
\] |
sub-neg [<=]0.22 | \[ y + \frac{-1 \cdot \color{blue}{\left(y - 1\right)}}{\frac{z}{x}}
\] |
mul-1-neg [=>]0.22 | \[ y + \frac{\color{blue}{-\left(y - 1\right)}}{\frac{z}{x}}
\] |
distribute-neg-frac [<=]0.22 | \[ y + \color{blue}{\left(-\frac{y - 1}{\frac{z}{x}}\right)}
\] |
associate-/l* [<=]5.25 | \[ y + \left(-\color{blue}{\frac{\left(y - 1\right) \cdot x}{z}}\right)
\] |
unsub-neg [=>]5.25 | \[ \color{blue}{y - \frac{\left(y - 1\right) \cdot x}{z}}
\] |
associate-/l* [=>]0.22 | \[ y - \color{blue}{\frac{y - 1}{\frac{z}{x}}}
\] |
sub-neg [=>]0.22 | \[ y - \frac{\color{blue}{y + \left(-1\right)}}{\frac{z}{x}}
\] |
metadata-eval [=>]0.22 | \[ y - \frac{y + \color{blue}{-1}}{\frac{z}{x}}
\] |
Final simplification0.22
| Alternative 1 | |
|---|---|
| Error | 2.14% |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Error | 2.13% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Error | 2.14% |
| Cost | 712 |
| Alternative 4 | |
|---|---|
| Error | 31.69% |
| Cost | 456 |
| Alternative 5 | |
|---|---|
| Error | 14.11% |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Error | 49.28% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:herbie-target
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))