
(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 6 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 (+ 0.75 (/ (- x z) y)))))
double code(double x, double y, double z) {
return 1.0 + (4.0 * (0.75 + ((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 = 1.0d0 + (4.0d0 * (0.75d0 + ((x - z) / y)))
end function
public static double code(double x, double y, double z) {
return 1.0 + (4.0 * (0.75 + ((x - z) / y)));
}
def code(x, y, z): return 1.0 + (4.0 * (0.75 + ((x - z) / y)))
function code(x, y, z) return Float64(1.0 + Float64(4.0 * Float64(0.75 + Float64(Float64(x - z) / y)))) end
function tmp = code(x, y, z) tmp = 1.0 + (4.0 * (0.75 + ((x - z) / y))); end
code[x_, y_, z_] := N[(1.0 + N[(4.0 * N[(0.75 + N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 4 \cdot \left(0.75 + \frac{x - z}{y}\right)
\end{array}
Initial program 99.9%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 97.7%
associate--l+97.7%
div-sub100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2e+79)
(and (not (<= x 3.9e+33))
(or (<= x 6.2e+108) (not (<= x 2.35e+132)))))
(+ 1.0 (* 4.0 (/ x y)))
(+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+79) || (!(x <= 3.9e+33) && ((x <= 6.2e+108) || !(x <= 2.35e+132)))) {
tmp = 1.0 + (4.0 * (x / 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 <= (-2d+79)) .or. (.not. (x <= 3.9d+33)) .and. (x <= 6.2d+108) .or. (.not. (x <= 2.35d+132))) then
tmp = 1.0d0 + (4.0d0 * (x / 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 <= -2e+79) || (!(x <= 3.9e+33) && ((x <= 6.2e+108) || !(x <= 2.35e+132)))) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+79) or (not (x <= 3.9e+33) and ((x <= 6.2e+108) or not (x <= 2.35e+132))): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 4.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+79) || (!(x <= 3.9e+33) && ((x <= 6.2e+108) || !(x <= 2.35e+132)))) tmp = Float64(1.0 + Float64(4.0 * Float64(x / 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 <= -2e+79) || (~((x <= 3.9e+33)) && ((x <= 6.2e+108) || ~((x <= 2.35e+132))))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 4.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+79], And[N[Not[LessEqual[x, 3.9e+33]], $MachinePrecision], Or[LessEqual[x, 6.2e+108], N[Not[LessEqual[x, 2.35e+132]], $MachinePrecision]]]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+79} \lor \neg \left(x \leq 3.9 \cdot 10^{+33}\right) \land \left(x \leq 6.2 \cdot 10^{+108} \lor \neg \left(x \leq 2.35 \cdot 10^{+132}\right)\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -1.99999999999999993e79 or 3.9000000000000002e33 < x < 6.2000000000000003e108 or 2.35e132 < x Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 86.3%
if -1.99999999999999993e79 < x < 3.9000000000000002e33 or 6.2000000000000003e108 < x < 2.35e132Initial program 99.9%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 90.1%
div-sub90.1%
associate-/l*90.2%
*-inverses90.2%
metadata-eval90.2%
Simplified90.2%
Taylor expanded in z around 0 90.2%
+-commutative90.2%
Simplified90.2%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e+78) (not (<= x 1850000000000.0))) (+ 1.0 (* 4.0 (/ (- x z) y))) (+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e+78) || !(x <= 1850000000000.0)) {
tmp = 1.0 + (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 <= (-6.5d+78)) .or. (.not. (x <= 1850000000000.0d0))) then
tmp = 1.0d0 + (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 <= -6.5e+78) || !(x <= 1850000000000.0)) {
tmp = 1.0 + (4.0 * ((x - z) / y));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e+78) or not (x <= 1850000000000.0): tmp = 1.0 + (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 <= -6.5e+78) || !(x <= 1850000000000.0)) tmp = Float64(1.0 + 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 <= -6.5e+78) || ~((x <= 1850000000000.0))) tmp = 1.0 + (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, -6.5e+78], N[Not[LessEqual[x, 1850000000000.0]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+78} \lor \neg \left(x \leq 1850000000000\right):\\
\;\;\;\;1 + 4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -6.50000000000000036e78 or 1.85e12 < x Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 92.2%
if -6.50000000000000036e78 < x < 1.85e12Initial program 99.9%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 90.2%
div-sub90.3%
associate-/l*90.3%
*-inverses90.3%
metadata-eval90.3%
Simplified90.3%
Taylor expanded in z around 0 90.3%
+-commutative90.3%
Simplified90.3%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.6e+62) (not (<= x 50000000000000.0))) (+ 1.0 (* 4.0 (/ x y))) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e+62) || !(x <= 50000000000000.0)) {
tmp = 1.0 + (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.6d+62)) .or. (.not. (x <= 50000000000000.0d0))) then
tmp = 1.0d0 + (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.6e+62) || !(x <= 50000000000000.0)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.6e+62) or not (x <= 50000000000000.0): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.6e+62) || !(x <= 50000000000000.0)) tmp = Float64(1.0 + 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.6e+62) || ~((x <= 50000000000000.0))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.6e+62], N[Not[LessEqual[x, 50000000000000.0]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+62} \lor \neg \left(x \leq 50000000000000\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -7.59999999999999967e62 or 5e13 < x Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 78.2%
if -7.59999999999999967e62 < x < 5e13Initial program 99.9%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 90.1%
div-sub90.1%
associate-/l*90.2%
*-inverses90.2%
metadata-eval90.2%
Simplified90.2%
Taylor expanded in z around 0 41.8%
Final simplification57.5%
(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.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around inf 42.4%
neg-mul-142.4%
distribute-neg-frac42.4%
Simplified42.4%
Taylor expanded in z around 0 6.7%
Final simplification6.7%
(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.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 65.0%
div-sub65.0%
associate-/l*65.1%
*-inverses65.1%
metadata-eval65.1%
Simplified65.1%
Taylor expanded in z around 0 28.3%
Final simplification28.3%
herbie shell --seed 2024039
(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)))