
(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 10 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 (- (/ y (- y z)) (/ x (- y z))))
double code(double x, double y, double z) {
return (y / (y - z)) - (x / (y - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y / (y - z)) - (x / (y - z))
end function
public static double code(double x, double y, double z) {
return (y / (y - z)) - (x / (y - z));
}
def code(x, y, z): return (y / (y - z)) - (x / (y - z))
function code(x, y, z) return Float64(Float64(y / Float64(y - z)) - Float64(x / Float64(y - z))) end
function tmp = code(x, y, z) tmp = (y / (y - z)) - (x / (y - z)); end
code[x_, y_, z_] := N[(N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision] - N[(x / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{y - z} - \frac{x}{y - z}
\end{array}
Initial program 100.0%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (- y z))) (t_1 (/ (- y x) (- y z))) (t_2 (/ x (- z y))))
(if (<= t_1 -500.0)
t_2
(if (<= t_1 -1e-252)
t_0
(if (<= t_1 1e-25) (/ x z) (if (<= t_1 2.0) t_0 t_2))))))
double code(double x, double y, double z) {
double t_0 = y / (y - z);
double t_1 = (y - x) / (y - z);
double t_2 = x / (z - y);
double tmp;
if (t_1 <= -500.0) {
tmp = t_2;
} else if (t_1 <= -1e-252) {
tmp = t_0;
} else if (t_1 <= 1e-25) {
tmp = x / z;
} else if (t_1 <= 2.0) {
tmp = t_0;
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: tmp
t_0 = y / (y - z)
t_1 = (y - x) / (y - z)
t_2 = x / (z - y)
if (t_1 <= (-500.0d0)) then
tmp = t_2
else if (t_1 <= (-1d-252)) then
tmp = t_0
else if (t_1 <= 1d-25) then
tmp = x / z
else if (t_1 <= 2.0d0) then
tmp = t_0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (y - z);
double t_1 = (y - x) / (y - z);
double t_2 = x / (z - y);
double tmp;
if (t_1 <= -500.0) {
tmp = t_2;
} else if (t_1 <= -1e-252) {
tmp = t_0;
} else if (t_1 <= 1e-25) {
tmp = x / z;
} else if (t_1 <= 2.0) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) t_1 = (y - x) / (y - z) t_2 = x / (z - y) tmp = 0 if t_1 <= -500.0: tmp = t_2 elif t_1 <= -1e-252: tmp = t_0 elif t_1 <= 1e-25: tmp = x / z elif t_1 <= 2.0: tmp = t_0 else: tmp = t_2 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) t_1 = Float64(Float64(y - x) / Float64(y - z)) t_2 = Float64(x / Float64(z - y)) tmp = 0.0 if (t_1 <= -500.0) tmp = t_2; elseif (t_1 <= -1e-252) tmp = t_0; elseif (t_1 <= 1e-25) tmp = Float64(x / z); elseif (t_1 <= 2.0) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); t_1 = (y - x) / (y - z); t_2 = x / (z - y); tmp = 0.0; if (t_1 <= -500.0) tmp = t_2; elseif (t_1 <= -1e-252) tmp = t_0; elseif (t_1 <= 1e-25) tmp = x / z; elseif (t_1 <= 2.0) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -500.0], t$95$2, If[LessEqual[t$95$1, -1e-252], t$95$0, If[LessEqual[t$95$1, 1e-25], N[(x / z), $MachinePrecision], If[LessEqual[t$95$1, 2.0], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
t_1 := \frac{y - x}{y - z}\\
t_2 := \frac{x}{z - y}\\
\mathbf{if}\;t\_1 \leq -500:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq -1 \cdot 10^{-252}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{-25}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 z y)) < -500 or 2 < (/.f64 (-.f64 x y) (-.f64 z y)) Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -500 < (/.f64 (-.f64 x y) (-.f64 z y)) < -9.99999999999999943e-253 or 1.00000000000000004e-25 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6482.4
Applied rewrites82.4%
if -9.99999999999999943e-253 < (/.f64 (-.f64 x y) (-.f64 z y)) < 1.00000000000000004e-25Initial program 100.0%
Taylor expanded in y around 0
lower-/.f6462.8
Applied rewrites62.8%
Final simplification84.1%
(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 2024230
(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)))