
(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 6 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 (+ (* 4.0 (/ (- x z) y)) 2.0))
double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 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 = (4.0d0 * ((x - z) / y)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 2.0;
}
def code(x, y, z): return (4.0 * ((x - z) / y)) + 2.0
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - z) / y)) + 2.0) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - z) / y)) + 2.0; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x - z}{y} + 2
\end{array}
Initial program 99.2%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* 4.0 (/ x y)))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
(if (<= z -1.75e+120)
t_1
(if (<= z -9.8e-54)
2.0
(if (<= z -3.7e-78)
t_0
(if (<= z -4.7e-168) 2.0 (if (<= z 2.1e-63) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (4.0 * (x / y));
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -1.75e+120) {
tmp = t_1;
} else if (z <= -9.8e-54) {
tmp = 2.0;
} else if (z <= -3.7e-78) {
tmp = t_0;
} else if (z <= -4.7e-168) {
tmp = 2.0;
} else if (z <= 2.1e-63) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = 1.0d0 + (4.0d0 * (x / y))
t_1 = 1.0d0 + ((-4.0d0) * (z / y))
if (z <= (-1.75d+120)) then
tmp = t_1
else if (z <= (-9.8d-54)) then
tmp = 2.0d0
else if (z <= (-3.7d-78)) then
tmp = t_0
else if (z <= (-4.7d-168)) then
tmp = 2.0d0
else if (z <= 2.1d-63) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (4.0 * (x / y));
double t_1 = 1.0 + (-4.0 * (z / y));
double tmp;
if (z <= -1.75e+120) {
tmp = t_1;
} else if (z <= -9.8e-54) {
tmp = 2.0;
} else if (z <= -3.7e-78) {
tmp = t_0;
} else if (z <= -4.7e-168) {
tmp = 2.0;
} else if (z <= 2.1e-63) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (4.0 * (x / y)) t_1 = 1.0 + (-4.0 * (z / y)) tmp = 0 if z <= -1.75e+120: tmp = t_1 elif z <= -9.8e-54: tmp = 2.0 elif z <= -3.7e-78: tmp = t_0 elif z <= -4.7e-168: tmp = 2.0 elif z <= 2.1e-63: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(4.0 * Float64(x / y))) t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y))) tmp = 0.0 if (z <= -1.75e+120) tmp = t_1; elseif (z <= -9.8e-54) tmp = 2.0; elseif (z <= -3.7e-78) tmp = t_0; elseif (z <= -4.7e-168) tmp = 2.0; elseif (z <= 2.1e-63) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (4.0 * (x / y)); t_1 = 1.0 + (-4.0 * (z / y)); tmp = 0.0; if (z <= -1.75e+120) tmp = t_1; elseif (z <= -9.8e-54) tmp = 2.0; elseif (z <= -3.7e-78) tmp = t_0; elseif (z <= -4.7e-168) tmp = 2.0; elseif (z <= 2.1e-63) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.75e+120], t$95$1, If[LessEqual[z, -9.8e-54], 2.0, If[LessEqual[z, -3.7e-78], t$95$0, If[LessEqual[z, -4.7e-168], 2.0, If[LessEqual[z, 2.1e-63], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 4 \cdot \frac{x}{y}\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+120}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -9.8 \cdot 10^{-54}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq -3.7 \cdot 10^{-78}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.7 \cdot 10^{-168}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if z < -1.75000000000000004e120 or 2.1e-63 < z Initial program 98.3%
associate-/l*99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in z around inf 71.5%
*-commutative71.5%
Simplified71.5%
if -1.75000000000000004e120 < z < -9.80000000000000042e-54 or -3.70000000000000006e-78 < z < -4.70000000000000026e-168Initial program 100.0%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 60.8%
if -9.80000000000000042e-54 < z < -3.70000000000000006e-78 or -4.70000000000000026e-168 < z < 2.1e-63Initial program 100.0%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around inf 61.5%
Final simplification65.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e+50) (not (<= x 5.5e+32))) (+ 1.0 (* 4.0 (/ x y))) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+50) || !(x <= 5.5e+32)) {
tmp = 1.0 + (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 <= (-3.7d+50)) .or. (.not. (x <= 5.5d+32))) then
tmp = 1.0d0 + (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 <= -3.7e+50) || !(x <= 5.5e+32)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e+50) or not (x <= 5.5e+32): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e+50) || !(x <= 5.5e+32)) tmp = Float64(1.0 + 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 <= -3.7e+50) || ~((x <= 5.5e+32))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e+50], N[Not[LessEqual[x, 5.5e+32]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+50} \lor \neg \left(x \leq 5.5 \cdot 10^{+32}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -3.7000000000000001e50 or 5.49999999999999984e32 < x Initial program 99.1%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around inf 70.4%
if -3.7000000000000001e50 < x < 5.49999999999999984e32Initial program 99.3%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 48.3%
Final simplification57.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e+172) (not (<= x 2.4e+159))) (+ 1.0 (* 4.0 (/ x y))) (+ 2.0 (* z (/ -4.0 y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+172) || !(x <= 2.4e+159)) {
tmp = 1.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 <= (-5.8d+172)) .or. (.not. (x <= 2.4d+159))) then
tmp = 1.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 <= -5.8e+172) || !(x <= 2.4e+159)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (z * (-4.0 / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e+172) or not (x <= 2.4e+159): tmp = 1.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 <= -5.8e+172) || !(x <= 2.4e+159)) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(z * Float64(-4.0 / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e+172) || ~((x <= 2.4e+159))) tmp = 1.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, -5.8e+172], N[Not[LessEqual[x, 2.4e+159]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+172} \lor \neg \left(x \leq 2.4 \cdot 10^{+159}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + z \cdot \frac{-4}{y}\\
\end{array}
\end{array}
if x < -5.7999999999999999e172 or 2.4e159 < x Initial program 98.2%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around inf 90.1%
if -5.7999999999999999e172 < x < 2.4e159Initial program 99.5%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around 0 85.9%
Simplified85.8%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+172) (not (<= x 3.9e+167))) (+ 1.0 (* 4.0 (/ x y))) (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+172) || !(x <= 3.9e+167)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 2.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 <= (-5.5d+172)) .or. (.not. (x <= 3.9d+167))) then
tmp = 1.0d0 + (4.0d0 * (x / y))
else
tmp = 2.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 <= -5.5e+172) || !(x <= 3.9e+167)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+172) or not (x <= 3.9e+167): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 2.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+172) || !(x <= 3.9e+167)) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e+172) || ~((x <= 3.9e+167))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 2.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+172], N[Not[LessEqual[x, 3.9e+167]], $MachinePrecision]], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+172} \lor \neg \left(x \leq 3.9 \cdot 10^{+167}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -5.4999999999999999e172 or 3.8999999999999998e167 < x Initial program 98.2%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around inf 90.1%
if -5.4999999999999999e172 < x < 3.8999999999999998e167Initial program 99.5%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 85.9%
neg-mul-185.9%
distribute-neg-frac85.9%
Simplified85.9%
Taylor expanded in z around 0 85.9%
Final simplification86.8%
(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.2%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 36.9%
Final simplification36.9%
herbie shell --seed 2023200
(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)))