
(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 (<= y -1.2e+27) (- 1.0 (/ x y)) (if (<= y 2.15e+15) (/ (- x y) z) (/ y (- y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.2e+27) {
tmp = 1.0 - (x / y);
} else if (y <= 2.15e+15) {
tmp = (x - y) / z;
} 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 (y <= (-1.2d+27)) then
tmp = 1.0d0 - (x / y)
else if (y <= 2.15d+15) then
tmp = (x - y) / z
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.2e+27) {
tmp = 1.0 - (x / y);
} else if (y <= 2.15e+15) {
tmp = (x - y) / z;
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.2e+27: tmp = 1.0 - (x / y) elif y <= 2.15e+15: tmp = (x - y) / z else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.2e+27) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 2.15e+15) tmp = Float64(Float64(x - y) / z); else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.2e+27) tmp = 1.0 - (x / y); elseif (y <= 2.15e+15) tmp = (x - y) / z; else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.2e+27], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.15e+15], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+27}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{+15}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -1.19999999999999999e27Initial program 99.9%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6481.6%
Simplified81.6%
if -1.19999999999999999e27 < y < 2.15e15Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in z around inf
associate-*r/N/A
/-lowering-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f6482.2%
Simplified82.2%
if 2.15e15 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
--lowering--.f6482.6%
Simplified82.6%
(FPCore (x y z) :precision binary64 (if (<= y -3.45e-62) (- 1.0 (/ x y)) (if (<= y 3.6e-25) (/ x z) (/ y (- y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e-62) {
tmp = 1.0 - (x / y);
} else if (y <= 3.6e-25) {
tmp = x / z;
} 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 (y <= (-3.45d-62)) then
tmp = 1.0d0 - (x / y)
else if (y <= 3.6d-25) then
tmp = x / z
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e-62) {
tmp = 1.0 - (x / y);
} else if (y <= 3.6e-25) {
tmp = x / z;
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.45e-62: tmp = 1.0 - (x / y) elif y <= 3.6e-25: tmp = x / z else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.45e-62) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 3.6e-25) tmp = Float64(x / z); else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.45e-62) tmp = 1.0 - (x / y); elseif (y <= 3.6e-25) tmp = x / z; else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.45e-62], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e-25], N[(x / z), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.45 \cdot 10^{-62}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-25}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -3.44999999999999979e-62Initial program 99.9%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6475.0%
Simplified75.0%
if -3.44999999999999979e-62 < y < 3.5999999999999999e-25Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6475.3%
Simplified75.3%
if 3.5999999999999999e-25 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
--lowering--.f6479.3%
Simplified79.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (/ x y)))) (if (<= y -1.76e-62) t_0 (if (<= y 1.55e-39) (/ x z) t_0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -1.76e-62) {
tmp = t_0;
} else if (y <= 1.55e-39) {
tmp = x / z;
} 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 <= (-1.76d-62)) then
tmp = t_0
else if (y <= 1.55d-39) then
tmp = x / z
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 <= -1.76e-62) {
tmp = t_0;
} else if (y <= 1.55e-39) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -1.76e-62: tmp = t_0 elif y <= 1.55e-39: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -1.76e-62) tmp = t_0; elseif (y <= 1.55e-39) tmp = Float64(x / z); 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 <= -1.76e-62) tmp = t_0; elseif (y <= 1.55e-39) tmp = x / z; 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, -1.76e-62], t$95$0, If[LessEqual[y, 1.55e-39], N[(x / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -1.76 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-39}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.76e-62 or 1.54999999999999985e-39 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6473.2%
Simplified73.2%
if -1.76e-62 < y < 1.54999999999999985e-39Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6475.8%
Simplified75.8%
(FPCore (x y z) :precision binary64 (if (<= y -2.1e+49) 1.0 (if (<= y 1.18e+24) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.1e+49) {
tmp = 1.0;
} else if (y <= 1.18e+24) {
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.1d+49)) then
tmp = 1.0d0
else if (y <= 1.18d+24) 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.1e+49) {
tmp = 1.0;
} else if (y <= 1.18e+24) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.1e+49: tmp = 1.0 elif y <= 1.18e+24: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.1e+49) tmp = 1.0; elseif (y <= 1.18e+24) 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.1e+49) tmp = 1.0; elseif (y <= 1.18e+24) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.1e+49], 1.0, If[LessEqual[y, 1.18e+24], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+49}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{+24}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.10000000000000011e49 or 1.17999999999999997e24 < y Initial program 99.9%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Taylor expanded in y around inf
Simplified65.2%
if -2.10000000000000011e49 < y < 1.17999999999999997e24Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6465.9%
Simplified65.9%
(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%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
Simplified36.3%
(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 2024138
(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)))