
(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 (+ (/ (- x z) (* y 0.25)) 2.0))
double code(double x, double y, double z) {
return ((x - z) / (y * 0.25)) + 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 = ((x - z) / (y * 0.25d0)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return ((x - z) / (y * 0.25)) + 2.0;
}
def code(x, y, z): return ((x - z) / (y * 0.25)) + 2.0
function code(x, y, z) return Float64(Float64(Float64(x - z) / Float64(y * 0.25)) + 2.0) end
function tmp = code(x, y, z) tmp = ((x - z) / (y * 0.25)) + 2.0; end
code[x_, y_, z_] := N[(N[(N[(x - z), $MachinePrecision] / N[(y * 0.25), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - z}{y \cdot 0.25} + 2
\end{array}
Initial program 99.6%
+-commutative99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
clear-num99.8%
div-inv99.8%
metadata-eval99.8%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -9.6e+19)
(not (or (<= x 3.1e+59) (and (not (<= x 2e+80)) (<= x 2.7e+149)))))
(+ (* 4.0 (/ x y)) 1.0)
(+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.6e+19) || !((x <= 3.1e+59) || (!(x <= 2e+80) && (x <= 2.7e+149)))) {
tmp = (4.0 * (x / y)) + 1.0;
} 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 <= (-9.6d+19)) .or. (.not. (x <= 3.1d+59) .or. (.not. (x <= 2d+80)) .and. (x <= 2.7d+149))) then
tmp = (4.0d0 * (x / y)) + 1.0d0
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 <= -9.6e+19) || !((x <= 3.1e+59) || (!(x <= 2e+80) && (x <= 2.7e+149)))) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 2.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.6e+19) or not ((x <= 3.1e+59) or (not (x <= 2e+80) and (x <= 2.7e+149))): tmp = (4.0 * (x / y)) + 1.0 else: tmp = 2.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.6e+19) || !((x <= 3.1e+59) || (!(x <= 2e+80) && (x <= 2.7e+149)))) tmp = Float64(Float64(4.0 * Float64(x / y)) + 1.0); 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 <= -9.6e+19) || ~(((x <= 3.1e+59) || (~((x <= 2e+80)) && (x <= 2.7e+149))))) tmp = (4.0 * (x / y)) + 1.0; else tmp = 2.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.6e+19], N[Not[Or[LessEqual[x, 3.1e+59], And[N[Not[LessEqual[x, 2e+80]], $MachinePrecision], LessEqual[x, 2.7e+149]]]], $MachinePrecision]], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.6 \cdot 10^{+19} \lor \neg \left(x \leq 3.1 \cdot 10^{+59} \lor \neg \left(x \leq 2 \cdot 10^{+80}\right) \land x \leq 2.7 \cdot 10^{+149}\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -9.6e19 or 3.10000000000000015e59 < x < 2e80 or 2.7000000000000001e149 < x Initial program 99.0%
Taylor expanded in x around inf 76.8%
if -9.6e19 < x < 3.10000000000000015e59 or 2e80 < x < 2.7000000000000001e149Initial program 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
clear-num99.8%
div-inv99.8%
metadata-eval99.8%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 90.4%
Final simplification85.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* -4.0 (/ z y)) 1.0)))
(if (<= z -3.8e+68)
t_0
(if (<= z 2.2e-242)
(+ (* 4.0 (/ x y)) 1.0)
(if (<= z 3.5e+109) 2.0 t_0)))))
double code(double x, double y, double z) {
double t_0 = (-4.0 * (z / y)) + 1.0;
double tmp;
if (z <= -3.8e+68) {
tmp = t_0;
} else if (z <= 2.2e-242) {
tmp = (4.0 * (x / y)) + 1.0;
} else if (z <= 3.5e+109) {
tmp = 2.0;
} else {
tmp = t_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 = ((-4.0d0) * (z / y)) + 1.0d0
if (z <= (-3.8d+68)) then
tmp = t_0
else if (z <= 2.2d-242) then
tmp = (4.0d0 * (x / y)) + 1.0d0
else if (z <= 3.5d+109) then
tmp = 2.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (-4.0 * (z / y)) + 1.0;
double tmp;
if (z <= -3.8e+68) {
tmp = t_0;
} else if (z <= 2.2e-242) {
tmp = (4.0 * (x / y)) + 1.0;
} else if (z <= 3.5e+109) {
tmp = 2.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (-4.0 * (z / y)) + 1.0 tmp = 0 if z <= -3.8e+68: tmp = t_0 elif z <= 2.2e-242: tmp = (4.0 * (x / y)) + 1.0 elif z <= 3.5e+109: tmp = 2.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-4.0 * Float64(z / y)) + 1.0) tmp = 0.0 if (z <= -3.8e+68) tmp = t_0; elseif (z <= 2.2e-242) tmp = Float64(Float64(4.0 * Float64(x / y)) + 1.0); elseif (z <= 3.5e+109) tmp = 2.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (-4.0 * (z / y)) + 1.0; tmp = 0.0; if (z <= -3.8e+68) tmp = t_0; elseif (z <= 2.2e-242) tmp = (4.0 * (x / y)) + 1.0; elseif (z <= 3.5e+109) tmp = 2.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[z, -3.8e+68], t$95$0, If[LessEqual[z, 2.2e-242], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[z, 3.5e+109], 2.0, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -4 \cdot \frac{z}{y} + 1\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-242}:\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+109}:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.8000000000000001e68 or 3.49999999999999983e109 < z Initial program 100.0%
Taylor expanded in z around inf 81.1%
*-commutative81.1%
Simplified81.1%
if -3.8000000000000001e68 < z < 2.20000000000000002e-242Initial program 99.0%
Taylor expanded in x around inf 59.9%
if 2.20000000000000002e-242 < z < 3.49999999999999983e109Initial program 99.9%
Taylor expanded in y around inf 51.9%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e+17) (not (<= x 1.35e+53))) (+ (* 4.0 (/ x y)) 1.0) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e+17) || !(x <= 1.35e+53)) {
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 ((x <= (-1.75d+17)) .or. (.not. (x <= 1.35d+53))) 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 ((x <= -1.75e+17) || !(x <= 1.35e+53)) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e+17) or not (x <= 1.35e+53): tmp = (4.0 * (x / y)) + 1.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e+17) || !(x <= 1.35e+53)) 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 ((x <= -1.75e+17) || ~((x <= 1.35e+53))) tmp = (4.0 * (x / y)) + 1.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e+17], N[Not[LessEqual[x, 1.35e+53]], $MachinePrecision]], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{+17} \lor \neg \left(x \leq 1.35 \cdot 10^{+53}\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -1.75e17 or 1.3500000000000001e53 < x Initial program 99.2%
Taylor expanded in x around inf 69.7%
if -1.75e17 < x < 1.3500000000000001e53Initial program 100.0%
Taylor expanded in y around inf 46.6%
Final simplification57.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.2e+68) (not (<= z 2.65e-50))) (+ 2.0 (* -4.0 (/ z y))) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.2e+68) || !(z <= 2.65e-50)) {
tmp = 2.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 <= (-6.2d+68)) .or. (.not. (z <= 2.65d-50))) then
tmp = 2.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 <= -6.2e+68) || !(z <= 2.65e-50)) {
tmp = 2.0 + (-4.0 * (z / y));
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.2e+68) or not (z <= 2.65e-50): tmp = 2.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 <= -6.2e+68) || !(z <= 2.65e-50)) tmp = Float64(2.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 <= -6.2e+68) || ~((z <= 2.65e-50))) tmp = 2.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, -6.2e+68], N[Not[LessEqual[z, 2.65e-50]], $MachinePrecision]], N[(2.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 -6.2 \cdot 10^{+68} \lor \neg \left(z \leq 2.65 \cdot 10^{-50}\right):\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -6.1999999999999997e68 or 2.65000000000000005e-50 < z Initial program 100.0%
+-commutative100.0%
associate-*l/99.9%
+-commutative99.9%
associate--l+99.9%
+-commutative99.9%
distribute-lft-in99.9%
associate-+l+99.9%
associate-*l/99.9%
*-commutative99.9%
associate-*l*99.9%
metadata-eval99.9%
*-rgt-identity99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
clear-num99.9%
div-inv99.9%
metadata-eval99.9%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 86.7%
if -6.1999999999999997e68 < z < 2.65000000000000005e-50Initial program 99.3%
+-commutative99.3%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
clear-num99.8%
div-inv99.8%
metadata-eval99.8%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 92.0%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / 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 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 2.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Initial program 99.6%
+-commutative99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(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 99.6%
Taylor expanded in x around inf 41.1%
Taylor expanded in x around 0 7.8%
Final simplification7.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 99.6%
Taylor expanded in y around inf 32.6%
Final simplification32.6%
herbie shell --seed 2024074
(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)))