
(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 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -8.5e-97)
t_0
(if (<= y -6e-154) (/ y (- z)) (if (<= y 3e-98) (/ x z) t_0)))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -8.5e-97) {
tmp = t_0;
} else if (y <= -6e-154) {
tmp = y / -z;
} else if (y <= 3e-98) {
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 <= (-8.5d-97)) then
tmp = t_0
else if (y <= (-6d-154)) then
tmp = y / -z
else if (y <= 3d-98) 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 <= -8.5e-97) {
tmp = t_0;
} else if (y <= -6e-154) {
tmp = y / -z;
} else if (y <= 3e-98) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -8.5e-97: tmp = t_0 elif y <= -6e-154: tmp = y / -z elif y <= 3e-98: 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 <= -8.5e-97) tmp = t_0; elseif (y <= -6e-154) tmp = Float64(y / Float64(-z)); elseif (y <= 3e-98) 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 <= -8.5e-97) tmp = t_0; elseif (y <= -6e-154) tmp = y / -z; elseif (y <= 3e-98) 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, -8.5e-97], t$95$0, If[LessEqual[y, -6e-154], N[(y / (-z)), $MachinePrecision], If[LessEqual[y, 3e-98], N[(x / z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-154}:\\
\;\;\;\;\frac{y}{-z}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-98}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5000000000000002e-97 or 3e-98 < y Initial program 100.0%
Taylor expanded in z around 0 70.7%
div-sub70.8%
sub-neg70.8%
*-inverses70.8%
metadata-eval70.8%
distribute-lft-in70.8%
metadata-eval70.8%
+-commutative70.8%
mul-1-neg70.8%
unsub-neg70.8%
Simplified70.8%
if -8.5000000000000002e-97 < y < -6.0000000000000005e-154Initial program 100.0%
Taylor expanded in z around inf 67.0%
Taylor expanded in x around 0 53.0%
neg-mul-153.0%
distribute-neg-frac53.0%
Simplified53.0%
if -6.0000000000000005e-154 < y < 3e-98Initial program 100.0%
Taylor expanded in y around 0 88.7%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.1e-32) (/ (- x y) z) (if (<= z 3.4e-21) (- 1.0 (/ x y)) (- (/ x z) (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-32) {
tmp = (x - y) / z;
} else if (z <= 3.4e-21) {
tmp = 1.0 - (x / y);
} else {
tmp = (x / z) - (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 (z <= (-2.1d-32)) then
tmp = (x - y) / z
else if (z <= 3.4d-21) then
tmp = 1.0d0 - (x / y)
else
tmp = (x / z) - (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-32) {
tmp = (x - y) / z;
} else if (z <= 3.4e-21) {
tmp = 1.0 - (x / y);
} else {
tmp = (x / z) - (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.1e-32: tmp = (x - y) / z elif z <= 3.4e-21: tmp = 1.0 - (x / y) else: tmp = (x / z) - (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.1e-32) tmp = Float64(Float64(x - y) / z); elseif (z <= 3.4e-21) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(Float64(x / z) - Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.1e-32) tmp = (x - y) / z; elseif (z <= 3.4e-21) tmp = 1.0 - (x / y); else tmp = (x / z) - (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.1e-32], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 3.4e-21], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-32}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-21}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} - \frac{y}{z}\\
\end{array}
\end{array}
if z < -2.0999999999999999e-32Initial program 100.0%
Taylor expanded in z around inf 82.1%
if -2.0999999999999999e-32 < z < 3.4e-21Initial program 100.0%
Taylor expanded in z around 0 83.0%
div-sub83.0%
sub-neg83.0%
*-inverses83.0%
metadata-eval83.0%
distribute-lft-in83.0%
metadata-eval83.0%
+-commutative83.0%
mul-1-neg83.0%
unsub-neg83.0%
Simplified83.0%
if 3.4e-21 < z Initial program 100.0%
Taylor expanded in z around inf 75.2%
div-sub75.2%
Applied egg-rr75.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65e-29) (not (<= z 1.6e-22))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e-29) || !(z <= 1.6e-22)) {
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.65d-29)) .or. (.not. (z <= 1.6d-22))) 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.65e-29) || !(z <= 1.6e-22)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e-29) or not (z <= 1.6e-22): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e-29) || !(z <= 1.6e-22)) 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.65e-29) || ~((z <= 1.6e-22))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e-29], N[Not[LessEqual[z, 1.6e-22]], $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.65 \cdot 10^{-29} \lor \neg \left(z \leq 1.6 \cdot 10^{-22}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.65000000000000014e-29 or 1.59999999999999994e-22 < z Initial program 100.0%
Taylor expanded in z around inf 78.6%
if -1.65000000000000014e-29 < z < 1.59999999999999994e-22Initial program 100.0%
Taylor expanded in z around 0 83.0%
div-sub83.0%
sub-neg83.0%
*-inverses83.0%
metadata-eval83.0%
distribute-lft-in83.0%
metadata-eval83.0%
+-commutative83.0%
mul-1-neg83.0%
unsub-neg83.0%
Simplified83.0%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.05e+32) (not (<= y 5.4e-18))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e+32) || !(y <= 5.4e-18)) {
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.05d+32)) .or. (.not. (y <= 5.4d-18))) 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.05e+32) || !(y <= 5.4e-18)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e+32) or not (y <= 5.4e-18): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e+32) || !(y <= 5.4e-18)) 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.05e+32) || ~((y <= 5.4e-18))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e+32], N[Not[LessEqual[y, 5.4e-18]], $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.05 \cdot 10^{+32} \lor \neg \left(y \leq 5.4 \cdot 10^{-18}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -1.05e32 or 5.39999999999999977e-18 < y Initial program 100.0%
Taylor expanded in z around 0 78.8%
div-sub78.8%
sub-neg78.8%
*-inverses78.8%
metadata-eval78.8%
distribute-lft-in78.8%
metadata-eval78.8%
+-commutative78.8%
mul-1-neg78.8%
unsub-neg78.8%
Simplified78.8%
if -1.05e32 < y < 5.39999999999999977e-18Initial program 100.0%
Taylor expanded in x around inf 76.1%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= y -4e+29) (+ 1.0 (/ z y)) (if (<= y 3e-18) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+29) {
tmp = 1.0 + (z / y);
} else if (y <= 3e-18) {
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 <= (-4d+29)) then
tmp = 1.0d0 + (z / y)
else if (y <= 3d-18) 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 <= -4e+29) {
tmp = 1.0 + (z / y);
} else if (y <= 3e-18) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e+29: tmp = 1.0 + (z / y) elif y <= 3e-18: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e+29) tmp = Float64(1.0 + Float64(z / y)); elseif (y <= 3e-18) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e+29) tmp = 1.0 + (z / y); elseif (y <= 3e-18) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e+29], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e-18], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+29}:\\
\;\;\;\;1 + \frac{z}{y}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-18}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.99999999999999966e29Initial program 100.0%
Taylor expanded in y around inf 79.0%
associate-+r-79.0%
distribute-lft-out--79.0%
div-sub79.0%
mul-1-neg79.0%
unsub-neg79.0%
Simplified79.0%
Taylor expanded in x around 0 60.5%
if -3.99999999999999966e29 < y < 2.99999999999999983e-18Initial program 100.0%
Taylor expanded in y around 0 65.2%
if 2.99999999999999983e-18 < y Initial program 100.0%
Taylor expanded in y around inf 66.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e+29) 1.0 (if (<= y 3.4e-16) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e+29) {
tmp = 1.0;
} else if (y <= 3.4e-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.7d+29)) then
tmp = 1.0d0
else if (y <= 3.4d-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.7e+29) {
tmp = 1.0;
} else if (y <= 3.4e-16) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e+29: tmp = 1.0 elif y <= 3.4e-16: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e+29) tmp = 1.0; elseif (y <= 3.4e-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.7e+29) tmp = 1.0; elseif (y <= 3.4e-16) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e+29], 1.0, If[LessEqual[y, 3.4e-16], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+29}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-16}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.69999999999999991e29 or 3.4e-16 < y Initial program 100.0%
Taylor expanded in y around inf 63.7%
if -1.69999999999999991e29 < y < 3.4e-16Initial program 100.0%
Taylor expanded in y around 0 65.2%
(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 35.6%
(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 2024086
(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)))