
(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 y) -4.0))) (t_1 (* 4.0 (/ x y))))
(if (<= y -12200000.0)
2.0
(if (<= y -8.2e-281)
t_1
(if (<= y 9.5e-248)
t_0
(if (<= y 3.6e-144)
t_1
(if (<= y 1.05e-97) t_0 (if (<= y 1.2e-8) t_1 2.0))))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + ((z / y) * -4.0);
double t_1 = 4.0 * (x / y);
double tmp;
if (y <= -12200000.0) {
tmp = 2.0;
} else if (y <= -8.2e-281) {
tmp = t_1;
} else if (y <= 9.5e-248) {
tmp = t_0;
} else if (y <= 3.6e-144) {
tmp = t_1;
} else if (y <= 1.05e-97) {
tmp = t_0;
} else if (y <= 1.2e-8) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + ((z / y) * (-4.0d0))
t_1 = 4.0d0 * (x / y)
if (y <= (-12200000.0d0)) then
tmp = 2.0d0
else if (y <= (-8.2d-281)) then
tmp = t_1
else if (y <= 9.5d-248) then
tmp = t_0
else if (y <= 3.6d-144) then
tmp = t_1
else if (y <= 1.05d-97) then
tmp = t_0
else if (y <= 1.2d-8) then
tmp = t_1
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 / y) * -4.0);
double t_1 = 4.0 * (x / y);
double tmp;
if (y <= -12200000.0) {
tmp = 2.0;
} else if (y <= -8.2e-281) {
tmp = t_1;
} else if (y <= 9.5e-248) {
tmp = t_0;
} else if (y <= 3.6e-144) {
tmp = t_1;
} else if (y <= 1.05e-97) {
tmp = t_0;
} else if (y <= 1.2e-8) {
tmp = t_1;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + ((z / y) * -4.0) t_1 = 4.0 * (x / y) tmp = 0 if y <= -12200000.0: tmp = 2.0 elif y <= -8.2e-281: tmp = t_1 elif y <= 9.5e-248: tmp = t_0 elif y <= 3.6e-144: tmp = t_1 elif y <= 1.05e-97: tmp = t_0 elif y <= 1.2e-8: tmp = t_1 else: tmp = 2.0 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(Float64(z / y) * -4.0)) t_1 = Float64(4.0 * Float64(x / y)) tmp = 0.0 if (y <= -12200000.0) tmp = 2.0; elseif (y <= -8.2e-281) tmp = t_1; elseif (y <= 9.5e-248) tmp = t_0; elseif (y <= 3.6e-144) tmp = t_1; elseif (y <= 1.05e-97) tmp = t_0; elseif (y <= 1.2e-8) tmp = t_1; else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + ((z / y) * -4.0); t_1 = 4.0 * (x / y); tmp = 0.0; if (y <= -12200000.0) tmp = 2.0; elseif (y <= -8.2e-281) tmp = t_1; elseif (y <= 9.5e-248) tmp = t_0; elseif (y <= 3.6e-144) tmp = t_1; elseif (y <= 1.05e-97) tmp = t_0; elseif (y <= 1.2e-8) tmp = t_1; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -12200000.0], 2.0, If[LessEqual[y, -8.2e-281], t$95$1, If[LessEqual[y, 9.5e-248], t$95$0, If[LessEqual[y, 3.6e-144], t$95$1, If[LessEqual[y, 1.05e-97], t$95$0, If[LessEqual[y, 1.2e-8], t$95$1, 2.0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{z}{y} \cdot -4\\
t_1 := 4 \cdot \frac{x}{y}\\
\mathbf{if}\;y \leq -12200000:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq -8.2 \cdot 10^{-281}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-248}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-144}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-97}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-8}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.22e7 or 1.19999999999999999e-8 < y Initial program 100.0%
Taylor expanded in y around inf 65.0%
if -1.22e7 < y < -8.1999999999999998e-281 or 9.49999999999999971e-248 < y < 3.6e-144 or 1.0500000000000001e-97 < y < 1.19999999999999999e-8Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
Taylor expanded in z around 0 67.7%
+-commutative67.7%
Simplified67.7%
Taylor expanded in x around inf 63.2%
if -8.1999999999999998e-281 < y < 9.49999999999999971e-248 or 3.6e-144 < y < 1.0500000000000001e-97Initial program 99.9%
Taylor expanded in z around inf 71.3%
*-commutative71.3%
Simplified71.3%
Final simplification64.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.7e+213) (not (<= z 2.7e+81))) (+ 1.0 (* (/ z y) -4.0)) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+213) || !(z <= 2.7e+81)) {
tmp = 1.0 + ((z / y) * -4.0);
} 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 <= (-3.7d+213)) .or. (.not. (z <= 2.7d+81))) then
tmp = 1.0d0 + ((z / y) * (-4.0d0))
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 <= -3.7e+213) || !(z <= 2.7e+81)) {
tmp = 1.0 + ((z / y) * -4.0);
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7e+213) or not (z <= 2.7e+81): tmp = 1.0 + ((z / y) * -4.0) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7e+213) || !(z <= 2.7e+81)) tmp = Float64(1.0 + Float64(Float64(z / y) * -4.0)); 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 <= -3.7e+213) || ~((z <= 2.7e+81))) tmp = 1.0 + ((z / y) * -4.0); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7e+213], N[Not[LessEqual[z, 2.7e+81]], $MachinePrecision]], N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+213} \lor \neg \left(z \leq 2.7 \cdot 10^{+81}\right):\\
\;\;\;\;1 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.69999999999999993e213 or 2.6999999999999999e81 < z Initial program 100.0%
Taylor expanded in z around inf 84.7%
*-commutative84.7%
Simplified84.7%
if -3.69999999999999993e213 < z < 2.6999999999999999e81Initial program 100.0%
associate-*l/99.3%
+-commutative99.3%
associate--l+99.3%
distribute-lft-in99.3%
associate-+r+99.3%
Simplified99.3%
Taylor expanded in z around 0 88.1%
+-commutative88.1%
Simplified88.1%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.7e+213) (not (<= z 1.2e+78))) (+ 2.0 (* (/ z y) -4.0)) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+213) || !(z <= 1.2e+78)) {
tmp = 2.0 + ((z / y) * -4.0);
} 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 <= (-3.7d+213)) .or. (.not. (z <= 1.2d+78))) then
tmp = 2.0d0 + ((z / y) * (-4.0d0))
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 <= -3.7e+213) || !(z <= 1.2e+78)) {
tmp = 2.0 + ((z / y) * -4.0);
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7e+213) or not (z <= 1.2e+78): tmp = 2.0 + ((z / y) * -4.0) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7e+213) || !(z <= 1.2e+78)) tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); 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 <= -3.7e+213) || ~((z <= 1.2e+78))) tmp = 2.0 + ((z / y) * -4.0); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7e+213], N[Not[LessEqual[z, 1.2e+78]], $MachinePrecision]], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+213} \lor \neg \left(z \leq 1.2 \cdot 10^{+78}\right):\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.69999999999999993e213 or 1.1999999999999999e78 < z Initial program 100.0%
associate-*l/99.9%
+-commutative99.9%
associate--l+99.9%
distribute-lft-in99.9%
associate-+r+99.9%
Simplified99.9%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
if -3.69999999999999993e213 < z < 1.1999999999999999e78Initial program 100.0%
associate-*l/99.3%
+-commutative99.3%
associate--l+99.3%
distribute-lft-in99.3%
associate-+r+99.3%
Simplified99.3%
Taylor expanded in z around 0 88.1%
+-commutative88.1%
Simplified88.1%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (<= y -16000000.0) 2.0 (if (<= y 1.4e-8) (* 4.0 (/ x y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -16000000.0) {
tmp = 2.0;
} else if (y <= 1.4e-8) {
tmp = 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 <= (-16000000.0d0)) then
tmp = 2.0d0
else if (y <= 1.4d-8) then
tmp = 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 <= -16000000.0) {
tmp = 2.0;
} else if (y <= 1.4e-8) {
tmp = 4.0 * (x / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -16000000.0: tmp = 2.0 elif y <= 1.4e-8: tmp = 4.0 * (x / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -16000000.0) tmp = 2.0; elseif (y <= 1.4e-8) tmp = Float64(4.0 * Float64(x / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -16000000.0) tmp = 2.0; elseif (y <= 1.4e-8) tmp = 4.0 * (x / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -16000000.0], 2.0, If[LessEqual[y, 1.4e-8], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000000:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-8}:\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.6e7 or 1.4e-8 < y Initial program 100.0%
Taylor expanded in y around inf 65.0%
if -1.6e7 < y < 1.4e-8Initial program 100.0%
associate-*l/98.9%
+-commutative98.9%
associate--l+98.9%
distribute-lft-in98.9%
associate-+r+98.9%
Simplified98.9%
Taylor expanded in z around 0 61.1%
+-commutative61.1%
Simplified61.1%
Taylor expanded in x around inf 57.3%
Final simplification61.6%
(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.4%
+-commutative99.4%
associate--l+99.4%
distribute-lft-in99.4%
associate-+r+99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
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
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 35.9%
*-commutative35.9%
Simplified35.9%
Taylor expanded in z around 0 8.8%
Final simplification8.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 39.2%
Final simplification39.2%
herbie shell --seed 2023290
(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)))