
(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 6 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%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.2e+88) (not (<= x 6.9e+78))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.2e+88) || !(x <= 6.9e+78)) {
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.2d+88)) .or. (.not. (x <= 6.9d+78))) 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.2e+88) || !(x <= 6.9e+78)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.2e+88) or not (x <= 6.9e+78): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.2e+88) || !(x <= 6.9e+78)) 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.2e+88) || ~((x <= 6.9e+78))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.2e+88], N[Not[LessEqual[x, 6.9e+78]], $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.2 \cdot 10^{+88} \lor \neg \left(x \leq 6.9 \cdot 10^{+78}\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -9.2000000000000007e88 or 6.8999999999999998e78 < x Initial program 99.9%
Taylor expanded in x around inf 86.2%
if -9.2000000000000007e88 < x < 6.8999999999999998e78Initial program 100.0%
Taylor expanded in x around 0 80.4%
neg-mul-180.4%
distribute-neg-frac280.4%
sub-neg80.4%
+-commutative80.4%
distribute-neg-in80.4%
remove-double-neg80.4%
sub-neg80.4%
Simplified80.4%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e+65) (not (<= y 1.1e-12))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+65) || !(y <= 1.1e-12)) {
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.9d+65)) .or. (.not. (y <= 1.1d-12))) 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.9e+65) || !(y <= 1.1e-12)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e+65) or not (y <= 1.1e-12): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e+65) || !(y <= 1.1e-12)) 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.9e+65) || ~((y <= 1.1e-12))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e+65], N[Not[LessEqual[y, 1.1e-12]], $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.9 \cdot 10^{+65} \lor \neg \left(y \leq 1.1 \cdot 10^{-12}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -1.90000000000000006e65 or 1.09999999999999996e-12 < y Initial program 99.9%
Taylor expanded in z around 0 82.4%
associate-*r/82.4%
neg-mul-182.4%
sub-neg82.4%
+-commutative82.4%
distribute-neg-in82.4%
remove-double-neg82.4%
sub-neg82.4%
div-sub82.5%
*-inverses82.5%
Simplified82.5%
if -1.90000000000000006e65 < y < 1.09999999999999996e-12Initial program 100.0%
Taylor expanded in x around inf 76.4%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.9e-54) (not (<= y 8e-105))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.9e-54) || !(y <= 8e-105)) {
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 <= (-4.9d-54)) .or. (.not. (y <= 8d-105))) 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 <= -4.9e-54) || !(y <= 8e-105)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.9e-54) or not (y <= 8e-105): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.9e-54) || !(y <= 8e-105)) 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 <= -4.9e-54) || ~((y <= 8e-105))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.9e-54], N[Not[LessEqual[y, 8e-105]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{-54} \lor \neg \left(y \leq 8 \cdot 10^{-105}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -4.90000000000000021e-54 or 7.99999999999999972e-105 < y Initial program 99.9%
Taylor expanded in z around 0 72.7%
associate-*r/72.7%
neg-mul-172.7%
sub-neg72.7%
+-commutative72.7%
distribute-neg-in72.7%
remove-double-neg72.7%
sub-neg72.7%
div-sub72.7%
*-inverses72.7%
Simplified72.7%
if -4.90000000000000021e-54 < y < 7.99999999999999972e-105Initial program 100.0%
Taylor expanded in y around 0 78.8%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.45e+59) 1.0 (if (<= y 13500000000.0) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+59) {
tmp = 1.0;
} else if (y <= 13500000000.0) {
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.45d+59)) then
tmp = 1.0d0
else if (y <= 13500000000.0d0) 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.45e+59) {
tmp = 1.0;
} else if (y <= 13500000000.0) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45e+59: tmp = 1.0 elif y <= 13500000000.0: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45e+59) tmp = 1.0; elseif (y <= 13500000000.0) 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.45e+59) tmp = 1.0; elseif (y <= 13500000000.0) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45e+59], 1.0, If[LessEqual[y, 13500000000.0], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+59}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 13500000000:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.44999999999999995e59 or 1.35e10 < y Initial program 99.9%
Taylor expanded in y around inf 69.0%
if -1.44999999999999995e59 < y < 1.35e10Initial program 100.0%
Taylor expanded in y around 0 65.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 39.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 2024144
(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)))