
(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 (+ 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}
Initial program 99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6e-43) (not (<= x 3.9e-50))) (+ 1.0 (/ 4.0 (/ y x))) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-43) || !(x <= 3.9e-50)) {
tmp = 1.0 + (4.0 / (y / x));
} 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 <= (-8.6d-43)) .or. (.not. (x <= 3.9d-50))) then
tmp = 1.0d0 + (4.0d0 / (y / x))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-43) || !(x <= 3.9e-50)) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-43) or not (x <= 3.9e-50): tmp = 1.0 + (4.0 / (y / x)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-43) || !(x <= 3.9e-50)) tmp = Float64(1.0 + Float64(4.0 / Float64(y / x))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.6e-43) || ~((x <= 3.9e-50))) tmp = 1.0 + (4.0 / (y / x)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-43], N[Not[LessEqual[x, 3.9e-50]], $MachinePrecision]], N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-43} \lor \neg \left(x \leq 3.9 \cdot 10^{-50}\right):\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -8.59999999999999927e-43 or 3.90000000000000021e-50 < x Initial program 99.3%
Taylor expanded in x around inf 63.0%
associate-*r/62.3%
associate-/l*62.8%
Simplified62.8%
if -8.59999999999999927e-43 < x < 3.90000000000000021e-50Initial program 100.0%
Taylor expanded in y around inf 46.1%
Final simplification55.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e+49) (not (<= x 1.3e+89))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (/ (* z -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+49) || !(x <= 1.3e+89)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z * -4.0) / 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 <= (-4.1d+49)) .or. (.not. (x <= 1.3d+89))) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + ((z * (-4.0d0)) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+49) || !(x <= 1.3e+89)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z * -4.0) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e+49) or not (x <= 1.3e+89): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + ((z * -4.0) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e+49) || !(x <= 1.3e+89)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(Float64(z * -4.0) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e+49) || ~((x <= 1.3e+89))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + ((z * -4.0) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+49], N[Not[LessEqual[x, 1.3e+89]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+49} \lor \neg \left(x \leq 1.3 \cdot 10^{+89}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z \cdot -4}{y}\\
\end{array}
\end{array}
if x < -4.1e49 or 1.3e89 < x Initial program 99.0%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
Simplified99.7%
Taylor expanded in z around 0 88.4%
if -4.1e49 < x < 1.3e89Initial program 100.0%
associate-*l/99.2%
+-commutative99.2%
associate--l+99.2%
distribute-lft-in99.2%
associate-+r+99.2%
Simplified99.2%
Taylor expanded in x around 0 87.8%
+-commutative87.8%
associate-*r/87.8%
Simplified87.8%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6e-43) (not (<= x 1.56e-49))) (* 4.0 (/ x y)) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-43) || !(x <= 1.56e-49)) {
tmp = 4.0 * (x / y);
} 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 <= (-8.6d-43)) .or. (.not. (x <= 1.56d-49))) then
tmp = 4.0d0 * (x / y)
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-43) || !(x <= 1.56e-49)) {
tmp = 4.0 * (x / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-43) or not (x <= 1.56e-49): tmp = 4.0 * (x / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-43) || !(x <= 1.56e-49)) tmp = Float64(4.0 * Float64(x / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.6e-43) || ~((x <= 1.56e-49))) tmp = 4.0 * (x / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-43], N[Not[LessEqual[x, 1.56e-49]], $MachinePrecision]], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-43} \lor \neg \left(x \leq 1.56 \cdot 10^{-49}\right):\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -8.59999999999999927e-43 or 1.56000000000000008e-49 < x Initial program 99.3%
Taylor expanded in z around 0 75.5%
Taylor expanded in x around inf 61.1%
if -8.59999999999999927e-43 < x < 1.56000000000000008e-49Initial program 100.0%
Taylor expanded in y around inf 46.1%
Final simplification54.5%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (/ 4.0 y) (- x z))))
double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
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 / y) * (x - z))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
def code(x, y, z): return 2.0 + ((4.0 / y) * (x - z))
function code(x, y, z) return Float64(2.0 + Float64(Float64(4.0 / y) * Float64(x - z))) end
function tmp = code(x, y, z) tmp = 2.0 + ((4.0 / y) * (x - z)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(4.0 / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{4}{y} \cdot \left(x - z\right)
\end{array}
Initial program 99.6%
associate-*l/99.4%
+-commutative99.4%
associate--l+99.4%
distribute-lft-in99.4%
associate-+r+99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (+ 2.0 (* 4.0 (/ x y))))
double code(double x, double y, double z) {
return 2.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 = 2.0d0 + (4.0d0 * (x / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
def code(x, y, z): return 2.0 + (4.0 * (x / y))
function code(x, y, z) return Float64(2.0 + Float64(4.0 * Float64(x / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (4.0 * (x / y)); end
code[x_, y_, z_] := N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + 4 \cdot \frac{x}{y}
\end{array}
Initial program 99.6%
associate-*l/99.4%
+-commutative99.4%
associate--l+99.4%
distribute-lft-in99.4%
associate-+r+99.4%
Simplified99.4%
Taylor expanded in z around 0 64.2%
Final simplification64.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.6%
Taylor expanded in x around inf 41.2%
associate-*r/40.8%
associate-/l*41.1%
Simplified41.1%
Taylor expanded in y around inf 7.1%
Final simplification7.1%
(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 28.0%
Final simplification28.0%
herbie shell --seed 2024019
(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)))