
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\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.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - 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.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ 4.0 (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - 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 = 4.0d0 + (4.0d0 * ((x - z) / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - z) / y));
}
def code(x, y, z): return 4.0 + (4.0 * ((x - z) / y))
function code(x, y, z) return Float64(4.0 + Float64(4.0 * Float64(Float64(x - z) / y))) end
function tmp = code(x, y, z) tmp = 4.0 + (4.0 * ((x - z) / y)); end
code[x_, y_, z_] := N[(4.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + 4 \cdot \frac{x - z}{y}
\end{array}
Initial program 99.6%
associate-*l/99.3%
sub-neg99.3%
sub-neg99.3%
+-commutative99.3%
fma-def99.3%
Simplified99.3%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x y))) (t_1 (/ (* z -4.0) y)))
(if (<= x -1.65e+50)
t_0
(if (<= x -3.1e-18)
t_1
(if (<= x -1.05e-42)
t_0
(if (<= x -2.2e-60)
4.0
(if (<= x -1.45e-174)
t_1
(if (<= x -1.45e-215)
4.0
(if (<= x 1.55e-299)
t_1
(if (<= x 2.2e-253) 4.0 (if (<= x 1.65e+95) t_1 t_0)))))))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / y);
double t_1 = (z * -4.0) / y;
double tmp;
if (x <= -1.65e+50) {
tmp = t_0;
} else if (x <= -3.1e-18) {
tmp = t_1;
} else if (x <= -1.05e-42) {
tmp = t_0;
} else if (x <= -2.2e-60) {
tmp = 4.0;
} else if (x <= -1.45e-174) {
tmp = t_1;
} else if (x <= -1.45e-215) {
tmp = 4.0;
} else if (x <= 1.55e-299) {
tmp = t_1;
} else if (x <= 2.2e-253) {
tmp = 4.0;
} else if (x <= 1.65e+95) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / y)
t_1 = (z * (-4.0d0)) / y
if (x <= (-1.65d+50)) then
tmp = t_0
else if (x <= (-3.1d-18)) then
tmp = t_1
else if (x <= (-1.05d-42)) then
tmp = t_0
else if (x <= (-2.2d-60)) then
tmp = 4.0d0
else if (x <= (-1.45d-174)) then
tmp = t_1
else if (x <= (-1.45d-215)) then
tmp = 4.0d0
else if (x <= 1.55d-299) then
tmp = t_1
else if (x <= 2.2d-253) then
tmp = 4.0d0
else if (x <= 1.65d+95) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (x / y);
double t_1 = (z * -4.0) / y;
double tmp;
if (x <= -1.65e+50) {
tmp = t_0;
} else if (x <= -3.1e-18) {
tmp = t_1;
} else if (x <= -1.05e-42) {
tmp = t_0;
} else if (x <= -2.2e-60) {
tmp = 4.0;
} else if (x <= -1.45e-174) {
tmp = t_1;
} else if (x <= -1.45e-215) {
tmp = 4.0;
} else if (x <= 1.55e-299) {
tmp = t_1;
} else if (x <= 2.2e-253) {
tmp = 4.0;
} else if (x <= 1.65e+95) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / y) t_1 = (z * -4.0) / y tmp = 0 if x <= -1.65e+50: tmp = t_0 elif x <= -3.1e-18: tmp = t_1 elif x <= -1.05e-42: tmp = t_0 elif x <= -2.2e-60: tmp = 4.0 elif x <= -1.45e-174: tmp = t_1 elif x <= -1.45e-215: tmp = 4.0 elif x <= 1.55e-299: tmp = t_1 elif x <= 2.2e-253: tmp = 4.0 elif x <= 1.65e+95: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / y)) t_1 = Float64(Float64(z * -4.0) / y) tmp = 0.0 if (x <= -1.65e+50) tmp = t_0; elseif (x <= -3.1e-18) tmp = t_1; elseif (x <= -1.05e-42) tmp = t_0; elseif (x <= -2.2e-60) tmp = 4.0; elseif (x <= -1.45e-174) tmp = t_1; elseif (x <= -1.45e-215) tmp = 4.0; elseif (x <= 1.55e-299) tmp = t_1; elseif (x <= 2.2e-253) tmp = 4.0; elseif (x <= 1.65e+95) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / y); t_1 = (z * -4.0) / y; tmp = 0.0; if (x <= -1.65e+50) tmp = t_0; elseif (x <= -3.1e-18) tmp = t_1; elseif (x <= -1.05e-42) tmp = t_0; elseif (x <= -2.2e-60) tmp = 4.0; elseif (x <= -1.45e-174) tmp = t_1; elseif (x <= -1.45e-215) tmp = 4.0; elseif (x <= 1.55e-299) tmp = t_1; elseif (x <= 2.2e-253) tmp = 4.0; elseif (x <= 1.65e+95) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -1.65e+50], t$95$0, If[LessEqual[x, -3.1e-18], t$95$1, If[LessEqual[x, -1.05e-42], t$95$0, If[LessEqual[x, -2.2e-60], 4.0, If[LessEqual[x, -1.45e-174], t$95$1, If[LessEqual[x, -1.45e-215], 4.0, If[LessEqual[x, 1.55e-299], t$95$1, If[LessEqual[x, 2.2e-253], 4.0, If[LessEqual[x, 1.65e+95], t$95$1, t$95$0]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
t_1 := \frac{z \cdot -4}{y}\\
\mathbf{if}\;x \leq -1.65 \cdot 10^{+50}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.1 \cdot 10^{-18}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-42}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{-60}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-174}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-215}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-299}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-253}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+95}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.65e50 or -3.10000000000000007e-18 < x < -1.05000000000000003e-42 or 1.6499999999999999e95 < x Initial program 99.0%
associate-*l/99.6%
sub-neg99.6%
sub-neg99.6%
+-commutative99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around 0 99.9%
Taylor expanded in x around inf 74.9%
if -1.65e50 < x < -3.10000000000000007e-18 or -2.1999999999999999e-60 < x < -1.45000000000000005e-174 or -1.45e-215 < x < 1.55e-299 or 2.19999999999999996e-253 < x < 1.6499999999999999e95Initial program 100.0%
associate-*l/99.0%
sub-neg99.0%
sub-neg99.0%
+-commutative99.0%
fma-def99.0%
Simplified99.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in z around inf 59.3%
associate-*r/59.3%
Simplified59.3%
if -1.05000000000000003e-42 < x < -2.1999999999999999e-60 or -1.45000000000000005e-174 < x < -1.45e-215 or 1.55e-299 < x < 2.19999999999999996e-253Initial program 99.8%
associate-*l/99.7%
sub-neg99.7%
sub-neg99.7%
+-commutative99.7%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around inf 82.8%
Final simplification67.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-46) (not (<= z 4.8e+53))) (* (- x z) (/ 4.0 y)) (+ 4.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-46) || !(z <= 4.8e+53)) {
tmp = (x - z) * (4.0 / y);
} else {
tmp = 4.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 <= (-1.75d-46)) .or. (.not. (z <= 4.8d+53))) then
tmp = (x - z) * (4.0d0 / y)
else
tmp = 4.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 <= -1.75e-46) || !(z <= 4.8e+53)) {
tmp = (x - z) * (4.0 / y);
} else {
tmp = 4.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.75e-46) or not (z <= 4.8e+53): tmp = (x - z) * (4.0 / y) else: tmp = 4.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-46) || !(z <= 4.8e+53)) tmp = Float64(Float64(x - z) * Float64(4.0 / y)); else tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.75e-46) || ~((z <= 4.8e+53))) tmp = (x - z) * (4.0 / y); else tmp = 4.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.75e-46], N[Not[LessEqual[z, 4.8e+53]], $MachinePrecision]], N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-46} \lor \neg \left(z \leq 4.8 \cdot 10^{+53}\right):\\
\;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.7500000000000001e-46 or 4.8e53 < z Initial program 99.2%
associate-*l/99.7%
sub-neg99.7%
sub-neg99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 90.5%
associate-*r/89.7%
associate-*l/90.3%
*-commutative90.3%
Simplified90.3%
if -1.7500000000000001e-46 < z < 4.8e53Initial program 99.9%
associate-*l/99.0%
sub-neg99.0%
sub-neg99.0%
+-commutative99.0%
fma-def98.9%
Simplified98.9%
Taylor expanded in y around 0 100.0%
Taylor expanded in z around 0 90.0%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -6.2e+182) 4.0 (if (<= y 1.85e+151) (* (- x z) (/ 4.0 y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+182) {
tmp = 4.0;
} else if (y <= 1.85e+151) {
tmp = (x - z) * (4.0 / y);
} else {
tmp = 4.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 <= (-6.2d+182)) then
tmp = 4.0d0
else if (y <= 1.85d+151) then
tmp = (x - z) * (4.0d0 / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+182) {
tmp = 4.0;
} else if (y <= 1.85e+151) {
tmp = (x - z) * (4.0 / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.2e+182: tmp = 4.0 elif y <= 1.85e+151: tmp = (x - z) * (4.0 / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.2e+182) tmp = 4.0; elseif (y <= 1.85e+151) tmp = Float64(Float64(x - z) * Float64(4.0 / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.2e+182) tmp = 4.0; elseif (y <= 1.85e+151) tmp = (x - z) * (4.0 / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.2e+182], 4.0, If[LessEqual[y, 1.85e+151], N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+182}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+151}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -6.19999999999999993e182 or 1.8499999999999999e151 < y Initial program 99.9%
associate-*l/99.6%
sub-neg99.6%
sub-neg99.6%
+-commutative99.6%
fma-def99.5%
Simplified99.5%
Taylor expanded in y around inf 71.7%
if -6.19999999999999993e182 < y < 1.8499999999999999e151Initial program 99.5%
associate-*l/99.3%
sub-neg99.3%
sub-neg99.3%
+-commutative99.3%
fma-def99.2%
Simplified99.2%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 81.0%
associate-*r/80.5%
associate-*l/80.3%
*-commutative80.3%
Simplified80.3%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-43) (not (<= x 1.75e-49))) (* 4.0 (/ x y)) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-43) || !(x <= 1.75e-49)) {
tmp = 4.0 * (x / y);
} else {
tmp = 4.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 <= (-8.2d-43)) .or. (.not. (x <= 1.75d-49))) then
tmp = 4.0d0 * (x / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-43) || !(x <= 1.75e-49)) {
tmp = 4.0 * (x / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-43) or not (x <= 1.75e-49): tmp = 4.0 * (x / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-43) || !(x <= 1.75e-49)) tmp = Float64(4.0 * Float64(x / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-43) || ~((x <= 1.75e-49))) tmp = 4.0 * (x / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-43], N[Not[LessEqual[x, 1.75e-49]], $MachinePrecision]], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-43} \lor \neg \left(x \leq 1.75 \cdot 10^{-49}\right):\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -8.1999999999999996e-43 or 1.75000000000000003e-49 < x Initial program 99.3%
associate-*l/99.0%
sub-neg99.0%
sub-neg99.0%
+-commutative99.0%
fma-def99.0%
Simplified99.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 60.9%
if -8.1999999999999996e-43 < x < 1.75000000000000003e-49Initial program 99.9%
associate-*l/99.7%
sub-neg99.7%
sub-neg99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in y around inf 46.1%
Final simplification54.4%
(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%
associate-*l/99.3%
sub-neg99.3%
sub-neg99.3%
+-commutative99.3%
fma-def99.3%
Simplified99.3%
Taylor expanded in x around inf 40.6%
Taylor expanded in x around 0 6.7%
Final simplification6.7%
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
return 4.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
end function
public static double code(double x, double y, double z) {
return 4.0;
}
def code(x, y, z): return 4.0
function code(x, y, z) return 4.0 end
function tmp = code(x, y, z) tmp = 4.0; end
code[x_, y_, z_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 99.6%
associate-*l/99.3%
sub-neg99.3%
sub-neg99.3%
+-commutative99.3%
fma-def99.3%
Simplified99.3%
Taylor expanded in y around inf 28.1%
Final simplification28.1%
herbie shell --seed 2024019
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))