
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ 4.0 (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - 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 = 4.0d0 + (4.0d0 * ((x - z) / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - z) / y));
}
def code(x, y, z): return 4.0 + (4.0 * ((x - z) / y))
function code(x, y, z) return Float64(4.0 + Float64(4.0 * Float64(Float64(x - z) / y))) end
function tmp = code(x, y, z) tmp = 4.0 + (4.0 * ((x - z) / y)); end
code[x_, y_, z_] := N[(4.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + 4 \cdot \frac{x - z}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.45e+87) (not (<= z 1.48e+85))) (+ 1.0 (/ -4.0 (/ y z))) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+87) || !(z <= 1.48e+85)) {
tmp = 1.0 + (-4.0 / (y / z));
} else {
tmp = 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 <= (-1.45d+87)) .or. (.not. (z <= 1.48d+85))) then
tmp = 1.0d0 + ((-4.0d0) / (y / z))
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+87) || !(z <= 1.48e+85)) {
tmp = 1.0 + (-4.0 / (y / z));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.45e+87) or not (z <= 1.48e+85): tmp = 1.0 + (-4.0 / (y / z)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e+87) || !(z <= 1.48e+85)) tmp = Float64(1.0 + Float64(-4.0 / Float64(y / z))); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.45e+87) || ~((z <= 1.48e+85))) tmp = 1.0 + (-4.0 / (y / z)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e+87], N[Not[LessEqual[z, 1.48e+85]], $MachinePrecision]], N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+87} \lor \neg \left(z \leq 1.48 \cdot 10^{+85}\right):\\
\;\;\;\;1 + \frac{-4}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if z < -1.4499999999999999e87 or 1.48e85 < z Initial program 100.0%
Taylor expanded in z around inf 70.0%
associate-*r/70.0%
associate-/l*69.9%
Simplified69.9%
if -1.4499999999999999e87 < z < 1.48e85Initial program 99.9%
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%
associate-*r*99.8%
associate-*l/99.9%
associate-/l*99.9%
*-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 45.3%
Final simplification54.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.7e+15) (not (<= z 3.2e+135))) (+ 4.0 (/ (* z -4.0) y)) (+ 4.0 (/ (* 4.0 x) y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.7e+15) || !(z <= 3.2e+135)) {
tmp = 4.0 + ((z * -4.0) / y);
} else {
tmp = 4.0 + ((4.0 * x) / 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
real(8) :: tmp
if ((z <= (-8.7d+15)) .or. (.not. (z <= 3.2d+135))) then
tmp = 4.0d0 + ((z * (-4.0d0)) / y)
else
tmp = 4.0d0 + ((4.0d0 * x) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.7e+15) || !(z <= 3.2e+135)) {
tmp = 4.0 + ((z * -4.0) / y);
} else {
tmp = 4.0 + ((4.0 * x) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.7e+15) or not (z <= 3.2e+135): tmp = 4.0 + ((z * -4.0) / y) else: tmp = 4.0 + ((4.0 * x) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.7e+15) || !(z <= 3.2e+135)) tmp = Float64(4.0 + Float64(Float64(z * -4.0) / y)); else tmp = Float64(4.0 + Float64(Float64(4.0 * x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.7e+15) || ~((z <= 3.2e+135))) tmp = 4.0 + ((z * -4.0) / y); else tmp = 4.0 + ((4.0 * x) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.7e+15], N[Not[LessEqual[z, 3.2e+135]], $MachinePrecision]], N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.7 \cdot 10^{+15} \lor \neg \left(z \leq 3.2 \cdot 10^{+135}\right):\\
\;\;\;\;4 + \frac{z \cdot -4}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + \frac{4 \cdot x}{y}\\
\end{array}
\end{array}
if z < -8.7e15 or 3.19999999999999975e135 < z Initial program 99.9%
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%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 86.7%
associate-*r/86.7%
Simplified86.7%
if -8.7e15 < z < 3.19999999999999975e135Initial program 99.9%
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%
associate-*r*99.8%
associate-*l/99.9%
associate-/l*99.9%
*-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in z around 0 90.9%
associate-*r/90.9%
Simplified90.9%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (+ 4.0 (/ (* z -4.0) y)))
double code(double x, double y, double z) {
return 4.0 + ((z * -4.0) / y);
}
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 + ((z * (-4.0d0)) / y)
end function
public static double code(double x, double y, double z) {
return 4.0 + ((z * -4.0) / y);
}
def code(x, y, z): return 4.0 + ((z * -4.0) / y)
function code(x, y, z) return Float64(4.0 + Float64(Float64(z * -4.0) / y)) end
function tmp = code(x, y, z) tmp = 4.0 + ((z * -4.0) / y); end
code[x_, y_, z_] := N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + \frac{z \cdot -4}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 63.8%
associate-*r/63.8%
Simplified63.8%
Final simplification63.8%
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
return 4.0;
}
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
end function
public static double code(double x, double y, double z) {
return 4.0;
}
def code(x, y, z): return 4.0
function code(x, y, z) return 4.0 end
function tmp = code(x, y, z) tmp = 4.0; end
code[x_, y_, z_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 34.7%
Final simplification34.7%
herbie shell --seed 2023242
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))