
(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 (+ 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e-31) (not (<= y 1.75e+136))) (+ 4.0 (* (/ z y) -4.0)) (+ 1.0 (/ 4.0 (/ y (- x z))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-31) || !(y <= 1.75e+136)) {
tmp = 4.0 + ((z / y) * -4.0);
} else {
tmp = 1.0 + (4.0 / (y / (x - z)));
}
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 <= (-7.2d-31)) .or. (.not. (y <= 1.75d+136))) then
tmp = 4.0d0 + ((z / y) * (-4.0d0))
else
tmp = 1.0d0 + (4.0d0 / (y / (x - z)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-31) || !(y <= 1.75e+136)) {
tmp = 4.0 + ((z / y) * -4.0);
} else {
tmp = 1.0 + (4.0 / (y / (x - z)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2e-31) or not (y <= 1.75e+136): tmp = 4.0 + ((z / y) * -4.0) else: tmp = 1.0 + (4.0 / (y / (x - z))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e-31) || !(y <= 1.75e+136)) tmp = Float64(4.0 + Float64(Float64(z / y) * -4.0)); else tmp = Float64(1.0 + Float64(4.0 / Float64(y / Float64(x - z)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.2e-31) || ~((y <= 1.75e+136))) tmp = 4.0 + ((z / y) * -4.0); else tmp = 1.0 + (4.0 / (y / (x - z))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e-31], N[Not[LessEqual[y, 1.75e+136]], $MachinePrecision]], N[(4.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(4.0 / N[(y / N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-31} \lor \neg \left(y \leq 1.75 \cdot 10^{+136}\right):\\
\;\;\;\;4 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\
\end{array}
\end{array}
if y < -7.20000000000000007e-31 or 1.75000000000000001e136 < y Initial program 99.9%
associate-*l/99.6%
+-commutative99.6%
associate--l+99.6%
distribute-lft-in99.6%
associate-+r+99.6%
*-commutative99.6%
+-commutative99.6%
fma-def99.6%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 89.4%
*-commutative89.4%
Simplified89.4%
if -7.20000000000000007e-31 < y < 1.75000000000000001e136Initial program 100.0%
associate-/l*99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in y around 0 89.7%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e+107) (not (<= x 1.25e+107))) (+ 4.0 (* 4.0 (/ x y))) (+ 4.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+107) || !(x <= 1.25e+107)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + ((z / y) * -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 <= (-4.1d+107)) .or. (.not. (x <= 1.25d+107))) then
tmp = 4.0d0 + (4.0d0 * (x / y))
else
tmp = 4.0d0 + ((z / y) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+107) || !(x <= 1.25e+107)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + ((z / y) * -4.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e+107) or not (x <= 1.25e+107): tmp = 4.0 + (4.0 * (x / y)) else: tmp = 4.0 + ((z / y) * -4.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e+107) || !(x <= 1.25e+107)) tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(4.0 + Float64(Float64(z / y) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e+107) || ~((x <= 1.25e+107))) tmp = 4.0 + (4.0 * (x / y)); else tmp = 4.0 + ((z / y) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+107], N[Not[LessEqual[x, 1.25e+107]], $MachinePrecision]], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+107} \lor \neg \left(x \leq 1.25 \cdot 10^{+107}\right):\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
if x < -4.0999999999999999e107 or 1.25e107 < x Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 86.7%
if -4.0999999999999999e107 < x < 1.25e107Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 87.2%
*-commutative87.2%
Simplified87.2%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.65e-30) 4.0 (if (<= y 1.95e+136) (+ 1.0 (/ 4.0 (/ y x))) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.65e-30) {
tmp = 4.0;
} else if (y <= 1.95e+136) {
tmp = 1.0 + (4.0 / (y / x));
} 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 <= (-2.65d-30)) then
tmp = 4.0d0
else if (y <= 1.95d+136) then
tmp = 1.0d0 + (4.0d0 / (y / x))
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.65e-30) {
tmp = 4.0;
} else if (y <= 1.95e+136) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.65e-30: tmp = 4.0 elif y <= 1.95e+136: tmp = 1.0 + (4.0 / (y / x)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.65e-30) tmp = 4.0; elseif (y <= 1.95e+136) tmp = Float64(1.0 + Float64(4.0 / Float64(y / x))); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.65e-30) tmp = 4.0; elseif (y <= 1.95e+136) tmp = 1.0 + (4.0 / (y / x)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.65e-30], 4.0, If[LessEqual[y, 1.95e+136], N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-30}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+136}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -2.64999999999999987e-30 or 1.9500000000000001e136 < y Initial program 99.9%
associate-*l/99.6%
+-commutative99.6%
associate--l+99.6%
distribute-lft-in99.6%
associate-+r+99.6%
*-commutative99.6%
+-commutative99.6%
fma-def99.6%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 63.7%
if -2.64999999999999987e-30 < y < 1.9500000000000001e136Initial program 100.0%
associate-/l*99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in x around inf 44.7%
Final simplification52.8%
(FPCore (x y z) :precision binary64 (+ 4.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 4.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 = 4.0d0 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 4.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(4.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 4.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(4.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
fma-udef99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ 4.0 (* 4.0 (/ x y))))
double code(double x, double y, double z) {
return 4.0 + (4.0 * (x / 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 / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + (4.0 * (x / y));
}
def code(x, y, z): return 4.0 + (4.0 * (x / y))
function code(x, y, z) return Float64(4.0 + Float64(4.0 * Float64(x / y))) end
function tmp = code(x, y, z) tmp = 4.0 + (4.0 * (x / y)); end
code[x_, y_, z_] := N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + 4 \cdot \frac{x}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 62.3%
Final simplification62.3%
(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.9%
associate-/l*99.5%
associate--l+99.5%
Simplified99.5%
Taylor expanded in z around inf 45.2%
associate-*r/45.2%
neg-mul-145.2%
Simplified45.2%
Taylor expanded in y around inf 7.8%
Final simplification7.8%
(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.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 34.5%
Final simplification34.5%
herbie shell --seed 2023178
(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)))