
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
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
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y); 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]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
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
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y); 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]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (fma (- x z) (/ 4.0 y) 2.0))
double code(double x, double y, double z) {
return fma((x - z), (4.0 / y), 2.0);
}
function code(x, y, z) return fma(Float64(x - z), Float64(4.0 / y), 2.0) end
code[x_, y_, z_] := N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - z, \frac{4}{y}, 2\right)
\end{array}
Initial program 99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (<= z -2.8e-36)
(+ 1.0 (/ 4.0 (/ y (- x z))))
(if (or (<= z 2.2e-37) (and (not (<= z 2.15e+16)) (<= z 3.85e+133)))
(+ 2.0 (* 4.0 (/ x y)))
(+ 2.0 (* (/ z y) -4.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e-36) {
tmp = 1.0 + (4.0 / (y / (x - z)));
} else if ((z <= 2.2e-37) || (!(z <= 2.15e+16) && (z <= 3.85e+133))) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
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 (z <= (-2.8d-36)) then
tmp = 1.0d0 + (4.0d0 / (y / (x - z)))
else if ((z <= 2.2d-37) .or. (.not. (z <= 2.15d+16)) .and. (z <= 3.85d+133)) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + ((z / y) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e-36) {
tmp = 1.0 + (4.0 / (y / (x - z)));
} else if ((z <= 2.2e-37) || (!(z <= 2.15e+16) && (z <= 3.85e+133))) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.8e-36: tmp = 1.0 + (4.0 / (y / (x - z))) elif (z <= 2.2e-37) or (not (z <= 2.15e+16) and (z <= 3.85e+133)): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + ((z / y) * -4.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.8e-36) tmp = Float64(1.0 + Float64(4.0 / Float64(y / Float64(x - z)))); elseif ((z <= 2.2e-37) || (!(z <= 2.15e+16) && (z <= 3.85e+133))) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.8e-36) tmp = 1.0 + (4.0 / (y / (x - z))); elseif ((z <= 2.2e-37) || (~((z <= 2.15e+16)) && (z <= 3.85e+133))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + ((z / y) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.8e-36], N[(1.0 + N[(4.0 / N[(y / N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, 2.2e-37], And[N[Not[LessEqual[z, 2.15e+16]], $MachinePrecision], LessEqual[z, 3.85e+133]]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-36}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-37} \lor \neg \left(z \leq 2.15 \cdot 10^{+16}\right) \land z \leq 3.85 \cdot 10^{+133}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
if z < -2.8000000000000001e-36Initial program 99.9%
associate-/l*99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in y around 0 92.2%
if -2.8000000000000001e-36 < z < 2.20000000000000002e-37 or 2.15e16 < z < 3.85e133Initial program 99.2%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 97.3%
if 2.20000000000000002e-37 < z < 2.15e16 or 3.85e133 < z Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.9%
*-commutative99.9%
+-commutative99.9%
fma-def99.9%
*-commutative99.9%
associate-*l*99.9%
associate-*r/99.9%
metadata-eval99.9%
rgt-mult-inverse99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 88.4%
+-commutative88.4%
*-commutative88.4%
Simplified88.4%
Final simplification93.8%
(FPCore (x y z) :precision binary64 (+ 1.0 (/ 4.0 (/ y (+ x (- (* y 0.25) z))))))
double code(double x, double y, double z) {
return 1.0 + (4.0 / (y / (x + ((y * 0.25) - z))));
}
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 / (y / (x + ((y * 0.25d0) - z))))
end function
public static double code(double x, double y, double z) {
return 1.0 + (4.0 / (y / (x + ((y * 0.25) - z))));
}
def code(x, y, z): return 1.0 + (4.0 / (y / (x + ((y * 0.25) - z))))
function code(x, y, z) return Float64(1.0 + Float64(4.0 / Float64(y / Float64(x + Float64(Float64(y * 0.25) - z))))) end
function tmp = code(x, y, z) tmp = 1.0 + (4.0 / (y / (x + ((y * 0.25) - z)))); end
code[x_, y_, z_] := N[(1.0 + N[(4.0 / N[(y / N[(x + N[(N[(y * 0.25), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4}{\frac{y}{x + \left(y \cdot 0.25 - z\right)}}
\end{array}
Initial program 99.6%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e+62) (not (<= x 1.15e-14))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+62) || !(x <= 1.15e-14)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
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 ((x <= (-2.9d+62)) .or. (.not. (x <= 1.15d-14))) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + ((z / y) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+62) || !(x <= 1.15e-14)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e+62) or not (x <= 1.15e-14): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + ((z / y) * -4.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e+62) || !(x <= 1.15e-14)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.9e+62) || ~((x <= 1.15e-14))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + ((z / y) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e+62], N[Not[LessEqual[x, 1.15e-14]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+62} \lor \neg \left(x \leq 1.15 \cdot 10^{-14}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
if x < -2.89999999999999984e62 or 1.14999999999999999e-14 < x Initial program 99.1%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r/99.7%
metadata-eval99.7%
rgt-mult-inverse99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 90.7%
if -2.89999999999999984e62 < x < 1.14999999999999999e-14Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 90.3%
+-commutative90.3%
*-commutative90.3%
Simplified90.3%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (+ 2.0 (* 4.0 (/ x y))))
double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 2.0d0 + (4.0d0 * (x / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
def code(x, y, z): return 2.0 + (4.0 * (x / y))
function code(x, y, z) return Float64(2.0 + Float64(4.0 * Float64(x / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (4.0 * (x / y)); end
code[x_, y_, z_] := N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + 4 \cdot \frac{x}{y}
\end{array}
Initial program 99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 68.0%
Final simplification68.0%
(FPCore (x y z) :precision binary64 2.0)
double code(double x, double y, double z) {
return 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 = 2.0d0
end function
public static double code(double x, double y, double z) {
return 2.0;
}
def code(x, y, z): return 2.0
function code(x, y, z) return 2.0 end
function tmp = code(x, y, z) tmp = 2.0; end
code[x_, y_, z_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 99.6%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 31.8%
Final simplification31.8%
herbie shell --seed 2023238
(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)))