
(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 8 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 (or (<= z -1.3e-20) (not (<= z 1.1e+65))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.3e-20) || !(z <= 1.1e+65)) {
tmp = (x - y) / z;
} else {
tmp = 1.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.3d-20)) .or. (.not. (z <= 1.1d+65))) then
tmp = (x - y) / z
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.3e-20) || !(z <= 1.1e+65)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.3e-20) or not (z <= 1.1e+65): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.3e-20) || !(z <= 1.1e+65)) tmp = Float64(Float64(x - y) / z); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.3e-20) || ~((z <= 1.1e+65))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.3e-20], N[Not[LessEqual[z, 1.1e+65]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{-20} \lor \neg \left(z \leq 1.1 \cdot 10^{+65}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.29999999999999997e-20 or 1.0999999999999999e65 < z Initial program 99.9%
Taylor expanded in z around inf 79.2%
if -1.29999999999999997e-20 < z < 1.0999999999999999e65Initial program 99.9%
Taylor expanded in z around 0 82.9%
associate-*r/82.9%
neg-mul-182.9%
sub-neg82.9%
+-commutative82.9%
distribute-neg-in82.9%
remove-double-neg82.9%
sub-neg82.9%
div-sub82.9%
*-inverses82.9%
Simplified82.9%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e-63) (not (<= x 4900000.0))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e-63) || !(x <= 4900000.0)) {
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 <= (-3.7d-63)) .or. (.not. (x <= 4900000.0d0))) 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 <= -3.7e-63) || !(x <= 4900000.0)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e-63) or not (x <= 4900000.0): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e-63) || !(x <= 4900000.0)) 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 <= -3.7e-63) || ~((x <= 4900000.0))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e-63], N[Not[LessEqual[x, 4900000.0]], $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 -3.7 \cdot 10^{-63} \lor \neg \left(x \leq 4900000\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -3.70000000000000012e-63 or 4.9e6 < x Initial program 100.0%
Taylor expanded in x around inf 76.5%
if -3.70000000000000012e-63 < x < 4.9e6Initial program 99.9%
Taylor expanded in x around 0 85.0%
neg-mul-185.0%
distribute-neg-frac285.0%
sub-neg85.0%
+-commutative85.0%
distribute-neg-in85.0%
remove-double-neg85.0%
sub-neg85.0%
Simplified85.0%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e+27) (not (<= y 1.4e-10))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+27) || !(y <= 1.4e-10)) {
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 <= (-1.45d+27)) .or. (.not. (y <= 1.4d-10))) 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 <= -1.45e+27) || !(y <= 1.4e-10)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+27) or not (y <= 1.4e-10): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+27) || !(y <= 1.4e-10)) 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 <= -1.45e+27) || ~((y <= 1.4e-10))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+27], N[Not[LessEqual[y, 1.4e-10]], $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 -1.45 \cdot 10^{+27} \lor \neg \left(y \leq 1.4 \cdot 10^{-10}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -1.4500000000000001e27 or 1.40000000000000008e-10 < y Initial program 99.9%
Taylor expanded in z around 0 80.3%
associate-*r/80.3%
neg-mul-180.3%
sub-neg80.3%
+-commutative80.3%
distribute-neg-in80.3%
remove-double-neg80.3%
sub-neg80.3%
div-sub80.3%
*-inverses80.3%
Simplified80.3%
if -1.4500000000000001e27 < y < 1.40000000000000008e-10Initial program 100.0%
Taylor expanded in x around inf 80.4%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.9e-57) (not (<= y 1.1e-55))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.9e-57) || !(y <= 1.1e-55)) {
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.9d-57)) .or. (.not. (y <= 1.1d-55))) 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.9e-57) || !(y <= 1.1e-55)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.9e-57) or not (y <= 1.1e-55): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.9e-57) || !(y <= 1.1e-55)) 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.9e-57) || ~((y <= 1.1e-55))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.9e-57], N[Not[LessEqual[y, 1.1e-55]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-57} \lor \neg \left(y \leq 1.1 \cdot 10^{-55}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.90000000000000025e-57 or 1.1e-55 < y Initial program 99.9%
Taylor expanded in z around 0 75.5%
associate-*r/75.5%
neg-mul-175.5%
sub-neg75.5%
+-commutative75.5%
distribute-neg-in75.5%
remove-double-neg75.5%
sub-neg75.5%
div-sub75.5%
*-inverses75.5%
Simplified75.5%
if -2.90000000000000025e-57 < y < 1.1e-55Initial program 100.0%
Taylor expanded in y around 0 72.2%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (<= y -4.5e+27) (+ 1.0 (/ z y)) (if (<= y 8.2e-8) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+27) {
tmp = 1.0 + (z / y);
} else if (y <= 8.2e-8) {
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 <= (-4.5d+27)) then
tmp = 1.0d0 + (z / y)
else if (y <= 8.2d-8) 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 <= -4.5e+27) {
tmp = 1.0 + (z / y);
} else if (y <= 8.2e-8) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+27: tmp = 1.0 + (z / y) elif y <= 8.2e-8: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+27) tmp = Float64(1.0 + Float64(z / y)); elseif (y <= 8.2e-8) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.5e+27) tmp = 1.0 + (z / y); elseif (y <= 8.2e-8) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+27], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.2e-8], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+27}:\\
\;\;\;\;1 + \frac{z}{y}\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.4999999999999999e27Initial program 99.9%
Taylor expanded in x around 0 70.1%
neg-mul-170.1%
distribute-neg-frac270.1%
sub-neg70.1%
+-commutative70.1%
distribute-neg-in70.1%
remove-double-neg70.1%
sub-neg70.1%
Simplified70.1%
Taylor expanded in y around inf 57.2%
+-commutative57.2%
Simplified57.2%
if -4.4999999999999999e27 < y < 8.20000000000000063e-8Initial program 100.0%
Taylor expanded in y around 0 62.5%
if 8.20000000000000063e-8 < y Initial program 100.0%
Taylor expanded in y around inf 63.6%
Final simplification61.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.75e+27) 1.0 (if (<= y 1.1e-6) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.75e+27) {
tmp = 1.0;
} else if (y <= 1.1e-6) {
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.75d+27)) then
tmp = 1.0d0
else if (y <= 1.1d-6) 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.75e+27) {
tmp = 1.0;
} else if (y <= 1.1e-6) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.75e+27: tmp = 1.0 elif y <= 1.1e-6: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.75e+27) tmp = 1.0; elseif (y <= 1.1e-6) 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.75e+27) tmp = 1.0; elseif (y <= 1.1e-6) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.75e+27], 1.0, If[LessEqual[y, 1.1e-6], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+27}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.7500000000000001e27 or 1.1000000000000001e-6 < y Initial program 99.9%
Taylor expanded in y around inf 60.8%
if -1.7500000000000001e27 < y < 1.1000000000000001e-6Initial program 100.0%
Taylor expanded in y around 0 62.5%
(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 33.2%
(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 2024170
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:alt
(! :herbie-platform default (- (/ x (- z y)) (/ y (- z y))))
(/ (- x y) (- z y)))