
(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 (+ 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%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (/ -4.0 (/ y z)))) (t_1 (+ 1.0 (/ 4.0 (/ y x)))))
(if (<= x -5.3e-11)
t_1
(if (<= x -5.2e-160)
t_0
(if (<= x -6e-200)
2.0
(if (<= x 1.2e-242)
t_0
(if (<= x 1.45e-173) 2.0 (if (<= x 1.45e-13) t_0 t_1))))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (-4.0 / (y / z));
double t_1 = 1.0 + (4.0 / (y / x));
double tmp;
if (x <= -5.3e-11) {
tmp = t_1;
} else if (x <= -5.2e-160) {
tmp = t_0;
} else if (x <= -6e-200) {
tmp = 2.0;
} else if (x <= 1.2e-242) {
tmp = t_0;
} else if (x <= 1.45e-173) {
tmp = 2.0;
} else if (x <= 1.45e-13) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + ((-4.0d0) / (y / z))
t_1 = 1.0d0 + (4.0d0 / (y / x))
if (x <= (-5.3d-11)) then
tmp = t_1
else if (x <= (-5.2d-160)) then
tmp = t_0
else if (x <= (-6d-200)) then
tmp = 2.0d0
else if (x <= 1.2d-242) then
tmp = t_0
else if (x <= 1.45d-173) then
tmp = 2.0d0
else if (x <= 1.45d-13) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (-4.0 / (y / z));
double t_1 = 1.0 + (4.0 / (y / x));
double tmp;
if (x <= -5.3e-11) {
tmp = t_1;
} else if (x <= -5.2e-160) {
tmp = t_0;
} else if (x <= -6e-200) {
tmp = 2.0;
} else if (x <= 1.2e-242) {
tmp = t_0;
} else if (x <= 1.45e-173) {
tmp = 2.0;
} else if (x <= 1.45e-13) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (-4.0 / (y / z)) t_1 = 1.0 + (4.0 / (y / x)) tmp = 0 if x <= -5.3e-11: tmp = t_1 elif x <= -5.2e-160: tmp = t_0 elif x <= -6e-200: tmp = 2.0 elif x <= 1.2e-242: tmp = t_0 elif x <= 1.45e-173: tmp = 2.0 elif x <= 1.45e-13: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(-4.0 / Float64(y / z))) t_1 = Float64(1.0 + Float64(4.0 / Float64(y / x))) tmp = 0.0 if (x <= -5.3e-11) tmp = t_1; elseif (x <= -5.2e-160) tmp = t_0; elseif (x <= -6e-200) tmp = 2.0; elseif (x <= 1.2e-242) tmp = t_0; elseif (x <= 1.45e-173) tmp = 2.0; elseif (x <= 1.45e-13) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (-4.0 / (y / z)); t_1 = 1.0 + (4.0 / (y / x)); tmp = 0.0; if (x <= -5.3e-11) tmp = t_1; elseif (x <= -5.2e-160) tmp = t_0; elseif (x <= -6e-200) tmp = 2.0; elseif (x <= 1.2e-242) tmp = t_0; elseif (x <= 1.45e-173) tmp = 2.0; elseif (x <= 1.45e-13) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.3e-11], t$95$1, If[LessEqual[x, -5.2e-160], t$95$0, If[LessEqual[x, -6e-200], 2.0, If[LessEqual[x, 1.2e-242], t$95$0, If[LessEqual[x, 1.45e-173], 2.0, If[LessEqual[x, 1.45e-13], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{-4}{\frac{y}{z}}\\
t_1 := 1 + \frac{4}{\frac{y}{x}}\\
\mathbf{if}\;x \leq -5.3 \cdot 10^{-11}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{-160}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-200}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-242}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-173}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -5.2999999999999998e-11 or 1.4499999999999999e-13 < x Initial program 99.9%
Taylor expanded in x around inf 61.0%
associate-*r/61.0%
associate-/l*60.8%
Simplified60.8%
if -5.2999999999999998e-11 < x < -5.20000000000000007e-160 or -5.99999999999999989e-200 < x < 1.2e-242 or 1.4499999999999999e-173 < x < 1.4499999999999999e-13Initial program 100.0%
Taylor expanded in z around inf 66.4%
associate-*r/66.4%
associate-/l*66.2%
Simplified66.2%
if -5.20000000000000007e-160 < x < -5.99999999999999989e-200 or 1.2e-242 < x < 1.4499999999999999e-173Initial program 100.0%
Taylor expanded in y around inf 82.2%
Final simplification65.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.3e-131) (not (<= z 1.25e+48))) (+ 1.0 (/ -4.0 (/ y z))) 2.0))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-131) || !(z <= 1.25e+48)) {
tmp = 1.0 + (-4.0 / (y / 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 ((z <= (-2.3d-131)) .or. (.not. (z <= 1.25d+48))) then
tmp = 1.0d0 + ((-4.0d0) / (y / z))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-131) || !(z <= 1.25e+48)) {
tmp = 1.0 + (-4.0 / (y / z));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e-131) or not (z <= 1.25e+48): tmp = 1.0 + (-4.0 / (y / z)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-131) || !(z <= 1.25e+48)) tmp = Float64(1.0 + Float64(-4.0 / Float64(y / z))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.3e-131) || ~((z <= 1.25e+48))) tmp = 1.0 + (-4.0 / (y / z)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-131], N[Not[LessEqual[z, 1.25e+48]], $MachinePrecision]], N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-131} \lor \neg \left(z \leq 1.25 \cdot 10^{+48}\right):\\
\;\;\;\;1 + \frac{-4}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if z < -2.30000000000000022e-131 or 1.24999999999999993e48 < z Initial program 99.9%
Taylor expanded in z around inf 65.2%
associate-*r/65.2%
associate-/l*65.0%
Simplified65.0%
if -2.30000000000000022e-131 < z < 1.24999999999999993e48Initial program 99.9%
Taylor expanded in y around inf 45.8%
Final simplification56.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e+81) (not (<= z 3.5e+86))) (+ 1.0 (/ -4.0 (/ y z))) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+81) || !(z <= 3.5e+86)) {
tmp = 1.0 + (-4.0 / (y / z));
} 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 <= (-3.2d+81)) .or. (.not. (z <= 3.5d+86))) then
tmp = 1.0d0 + ((-4.0d0) / (y / z))
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 <= -3.2e+81) || !(z <= 3.5e+86)) {
tmp = 1.0 + (-4.0 / (y / z));
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+81) or not (z <= 3.5e+86): tmp = 1.0 + (-4.0 / (y / z)) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+81) || !(z <= 3.5e+86)) tmp = Float64(1.0 + Float64(-4.0 / Float64(y / z))); 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 <= -3.2e+81) || ~((z <= 3.5e+86))) tmp = 1.0 + (-4.0 / (y / z)); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+81], N[Not[LessEqual[z, 3.5e+86]], $MachinePrecision]], N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+81} \lor \neg \left(z \leq 3.5 \cdot 10^{+86}\right):\\
\;\;\;\;1 + \frac{-4}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.2e81 or 3.50000000000000019e86 < z Initial program 99.9%
Taylor expanded in z around inf 77.7%
associate-*r/77.7%
associate-/l*77.5%
Simplified77.5%
if -3.2e81 < z < 3.50000000000000019e86Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
Taylor expanded in z around 0 86.4%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e+79) (not (<= z 1.46e+32))) (+ 2.0 (/ (* z -4.0) y)) (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e+79) || !(z <= 1.46e+32)) {
tmp = 2.0 + ((z * -4.0) / y);
} 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 <= (-4d+79)) .or. (.not. (z <= 1.46d+32))) then
tmp = 2.0d0 + ((z * (-4.0d0)) / y)
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 <= -4e+79) || !(z <= 1.46e+32)) {
tmp = 2.0 + ((z * -4.0) / y);
} else {
tmp = 2.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e+79) or not (z <= 1.46e+32): tmp = 2.0 + ((z * -4.0) / y) else: tmp = 2.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e+79) || !(z <= 1.46e+32)) tmp = Float64(2.0 + Float64(Float64(z * -4.0) / y)); 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 <= -4e+79) || ~((z <= 1.46e+32))) tmp = 2.0 + ((z * -4.0) / y); else tmp = 2.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e+79], N[Not[LessEqual[z, 1.46e+32]], $MachinePrecision]], N[(2.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+79} \lor \neg \left(z \leq 1.46 \cdot 10^{+32}\right):\\
\;\;\;\;2 + \frac{z \cdot -4}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.99999999999999987e79 or 1.46000000000000005e32 < z Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
Simplified99.7%
Taylor expanded in x around 0 86.2%
+-commutative86.2%
associate-*r/86.2%
Simplified86.2%
if -3.99999999999999987e79 < z < 1.46000000000000005e32Initial program 100.0%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.8%
associate-+r+99.8%
Simplified99.8%
Taylor expanded in z around 0 89.1%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (/ 4.0 y) (- x z))))
double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (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 = 2.0d0 + ((4.0d0 / y) * (x - z))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
def code(x, y, z): return 2.0 + ((4.0 / y) * (x - z))
function code(x, y, z) return Float64(2.0 + Float64(Float64(4.0 / y) * Float64(x - z))) end
function tmp = code(x, y, z) tmp = 2.0 + ((4.0 / y) * (x - z)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(4.0 / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{4}{y} \cdot \left(x - z\right)
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
Simplified99.7%
Final simplification99.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.9%
Taylor expanded in y around inf 31.4%
Final simplification31.4%
herbie shell --seed 2024096
(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)))