
(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 7 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.9%
Taylor expanded in y around inf 100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-9) (not (<= x 1.25e+76))) (* 4.0 (/ (- x z) y)) (+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-9) || !(x <= 1.25e+76)) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.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 <= (-1.2d-9)) .or. (.not. (x <= 1.25d+76))) then
tmp = 4.0d0 * ((x - z) / y)
else
tmp = 4.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 <= -1.2e-9) || !(x <= 1.25e+76)) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-9) or not (x <= 1.25e+76): tmp = 4.0 * ((x - z) / y) else: tmp = 4.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-9) || !(x <= 1.25e+76)) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); else tmp = Float64(4.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-9) || ~((x <= 1.25e+76))) tmp = 4.0 * ((x - z) / y); else tmp = 4.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-9], N[Not[LessEqual[x, 1.25e+76]], $MachinePrecision]], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-9} \lor \neg \left(x \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -1.2e-9 or 1.24999999999999998e76 < x Initial program 99.9%
Taylor expanded in y around 0 89.8%
if -1.2e-9 < x < 1.24999999999999998e76Initial program 99.9%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 92.4%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (<= y -8.8e+120) 4.0 (if (<= y 2.4e+206) (* 4.0 (/ (- x z) y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.8e+120) {
tmp = 4.0;
} else if (y <= 2.4e+206) {
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 <= (-8.8d+120)) then
tmp = 4.0d0
else if (y <= 2.4d+206) 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 <= -8.8e+120) {
tmp = 4.0;
} else if (y <= 2.4e+206) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.8e+120: tmp = 4.0 elif y <= 2.4e+206: tmp = 4.0 * ((x - z) / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.8e+120) tmp = 4.0; elseif (y <= 2.4e+206) 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 <= -8.8e+120) tmp = 4.0; elseif (y <= 2.4e+206) tmp = 4.0 * ((x - z) / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.8e+120], 4.0, If[LessEqual[y, 2.4e+206], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+120}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+206}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -8.8000000000000005e120 or 2.4e206 < y Initial program 99.7%
Taylor expanded in y around inf 73.2%
if -8.8000000000000005e120 < y < 2.4e206Initial program 99.9%
Taylor expanded in y around 0 83.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e+37) (not (<= x 6.2e+128))) (* 4.0 (/ x y)) (* -4.0 (/ z y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e+37) || !(x <= 6.2e+128)) {
tmp = 4.0 * (x / y);
} else {
tmp = -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 <= (-6.5d+37)) .or. (.not. (x <= 6.2d+128))) then
tmp = 4.0d0 * (x / y)
else
tmp = (-4.0d0) * (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e+37) || !(x <= 6.2e+128)) {
tmp = 4.0 * (x / y);
} else {
tmp = -4.0 * (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e+37) or not (x <= 6.2e+128): tmp = 4.0 * (x / y) else: tmp = -4.0 * (z / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e+37) || !(x <= 6.2e+128)) tmp = Float64(4.0 * Float64(x / y)); else tmp = Float64(-4.0 * Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e+37) || ~((x <= 6.2e+128))) tmp = 4.0 * (x / y); else tmp = -4.0 * (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e+37], N[Not[LessEqual[x, 6.2e+128]], $MachinePrecision]], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+37} \lor \neg \left(x \leq 6.2 \cdot 10^{+128}\right):\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -6.4999999999999998e37 or 6.20000000000000008e128 < x Initial program 99.9%
Taylor expanded in x around inf 77.8%
if -6.4999999999999998e37 < x < 6.20000000000000008e128Initial program 99.9%
Taylor expanded in z around inf 53.7%
*-commutative53.7%
Simplified53.7%
Final simplification63.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+34) (not (<= x 4.1e+129))) (* 4.0 (/ x y)) (* z (/ -4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+34) || !(x <= 4.1e+129)) {
tmp = 4.0 * (x / y);
} else {
tmp = 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 <= (-5.5d+34)) .or. (.not. (x <= 4.1d+129))) then
tmp = 4.0d0 * (x / y)
else
tmp = z * ((-4.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+34) || !(x <= 4.1e+129)) {
tmp = 4.0 * (x / y);
} else {
tmp = z * (-4.0 / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+34) or not (x <= 4.1e+129): tmp = 4.0 * (x / y) else: tmp = z * (-4.0 / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+34) || !(x <= 4.1e+129)) tmp = Float64(4.0 * Float64(x / y)); else tmp = Float64(z * Float64(-4.0 / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e+34) || ~((x <= 4.1e+129))) tmp = 4.0 * (x / y); else tmp = z * (-4.0 / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+34], N[Not[LessEqual[x, 4.1e+129]], $MachinePrecision]], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+34} \lor \neg \left(x \leq 4.1 \cdot 10^{+129}\right):\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-4}{y}\\
\end{array}
\end{array}
if x < -5.4999999999999996e34 or 4.1000000000000003e129 < x Initial program 99.9%
Taylor expanded in x around inf 77.8%
if -5.4999999999999996e34 < x < 4.1000000000000003e129Initial program 99.9%
Taylor expanded in z around inf 53.7%
associate-*r/53.7%
*-commutative53.7%
associate-/l*53.6%
Simplified53.6%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e+31) (not (<= x 1.1e+81))) (* 4.0 (/ x y)) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+31) || !(x <= 1.1e+81)) {
tmp = 4.0 * (x / 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 ((x <= (-7.2d+31)) .or. (.not. (x <= 1.1d+81))) then
tmp = 4.0d0 * (x / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+31) || !(x <= 1.1e+81)) {
tmp = 4.0 * (x / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e+31) or not (x <= 1.1e+81): tmp = 4.0 * (x / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e+31) || !(x <= 1.1e+81)) tmp = Float64(4.0 * Float64(x / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e+31) || ~((x <= 1.1e+81))) tmp = 4.0 * (x / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e+31], N[Not[LessEqual[x, 1.1e+81]], $MachinePrecision]], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+31} \lor \neg \left(x \leq 1.1 \cdot 10^{+81}\right):\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -7.19999999999999992e31 or 1.09999999999999993e81 < x Initial program 99.9%
Taylor expanded in x around inf 73.0%
if -7.19999999999999992e31 < x < 1.09999999999999993e81Initial program 99.9%
Taylor expanded in y around inf 40.3%
Final simplification54.4%
(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%
Taylor expanded in y around inf 27.3%
herbie shell --seed 2024132
(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)))