
(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 8 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.5%
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
(let* ((t_0 (* 4.0 (/ x y))) (t_1 (* -4.0 (/ z y))))
(if (<= x -2.7e-92)
t_0
(if (<= x -2.25e-299)
t_1
(if (<= x 1.5e-155)
4.0
(if (<= x 6.8e-46) t_1 (if (<= x 2.5e-14) 4.0 t_0)))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / y);
double t_1 = -4.0 * (z / y);
double tmp;
if (x <= -2.7e-92) {
tmp = t_0;
} else if (x <= -2.25e-299) {
tmp = t_1;
} else if (x <= 1.5e-155) {
tmp = 4.0;
} else if (x <= 6.8e-46) {
tmp = t_1;
} else if (x <= 2.5e-14) {
tmp = 4.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) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / y)
t_1 = (-4.0d0) * (z / y)
if (x <= (-2.7d-92)) then
tmp = t_0
else if (x <= (-2.25d-299)) then
tmp = t_1
else if (x <= 1.5d-155) then
tmp = 4.0d0
else if (x <= 6.8d-46) then
tmp = t_1
else if (x <= 2.5d-14) then
tmp = 4.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 * (x / y);
double t_1 = -4.0 * (z / y);
double tmp;
if (x <= -2.7e-92) {
tmp = t_0;
} else if (x <= -2.25e-299) {
tmp = t_1;
} else if (x <= 1.5e-155) {
tmp = 4.0;
} else if (x <= 6.8e-46) {
tmp = t_1;
} else if (x <= 2.5e-14) {
tmp = 4.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / y) t_1 = -4.0 * (z / y) tmp = 0 if x <= -2.7e-92: tmp = t_0 elif x <= -2.25e-299: tmp = t_1 elif x <= 1.5e-155: tmp = 4.0 elif x <= 6.8e-46: tmp = t_1 elif x <= 2.5e-14: tmp = 4.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / y)) t_1 = Float64(-4.0 * Float64(z / y)) tmp = 0.0 if (x <= -2.7e-92) tmp = t_0; elseif (x <= -2.25e-299) tmp = t_1; elseif (x <= 1.5e-155) tmp = 4.0; elseif (x <= 6.8e-46) tmp = t_1; elseif (x <= 2.5e-14) tmp = 4.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / y); t_1 = -4.0 * (z / y); tmp = 0.0; if (x <= -2.7e-92) tmp = t_0; elseif (x <= -2.25e-299) tmp = t_1; elseif (x <= 1.5e-155) tmp = 4.0; elseif (x <= 6.8e-46) tmp = t_1; elseif (x <= 2.5e-14) tmp = 4.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.7e-92], t$95$0, If[LessEqual[x, -2.25e-299], t$95$1, If[LessEqual[x, 1.5e-155], 4.0, If[LessEqual[x, 6.8e-46], t$95$1, If[LessEqual[x, 2.5e-14], 4.0, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
t_1 := -4 \cdot \frac{z}{y}\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-92}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.25 \cdot 10^{-299}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{-155}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-46}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;4\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -2.69999999999999995e-92 or 2.5000000000000001e-14 < x Initial 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 inf 82.9%
Taylor expanded in x around inf 64.0%
if -2.69999999999999995e-92 < x < -2.25000000000000001e-299 or 1.49999999999999992e-155 < x < 6.79999999999999992e-46Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 66.3%
Taylor expanded in x around 0 58.2%
if -2.25000000000000001e-299 < x < 1.49999999999999992e-155 or 6.79999999999999992e-46 < x < 2.5000000000000001e-14Initial program 99.8%
associate-*l/99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around inf 74.9%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e+101) (not (<= y 1.05e+23))) (+ 4.0 (* -4.0 (/ z y))) (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e+101) || !(y <= 1.05e+23)) {
tmp = 4.0 + (-4.0 * (z / y));
} else {
tmp = 4.0 * ((x - 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 ((y <= (-8d+101)) .or. (.not. (y <= 1.05d+23))) then
tmp = 4.0d0 + ((-4.0d0) * (z / y))
else
tmp = 4.0d0 * ((x - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8e+101) || !(y <= 1.05e+23)) {
tmp = 4.0 + (-4.0 * (z / y));
} else {
tmp = 4.0 * ((x - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8e+101) or not (y <= 1.05e+23): tmp = 4.0 + (-4.0 * (z / y)) else: tmp = 4.0 * ((x - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8e+101) || !(y <= 1.05e+23)) tmp = Float64(4.0 + Float64(-4.0 * Float64(z / y))); else tmp = Float64(4.0 * Float64(Float64(x - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8e+101) || ~((y <= 1.05e+23))) tmp = 4.0 + (-4.0 * (z / y)); else tmp = 4.0 * ((x - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e+101], N[Not[LessEqual[y, 1.05e+23]], $MachinePrecision]], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+101} \lor \neg \left(y \leq 1.05 \cdot 10^{+23}\right):\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\end{array}
\end{array}
if y < -7.9999999999999998e101 or 1.0500000000000001e23 < y Initial program 98.7%
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 83.0%
if -7.9999999999999998e101 < y < 1.0500000000000001e23Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 87.1%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e+16) (not (<= y 1.1e-55))) (+ 4.0 (* 4.0 (/ x y))) (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+16) || !(y <= 1.1e-55)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 * ((x - 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 ((y <= (-3.8d+16)) .or. (.not. (y <= 1.1d-55))) then
tmp = 4.0d0 + (4.0d0 * (x / y))
else
tmp = 4.0d0 * ((x - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+16) || !(y <= 1.1e-55)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 * ((x - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e+16) or not (y <= 1.1e-55): tmp = 4.0 + (4.0 * (x / y)) else: tmp = 4.0 * ((x - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+16) || !(y <= 1.1e-55)) tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(4.0 * Float64(Float64(x - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.8e+16) || ~((y <= 1.1e-55))) tmp = 4.0 + (4.0 * (x / y)); else tmp = 4.0 * ((x - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+16], N[Not[LessEqual[y, 1.1e-55]], $MachinePrecision]], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+16} \lor \neg \left(y \leq 1.1 \cdot 10^{-55}\right):\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\end{array}
\end{array}
if y < -3.8e16 or 1.1e-55 < y Initial program 99.1%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 86.4%
if -3.8e16 < y < 1.1e-55Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 92.6%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e+165) 4.0 (if (<= y 1.8e+94) (* 4.0 (/ (- x z) y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+165) {
tmp = 4.0;
} else if (y <= 1.8e+94) {
tmp = 4.0 * ((x - z) / 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 (y <= (-3.8d+165)) then
tmp = 4.0d0
else if (y <= 1.8d+94) then
tmp = 4.0d0 * ((x - z) / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+165) {
tmp = 4.0;
} else if (y <= 1.8e+94) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e+165: tmp = 4.0 elif y <= 1.8e+94: tmp = 4.0 * ((x - z) / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+165) tmp = 4.0; elseif (y <= 1.8e+94) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e+165) tmp = 4.0; elseif (y <= 1.8e+94) tmp = 4.0 * ((x - z) / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+165], 4.0, If[LessEqual[y, 1.8e+94], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+165}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+94}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -3.7999999999999999e165 or 1.79999999999999996e94 < y Initial program 99.8%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 77.7%
if -3.7999999999999999e165 < y < 1.79999999999999996e94Initial program 99.5%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 83.6%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (<= y -92000000000000.0) 4.0 (if (<= y 5e-55) (* -4.0 (/ z y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -92000000000000.0) {
tmp = 4.0;
} else if (y <= 5e-55) {
tmp = -4.0 * (z / 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 (y <= (-92000000000000.0d0)) then
tmp = 4.0d0
else if (y <= 5d-55) then
tmp = (-4.0d0) * (z / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -92000000000000.0) {
tmp = 4.0;
} else if (y <= 5e-55) {
tmp = -4.0 * (z / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -92000000000000.0: tmp = 4.0 elif y <= 5e-55: tmp = -4.0 * (z / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -92000000000000.0) tmp = 4.0; elseif (y <= 5e-55) tmp = Float64(-4.0 * Float64(z / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -92000000000000.0) tmp = 4.0; elseif (y <= 5e-55) tmp = -4.0 * (z / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -92000000000000.0], 4.0, If[LessEqual[y, 5e-55], N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -92000000000000:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-55}:\\
\;\;\;\;-4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -9.2e13 or 5.0000000000000002e-55 < y Initial program 99.1%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 57.5%
if -9.2e13 < y < 5.0000000000000002e-55Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 92.6%
Taylor expanded in x around 0 45.2%
Final simplification51.2%
(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.5%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in x around inf 45.5%
Taylor expanded in x around 0 7.2%
Final simplification7.2%
(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.5%
associate-*l/99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 32.6%
Final simplification32.6%
herbie shell --seed 2023310
(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)))