
(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 (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (* z -4.0) y))))
(if (<= y -1.48e+53)
2.0
(if (<= y -9.5e-56)
t_0
(if (<= y 8.5e-285)
(+ 1.0 (/ (* 4.0 x) y))
(if (<= y 3.9e+79) t_0 2.0))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + ((z * -4.0) / y);
double tmp;
if (y <= -1.48e+53) {
tmp = 2.0;
} else if (y <= -9.5e-56) {
tmp = t_0;
} else if (y <= 8.5e-285) {
tmp = 1.0 + ((4.0 * x) / y);
} else if (y <= 3.9e+79) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((z * (-4.0d0)) / y)
if (y <= (-1.48d+53)) then
tmp = 2.0d0
else if (y <= (-9.5d-56)) then
tmp = t_0
else if (y <= 8.5d-285) then
tmp = 1.0d0 + ((4.0d0 * x) / y)
else if (y <= 3.9d+79) then
tmp = t_0
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + ((z * -4.0) / y);
double tmp;
if (y <= -1.48e+53) {
tmp = 2.0;
} else if (y <= -9.5e-56) {
tmp = t_0;
} else if (y <= 8.5e-285) {
tmp = 1.0 + ((4.0 * x) / y);
} else if (y <= 3.9e+79) {
tmp = t_0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + ((z * -4.0) / y) tmp = 0 if y <= -1.48e+53: tmp = 2.0 elif y <= -9.5e-56: tmp = t_0 elif y <= 8.5e-285: tmp = 1.0 + ((4.0 * x) / y) elif y <= 3.9e+79: tmp = t_0 else: tmp = 2.0 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(Float64(z * -4.0) / y)) tmp = 0.0 if (y <= -1.48e+53) tmp = 2.0; elseif (y <= -9.5e-56) tmp = t_0; elseif (y <= 8.5e-285) tmp = Float64(1.0 + Float64(Float64(4.0 * x) / y)); elseif (y <= 3.9e+79) tmp = t_0; else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + ((z * -4.0) / y); tmp = 0.0; if (y <= -1.48e+53) tmp = 2.0; elseif (y <= -9.5e-56) tmp = t_0; elseif (y <= 8.5e-285) tmp = 1.0 + ((4.0 * x) / y); elseif (y <= 3.9e+79) tmp = t_0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.48e+53], 2.0, If[LessEqual[y, -9.5e-56], t$95$0, If[LessEqual[y, 8.5e-285], N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.9e+79], t$95$0, 2.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{z \cdot -4}{y}\\
\mathbf{if}\;y \leq -1.48 \cdot 10^{+53}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-56}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-285}:\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.48e53 or 3.8999999999999997e79 < y Initial program 100.0%
Taylor expanded in y around inf 74.9%
if -1.48e53 < y < -9.4999999999999991e-56 or 8.49999999999999979e-285 < y < 3.8999999999999997e79Initial program 100.0%
Taylor expanded in z around inf 58.3%
*-commutative58.3%
associate-*l/58.3%
Simplified58.3%
if -9.4999999999999991e-56 < y < 8.49999999999999979e-285Initial program 100.0%
Taylor expanded in x around inf 66.3%
associate-*r/66.3%
Simplified66.3%
Final simplification65.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e+84) (not (<= x 5.3e+107))) (+ 1.0 (/ (* 4.0 x) y)) (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+84) || !(x <= 5.3e+107)) {
tmp = 1.0 + ((4.0 * x) / y);
} else {
tmp = 2.0 + (-4.0 * (z / 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 ((x <= (-1.5d+84)) .or. (.not. (x <= 5.3d+107))) then
tmp = 1.0d0 + ((4.0d0 * x) / y)
else
tmp = 2.0d0 + ((-4.0d0) * (z / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+84) || !(x <= 5.3e+107)) {
tmp = 1.0 + ((4.0 * x) / y);
} else {
tmp = 2.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e+84) or not (x <= 5.3e+107): tmp = 1.0 + ((4.0 * x) / y) else: tmp = 2.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e+84) || !(x <= 5.3e+107)) tmp = Float64(1.0 + Float64(Float64(4.0 * x) / y)); else tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e+84) || ~((x <= 5.3e+107))) tmp = 1.0 + ((4.0 * x) / y); else tmp = 2.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e+84], N[Not[LessEqual[x, 5.3e+107]], $MachinePrecision]], N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+84} \lor \neg \left(x \leq 5.3 \cdot 10^{+107}\right):\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -1.49999999999999998e84 or 5.3e107 < x Initial program 100.0%
Taylor expanded in x around inf 79.5%
associate-*r/79.5%
Simplified79.5%
if -1.49999999999999998e84 < x < 5.3e107Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
associate-*l/100.0%
associate-/l*99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 86.7%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.1e+62) (not (<= x 1.05e-40))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.1e+62) || !(x <= 1.05e-40)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (-4.0 * (z / 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 ((x <= (-8.1d+62)) .or. (.not. (x <= 1.05d-40))) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + ((-4.0d0) * (z / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.1e+62) || !(x <= 1.05e-40)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.1e+62) or not (x <= 1.05e-40): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.1e+62) || !(x <= 1.05e-40)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.1e+62) || ~((x <= 1.05e-40))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.1e+62], N[Not[LessEqual[x, 1.05e-40]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.1 \cdot 10^{+62} \lor \neg \left(x \leq 1.05 \cdot 10^{-40}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -8.09999999999999998e62 or 1.05000000000000009e-40 < x Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
associate-*l/100.0%
associate-/l*99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 87.5%
clear-num87.5%
associate-/r/87.5%
clear-num87.6%
Applied egg-rr87.6%
if -8.09999999999999998e62 < x < 1.05000000000000009e-40Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
associate-*l/100.0%
associate-/l*99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 92.3%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (<= y -4.7e-17) 2.0 (if (<= y 8e-41) (+ 1.0 (* x (/ 4.0 y))) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.7e-17) {
tmp = 2.0;
} else if (y <= 8e-41) {
tmp = 1.0 + (x * (4.0 / 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 <= (-4.7d-17)) then
tmp = 2.0d0
else if (y <= 8d-41) then
tmp = 1.0d0 + (x * (4.0d0 / 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 <= -4.7e-17) {
tmp = 2.0;
} else if (y <= 8e-41) {
tmp = 1.0 + (x * (4.0 / y));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.7e-17: tmp = 2.0 elif y <= 8e-41: tmp = 1.0 + (x * (4.0 / y)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.7e-17) tmp = 2.0; elseif (y <= 8e-41) tmp = Float64(1.0 + Float64(x * Float64(4.0 / y))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.7e-17) tmp = 2.0; elseif (y <= 8e-41) tmp = 1.0 + (x * (4.0 / y)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.7e-17], 2.0, If[LessEqual[y, 8e-41], N[(1.0 + N[(x * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.7 \cdot 10^{-17}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-41}:\\
\;\;\;\;1 + x \cdot \frac{4}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -4.7e-17 or 8.00000000000000005e-41 < y Initial program 100.0%
Taylor expanded in y around inf 61.6%
if -4.7e-17 < y < 8.00000000000000005e-41Initial program 100.0%
Taylor expanded in x around inf 52.0%
associate-*r/52.0%
associate-*l/51.9%
*-commutative51.9%
Simplified51.9%
Final simplification56.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-14) 2.0 (if (<= y 2.9e-40) (+ 1.0 (/ (* 4.0 x) y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-14) {
tmp = 2.0;
} else if (y <= 2.9e-40) {
tmp = 1.0 + ((4.0 * x) / 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 <= (-1.9d-14)) then
tmp = 2.0d0
else if (y <= 2.9d-40) then
tmp = 1.0d0 + ((4.0d0 * x) / 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 <= -1.9e-14) {
tmp = 2.0;
} else if (y <= 2.9e-40) {
tmp = 1.0 + ((4.0 * x) / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-14: tmp = 2.0 elif y <= 2.9e-40: tmp = 1.0 + ((4.0 * x) / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-14) tmp = 2.0; elseif (y <= 2.9e-40) tmp = Float64(1.0 + Float64(Float64(4.0 * x) / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e-14) tmp = 2.0; elseif (y <= 2.9e-40) tmp = 1.0 + ((4.0 * x) / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-14], 2.0, If[LessEqual[y, 2.9e-40], N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-14}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-40}:\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.9000000000000001e-14 or 2.8999999999999999e-40 < y Initial program 100.0%
Taylor expanded in y around inf 61.6%
if -1.9000000000000001e-14 < y < 2.8999999999999999e-40Initial program 100.0%
Taylor expanded in x around inf 52.0%
associate-*r/52.0%
Simplified52.0%
Final simplification56.5%
(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}
Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
Final simplification99.8%
(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 100.0%
Taylor expanded in y around inf 34.1%
Final simplification34.1%
herbie shell --seed 2024036
(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)))