
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (fma (- x y) (/ 4.0 z) -2.0))
double code(double x, double y, double z) {
return fma((x - y), (4.0 / z), -2.0);
}
function code(x, y, z) return fma(Float64(x - y), Float64(4.0 / z), -2.0) end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] * N[(4.0 / z), $MachinePrecision] + -2.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* -4.0 (/ y z))) (t_1 (* 4.0 (/ x z))))
(if (<= x -1.8e+155)
t_1
(if (<= x -1.96e-25)
-2.0
(if (<= x -2.95e-282)
t_0
(if (<= x 2.45e-241)
-2.0
(if (<= x 5e-203)
t_0
(if (<= x 1.4e-79)
-2.0
(if (<= x 5.6e+28) t_0 (if (<= x 3.3e+61) -2.0 t_1))))))))))
double code(double x, double y, double z) {
double t_0 = -4.0 * (y / z);
double t_1 = 4.0 * (x / z);
double tmp;
if (x <= -1.8e+155) {
tmp = t_1;
} else if (x <= -1.96e-25) {
tmp = -2.0;
} else if (x <= -2.95e-282) {
tmp = t_0;
} else if (x <= 2.45e-241) {
tmp = -2.0;
} else if (x <= 5e-203) {
tmp = t_0;
} else if (x <= 1.4e-79) {
tmp = -2.0;
} else if (x <= 5.6e+28) {
tmp = t_0;
} else if (x <= 3.3e+61) {
tmp = -2.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 = (-4.0d0) * (y / z)
t_1 = 4.0d0 * (x / z)
if (x <= (-1.8d+155)) then
tmp = t_1
else if (x <= (-1.96d-25)) then
tmp = -2.0d0
else if (x <= (-2.95d-282)) then
tmp = t_0
else if (x <= 2.45d-241) then
tmp = -2.0d0
else if (x <= 5d-203) then
tmp = t_0
else if (x <= 1.4d-79) then
tmp = -2.0d0
else if (x <= 5.6d+28) then
tmp = t_0
else if (x <= 3.3d+61) then
tmp = -2.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -4.0 * (y / z);
double t_1 = 4.0 * (x / z);
double tmp;
if (x <= -1.8e+155) {
tmp = t_1;
} else if (x <= -1.96e-25) {
tmp = -2.0;
} else if (x <= -2.95e-282) {
tmp = t_0;
} else if (x <= 2.45e-241) {
tmp = -2.0;
} else if (x <= 5e-203) {
tmp = t_0;
} else if (x <= 1.4e-79) {
tmp = -2.0;
} else if (x <= 5.6e+28) {
tmp = t_0;
} else if (x <= 3.3e+61) {
tmp = -2.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = -4.0 * (y / z) t_1 = 4.0 * (x / z) tmp = 0 if x <= -1.8e+155: tmp = t_1 elif x <= -1.96e-25: tmp = -2.0 elif x <= -2.95e-282: tmp = t_0 elif x <= 2.45e-241: tmp = -2.0 elif x <= 5e-203: tmp = t_0 elif x <= 1.4e-79: tmp = -2.0 elif x <= 5.6e+28: tmp = t_0 elif x <= 3.3e+61: tmp = -2.0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(-4.0 * Float64(y / z)) t_1 = Float64(4.0 * Float64(x / z)) tmp = 0.0 if (x <= -1.8e+155) tmp = t_1; elseif (x <= -1.96e-25) tmp = -2.0; elseif (x <= -2.95e-282) tmp = t_0; elseif (x <= 2.45e-241) tmp = -2.0; elseif (x <= 5e-203) tmp = t_0; elseif (x <= 1.4e-79) tmp = -2.0; elseif (x <= 5.6e+28) tmp = t_0; elseif (x <= 3.3e+61) tmp = -2.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -4.0 * (y / z); t_1 = 4.0 * (x / z); tmp = 0.0; if (x <= -1.8e+155) tmp = t_1; elseif (x <= -1.96e-25) tmp = -2.0; elseif (x <= -2.95e-282) tmp = t_0; elseif (x <= 2.45e-241) tmp = -2.0; elseif (x <= 5e-203) tmp = t_0; elseif (x <= 1.4e-79) tmp = -2.0; elseif (x <= 5.6e+28) tmp = t_0; elseif (x <= 3.3e+61) tmp = -2.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.8e+155], t$95$1, If[LessEqual[x, -1.96e-25], -2.0, If[LessEqual[x, -2.95e-282], t$95$0, If[LessEqual[x, 2.45e-241], -2.0, If[LessEqual[x, 5e-203], t$95$0, If[LessEqual[x, 1.4e-79], -2.0, If[LessEqual[x, 5.6e+28], t$95$0, If[LessEqual[x, 3.3e+61], -2.0, t$95$1]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -4 \cdot \frac{y}{z}\\
t_1 := 4 \cdot \frac{x}{z}\\
\mathbf{if}\;x \leq -1.8 \cdot 10^{+155}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.96 \cdot 10^{-25}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq -2.95 \cdot 10^{-282}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 2.45 \cdot 10^{-241}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-203}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-79}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{+28}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+61}:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -1.8e+155) (not (<= x 2.55e+60))) (* 4.0 (/ (- x y) z)) (- (* -4.0 (/ y z)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.8e+155) || !(x <= 2.55e+60)) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = (-4.0 * (y / z)) - 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 ((x <= (-1.8d+155)) .or. (.not. (x <= 2.55d+60))) then
tmp = 4.0d0 * ((x - y) / z)
else
tmp = ((-4.0d0) * (y / z)) - 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.8e+155) || !(x <= 2.55e+60)) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = (-4.0 * (y / z)) - 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.8e+155) or not (x <= 2.55e+60): tmp = 4.0 * ((x - y) / z) else: tmp = (-4.0 * (y / z)) - 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.8e+155) || !(x <= 2.55e+60)) tmp = Float64(4.0 * Float64(Float64(x - y) / z)); else tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.8e+155) || ~((x <= 2.55e+60))) tmp = 4.0 * ((x - y) / z); else tmp = (-4.0 * (y / z)) - 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.8e+155], N[Not[LessEqual[x, 2.55e+60]], $MachinePrecision]], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+155} \lor \neg \left(x \leq 2.55 \cdot 10^{+60}\right):\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -6.8e+131) -2.0 (if (<= z 7.2e+179) (* 4.0 (/ (- x y) z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+131) {
tmp = -2.0;
} else if (z <= 7.2e+179) {
tmp = 4.0 * ((x - y) / z);
} 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 <= (-6.8d+131)) then
tmp = -2.0d0
else if (z <= 7.2d+179) then
tmp = 4.0d0 * ((x - y) / z)
else
tmp = -2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+131) {
tmp = -2.0;
} else if (z <= 7.2e+179) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.8e+131: tmp = -2.0 elif z <= 7.2e+179: tmp = 4.0 * ((x - y) / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.8e+131) tmp = -2.0; elseif (z <= 7.2e+179) tmp = Float64(4.0 * Float64(Float64(x - y) / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.8e+131) tmp = -2.0; elseif (z <= 7.2e+179) tmp = 4.0 * ((x - y) / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.8e+131], -2.0, If[LessEqual[z, 7.2e+179], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], -2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{+131}:\\
\;\;\;\;-2\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{+179}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= x -1.28e+110) (- (* 4.0 (/ x z)) 2.0) (if (<= x 5e+60) (- (* -4.0 (/ y z)) 2.0) (* 4.0 (/ (- x y) z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.28e+110) {
tmp = (4.0 * (x / z)) - 2.0;
} else if (x <= 5e+60) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = 4.0 * ((x - y) / z);
}
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 <= (-1.28d+110)) then
tmp = (4.0d0 * (x / z)) - 2.0d0
else if (x <= 5d+60) then
tmp = ((-4.0d0) * (y / z)) - 2.0d0
else
tmp = 4.0d0 * ((x - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.28e+110) {
tmp = (4.0 * (x / z)) - 2.0;
} else if (x <= 5e+60) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = 4.0 * ((x - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.28e+110: tmp = (4.0 * (x / z)) - 2.0 elif x <= 5e+60: tmp = (-4.0 * (y / z)) - 2.0 else: tmp = 4.0 * ((x - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.28e+110) tmp = Float64(Float64(4.0 * Float64(x / z)) - 2.0); elseif (x <= 5e+60) tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); else tmp = Float64(4.0 * Float64(Float64(x - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.28e+110) tmp = (4.0 * (x / z)) - 2.0; elseif (x <= 5e+60) tmp = (-4.0 * (y / z)) - 2.0; else tmp = 4.0 * ((x - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.28e+110], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[x, 5e+60], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.28 \cdot 10^{+110}:\\
\;\;\;\;4 \cdot \frac{x}{z} - 2\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+60}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (* (/ 4.0 z) (+ (- x y) (* z -0.5))))
double code(double x, double y, double z) {
return (4.0 / z) * ((x - y) + (z * -0.5));
}
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) * ((x - y) + (z * (-0.5d0)))
end function
public static double code(double x, double y, double z) {
return (4.0 / z) * ((x - y) + (z * -0.5));
}
def code(x, y, z): return (4.0 / z) * ((x - y) + (z * -0.5))
function code(x, y, z) return Float64(Float64(4.0 / z) * Float64(Float64(x - y) + Float64(z * -0.5))) end
function tmp = code(x, y, z) tmp = (4.0 / z) * ((x - y) + (z * -0.5)); end
code[x_, y_, z_] := N[(N[(4.0 / z), $MachinePrecision] * N[(N[(x - y), $MachinePrecision] + N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot -0.5\right)
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -2.45e+51) (not (<= y 8.9e+21))) (* -4.0 (/ y z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e+51) || !(y <= 8.9e+21)) {
tmp = -4.0 * (y / z);
} 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 <= (-2.45d+51)) .or. (.not. (y <= 8.9d+21))) then
tmp = (-4.0d0) * (y / z)
else
tmp = -2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e+51) || !(y <= 8.9e+21)) {
tmp = -4.0 * (y / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.45e+51) or not (y <= 8.9e+21): tmp = -4.0 * (y / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.45e+51) || !(y <= 8.9e+21)) tmp = Float64(-4.0 * Float64(y / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.45e+51) || ~((y <= 8.9e+21))) tmp = -4.0 * (y / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.45e+51], N[Not[LessEqual[y, 8.9e+21]], $MachinePrecision]], N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{+51} \lor \neg \left(y \leq 8.9 \cdot 10^{+21}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z}\\
\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}
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
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)) - (2.0d0 + (4.0d0 * (y / z)))
end function
public static double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
def code(x, y, z): return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)))
function code(x, y, z) return Float64(Float64(4.0 * Float64(x / z)) - Float64(2.0 + Float64(4.0 * Float64(y / z)))) end
function tmp = code(x, y, z) tmp = (4.0 * (x / z)) - (2.0 + (4.0 * (y / z))); end
code[x_, y_, z_] := N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 + N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right)
\end{array}
herbie shell --seed 2024008
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:herbie-target
(- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))