
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ 4.0 (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - 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 = 4.0d0 + (4.0d0 * ((x - z) / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - z) / y));
}
def code(x, y, z): return 4.0 + (4.0 * ((x - z) / y))
function code(x, y, z) return Float64(4.0 + Float64(4.0 * Float64(Float64(x - z) / y))) end
function tmp = code(x, y, z) tmp = 4.0 + (4.0 * ((x - z) / y)); end
code[x_, y_, z_] := N[(4.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + 4 \cdot \frac{x - z}{y}
\end{array}
Initial program 99.6%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6.2e+128)
(and (not (<= x 3.5e-94)) (or (<= x 1.06e-13) (not (<= x 1.3e+107)))))
(+ 1.0 (* 4.0 (/ x y)))
(+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e+128) || (!(x <= 3.5e-94) && ((x <= 1.06e-13) || !(x <= 1.3e+107)))) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.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 <= (-6.2d+128)) .or. (.not. (x <= 3.5d-94)) .and. (x <= 1.06d-13) .or. (.not. (x <= 1.3d+107))) then
tmp = 1.0d0 + (4.0d0 * (x / y))
else
tmp = 4.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 <= -6.2e+128) || (!(x <= 3.5e-94) && ((x <= 1.06e-13) || !(x <= 1.3e+107)))) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e+128) or (not (x <= 3.5e-94) and ((x <= 1.06e-13) or not (x <= 1.3e+107))): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 4.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e+128) || (!(x <= 3.5e-94) && ((x <= 1.06e-13) || !(x <= 1.3e+107)))) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(4.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e+128) || (~((x <= 3.5e-94)) && ((x <= 1.06e-13) || ~((x <= 1.3e+107))))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 4.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e+128], And[N[Not[LessEqual[x, 3.5e-94]], $MachinePrecision], Or[LessEqual[x, 1.06e-13], N[Not[LessEqual[x, 1.3e+107]], $MachinePrecision]]]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+128} \lor \neg \left(x \leq 3.5 \cdot 10^{-94}\right) \land \left(x \leq 1.06 \cdot 10^{-13} \lor \neg \left(x \leq 1.3 \cdot 10^{+107}\right)\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -6.20000000000000008e128 or 3.49999999999999998e-94 < x < 1.06e-13 or 1.3000000000000001e107 < x Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 80.9%
if -6.20000000000000008e128 < x < 3.49999999999999998e-94 or 1.06e-13 < x < 1.3000000000000001e107Initial program 99.3%
associate-*l/99.6%
+-commutative99.6%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 92.2%
Final simplification88.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* 4.0 (/ x y)))) (t_1 (+ 1.0 (/ (* z -4.0) y))))
(if (<= z -1.55e+49)
t_1
(if (<= z -2.35e-141)
t_0
(if (<= z 1.1e-286) 4.0 (if (<= z 5.5e+14) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (4.0 * (x / y));
double t_1 = 1.0 + ((z * -4.0) / y);
double tmp;
if (z <= -1.55e+49) {
tmp = t_1;
} else if (z <= -2.35e-141) {
tmp = t_0;
} else if (z <= 1.1e-286) {
tmp = 4.0;
} else if (z <= 5.5e+14) {
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 * (x / y))
t_1 = 1.0d0 + ((z * (-4.0d0)) / y)
if (z <= (-1.55d+49)) then
tmp = t_1
else if (z <= (-2.35d-141)) then
tmp = t_0
else if (z <= 1.1d-286) then
tmp = 4.0d0
else if (z <= 5.5d+14) 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 * (x / y));
double t_1 = 1.0 + ((z * -4.0) / y);
double tmp;
if (z <= -1.55e+49) {
tmp = t_1;
} else if (z <= -2.35e-141) {
tmp = t_0;
} else if (z <= 1.1e-286) {
tmp = 4.0;
} else if (z <= 5.5e+14) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (4.0 * (x / y)) t_1 = 1.0 + ((z * -4.0) / y) tmp = 0 if z <= -1.55e+49: tmp = t_1 elif z <= -2.35e-141: tmp = t_0 elif z <= 1.1e-286: tmp = 4.0 elif z <= 5.5e+14: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(4.0 * Float64(x / y))) t_1 = Float64(1.0 + Float64(Float64(z * -4.0) / y)) tmp = 0.0 if (z <= -1.55e+49) tmp = t_1; elseif (z <= -2.35e-141) tmp = t_0; elseif (z <= 1.1e-286) tmp = 4.0; elseif (z <= 5.5e+14) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (4.0 * (x / y)); t_1 = 1.0 + ((z * -4.0) / y); tmp = 0.0; if (z <= -1.55e+49) tmp = t_1; elseif (z <= -2.35e-141) tmp = t_0; elseif (z <= 1.1e-286) tmp = 4.0; elseif (z <= 5.5e+14) 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[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.55e+49], t$95$1, If[LessEqual[z, -2.35e-141], t$95$0, If[LessEqual[z, 1.1e-286], 4.0, If[LessEqual[z, 5.5e+14], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 4 \cdot \frac{x}{y}\\
t_1 := 1 + \frac{z \cdot -4}{y}\\
\mathbf{if}\;z \leq -1.55 \cdot 10^{+49}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -2.35 \cdot 10^{-141}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{-286}:\\
\;\;\;\;4\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+14}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if z < -1.54999999999999996e49 or 5.5e14 < z Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around inf 69.4%
associate-*r/69.4%
metadata-eval69.4%
associate-*r*69.4%
neg-mul-169.4%
associate-*l/69.2%
*-commutative69.2%
associate-*r/69.4%
neg-mul-169.4%
*-commutative69.4%
associate-*l*69.4%
metadata-eval69.4%
Simplified69.4%
if -1.54999999999999996e49 < z < -2.3499999999999999e-141 or 1.1e-286 < z < 5.5e14Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 62.5%
if -2.3499999999999999e-141 < z < 1.1e-286Initial program 97.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 68.5%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e+127) (not (<= x 3.5e-94))) (+ 1.0 (* 4.0 (/ x y))) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e+127) || !(x <= 3.5e-94)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 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 <= (-2.1d+127)) .or. (.not. (x <= 3.5d-94))) then
tmp = 1.0d0 + (4.0d0 * (x / y))
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e+127) || !(x <= 3.5e-94)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e+127) or not (x <= 3.5e-94): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e+127) || !(x <= 3.5e-94)) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1e+127) || ~((x <= 3.5e-94))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e+127], N[Not[LessEqual[x, 3.5e-94]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+127} \lor \neg \left(x \leq 3.5 \cdot 10^{-94}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -2.09999999999999992e127 or 3.49999999999999998e-94 < x Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 74.9%
if -2.09999999999999992e127 < x < 3.49999999999999998e-94Initial program 99.3%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 51.4%
Final simplification61.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.2e+127) (not (<= x 2.8e-95))) (+ 4.0 (/ x (* y 0.25))) (+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e+127) || !(x <= 2.8e-95)) {
tmp = 4.0 + (x / (y * 0.25));
} else {
tmp = 4.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 <= (-2.2d+127)) .or. (.not. (x <= 2.8d-95))) then
tmp = 4.0d0 + (x / (y * 0.25d0))
else
tmp = 4.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 <= -2.2e+127) || !(x <= 2.8e-95)) {
tmp = 4.0 + (x / (y * 0.25));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.2e+127) or not (x <= 2.8e-95): tmp = 4.0 + (x / (y * 0.25)) else: tmp = 4.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.2e+127) || !(x <= 2.8e-95)) tmp = Float64(4.0 + Float64(x / Float64(y * 0.25))); else tmp = Float64(4.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.2e+127) || ~((x <= 2.8e-95))) tmp = 4.0 + (x / (y * 0.25)); else tmp = 4.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e+127], N[Not[LessEqual[x, 2.8e-95]], $MachinePrecision]], N[(4.0 + N[(x / N[(y * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+127} \lor \neg \left(x \leq 2.8 \cdot 10^{-95}\right):\\
\;\;\;\;4 + \frac{x}{y \cdot 0.25}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -2.2000000000000002e127 or 2.7999999999999999e-95 < x Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 87.0%
associate-*r/87.0%
*-commutative87.0%
/-rgt-identity87.0%
associate-/l*87.0%
metadata-eval87.0%
associate-/l/87.0%
Simplified87.0%
if -2.2000000000000002e127 < x < 2.7999999999999999e-95Initial program 99.3%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 93.4%
Final simplification90.6%
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
return 4.0;
}
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
end function
public static double code(double x, double y, double z) {
return 4.0;
}
def code(x, y, z): return 4.0
function code(x, y, z) return 4.0 end
function tmp = code(x, y, z) tmp = 4.0; end
code[x_, y_, z_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 99.6%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 35.8%
Final simplification35.8%
herbie shell --seed 2023271
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))