
(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 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.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
(let* ((t_0 (/ (* x 4.0) y)))
(if (<= x -1.85e+177)
t_0
(if (<= x -3.75e+81)
2.0
(if (<= x -650000000000.0)
t_0
(if (<= x -2.25e-221)
2.0
(if (<= x 3.4e-202)
(* (/ z y) -4.0)
(if (<= x 4.8e+70) 2.0 t_0))))))))
double code(double x, double y, double z) {
double t_0 = (x * 4.0) / y;
double tmp;
if (x <= -1.85e+177) {
tmp = t_0;
} else if (x <= -3.75e+81) {
tmp = 2.0;
} else if (x <= -650000000000.0) {
tmp = t_0;
} else if (x <= -2.25e-221) {
tmp = 2.0;
} else if (x <= 3.4e-202) {
tmp = (z / y) * -4.0;
} else if (x <= 4.8e+70) {
tmp = 2.0;
} 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 = (x * 4.0d0) / y
if (x <= (-1.85d+177)) then
tmp = t_0
else if (x <= (-3.75d+81)) then
tmp = 2.0d0
else if (x <= (-650000000000.0d0)) then
tmp = t_0
else if (x <= (-2.25d-221)) then
tmp = 2.0d0
else if (x <= 3.4d-202) then
tmp = (z / y) * (-4.0d0)
else if (x <= 4.8d+70) then
tmp = 2.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 4.0) / y;
double tmp;
if (x <= -1.85e+177) {
tmp = t_0;
} else if (x <= -3.75e+81) {
tmp = 2.0;
} else if (x <= -650000000000.0) {
tmp = t_0;
} else if (x <= -2.25e-221) {
tmp = 2.0;
} else if (x <= 3.4e-202) {
tmp = (z / y) * -4.0;
} else if (x <= 4.8e+70) {
tmp = 2.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 4.0) / y tmp = 0 if x <= -1.85e+177: tmp = t_0 elif x <= -3.75e+81: tmp = 2.0 elif x <= -650000000000.0: tmp = t_0 elif x <= -2.25e-221: tmp = 2.0 elif x <= 3.4e-202: tmp = (z / y) * -4.0 elif x <= 4.8e+70: tmp = 2.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 4.0) / y) tmp = 0.0 if (x <= -1.85e+177) tmp = t_0; elseif (x <= -3.75e+81) tmp = 2.0; elseif (x <= -650000000000.0) tmp = t_0; elseif (x <= -2.25e-221) tmp = 2.0; elseif (x <= 3.4e-202) tmp = Float64(Float64(z / y) * -4.0); elseif (x <= 4.8e+70) tmp = 2.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 4.0) / y; tmp = 0.0; if (x <= -1.85e+177) tmp = t_0; elseif (x <= -3.75e+81) tmp = 2.0; elseif (x <= -650000000000.0) tmp = t_0; elseif (x <= -2.25e-221) tmp = 2.0; elseif (x <= 3.4e-202) tmp = (z / y) * -4.0; elseif (x <= 4.8e+70) tmp = 2.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 4.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -1.85e+177], t$95$0, If[LessEqual[x, -3.75e+81], 2.0, If[LessEqual[x, -650000000000.0], t$95$0, If[LessEqual[x, -2.25e-221], 2.0, If[LessEqual[x, 3.4e-202], N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision], If[LessEqual[x, 4.8e+70], 2.0, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot 4}{y}\\
\mathbf{if}\;x \leq -1.85 \cdot 10^{+177}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.75 \cdot 10^{+81}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq -650000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.25 \cdot 10^{-221}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-202}:\\
\;\;\;\;\frac{z}{y} \cdot -4\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+70}:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.85000000000000007e177 or -3.74999999999999986e81 < x < -6.5e11 or 4.79999999999999974e70 < x Initial program 100.0%
Taylor expanded in x around inf 71.7%
associate-*r/71.7%
*-commutative71.7%
Simplified71.7%
if -1.85000000000000007e177 < x < -3.74999999999999986e81 or -6.5e11 < x < -2.25000000000000013e-221 or 3.40000000000000012e-202 < x < 4.79999999999999974e70Initial program 100.0%
Taylor expanded in y around inf 58.0%
if -2.25000000000000013e-221 < x < 3.40000000000000012e-202Initial program 100.0%
Taylor expanded in z around inf 58.6%
*-commutative58.6%
Simplified58.6%
Final simplification63.5%
(FPCore (x y z) :precision binary64 (if (<= y -5.5e+149) 2.0 (if (<= y 4.1e+108) (* 4.0 (/ (- x z) y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+149) {
tmp = 2.0;
} else if (y <= 4.1e+108) {
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 <= (-5.5d+149)) then
tmp = 2.0d0
else if (y <= 4.1d+108) 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 <= -5.5e+149) {
tmp = 2.0;
} else if (y <= 4.1e+108) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e+149: tmp = 2.0 elif y <= 4.1e+108: tmp = 4.0 * ((x - z) / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e+149) tmp = 2.0; elseif (y <= 4.1e+108) 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 <= -5.5e+149) tmp = 2.0; elseif (y <= 4.1e+108) tmp = 4.0 * ((x - z) / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e+149], 2.0, If[LessEqual[y, 4.1e+108], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+149}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+108}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -5.49999999999999999e149 or 4.0999999999999999e108 < y Initial program 100.0%
Taylor expanded in y around inf 82.5%
if -5.49999999999999999e149 < y < 4.0999999999999999e108Initial program 100.0%
Taylor expanded in y around 0 84.3%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (if (<= y -4.5e+148) 2.0 (if (<= y 1.1e+36) (* z (/ -4.0 y)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+148) {
tmp = 2.0;
} else if (y <= 1.1e+36) {
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 <= (-4.5d+148)) then
tmp = 2.0d0
else if (y <= 1.1d+36) 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 <= -4.5e+148) {
tmp = 2.0;
} else if (y <= 1.1e+36) {
tmp = z * (-4.0 / y);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+148: tmp = 2.0 elif y <= 1.1e+36: tmp = z * (-4.0 / y) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+148) tmp = 2.0; elseif (y <= 1.1e+36) 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 <= -4.5e+148) tmp = 2.0; elseif (y <= 1.1e+36) tmp = z * (-4.0 / y); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+148], 2.0, If[LessEqual[y, 1.1e+36], N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+148}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+36}:\\
\;\;\;\;z \cdot \frac{-4}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -4.49999999999999994e148 or 1.1e36 < y Initial program 100.0%
Taylor expanded in y around inf 74.3%
if -4.49999999999999994e148 < y < 1.1e36Initial program 100.0%
Taylor expanded in y around 0 86.5%
Taylor expanded in x around 0 46.6%
associate-*r/46.6%
associate-*l/46.5%
*-commutative46.5%
Simplified46.5%
Final simplification57.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.45e+151) 2.0 (if (<= y 4.4e+35) (* (/ z y) -4.0) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.45e+151) {
tmp = 2.0;
} else if (y <= 4.4e+35) {
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 <= (-2.45d+151)) then
tmp = 2.0d0
else if (y <= 4.4d+35) 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 <= -2.45e+151) {
tmp = 2.0;
} else if (y <= 4.4e+35) {
tmp = (z / y) * -4.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.45e+151: tmp = 2.0 elif y <= 4.4e+35: tmp = (z / y) * -4.0 else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.45e+151) tmp = 2.0; elseif (y <= 4.4e+35) 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 <= -2.45e+151) tmp = 2.0; elseif (y <= 4.4e+35) tmp = (z / y) * -4.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.45e+151], 2.0, If[LessEqual[y, 4.4e+35], N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{+151}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{+35}:\\
\;\;\;\;\frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -2.45e151 or 4.3999999999999997e35 < y Initial program 100.0%
Taylor expanded in y around inf 74.3%
if -2.45e151 < y < 4.3999999999999997e35Initial program 100.0%
Taylor expanded in z around inf 46.6%
*-commutative46.6%
Simplified46.6%
Final simplification57.4%
(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%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
Final simplification99.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 100.0%
Taylor expanded in y around inf 37.9%
Final simplification37.9%
herbie shell --seed 2024010
(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)))