
(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 8 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 (+ 2.0 (/ (- x z) (* y 0.25))))
double code(double x, double y, double z) {
return 2.0 + ((x - z) / (y * 0.25));
}
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 + ((x - z) / (y * 0.25d0))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) / (y * 0.25));
}
def code(x, y, z): return 2.0 + ((x - z) / (y * 0.25))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) / Float64(y * 0.25))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) / (y * 0.25)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] / N[(y * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{x - z}{y \cdot 0.25}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (/ 4.0 (/ y x)))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
(if (<= z -2.6e+105)
t_1
(if (<= z -60000000000.0)
2.0
(if (<= z -8.4e-302)
t_0
(if (<= z 5.5e-199) 2.0 (if (<= z 1e+37) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (4.0 / (y / x));
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.6e+105) {
tmp = t_1;
} else if (z <= -60000000000.0) {
tmp = 2.0;
} else if (z <= -8.4e-302) {
tmp = t_0;
} else if (z <= 5.5e-199) {
tmp = 2.0;
} else if (z <= 1e+37) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + (4.0d0 / (y / x))
t_1 = 1.0d0 + ((-4.0d0) * (z / y))
if (z <= (-2.6d+105)) then
tmp = t_1
else if (z <= (-60000000000.0d0)) then
tmp = 2.0d0
else if (z <= (-8.4d-302)) then
tmp = t_0
else if (z <= 5.5d-199) then
tmp = 2.0d0
else if (z <= 1d+37) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (4.0 / (y / x));
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.6e+105) {
tmp = t_1;
} else if (z <= -60000000000.0) {
tmp = 2.0;
} else if (z <= -8.4e-302) {
tmp = t_0;
} else if (z <= 5.5e-199) {
tmp = 2.0;
} else if (z <= 1e+37) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (4.0 / (y / x)) t_1 = 1.0 + (-4.0 * (z / y)) tmp = 0 if z <= -2.6e+105: tmp = t_1 elif z <= -60000000000.0: tmp = 2.0 elif z <= -8.4e-302: tmp = t_0 elif z <= 5.5e-199: tmp = 2.0 elif z <= 1e+37: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(4.0 / Float64(y / x))) t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y))) tmp = 0.0 if (z <= -2.6e+105) tmp = t_1; elseif (z <= -60000000000.0) tmp = 2.0; elseif (z <= -8.4e-302) tmp = t_0; elseif (z <= 5.5e-199) tmp = 2.0; elseif (z <= 1e+37) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (4.0 / (y / x)); t_1 = 1.0 + (-4.0 * (z / y)); tmp = 0.0; if (z <= -2.6e+105) tmp = t_1; elseif (z <= -60000000000.0) tmp = 2.0; elseif (z <= -8.4e-302) tmp = t_0; elseif (z <= 5.5e-199) tmp = 2.0; elseif (z <= 1e+37) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.6e+105], t$95$1, If[LessEqual[z, -60000000000.0], 2.0, If[LessEqual[z, -8.4e-302], t$95$0, If[LessEqual[z, 5.5e-199], 2.0, If[LessEqual[z, 1e+37], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{4}{\frac{y}{x}}\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -2.6 \cdot 10^{+105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -60000000000:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq -8.4 \cdot 10^{-302}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-199}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq 10^{+37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (* x 4.0) y))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
(if (<= z -2.3e+105)
t_1
(if (<= z -2000000000.0)
2.0
(if (<= z -2.9e-302)
t_0
(if (<= z 1.02e-198) 2.0 (if (<= z 3.7e+37) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + ((x * 4.0) / y);
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.3e+105) {
tmp = t_1;
} else if (z <= -2000000000.0) {
tmp = 2.0;
} else if (z <= -2.9e-302) {
tmp = t_0;
} else if (z <= 1.02e-198) {
tmp = 2.0;
} else if (z <= 3.7e+37) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + ((x * 4.0d0) / y)
t_1 = 1.0d0 + ((-4.0d0) * (z / y))
if (z <= (-2.3d+105)) then
tmp = t_1
else if (z <= (-2000000000.0d0)) then
tmp = 2.0d0
else if (z <= (-2.9d-302)) then
tmp = t_0
else if (z <= 1.02d-198) then
tmp = 2.0d0
else if (z <= 3.7d+37) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + ((x * 4.0) / y);
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.3e+105) {
tmp = t_1;
} else if (z <= -2000000000.0) {
tmp = 2.0;
} else if (z <= -2.9e-302) {
tmp = t_0;
} else if (z <= 1.02e-198) {
tmp = 2.0;
} else if (z <= 3.7e+37) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + ((x * 4.0) / y) t_1 = 1.0 + (-4.0 * (z / y)) tmp = 0 if z <= -2.3e+105: tmp = t_1 elif z <= -2000000000.0: tmp = 2.0 elif z <= -2.9e-302: tmp = t_0 elif z <= 1.02e-198: tmp = 2.0 elif z <= 3.7e+37: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(Float64(x * 4.0) / y)) t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y))) tmp = 0.0 if (z <= -2.3e+105) tmp = t_1; elseif (z <= -2000000000.0) tmp = 2.0; elseif (z <= -2.9e-302) tmp = t_0; elseif (z <= 1.02e-198) tmp = 2.0; elseif (z <= 3.7e+37) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + ((x * 4.0) / y); t_1 = 1.0 + (-4.0 * (z / y)); tmp = 0.0; if (z <= -2.3e+105) tmp = t_1; elseif (z <= -2000000000.0) tmp = 2.0; elseif (z <= -2.9e-302) tmp = t_0; elseif (z <= 1.02e-198) tmp = 2.0; elseif (z <= 3.7e+37) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(x * 4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.3e+105], t$95$1, If[LessEqual[z, -2000000000.0], 2.0, If[LessEqual[z, -2.9e-302], t$95$0, If[LessEqual[z, 1.02e-198], 2.0, If[LessEqual[z, 3.7e+37], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x \cdot 4}{y}\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -2.3 \cdot 10^{+105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -2000000000:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-302}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{-198}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{+37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -7e+144) (not (<= z 1.9e+61))) (+ 1.0 (* -4.0 (/ z y))) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e+144) || !(z <= 1.9e+61)) {
tmp = 1.0 + (-4.0 * (z / y));
} else {
tmp = 2.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 <= (-7d+144)) .or. (.not. (z <= 1.9d+61))) then
tmp = 1.0d0 + ((-4.0d0) * (z / y))
else
tmp = 2.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 <= -7e+144) || !(z <= 1.9e+61)) {
tmp = 1.0 + (-4.0 * (z / y));
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7e+144) or not (z <= 1.9e+61): tmp = 1.0 + (-4.0 * (z / y)) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7e+144) || !(z <= 1.9e+61)) tmp = Float64(1.0 + Float64(-4.0 * Float64(z / y))); else tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7e+144) || ~((z <= 1.9e+61))) tmp = 1.0 + (-4.0 * (z / y)); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7e+144], N[Not[LessEqual[z, 1.9e+61]], $MachinePrecision]], N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+144} \lor \neg \left(z \leq 1.9 \cdot 10^{+61}\right):\\
\;\;\;\;1 + -4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e+46) (not (<= x 7.8e+54))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (/ z (/ y -4.0)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+46) || !(x <= 7.8e+54)) {
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 <= (-3.9d+46)) .or. (.not. (x <= 7.8d+54))) 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 <= -3.9e+46) || !(x <= 7.8e+54)) {
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 <= -3.9e+46) or not (x <= 7.8e+54): 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 <= -3.9e+46) || !(x <= 7.8e+54)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(z / Float64(y / -4.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.9e+46) || ~((x <= 7.8e+54))) 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, -3.9e+46], N[Not[LessEqual[x, 7.8e+54]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(z / N[(y / -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+46} \lor \neg \left(x \leq 7.8 \cdot 10^{+54}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{\frac{y}{-4}}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -8.5e+159) 2.0 (if (<= y 6.4e+72) (+ 1.0 (* -4.0 (/ z y))) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e+159) {
tmp = 2.0;
} else if (y <= 6.4e+72) {
tmp = 1.0 + (-4.0 * (z / y));
} else {
tmp = 2.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 (y <= (-8.5d+159)) then
tmp = 2.0d0
else if (y <= 6.4d+72) then
tmp = 1.0d0 + ((-4.0d0) * (z / y))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e+159) {
tmp = 2.0;
} else if (y <= 6.4e+72) {
tmp = 1.0 + (-4.0 * (z / y));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e+159: tmp = 2.0 elif y <= 6.4e+72: tmp = 1.0 + (-4.0 * (z / y)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e+159) tmp = 2.0; elseif (y <= 6.4e+72) tmp = Float64(1.0 + Float64(-4.0 * Float64(z / y))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.5e+159) tmp = 2.0; elseif (y <= 6.4e+72) tmp = 1.0 + (-4.0 * (z / y)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e+159], 2.0, If[LessEqual[y, 6.4e+72], N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+159}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+72}:\\
\;\;\;\;1 + -4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (+ 2.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 2.0 + ((x - 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 = 2.0d0 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 2.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
(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}
herbie shell --seed 2023343
(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)))