| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 713 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\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
(if (<= y -1.3e+15)
(- y (/ y (/ z x)))
(if (<= y 2000000000000.0)
(/ (+ x (* y (- z x))) z)
(* y (- 1.0 (/ x z))))))double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e+15) {
tmp = y - (y / (z / x));
} else if (y <= 2000000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
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
real(8) :: tmp
if (y <= (-1.3d+15)) then
tmp = y - (y / (z / x))
else if (y <= 2000000000000.0d0) then
tmp = (x + (y * (z - x))) / z
else
tmp = y * (1.0d0 - (x / z))
end if
code = tmp
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) {
double tmp;
if (y <= -1.3e+15) {
tmp = y - (y / (z / x));
} else if (y <= 2000000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
def code(x, y, z): return (x + (y * (z - x))) / z
def code(x, y, z): tmp = 0 if y <= -1.3e+15: tmp = y - (y / (z / x)) elif y <= 2000000000000.0: tmp = (x + (y * (z - x))) / z else: tmp = y * (1.0 - (x / z)) return tmp
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function code(x, y, z) tmp = 0.0 if (y <= -1.3e+15) tmp = Float64(y - Float64(y / Float64(z / x))); elseif (y <= 2000000000000.0) tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); else tmp = Float64(y * Float64(1.0 - Float64(x / z))); end return tmp end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.3e+15) tmp = y - (y / (z / x)); elseif (y <= 2000000000000.0) tmp = (x + (y * (z - x))) / z; else tmp = y * (1.0 - (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, -1.3e+15], N[(y - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2000000000000.0], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+15}:\\
\;\;\;\;y - \frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;y \leq 2000000000000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 88.1% |
|---|---|
| Target | 93.5% |
| Herbie | 99.9% |
if y < -1.3e15Initial program 79.7%
Taylor expanded in y around 0 99.9%
Taylor expanded in y around inf 99.9%
Simplified100.0%
[Start]99.9 | \[ \left(1 - \frac{x}{z}\right) \cdot y
\] |
|---|---|
sub-neg [=>]99.9 | \[ \color{blue}{\left(1 + \left(-\frac{x}{z}\right)\right)} \cdot y
\] |
+-commutative [=>]99.9 | \[ \color{blue}{\left(\left(-\frac{x}{z}\right) + 1\right)} \cdot y
\] |
distribute-rgt1-in [<=]99.9 | \[ \color{blue}{y + \left(-\frac{x}{z}\right) \cdot y}
\] |
*-commutative [<=]99.9 | \[ y + \color{blue}{y \cdot \left(-\frac{x}{z}\right)}
\] |
distribute-rgt-neg-out [=>]99.9 | \[ y + \color{blue}{\left(-y \cdot \frac{x}{z}\right)}
\] |
unsub-neg [=>]99.9 | \[ \color{blue}{y - y \cdot \frac{x}{z}}
\] |
associate-*r/ [=>]94.1 | \[ y - \color{blue}{\frac{y \cdot x}{z}}
\] |
associate-/l* [=>]100.0 | \[ y - \color{blue}{\frac{y}{\frac{z}{x}}}
\] |
if -1.3e15 < y < 2e12Initial program 99.9%
if 2e12 < y Initial program 69.1%
Taylor expanded in y around 0 89.5%
Taylor expanded in y around inf 100.0%
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Accuracy | 63.2% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 76.8% |
| Cost | 516 |
| Alternative 5 | |
|---|---|
| Accuracy | 76.7% |
| Cost | 516 |
| Alternative 6 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 77.9% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 40.3% |
| Cost | 64 |
herbie shell --seed 2023161
(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))