| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 713 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1 \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 (if (or (<= y -1.55e+28) (not (<= y 2e+15))) (/ y (/ z (- z x))) (+ y (/ x (/ z (- 1.0 y))))))
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.55e+28) || !(y <= 2e+15)) {
tmp = y / (z / (z - x));
} else {
tmp = y + (x / (z / (1.0 - y)));
}
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.55d+28)) .or. (.not. (y <= 2d+15))) then
tmp = y / (z / (z - x))
else
tmp = y + (x / (z / (1.0d0 - y)))
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.55e+28) || !(y <= 2e+15)) {
tmp = y / (z / (z - x));
} else {
tmp = y + (x / (z / (1.0 - y)));
}
return tmp;
}
def code(x, y, z): return (x + (y * (z - x))) / z
def code(x, y, z): tmp = 0 if (y <= -1.55e+28) or not (y <= 2e+15): tmp = y / (z / (z - x)) else: tmp = y + (x / (z / (1.0 - y))) 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.55e+28) || !(y <= 2e+15)) tmp = Float64(y / Float64(z / Float64(z - x))); else tmp = Float64(y + Float64(x / Float64(z / Float64(1.0 - y)))); 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.55e+28) || ~((y <= 2e+15))) tmp = y / (z / (z - x)); else tmp = y + (x / (z / (1.0 - y))); 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[Or[LessEqual[y, -1.55e+28], N[Not[LessEqual[y, 2e+15]], $MachinePrecision]], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / N[(z / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+28} \lor \neg \left(y \leq 2 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\
\end{array}
Results
| Original | 84.2% |
|---|---|
| Target | 99.9% |
| Herbie | 99.9% |
if y < -1.55e28 or 2e15 < y Initial program 61.7%
Taylor expanded in y around inf 61.7%
Simplified99.9%
[Start]61.7 | \[ \frac{y \cdot \left(z - x\right)}{z}
\] |
|---|---|
associate-/l* [=>]99.9 | \[ \color{blue}{\frac{y}{\frac{z}{z - x}}}
\] |
if -1.55e28 < y < 2e15Initial program 99.7%
Taylor expanded in x around inf 99.9%
Simplified99.9%
[Start]99.9 | \[ y + \frac{\left(1 + -1 \cdot y\right) \cdot x}{z}
\] |
|---|---|
*-commutative [=>]99.9 | \[ y + \frac{\color{blue}{x \cdot \left(1 + -1 \cdot y\right)}}{z}
\] |
associate-/l* [=>]99.9 | \[ y + \color{blue}{\frac{x}{\frac{z}{1 + -1 \cdot y}}}
\] |
mul-1-neg [=>]99.9 | \[ y + \frac{x}{\frac{z}{1 + \color{blue}{\left(-y\right)}}}
\] |
unsub-neg [=>]99.9 | \[ y + \frac{x}{\frac{z}{\color{blue}{1 - y}}}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.9% |
| Cost | 648 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.9% |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Accuracy | 69.3% |
| Cost | 456 |
| Alternative 6 | |
|---|---|
| Accuracy | 86.6% |
| Cost | 320 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.7% |
| Cost | 64 |
herbie shell --seed 2023137
(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))