
(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 7 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 (+ 2.0 (/ (- x z) (* y 0.25))))
double code(double x, double y, double z) {
return 2.0 + ((x - z) / (y * 0.25));
}
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 + ((x - z) / (y * 0.25d0))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) / (y * 0.25));
}
def code(x, y, z): return 2.0 + ((x - z) / (y * 0.25))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) / Float64(y * 0.25))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) / (y * 0.25)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] / N[(y * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{x - z}{y \cdot 0.25}
\end{array}
Initial program 99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
metadata-eval99.8%
associate-/l*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-out99.8%
associate-/l*99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-lft-neg-out99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
clear-num99.8%
div-inv99.8%
metadata-eval99.8%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.4e-132) (not (<= x 1.9e-14))) (+ (* 4.0 (/ x y)) 1.0) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.4e-132) || !(x <= 1.9e-14)) {
tmp = (4.0 * (x / y)) + 1.0;
} 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 <= (-5.4d-132)) .or. (.not. (x <= 1.9d-14))) then
tmp = (4.0d0 * (x / y)) + 1.0d0
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.4e-132) || !(x <= 1.9e-14)) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.4e-132) or not (x <= 1.9e-14): tmp = (4.0 * (x / y)) + 1.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.4e-132) || !(x <= 1.9e-14)) tmp = Float64(Float64(4.0 * Float64(x / y)) + 1.0); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.4e-132) || ~((x <= 1.9e-14))) tmp = (4.0 * (x / y)) + 1.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.4e-132], N[Not[LessEqual[x, 1.9e-14]], $MachinePrecision]], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-132} \lor \neg \left(x \leq 1.9 \cdot 10^{-14}\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -5.3999999999999998e-132 or 1.9000000000000001e-14 < x Initial program 99.4%
Taylor expanded in x around inf 65.0%
if -5.3999999999999998e-132 < x < 1.9000000000000001e-14Initial program 100.0%
Taylor expanded in y around inf 50.6%
Final simplification59.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-40) (not (<= z 1.78e+196))) (+ 2.0 (* (/ z y) -4.0)) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-40) || !(z <= 1.78e+196)) {
tmp = 2.0 + ((z / y) * -4.0);
} else {
tmp = 2.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 <= (-8.5d-40)) .or. (.not. (z <= 1.78d+196))) then
tmp = 2.0d0 + ((z / y) * (-4.0d0))
else
tmp = 2.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 <= -8.5e-40) || !(z <= 1.78e+196)) {
tmp = 2.0 + ((z / y) * -4.0);
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-40) or not (z <= 1.78e+196): tmp = 2.0 + ((z / y) * -4.0) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-40) || !(z <= 1.78e+196)) tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); else tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-40) || ~((z <= 1.78e+196))) tmp = 2.0 + ((z / y) * -4.0); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-40], N[Not[LessEqual[z, 1.78e+196]], $MachinePrecision]], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-40} \lor \neg \left(z \leq 1.78 \cdot 10^{+196}\right):\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -8.4999999999999998e-40 or 1.7799999999999999e196 < z Initial program 98.9%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
metadata-eval99.8%
associate-/l*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-out99.8%
associate-/l*99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-lft-neg-out99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 85.6%
+-commutative85.6%
*-commutative85.6%
Simplified85.6%
if -8.4999999999999998e-40 < z < 1.7799999999999999e196Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
metadata-eval99.8%
associate-/l*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-out99.8%
associate-/l*99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-lft-neg-out99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 90.1%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / y));
}
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 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 2.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Initial program 99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
metadata-eval99.8%
associate-/l*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-out99.8%
associate-/l*99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-lft-neg-out99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ 2.0 (* 4.0 (/ x y))))
double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
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 + (4.0d0 * (x / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
def code(x, y, z): return 2.0 + (4.0 * (x / y))
function code(x, y, z) return Float64(2.0 + Float64(4.0 * Float64(x / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (4.0 * (x / y)); end
code[x_, y_, z_] := N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + 4 \cdot \frac{x}{y}
\end{array}
Initial program 99.6%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
metadata-eval99.8%
associate-/l*99.8%
distribute-rgt-neg-in99.8%
distribute-lft-neg-out99.8%
associate-/l*99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-lft-neg-out99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 71.7%
Final simplification71.7%
(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.6%
Taylor expanded in x around inf 46.1%
Taylor expanded in x around 0 7.7%
Final simplification7.7%
(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.6%
Taylor expanded in y around inf 32.5%
Final simplification32.5%
herbie shell --seed 2023310
(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)))