
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (* -4.0 (- (/ (- y x) z) -0.5)))
double code(double x, double y, double z) {
return -4.0 * (((y - x) / z) - -0.5);
}
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) * (((y - x) / z) - (-0.5d0))
end function
public static double code(double x, double y, double z) {
return -4.0 * (((y - x) / z) - -0.5);
}
def code(x, y, z): return -4.0 * (((y - x) / z) - -0.5)
function code(x, y, z) return Float64(-4.0 * Float64(Float64(Float64(y - x) / z) - -0.5)) end
function tmp = code(x, y, z) tmp = -4.0 * (((y - x) / z) - -0.5); end
code[x_, y_, z_] := N[(-4.0 * N[(N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(\frac{y - x}{z} - -0.5\right)
\end{array}
Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e+67) (not (<= x 0.0145))) (* -4.0 (- 0.5 (/ x z))) (* -4.0 (- (/ y z) -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+67) || !(x <= 0.0145)) {
tmp = -4.0 * (0.5 - (x / z));
} else {
tmp = -4.0 * ((y / z) - -0.5);
}
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 <= (-2.9d+67)) .or. (.not. (x <= 0.0145d0))) then
tmp = (-4.0d0) * (0.5d0 - (x / z))
else
tmp = (-4.0d0) * ((y / z) - (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+67) || !(x <= 0.0145)) {
tmp = -4.0 * (0.5 - (x / z));
} else {
tmp = -4.0 * ((y / z) - -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e+67) or not (x <= 0.0145): tmp = -4.0 * (0.5 - (x / z)) else: tmp = -4.0 * ((y / z) - -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e+67) || !(x <= 0.0145)) tmp = Float64(-4.0 * Float64(0.5 - Float64(x / z))); else tmp = Float64(-4.0 * Float64(Float64(y / z) - -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.9e+67) || ~((x <= 0.0145))) tmp = -4.0 * (0.5 - (x / z)); else tmp = -4.0 * ((y / z) - -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e+67], N[Not[LessEqual[x, 0.0145]], $MachinePrecision]], N[(-4.0 * N[(0.5 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(y / z), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+67} \lor \neg \left(x \leq 0.0145\right):\\
\;\;\;\;-4 \cdot \left(0.5 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\frac{y}{z} - -0.5\right)\\
\end{array}
\end{array}
if x < -2.90000000000000023e67 or 0.0145000000000000007 < x Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 86.1%
neg-mul-186.1%
distribute-neg-frac86.1%
Simplified86.1%
Taylor expanded in x around 0 86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
if -2.90000000000000023e67 < x < 0.0145000000000000007Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 91.7%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e+67) (not (<= x 1.25e+150))) (* -4.0 (/ x (- z))) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e+67) || !(x <= 1.25e+150)) {
tmp = -4.0 * (x / -z);
} 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.6d+67)) .or. (.not. (x <= 1.25d+150))) then
tmp = (-4.0d0) * (x / -z)
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.6e+67) || !(x <= 1.25e+150)) {
tmp = -4.0 * (x / -z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e+67) or not (x <= 1.25e+150): tmp = -4.0 * (x / -z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e+67) || !(x <= 1.25e+150)) tmp = Float64(-4.0 * Float64(x / Float64(-z))); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e+67) || ~((x <= 1.25e+150))) tmp = -4.0 * (x / -z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e+67], N[Not[LessEqual[x, 1.25e+150]], $MachinePrecision]], N[(-4.0 * N[(x / (-z)), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+67} \lor \neg \left(x \leq 1.25 \cdot 10^{+150}\right):\\
\;\;\;\;-4 \cdot \frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if x < -3.5999999999999999e67 or 1.25000000000000002e150 < x Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 91.2%
neg-mul-191.2%
distribute-neg-frac91.2%
Simplified91.2%
Taylor expanded in x around 0 91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
Taylor expanded in x around inf 76.5%
mul-1-neg76.5%
distribute-frac-neg76.5%
Simplified76.5%
if -3.5999999999999999e67 < x < 1.25000000000000002e150Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 57.3%
neg-mul-157.3%
distribute-neg-frac57.3%
Simplified57.3%
Taylor expanded in x around 0 46.1%
Final simplification53.9%
(FPCore (x y z) :precision binary64 (* -4.0 (- 0.5 (/ x z))))
double code(double x, double y, double z) {
return -4.0 * (0.5 - (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 = (-4.0d0) * (0.5d0 - (x / z))
end function
public static double code(double x, double y, double z) {
return -4.0 * (0.5 - (x / z));
}
def code(x, y, z): return -4.0 * (0.5 - (x / z))
function code(x, y, z) return Float64(-4.0 * Float64(0.5 - Float64(x / z))) end
function tmp = code(x, y, z) tmp = -4.0 * (0.5 - (x / z)); end
code[x_, y_, z_] := N[(-4.0 * N[(0.5 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(0.5 - \frac{x}{z}\right)
\end{array}
Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 66.0%
neg-mul-166.0%
distribute-neg-frac66.0%
Simplified66.0%
Taylor expanded in x around 0 66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
Final simplification66.0%
(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 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 66.0%
neg-mul-166.0%
distribute-neg-frac66.0%
Simplified66.0%
Taylor expanded in x around 0 38.4%
Final simplification38.4%
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
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)) - (2.0d0 + (4.0d0 * (y / z)))
end function
public static double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
def code(x, y, z): return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)))
function code(x, y, z) return Float64(Float64(4.0 * Float64(x / z)) - Float64(2.0 + Float64(4.0 * Float64(y / z)))) end
function tmp = code(x, y, z) tmp = (4.0 * (x / z)) - (2.0 + (4.0 * (y / z))); end
code[x_, y_, z_] := N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 + N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right)
\end{array}
herbie shell --seed 2024067
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:alt
(- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))