
(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 8 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 (+ 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}
Initial program 99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ z y) -4.0)))
(if (<= z -1.4e+75)
t_0
(if (<= z -9.5e-172) 2.0 (if (<= z 4.5e+30) (/ (* 4.0 x) y) t_0)))))
double code(double x, double y, double z) {
double t_0 = (z / y) * -4.0;
double tmp;
if (z <= -1.4e+75) {
tmp = t_0;
} else if (z <= -9.5e-172) {
tmp = 2.0;
} else if (z <= 4.5e+30) {
tmp = (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 = (z / y) * (-4.0d0)
if (z <= (-1.4d+75)) then
tmp = t_0
else if (z <= (-9.5d-172)) then
tmp = 2.0d0
else if (z <= 4.5d+30) then
tmp = (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 = (z / y) * -4.0;
double tmp;
if (z <= -1.4e+75) {
tmp = t_0;
} else if (z <= -9.5e-172) {
tmp = 2.0;
} else if (z <= 4.5e+30) {
tmp = (4.0 * x) / y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z / y) * -4.0 tmp = 0 if z <= -1.4e+75: tmp = t_0 elif z <= -9.5e-172: tmp = 2.0 elif z <= 4.5e+30: tmp = (4.0 * x) / y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z / y) * -4.0) tmp = 0.0 if (z <= -1.4e+75) tmp = t_0; elseif (z <= -9.5e-172) tmp = 2.0; elseif (z <= 4.5e+30) tmp = Float64(Float64(4.0 * x) / y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z / y) * -4.0; tmp = 0.0; if (z <= -1.4e+75) tmp = t_0; elseif (z <= -9.5e-172) tmp = 2.0; elseif (z <= 4.5e+30) tmp = (4.0 * x) / y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]}, If[LessEqual[z, -1.4e+75], t$95$0, If[LessEqual[z, -9.5e-172], 2.0, If[LessEqual[z, 4.5e+30], N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{z}{y} \cdot -4\\
\mathbf{if}\;z \leq -1.4 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{-172}:\\
\;\;\;\;2\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{4 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.40000000000000006e75 or 4.49999999999999995e30 < z Initial program 99.9%
Taylor expanded in z around inf 67.1%
*-commutative67.1%
Simplified67.1%
if -1.40000000000000006e75 < z < -9.50000000000000053e-172Initial program 100.0%
Taylor expanded in y around inf 50.3%
if -9.50000000000000053e-172 < z < 4.49999999999999995e30Initial program 100.0%
Taylor expanded in x around inf 58.3%
associate-*r/58.3%
Simplified58.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e+66) (not (<= y 2.25e+14))) (+ 2.0 (* (/ z y) -4.0)) (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e+66) || !(y <= 2.25e+14)) {
tmp = 2.0 + ((z / y) * -4.0);
} else {
tmp = 4.0 * ((x - 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 ((y <= (-1.35d+66)) .or. (.not. (y <= 2.25d+14))) then
tmp = 2.0d0 + ((z / y) * (-4.0d0))
else
tmp = 4.0d0 * ((x - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e+66) || !(y <= 2.25e+14)) {
tmp = 2.0 + ((z / y) * -4.0);
} else {
tmp = 4.0 * ((x - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e+66) or not (y <= 2.25e+14): tmp = 2.0 + ((z / y) * -4.0) else: tmp = 4.0 * ((x - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e+66) || !(y <= 2.25e+14)) tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); else tmp = Float64(4.0 * Float64(Float64(x - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e+66) || ~((y <= 2.25e+14))) tmp = 2.0 + ((z / y) * -4.0); else tmp = 4.0 * ((x - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e+66], N[Not[LessEqual[y, 2.25e+14]], $MachinePrecision]], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+66} \lor \neg \left(y \leq 2.25 \cdot 10^{+14}\right):\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\end{array}
\end{array}
if y < -1.35e66 or 2.25e14 < 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.9%
associate-*l/99.9%
*-commutative99.9%
associate-*r*99.9%
metadata-eval99.9%
*-lft-identity99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 83.3%
*-commutative83.3%
Simplified83.3%
if -1.35e66 < y < 2.25e14Initial program 100.0%
Taylor expanded in y around 0 95.4%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (<= y -9.5e+107) 2.0 (if (<= y 4e+130) (* 4.0 (/ (- x z) y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e+107) {
tmp = 2.0;
} else if (y <= 4e+130) {
tmp = 4.0 * ((x - 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 <= (-9.5d+107)) then
tmp = 2.0d0
else if (y <= 4d+130) then
tmp = 4.0d0 * ((x - 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 <= -9.5e+107) {
tmp = 2.0;
} else if (y <= 4e+130) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.5e+107: tmp = 2.0 elif y <= 4e+130: tmp = 4.0 * ((x - z) / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.5e+107) tmp = 2.0; elseif (y <= 4e+130) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.5e+107) tmp = 2.0; elseif (y <= 4e+130) tmp = 4.0 * ((x - z) / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.5e+107], 2.0, If[LessEqual[y, 4e+130], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+107}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+130}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -9.50000000000000019e107 or 4.0000000000000002e130 < y Initial program 99.9%
Taylor expanded in y around inf 74.1%
if -9.50000000000000019e107 < y < 4.0000000000000002e130Initial program 99.9%
Taylor expanded in y around 0 87.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.55e+66) 2.0 (if (<= y 2e-18) (* (/ z y) -4.0) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+66) {
tmp = 2.0;
} else if (y <= 2e-18) {
tmp = (z / y) * -4.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 (y <= (-1.55d+66)) then
tmp = 2.0d0
else if (y <= 2d-18) then
tmp = (z / y) * (-4.0d0)
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+66) {
tmp = 2.0;
} else if (y <= 2e-18) {
tmp = (z / y) * -4.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e+66: tmp = 2.0 elif y <= 2e-18: tmp = (z / y) * -4.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e+66) tmp = 2.0; elseif (y <= 2e-18) tmp = Float64(Float64(z / y) * -4.0); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.55e+66) tmp = 2.0; elseif (y <= 2e-18) tmp = (z / y) * -4.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e+66], 2.0, If[LessEqual[y, 2e-18], N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+66}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-18}:\\
\;\;\;\;\frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.55000000000000009e66 or 2.0000000000000001e-18 < y Initial program 99.9%
Taylor expanded in y around inf 63.2%
if -1.55000000000000009e66 < y < 2.0000000000000001e-18Initial program 100.0%
Taylor expanded in z around inf 50.3%
*-commutative50.3%
Simplified50.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.25e+66) 2.0 (if (<= y 1.55e-15) (* z (/ -4.0 y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.25e+66) {
tmp = 2.0;
} else if (y <= 1.55e-15) {
tmp = z * (-4.0 / 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 <= (-1.25d+66)) then
tmp = 2.0d0
else if (y <= 1.55d-15) then
tmp = z * ((-4.0d0) / 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 <= -1.25e+66) {
tmp = 2.0;
} else if (y <= 1.55e-15) {
tmp = z * (-4.0 / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.25e+66: tmp = 2.0 elif y <= 1.55e-15: tmp = z * (-4.0 / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.25e+66) tmp = 2.0; elseif (y <= 1.55e-15) tmp = Float64(z * Float64(-4.0 / y)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.25e+66) tmp = 2.0; elseif (y <= 1.55e-15) tmp = z * (-4.0 / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.25e+66], 2.0, If[LessEqual[y, 1.55e-15], N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+66}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-15}:\\
\;\;\;\;z \cdot \frac{-4}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.24999999999999998e66 or 1.5499999999999999e-15 < y Initial program 99.9%
Taylor expanded in y around inf 63.2%
if -1.24999999999999998e66 < y < 1.5499999999999999e-15Initial program 100.0%
Taylor expanded in z around inf 50.3%
associate-*r/50.3%
*-commutative50.3%
associate-/l*50.2%
Simplified50.2%
(FPCore (x y z) :precision binary64 (+ (* (/ 4.0 y) (- x z)) 2.0))
double code(double x, double y, double z) {
return ((4.0 / y) * (x - z)) + 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 / y) * (x - z)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return ((4.0 / y) * (x - z)) + 2.0;
}
def code(x, y, z): return ((4.0 / y) * (x - z)) + 2.0
function code(x, y, z) return Float64(Float64(Float64(4.0 / y) * Float64(x - z)) + 2.0) end
function tmp = code(x, y, z) tmp = ((4.0 / y) * (x - z)) + 2.0; end
code[x_, y_, z_] := N[(N[(N[(4.0 / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{y} \cdot \left(x - z\right) + 2
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
+-commutative99.7%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
*-lft-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.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.9%
Taylor expanded in y around inf 30.5%
herbie shell --seed 2024163
(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)))