
(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 7 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 (* (/ 4.0 y) (- x z))))
double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
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 / y) * (x - z))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
def code(x, y, z): return 2.0 + ((4.0 / y) * (x - z))
function code(x, y, z) return Float64(2.0 + Float64(Float64(4.0 / y) * Float64(x - z))) end
function tmp = code(x, y, z) tmp = 2.0 + ((4.0 / y) * (x - z)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(4.0 / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{4}{y} \cdot \left(x - z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x y))) (t_1 (* (/ z y) -4.0)))
(if (<= x -2.25e+52)
t_0
(if (<= x -7.3e-143)
t_1
(if (<= x -5.1e-191)
2.0
(if (<= x -1.65e-279)
t_1
(if (<= x 5.5e-220) 2.0 (if (<= x 5e-70) t_1 t_0))))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / y);
double t_1 = (z / y) * -4.0;
double tmp;
if (x <= -2.25e+52) {
tmp = t_0;
} else if (x <= -7.3e-143) {
tmp = t_1;
} else if (x <= -5.1e-191) {
tmp = 2.0;
} else if (x <= -1.65e-279) {
tmp = t_1;
} else if (x <= 5.5e-220) {
tmp = 2.0;
} else if (x <= 5e-70) {
tmp = t_1;
} else {
tmp = t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / y)
t_1 = (z / y) * (-4.0d0)
if (x <= (-2.25d+52)) then
tmp = t_0
else if (x <= (-7.3d-143)) then
tmp = t_1
else if (x <= (-5.1d-191)) then
tmp = 2.0d0
else if (x <= (-1.65d-279)) then
tmp = t_1
else if (x <= 5.5d-220) then
tmp = 2.0d0
else if (x <= 5d-70) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (x / y);
double t_1 = (z / y) * -4.0;
double tmp;
if (x <= -2.25e+52) {
tmp = t_0;
} else if (x <= -7.3e-143) {
tmp = t_1;
} else if (x <= -5.1e-191) {
tmp = 2.0;
} else if (x <= -1.65e-279) {
tmp = t_1;
} else if (x <= 5.5e-220) {
tmp = 2.0;
} else if (x <= 5e-70) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / y) t_1 = (z / y) * -4.0 tmp = 0 if x <= -2.25e+52: tmp = t_0 elif x <= -7.3e-143: tmp = t_1 elif x <= -5.1e-191: tmp = 2.0 elif x <= -1.65e-279: tmp = t_1 elif x <= 5.5e-220: tmp = 2.0 elif x <= 5e-70: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / y)) t_1 = Float64(Float64(z / y) * -4.0) tmp = 0.0 if (x <= -2.25e+52) tmp = t_0; elseif (x <= -7.3e-143) tmp = t_1; elseif (x <= -5.1e-191) tmp = 2.0; elseif (x <= -1.65e-279) tmp = t_1; elseif (x <= 5.5e-220) tmp = 2.0; elseif (x <= 5e-70) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / y); t_1 = (z / y) * -4.0; tmp = 0.0; if (x <= -2.25e+52) tmp = t_0; elseif (x <= -7.3e-143) tmp = t_1; elseif (x <= -5.1e-191) tmp = 2.0; elseif (x <= -1.65e-279) tmp = t_1; elseif (x <= 5.5e-220) tmp = 2.0; elseif (x <= 5e-70) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]}, If[LessEqual[x, -2.25e+52], t$95$0, If[LessEqual[x, -7.3e-143], t$95$1, If[LessEqual[x, -5.1e-191], 2.0, If[LessEqual[x, -1.65e-279], t$95$1, If[LessEqual[x, 5.5e-220], 2.0, If[LessEqual[x, 5e-70], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
t_1 := \frac{z}{y} \cdot -4\\
\mathbf{if}\;x \leq -2.25 \cdot 10^{+52}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -7.3 \cdot 10^{-143}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -5.1 \cdot 10^{-191}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq -1.65 \cdot 10^{-279}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-220}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-70}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (or (<= x -3.4e+94)
(and (not (<= x -3.2)) (or (<= x -3.2e-67) (not (<= x 4e-54)))))
(* 4.0 (/ (- x z) y))
(+ 2.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e+94) || (!(x <= -3.2) && ((x <= -3.2e-67) || !(x <= 4e-54)))) {
tmp = 4.0 * ((x - z) / 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.4d+94)) .or. (.not. (x <= (-3.2d0))) .and. (x <= (-3.2d-67)) .or. (.not. (x <= 4d-54))) then
tmp = 4.0d0 * ((x - z) / 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.4e+94) || (!(x <= -3.2) && ((x <= -3.2e-67) || !(x <= 4e-54)))) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e+94) or (not (x <= -3.2) and ((x <= -3.2e-67) or not (x <= 4e-54))): tmp = 4.0 * ((x - z) / y) else: tmp = 2.0 + ((z / y) * -4.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e+94) || (!(x <= -3.2) && ((x <= -3.2e-67) || !(x <= 4e-54)))) tmp = Float64(4.0 * Float64(Float64(x - z) / 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 <= -3.4e+94) || (~((x <= -3.2)) && ((x <= -3.2e-67) || ~((x <= 4e-54))))) tmp = 4.0 * ((x - z) / y); else tmp = 2.0 + ((z / y) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e+94], And[N[Not[LessEqual[x, -3.2]], $MachinePrecision], Or[LessEqual[x, -3.2e-67], N[Not[LessEqual[x, 4e-54]], $MachinePrecision]]]], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+94} \lor \neg \left(x \leq -3.2\right) \land \left(x \leq -3.2 \cdot 10^{-67} \lor \neg \left(x \leq 4 \cdot 10^{-54}\right)\right):\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -3.2e+143) 2.0 (if (<= y 6.2e+198) (* 4.0 (/ (- x z) y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+143) {
tmp = 2.0;
} else if (y <= 6.2e+198) {
tmp = 4.0 * ((x - 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 <= (-3.2d+143)) then
tmp = 2.0d0
else if (y <= 6.2d+198) then
tmp = 4.0d0 * ((x - 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 <= -3.2e+143) {
tmp = 2.0;
} else if (y <= 6.2e+198) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+143: tmp = 2.0 elif y <= 6.2e+198: tmp = 4.0 * ((x - z) / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e+143) tmp = 2.0; elseif (y <= 6.2e+198) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.2e+143) tmp = 2.0; elseif (y <= 6.2e+198) tmp = 4.0 * ((x - z) / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e+143], 2.0, If[LessEqual[y, 6.2e+198], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+143}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+198}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -7.2e+34) (* 4.0 (/ (- x z) y)) (if (<= z 2.8e+53) (+ 2.0 (/ (* 4.0 x) y)) (+ 2.0 (* (/ z y) -4.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e+34) {
tmp = 4.0 * ((x - z) / y);
} else if (z <= 2.8e+53) {
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 <= (-7.2d+34)) then
tmp = 4.0d0 * ((x - z) / y)
else if (z <= 2.8d+53) 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 <= -7.2e+34) {
tmp = 4.0 * ((x - z) / y);
} else if (z <= 2.8e+53) {
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 <= -7.2e+34: tmp = 4.0 * ((x - z) / y) elif z <= 2.8e+53: 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 <= -7.2e+34) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); elseif (z <= 2.8e+53) tmp = Float64(2.0 + Float64(Float64(4.0 * 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 <= -7.2e+34) tmp = 4.0 * ((x - z) / y); elseif (z <= 2.8e+53) 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, -7.2e+34], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.8e+53], N[(2.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{+34}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{+53}:\\
\;\;\;\;2 + \frac{4 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e+34) (not (<= z 2.3e+49))) (* (/ z y) -4.0) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+34) || !(z <= 2.3e+49)) {
tmp = (z / y) * -4.0;
} 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 ((z <= (-3.3d+34)) .or. (.not. (z <= 2.3d+49))) then
tmp = (z / y) * (-4.0d0)
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+34) || !(z <= 2.3e+49)) {
tmp = (z / y) * -4.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e+34) or not (z <= 2.3e+49): tmp = (z / y) * -4.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e+34) || !(z <= 2.3e+49)) tmp = Float64(Float64(z / y) * -4.0); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e+34) || ~((z <= 2.3e+49))) tmp = (z / y) * -4.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e+34], N[Not[LessEqual[z, 2.3e+49]], $MachinePrecision]], N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+34} \lor \neg \left(z \leq 2.3 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\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 2024008
(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)))