
(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 99.9%
(FPCore (x y z)
:precision binary64
(if (<= y -1.9e+179)
1.0
(if (<= y -2.7e-30)
(/ x (- y))
(if (<= y -6.8e-44) 1.0 (if (<= y 2.45e+16) (/ x z) 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+179) {
tmp = 1.0;
} else if (y <= -2.7e-30) {
tmp = x / -y;
} else if (y <= -6.8e-44) {
tmp = 1.0;
} else if (y <= 2.45e+16) {
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 <= (-1.9d+179)) then
tmp = 1.0d0
else if (y <= (-2.7d-30)) then
tmp = x / -y
else if (y <= (-6.8d-44)) then
tmp = 1.0d0
else if (y <= 2.45d+16) 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 <= -1.9e+179) {
tmp = 1.0;
} else if (y <= -2.7e-30) {
tmp = x / -y;
} else if (y <= -6.8e-44) {
tmp = 1.0;
} else if (y <= 2.45e+16) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e+179: tmp = 1.0 elif y <= -2.7e-30: tmp = x / -y elif y <= -6.8e-44: tmp = 1.0 elif y <= 2.45e+16: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e+179) tmp = 1.0; elseif (y <= -2.7e-30) tmp = Float64(x / Float64(-y)); elseif (y <= -6.8e-44) tmp = 1.0; elseif (y <= 2.45e+16) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e+179) tmp = 1.0; elseif (y <= -2.7e-30) tmp = x / -y; elseif (y <= -6.8e-44) tmp = 1.0; elseif (y <= 2.45e+16) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e+179], 1.0, If[LessEqual[y, -2.7e-30], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -6.8e-44], 1.0, If[LessEqual[y, 2.45e+16], N[(x / z), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+179}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-30}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -6.8 \cdot 10^{-44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+16}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.9e179 or -2.69999999999999987e-30 < y < -6.80000000000000033e-44 or 2.45e16 < y Initial program 99.9%
Taylor expanded in y around inf 61.8%
if -1.9e179 < y < -2.69999999999999987e-30Initial program 100.0%
Taylor expanded in z around 0 70.6%
div-sub70.6%
sub-neg70.6%
*-inverses70.6%
metadata-eval70.6%
distribute-lft-in70.6%
metadata-eval70.6%
+-commutative70.6%
mul-1-neg70.6%
unsub-neg70.6%
Simplified70.6%
Taylor expanded in x around inf 41.9%
mul-1-neg41.9%
distribute-frac-neg241.9%
Simplified41.9%
if -6.80000000000000033e-44 < y < 2.45e16Initial program 100.0%
Taylor expanded in y around 0 74.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.4e-57) (not (<= x 4.5e-48))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.4e-57) || !(x <= 4.5e-48)) {
tmp = x / (z - y);
} else {
tmp = y / (y - 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 ((x <= (-9.4d-57)) .or. (.not. (x <= 4.5d-48))) then
tmp = x / (z - y)
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.4e-57) || !(x <= 4.5e-48)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.4e-57) or not (x <= 4.5e-48): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.4e-57) || !(x <= 4.5e-48)) tmp = Float64(x / Float64(z - y)); else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.4e-57) || ~((x <= 4.5e-48))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.4e-57], N[Not[LessEqual[x, 4.5e-48]], $MachinePrecision]], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.4 \cdot 10^{-57} \lor \neg \left(x \leq 4.5 \cdot 10^{-48}\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -9.3999999999999996e-57 or 4.49999999999999988e-48 < x Initial program 99.9%
Taylor expanded in x around inf 82.2%
if -9.3999999999999996e-57 < x < 4.49999999999999988e-48Initial program 99.9%
Taylor expanded in x around 0 90.4%
neg-mul-190.4%
distribute-neg-frac90.4%
Simplified90.4%
frac-2neg90.4%
div-inv90.1%
remove-double-neg90.1%
sub-neg90.1%
distribute-neg-in90.1%
remove-double-neg90.1%
Applied egg-rr90.1%
associate-*r/90.4%
*-rgt-identity90.4%
+-commutative90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.2e-44) (not (<= y 9e+40))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-44) || !(y <= 9e+40)) {
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 <= (-3.2d-44)) .or. (.not. (y <= 9d+40))) 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 <= -3.2e-44) || !(y <= 9e+40)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.2e-44) or not (y <= 9e+40): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.2e-44) || !(y <= 9e+40)) 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 <= -3.2e-44) || ~((y <= 9e+40))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e-44], N[Not[LessEqual[y, 9e+40]], $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 -3.2 \cdot 10^{-44} \lor \neg \left(y \leq 9 \cdot 10^{+40}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -3.19999999999999995e-44 or 9.00000000000000064e40 < y Initial program 99.9%
Taylor expanded in z around 0 75.7%
div-sub75.7%
sub-neg75.7%
*-inverses75.7%
metadata-eval75.7%
distribute-lft-in75.7%
metadata-eval75.7%
+-commutative75.7%
mul-1-neg75.7%
unsub-neg75.7%
Simplified75.7%
if -3.19999999999999995e-44 < y < 9.00000000000000064e40Initial program 100.0%
Taylor expanded in x around inf 85.7%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-48) (not (<= y 6.5e-36))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-48) || !(y <= 6.5e-36)) {
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 <= (-2.5d-48)) .or. (.not. (y <= 6.5d-36))) 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 <= -2.5e-48) || !(y <= 6.5e-36)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-48) or not (y <= 6.5e-36): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-48) || !(y <= 6.5e-36)) 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 <= -2.5e-48) || ~((y <= 6.5e-36))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-48], N[Not[LessEqual[y, 6.5e-36]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-48} \lor \neg \left(y \leq 6.5 \cdot 10^{-36}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.4999999999999999e-48 or 6.50000000000000012e-36 < y Initial program 99.9%
Taylor expanded in z around 0 72.6%
div-sub72.6%
sub-neg72.6%
*-inverses72.6%
metadata-eval72.6%
distribute-lft-in72.6%
metadata-eval72.6%
+-commutative72.6%
mul-1-neg72.6%
unsub-neg72.6%
Simplified72.6%
if -2.4999999999999999e-48 < y < 6.50000000000000012e-36Initial program 100.0%
Taylor expanded in y around 0 78.4%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.2e-44) 1.0 (if (<= y 5.5e+20) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-44) {
tmp = 1.0;
} else if (y <= 5.5e+20) {
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 <= (-2.2d-44)) then
tmp = 1.0d0
else if (y <= 5.5d+20) 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 <= -2.2e-44) {
tmp = 1.0;
} else if (y <= 5.5e+20) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e-44: tmp = 1.0 elif y <= 5.5e+20: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e-44) tmp = 1.0; elseif (y <= 5.5e+20) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.2e-44) tmp = 1.0; elseif (y <= 5.5e+20) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e-44], 1.0, If[LessEqual[y, 5.5e+20], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+20}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.20000000000000012e-44 or 5.5e20 < y Initial program 99.9%
Taylor expanded in y around inf 51.5%
if -2.20000000000000012e-44 < y < 5.5e20Initial program 100.0%
Taylor expanded in y around 0 74.3%
(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.9%
Taylor expanded in y around inf 30.4%
(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 2024100
(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)))