
(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 (+ 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%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* z (/ -4.0 y)))))
(if (<= z -4e+82)
t_0
(if (<= z -3.1e-93)
4.0
(if (<= z 2.9e+60) (+ 1.0 (* 4.0 (/ x y))) t_0)))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (z * (-4.0 / y));
double tmp;
if (z <= -4e+82) {
tmp = t_0;
} else if (z <= -3.1e-93) {
tmp = 4.0;
} else if (z <= 2.9e+60) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + (z * ((-4.0d0) / y))
if (z <= (-4d+82)) then
tmp = t_0
else if (z <= (-3.1d-93)) then
tmp = 4.0d0
else if (z <= 2.9d+60) then
tmp = 1.0d0 + (4.0d0 * (x / y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (z * (-4.0 / y));
double tmp;
if (z <= -4e+82) {
tmp = t_0;
} else if (z <= -3.1e-93) {
tmp = 4.0;
} else if (z <= 2.9e+60) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (z * (-4.0 / y)) tmp = 0 if z <= -4e+82: tmp = t_0 elif z <= -3.1e-93: tmp = 4.0 elif z <= 2.9e+60: tmp = 1.0 + (4.0 * (x / y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(z * Float64(-4.0 / y))) tmp = 0.0 if (z <= -4e+82) tmp = t_0; elseif (z <= -3.1e-93) tmp = 4.0; elseif (z <= 2.9e+60) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (z * (-4.0 / y)); tmp = 0.0; if (z <= -4e+82) tmp = t_0; elseif (z <= -3.1e-93) tmp = 4.0; elseif (z <= 2.9e+60) tmp = 1.0 + (4.0 * (x / y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4e+82], t$95$0, If[LessEqual[z, -3.1e-93], 4.0, If[LessEqual[z, 2.9e+60], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + z \cdot \frac{-4}{y}\\
\mathbf{if}\;z \leq -4 \cdot 10^{+82}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.1 \cdot 10^{-93}:\\
\;\;\;\;4\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+60}:\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.9999999999999999e82 or 2.9e60 < z Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 70.8%
associate-*r/70.8%
metadata-eval70.8%
associate-*r*70.8%
neg-mul-170.8%
associate-*l/70.7%
*-commutative70.7%
distribute-lft-neg-out70.7%
distribute-rgt-neg-in70.7%
distribute-neg-frac70.7%
metadata-eval70.7%
Simplified70.7%
if -3.9999999999999999e82 < z < -3.1e-93Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around inf 62.2%
if -3.1e-93 < z < 2.9e60Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 62.2%
Final simplification65.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* (/ z y) -4.0))))
(if (<= z -4e+82)
t_0
(if (<= z -2.3e-93)
4.0
(if (<= z 2.7e+60) (+ 1.0 (* 4.0 (/ x y))) t_0)))))
double code(double x, double y, double z) {
double t_0 = 1.0 + ((z / y) * -4.0);
double tmp;
if (z <= -4e+82) {
tmp = t_0;
} else if (z <= -2.3e-93) {
tmp = 4.0;
} else if (z <= 2.7e+60) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((z / y) * (-4.0d0))
if (z <= (-4d+82)) then
tmp = t_0
else if (z <= (-2.3d-93)) then
tmp = 4.0d0
else if (z <= 2.7d+60) then
tmp = 1.0d0 + (4.0d0 * (x / y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + ((z / y) * -4.0);
double tmp;
if (z <= -4e+82) {
tmp = t_0;
} else if (z <= -2.3e-93) {
tmp = 4.0;
} else if (z <= 2.7e+60) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + ((z / y) * -4.0) tmp = 0 if z <= -4e+82: tmp = t_0 elif z <= -2.3e-93: tmp = 4.0 elif z <= 2.7e+60: tmp = 1.0 + (4.0 * (x / y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(Float64(z / y) * -4.0)) tmp = 0.0 if (z <= -4e+82) tmp = t_0; elseif (z <= -2.3e-93) tmp = 4.0; elseif (z <= 2.7e+60) tmp = Float64(1.0 + Float64(4.0 * Float64(x / y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + ((z / y) * -4.0); tmp = 0.0; if (z <= -4e+82) tmp = t_0; elseif (z <= -2.3e-93) tmp = 4.0; elseif (z <= 2.7e+60) tmp = 1.0 + (4.0 * (x / y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4e+82], t$95$0, If[LessEqual[z, -2.3e-93], 4.0, If[LessEqual[z, 2.7e+60], N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{z}{y} \cdot -4\\
\mathbf{if}\;z \leq -4 \cdot 10^{+82}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-93}:\\
\;\;\;\;4\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+60}:\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.9999999999999999e82 or 2.6999999999999999e60 < z Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 70.8%
*-commutative70.8%
Simplified70.8%
if -3.9999999999999999e82 < z < -2.2999999999999998e-93Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around inf 62.2%
if -2.2999999999999998e-93 < z < 2.6999999999999999e60Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 62.2%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e+16) (not (<= x 6.8e-53))) (+ 1.0 (* 4.0 (/ x y))) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+16) || !(x <= 6.8e-53)) {
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 <= (-6.8d+16)) .or. (.not. (x <= 6.8d-53))) 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 <= -6.8e+16) || !(x <= 6.8e-53)) {
tmp = 1.0 + (4.0 * (x / y));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e+16) or not (x <= 6.8e-53): tmp = 1.0 + (4.0 * (x / y)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e+16) || !(x <= 6.8e-53)) 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 <= -6.8e+16) || ~((x <= 6.8e-53))) tmp = 1.0 + (4.0 * (x / y)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e+16], N[Not[LessEqual[x, 6.8e-53]], $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 -6.8 \cdot 10^{+16} \lor \neg \left(x \leq 6.8 \cdot 10^{-53}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -6.8e16 or 6.8e-53 < x Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 64.5%
if -6.8e16 < x < 6.8e-53Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around inf 46.3%
Final simplification56.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.02e+93) (not (<= z 7e+160))) (+ 1.0 (* (/ z y) -4.0)) (+ 4.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e+93) || !(z <= 7e+160)) {
tmp = 1.0 + ((z / y) * -4.0);
} else {
tmp = 4.0 + (4.0 * (x / 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 ((z <= (-1.02d+93)) .or. (.not. (z <= 7d+160))) then
tmp = 1.0d0 + ((z / y) * (-4.0d0))
else
tmp = 4.0d0 + (4.0d0 * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e+93) || !(z <= 7e+160)) {
tmp = 1.0 + ((z / y) * -4.0);
} else {
tmp = 4.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.02e+93) or not (z <= 7e+160): tmp = 1.0 + ((z / y) * -4.0) else: tmp = 4.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.02e+93) || !(z <= 7e+160)) tmp = Float64(1.0 + Float64(Float64(z / y) * -4.0)); else tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.02e+93) || ~((z <= 7e+160))) tmp = 1.0 + ((z / y) * -4.0); else tmp = 4.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.02e+93], N[Not[LessEqual[z, 7e+160]], $MachinePrecision]], N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+93} \lor \neg \left(z \leq 7 \cdot 10^{+160}\right):\\
\;\;\;\;1 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.0200000000000001e93 or 7.00000000000000051e160 < z Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 78.8%
*-commutative78.8%
Simplified78.8%
if -1.0200000000000001e93 < z < 7.00000000000000051e160Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 84.5%
Final simplification82.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.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around inf 32.0%
Final simplification32.0%
herbie shell --seed 2023322
(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)))