| Alternative 1 | |
|---|---|
| Accuracy | 86.4% |
| Cost | 713 |
\[\begin{array}{l}
\mathbf{if}\;z \leq -1300 \lor \neg \left(z \leq 540000000\right):\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\]

(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
(FPCore (x y z) :precision binary64 (+ (* 4.0 (/ (- x z) y)) 2.0))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + ((4.0d0 * ((x + (y * 0.25d0)) - z)) / y)
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 = (4.0d0 * ((x - z) / y)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
public static double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 2.0;
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
def code(x, y, z): return (4.0 * ((x - z) / y)) + 2.0
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y)) end
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - z) / y)) + 2.0) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y); end
function tmp = code(x, y, z) tmp = (4.0 * ((x - z) / y)) + 2.0; end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
4 \cdot \frac{x - z}{y} + 2
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 100.0%
Simplified99.8%
[Start]100.0% | \[ 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
\] |
|---|---|
associate-/l* [=>]99.8% | \[ 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}}
\] |
associate--l+ [=>]99.8% | \[ 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}}
\] |
Taylor expanded in y around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ 2 + 4 \cdot \frac{x - z}{y}
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{4 \cdot \frac{x - z}{y} + 2}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 86.4% |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Accuracy | 54.5% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Accuracy | 8.0% |
| Cost | 64 |
| Alternative 5 | |
|---|---|
| Accuracy | 33.3% |
| Cost | 64 |
herbie shell --seed 2023164
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, C"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))