
(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 6 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 (/ (- x z) y))))
double code(double x, double y, double z) {
return 2.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 = 2.0d0 + (4.0d0 * ((x - z) / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (4.0 * ((x - z) / y));
}
def code(x, y, z): return 2.0 + (4.0 * ((x - z) / y))
function code(x, y, z) return Float64(2.0 + Float64(4.0 * Float64(Float64(x - z) / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (4.0 * ((x - z) / y)); end
code[x_, y_, z_] := N[(2.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + 4 \cdot \frac{x - z}{y}
\end{array}
Initial program 99.2%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.5e+200)
(and (not (<= z -8.2e+85)) (or (<= z -5.9e+57) (not (<= z 3e+159)))))
(+ 1.0 (* -4.0 (/ z y)))
(+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+200) || (!(z <= -8.2e+85) && ((z <= -5.9e+57) || !(z <= 3e+159)))) {
tmp = 1.0 + (-4.0 * (z / y));
} 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 <= (-1.5d+200)) .or. (.not. (z <= (-8.2d+85))) .and. (z <= (-5.9d+57)) .or. (.not. (z <= 3d+159))) then
tmp = 1.0d0 + ((-4.0d0) * (z / y))
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 <= -1.5e+200) || (!(z <= -8.2e+85) && ((z <= -5.9e+57) || !(z <= 3e+159)))) {
tmp = 1.0 + (-4.0 * (z / y));
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e+200) or (not (z <= -8.2e+85) and ((z <= -5.9e+57) or not (z <= 3e+159))): tmp = 1.0 + (-4.0 * (z / y)) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e+200) || (!(z <= -8.2e+85) && ((z <= -5.9e+57) || !(z <= 3e+159)))) tmp = Float64(1.0 + Float64(-4.0 * Float64(z / y))); 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 <= -1.5e+200) || (~((z <= -8.2e+85)) && ((z <= -5.9e+57) || ~((z <= 3e+159))))) tmp = 1.0 + (-4.0 * (z / y)); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e+200], And[N[Not[LessEqual[z, -8.2e+85]], $MachinePrecision], Or[LessEqual[z, -5.9e+57], N[Not[LessEqual[z, 3e+159]], $MachinePrecision]]]], N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+200} \lor \neg \left(z \leq -8.2 \cdot 10^{+85}\right) \land \left(z \leq -5.9 \cdot 10^{+57} \lor \neg \left(z \leq 3 \cdot 10^{+159}\right)\right):\\
\;\;\;\;1 + -4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.49999999999999995e200 or -8.19999999999999957e85 < z < -5.90000000000000013e57 or 3.0000000000000002e159 < z Initial program 98.5%
Taylor expanded in z around inf 91.1%
*-commutative91.1%
Simplified91.1%
if -1.49999999999999995e200 < z < -8.19999999999999957e85 or -5.90000000000000013e57 < z < 3.0000000000000002e159Initial program 99.5%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 84.6%
Final simplification86.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* 4.0 (/ x y)) 1.0)) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
(if (<= z -2.9e+35)
t_1
(if (<= z -1.16e-241)
t_0
(if (<= z 4.2e-181) 2.0 (if (<= z 1.8e+159) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = (4.0 * (x / y)) + 1.0;
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.9e+35) {
tmp = t_1;
} else if (z <= -1.16e-241) {
tmp = t_0;
} else if (z <= 4.2e-181) {
tmp = 2.0;
} else if (z <= 1.8e+159) {
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 = (4.0d0 * (x / y)) + 1.0d0
t_1 = 1.0d0 + ((-4.0d0) * (z / y))
if (z <= (-2.9d+35)) then
tmp = t_1
else if (z <= (-1.16d-241)) then
tmp = t_0
else if (z <= 4.2d-181) then
tmp = 2.0d0
else if (z <= 1.8d+159) 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 = (4.0 * (x / y)) + 1.0;
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -2.9e+35) {
tmp = t_1;
} else if (z <= -1.16e-241) {
tmp = t_0;
} else if (z <= 4.2e-181) {
tmp = 2.0;
} else if (z <= 1.8e+159) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (4.0 * (x / y)) + 1.0 t_1 = 1.0 + (-4.0 * (z / y)) tmp = 0 if z <= -2.9e+35: tmp = t_1 elif z <= -1.16e-241: tmp = t_0 elif z <= 4.2e-181: tmp = 2.0 elif z <= 1.8e+159: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(4.0 * Float64(x / y)) + 1.0) t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y))) tmp = 0.0 if (z <= -2.9e+35) tmp = t_1; elseif (z <= -1.16e-241) tmp = t_0; elseif (z <= 4.2e-181) tmp = 2.0; elseif (z <= 1.8e+159) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (4.0 * (x / y)) + 1.0; t_1 = 1.0 + (-4.0 * (z / y)); tmp = 0.0; if (z <= -2.9e+35) tmp = t_1; elseif (z <= -1.16e-241) tmp = t_0; elseif (z <= 4.2e-181) tmp = 2.0; elseif (z <= 1.8e+159) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e+35], t$95$1, If[LessEqual[z, -1.16e-241], t$95$0, If[LessEqual[z, 4.2e-181], 2.0, If[LessEqual[z, 1.8e+159], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y} + 1\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{+35}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -1.16 \cdot 10^{-241}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-181}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+159}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.89999999999999995e35 or 1.80000000000000018e159 < z Initial program 98.9%
Taylor expanded in z around inf 77.1%
*-commutative77.1%
Simplified77.1%
if -2.89999999999999995e35 < z < -1.16e-241 or 4.20000000000000006e-181 < z < 1.80000000000000018e159Initial program 100.0%
Taylor expanded in x around inf 53.3%
if -1.16e-241 < z < 4.20000000000000006e-181Initial program 98.0%
Taylor expanded in y around inf 63.3%
Final simplification63.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.85e+55) (not (<= z 1.8e+159))) (+ 2.0 (/ (* z -4.0) y)) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.85e+55) || !(z <= 1.8e+159)) {
tmp = 2.0 + ((z * -4.0) / y);
} 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 <= (-1.85d+55)) .or. (.not. (z <= 1.8d+159))) then
tmp = 2.0d0 + ((z * (-4.0d0)) / y)
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 <= -1.85e+55) || !(z <= 1.8e+159)) {
tmp = 2.0 + ((z * -4.0) / y);
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.85e+55) or not (z <= 1.8e+159): tmp = 2.0 + ((z * -4.0) / y) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.85e+55) || !(z <= 1.8e+159)) tmp = Float64(2.0 + Float64(Float64(z * -4.0) / y)); 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 <= -1.85e+55) || ~((z <= 1.8e+159))) tmp = 2.0 + ((z * -4.0) / y); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.85e+55], N[Not[LessEqual[z, 1.8e+159]], $MachinePrecision]], N[(2.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+55} \lor \neg \left(z \leq 1.8 \cdot 10^{+159}\right):\\
\;\;\;\;2 + \frac{z \cdot -4}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.8500000000000001e55 or 1.80000000000000018e159 < z Initial program 98.9%
+-commutative98.9%
associate-/l*100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 84.5%
sub-neg84.5%
distribute-lft-in84.5%
metadata-eval84.5%
associate-+r+84.5%
metadata-eval84.5%
neg-mul-184.5%
associate-*r*84.5%
metadata-eval84.5%
*-commutative84.5%
associate-*l/83.4%
Simplified83.4%
if -1.8500000000000001e55 < z < 1.80000000000000018e159Initial program 99.4%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 87.5%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (<= y -3e+92) 2.0 (if (<= y 6e+44) (+ (* 4.0 (/ x y)) 1.0) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+92) {
tmp = 2.0;
} else if (y <= 6e+44) {
tmp = (4.0 * (x / y)) + 1.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 (y <= (-3d+92)) then
tmp = 2.0d0
else if (y <= 6d+44) then
tmp = (4.0d0 * (x / y)) + 1.0d0
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3e+92) {
tmp = 2.0;
} else if (y <= 6e+44) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+92: tmp = 2.0 elif y <= 6e+44: tmp = (4.0 * (x / y)) + 1.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+92) tmp = 2.0; elseif (y <= 6e+44) tmp = Float64(Float64(4.0 * Float64(x / y)) + 1.0); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e+92) tmp = 2.0; elseif (y <= 6e+44) tmp = (4.0 * (x / y)) + 1.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+92], 2.0, If[LessEqual[y, 6e+44], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+92}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+44}:\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -3.00000000000000013e92 or 5.99999999999999974e44 < y Initial program 98.9%
Taylor expanded in y around inf 69.8%
if -3.00000000000000013e92 < y < 5.99999999999999974e44Initial program 99.4%
Taylor expanded in x around inf 51.3%
Final simplification58.0%
(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 99.2%
Taylor expanded in y around inf 33.5%
Final simplification33.5%
herbie shell --seed 2024046
(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)))