
(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(Float64(4.0 * 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[(N[(4.0 * N[(x - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(x - z\right)}{y} + 2
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1250000000.0) (not (<= x 1.25e-68))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1250000000.0) || !(x <= 1.25e-68)) {
tmp = 2.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 <= (-1250000000.0d0)) .or. (.not. (x <= 1.25d-68))) then
tmp = 2.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 <= -1250000000.0) || !(x <= 1.25e-68)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1250000000.0) or not (x <= 1.25e-68): tmp = 2.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 <= -1250000000.0) || !(x <= 1.25e-68)) tmp = Float64(2.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 <= -1250000000.0) || ~((x <= 1.25e-68))) tmp = 2.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, -1250000000.0], N[Not[LessEqual[x, 1.25e-68]], $MachinePrecision]], N[(2.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 -1250000000 \lor \neg \left(x \leq 1.25 \cdot 10^{-68}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -1.25e9 or 1.24999999999999993e-68 < x Initial program 100.0%
+-commutative100.0%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
+-commutative99.7%
distribute-lft-in99.7%
associate-+l+99.7%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 84.0%
if -1.25e9 < x < 1.24999999999999993e-68Initial program 99.9%
+-commutative99.9%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.9%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 93.4%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= y -4300000000000.0) 2.0 (if (<= y 4.1e+85) (* -4.0 (/ z y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4300000000000.0) {
tmp = 2.0;
} else if (y <= 4.1e+85) {
tmp = -4.0 * (z / 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 (y <= (-4300000000000.0d0)) then
tmp = 2.0d0
else if (y <= 4.1d+85) then
tmp = (-4.0d0) * (z / y)
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4300000000000.0) {
tmp = 2.0;
} else if (y <= 4.1e+85) {
tmp = -4.0 * (z / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4300000000000.0: tmp = 2.0 elif y <= 4.1e+85: tmp = -4.0 * (z / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4300000000000.0) tmp = 2.0; elseif (y <= 4.1e+85) tmp = Float64(-4.0 * Float64(z / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4300000000000.0) tmp = 2.0; elseif (y <= 4.1e+85) tmp = -4.0 * (z / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4300000000000.0], 2.0, If[LessEqual[y, 4.1e+85], N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4300000000000:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+85}:\\
\;\;\;\;-4 \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -4.3e12 or 4.09999999999999978e85 < y Initial program 99.9%
+-commutative99.9%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 81.8%
Taylor expanded in z around 0 65.4%
if -4.3e12 < y < 4.09999999999999978e85Initial program 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 53.6%
Taylor expanded in z around inf 47.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 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 97.3%
*-commutative97.3%
associate-*l/97.3%
associate-*r/97.2%
metadata-eval97.2%
distribute-neg-frac97.2%
metadata-eval97.2%
associate-*r/97.2%
distribute-rgt-neg-in97.2%
*-commutative97.2%
distribute-rgt-neg-in97.2%
associate-*r/97.2%
associate-*l/97.1%
metadata-eval97.1%
associate-*r/97.1%
distribute-lft-in99.8%
+-commutative99.8%
sub-neg99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ 2.0 (* -4.0 (/ z y))))
double code(double x, double y, double z) {
return 2.0 + (-4.0 * (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 = 2.0d0 + ((-4.0d0) * (z / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (-4.0 * (z / y));
}
def code(x, y, z): return 2.0 + (-4.0 * (z / y))
function code(x, y, z) return Float64(2.0 + Float64(-4.0 * Float64(z / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (-4.0 * (z / y)); end
code[x_, y_, z_] := N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + -4 \cdot \frac{z}{y}
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 64.7%
Final simplification64.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 100.0%
+-commutative100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
*-rgt-identity100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 64.7%
Taylor expanded in z around 0 31.1%
herbie shell --seed 2024097
(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)))