
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (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 = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (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 = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (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 = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -2.3e-14)
t_0
(if (<= y -4.9e-56)
(/ y (- y z))
(if (or (<= y -1.05e-71) (not (<= y 3.1e-37))) t_0 (/ x (- z y)))))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -2.3e-14) {
tmp = t_0;
} else if (y <= -4.9e-56) {
tmp = y / (y - z);
} else if ((y <= -1.05e-71) || !(y <= 3.1e-37)) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (y <= (-2.3d-14)) then
tmp = t_0
else if (y <= (-4.9d-56)) then
tmp = y / (y - z)
else if ((y <= (-1.05d-71)) .or. (.not. (y <= 3.1d-37))) then
tmp = t_0
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -2.3e-14) {
tmp = t_0;
} else if (y <= -4.9e-56) {
tmp = y / (y - z);
} else if ((y <= -1.05e-71) || !(y <= 3.1e-37)) {
tmp = t_0;
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -2.3e-14: tmp = t_0 elif y <= -4.9e-56: tmp = y / (y - z) elif (y <= -1.05e-71) or not (y <= 3.1e-37): tmp = t_0 else: tmp = x / (z - y) return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -2.3e-14) tmp = t_0; elseif (y <= -4.9e-56) tmp = Float64(y / Float64(y - z)); elseif ((y <= -1.05e-71) || !(y <= 3.1e-37)) tmp = t_0; else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -2.3e-14) tmp = t_0; elseif (y <= -4.9e-56) tmp = y / (y - z); elseif ((y <= -1.05e-71) || ~((y <= 3.1e-37))) tmp = t_0; else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.3e-14], t$95$0, If[LessEqual[y, -4.9e-56], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -1.05e-71], N[Not[LessEqual[y, 3.1e-37]], $MachinePrecision]], t$95$0, N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -4.9 \cdot 10^{-56}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{-71} \lor \neg \left(y \leq 3.1 \cdot 10^{-37}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -2.29999999999999998e-14 or -4.9e-56 < y < -1.0500000000000001e-71 or 3.09999999999999993e-37 < y Initial program 100.0%
Taylor expanded in z around 0 79.2%
div-sub79.2%
sub-neg79.2%
*-inverses79.2%
metadata-eval79.2%
distribute-lft-in79.2%
metadata-eval79.2%
+-commutative79.2%
mul-1-neg79.2%
unsub-neg79.2%
Simplified79.2%
if -2.29999999999999998e-14 < y < -4.9e-56Initial program 100.0%
clear-num99.8%
associate-/r/99.7%
Applied egg-rr99.7%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
neg-sub086.4%
associate-+l-86.4%
neg-sub086.4%
+-commutative86.4%
unsub-neg86.4%
Simplified86.4%
if -1.0500000000000001e-71 < y < 3.09999999999999993e-37Initial program 100.0%
Taylor expanded in x around inf 88.3%
Final simplification83.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -5.2e-47)
t_0
(if (<= y 4e-214) (/ (- x y) z) (if (<= y 6e-37) (/ x (- z y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -5.2e-47) {
tmp = t_0;
} else if (y <= 4e-214) {
tmp = (x - y) / z;
} else if (y <= 6e-37) {
tmp = x / (z - 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 = 1.0d0 - (x / y)
if (y <= (-5.2d-47)) then
tmp = t_0
else if (y <= 4d-214) then
tmp = (x - y) / z
else if (y <= 6d-37) then
tmp = x / (z - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -5.2e-47) {
tmp = t_0;
} else if (y <= 4e-214) {
tmp = (x - y) / z;
} else if (y <= 6e-37) {
tmp = x / (z - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -5.2e-47: tmp = t_0 elif y <= 4e-214: tmp = (x - y) / z elif y <= 6e-37: tmp = x / (z - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -5.2e-47) tmp = t_0; elseif (y <= 4e-214) tmp = Float64(Float64(x - y) / z); elseif (y <= 6e-37) tmp = Float64(x / Float64(z - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -5.2e-47) tmp = t_0; elseif (y <= 4e-214) tmp = (x - y) / z; elseif (y <= 6e-37) tmp = x / (z - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.2e-47], t$95$0, If[LessEqual[y, 4e-214], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 6e-37], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-214}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.2e-47 or 6e-37 < y Initial program 100.0%
Taylor expanded in z around 0 78.2%
div-sub78.2%
sub-neg78.2%
*-inverses78.2%
metadata-eval78.2%
distribute-lft-in78.2%
metadata-eval78.2%
+-commutative78.2%
mul-1-neg78.2%
unsub-neg78.2%
Simplified78.2%
if -5.2e-47 < y < 3.99999999999999965e-214Initial program 99.9%
Taylor expanded in z around inf 88.6%
if 3.99999999999999965e-214 < y < 6e-37Initial program 100.0%
Taylor expanded in x around inf 90.8%
Final simplification83.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2e-77) (not (<= y 4.4e-43))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-77) || !(y <= 4.4e-43)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
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 <= (-2d-77)) .or. (.not. (y <= 4.4d-43))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-77) || !(y <= 4.4e-43)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e-77) or not (y <= 4.4e-43): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e-77) || !(y <= 4.4e-43)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2e-77) || ~((y <= 4.4e-43))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e-77], N[Not[LessEqual[y, 4.4e-43]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-77} \lor \neg \left(y \leq 4.4 \cdot 10^{-43}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -1.9999999999999999e-77 or 4.39999999999999994e-43 < y Initial program 100.0%
Taylor expanded in z around 0 76.4%
div-sub76.4%
sub-neg76.4%
*-inverses76.4%
metadata-eval76.4%
distribute-lft-in76.4%
metadata-eval76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
if -1.9999999999999999e-77 < y < 4.39999999999999994e-43Initial program 100.0%
Taylor expanded in y around 0 75.5%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.6e-47) (not (<= y 4e-38))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.6e-47) || !(y <= 4e-38)) {
tmp = 1.0 - (x / y);
} else {
tmp = 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 <= (-4.6d-47)) .or. (.not. (y <= 4d-38))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.6e-47) || !(y <= 4e-38)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.6e-47) or not (y <= 4e-38): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.6e-47) || !(y <= 4e-38)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.6e-47) || ~((y <= 4e-38))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.6e-47], N[Not[LessEqual[y, 4e-38]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-47} \lor \neg \left(y \leq 4 \cdot 10^{-38}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -4.59999999999999964e-47 or 3.9999999999999998e-38 < y Initial program 100.0%
Taylor expanded in z around 0 78.2%
div-sub78.2%
sub-neg78.2%
*-inverses78.2%
metadata-eval78.2%
distribute-lft-in78.2%
metadata-eval78.2%
+-commutative78.2%
mul-1-neg78.2%
unsub-neg78.2%
Simplified78.2%
if -4.59999999999999964e-47 < y < 3.9999999999999998e-38Initial program 100.0%
Taylor expanded in x around inf 85.8%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e-47) 1.0 (if (<= y 6.5e-37) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-47) {
tmp = 1.0;
} else if (y <= 6.5e-37) {
tmp = x / z;
} else {
tmp = 1.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.2d-47)) then
tmp = 1.0d0
else if (y <= 6.5d-37) then
tmp = x / z
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-47) {
tmp = 1.0;
} else if (y <= 6.5e-37) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e-47: tmp = 1.0 elif y <= 6.5e-37: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-47) tmp = 1.0; elseif (y <= 6.5e-37) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e-47) tmp = 1.0; elseif (y <= 6.5e-37) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-47], 1.0, If[LessEqual[y, 6.5e-37], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-47}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.2e-47 or 6.5000000000000001e-37 < y Initial program 100.0%
Taylor expanded in y around inf 59.8%
if -5.2e-47 < y < 6.5000000000000001e-37Initial program 100.0%
Taylor expanded in y around 0 72.8%
Final simplification66.0%
(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 100.0%
Taylor expanded in y around inf 34.6%
Final simplification34.6%
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (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 = (x / (z - y)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
herbie shell --seed 2024071
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:alt
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))