
(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 7 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 -2.7e-34)
(- 1.0 (/ x y))
(if (<= y -2.2e-225)
(/ (- x y) z)
(if (<= y 5.2e+143) (/ x (- z y)) (/ y (- y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e-34) {
tmp = 1.0 - (x / y);
} else if (y <= -2.2e-225) {
tmp = (x - y) / z;
} else if (y <= 5.2e+143) {
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 (y <= (-2.7d-34)) then
tmp = 1.0d0 - (x / y)
else if (y <= (-2.2d-225)) then
tmp = (x - y) / z
else if (y <= 5.2d+143) 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 (y <= -2.7e-34) {
tmp = 1.0 - (x / y);
} else if (y <= -2.2e-225) {
tmp = (x - y) / z;
} else if (y <= 5.2e+143) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.7e-34: tmp = 1.0 - (x / y) elif y <= -2.2e-225: tmp = (x - y) / z elif y <= 5.2e+143: tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.7e-34) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= -2.2e-225) tmp = Float64(Float64(x - y) / z); elseif (y <= 5.2e+143) 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 (y <= -2.7e-34) tmp = 1.0 - (x / y); elseif (y <= -2.2e-225) tmp = (x - y) / z; elseif (y <= 5.2e+143) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.7e-34], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.2e-225], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 5.2e+143], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-34}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{-225}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+143}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -2.70000000000000017e-34Initial program 100.0%
Taylor expanded in z around 0 77.4%
associate-*r/77.4%
neg-mul-177.4%
sub-neg77.4%
+-commutative77.4%
distribute-neg-in77.4%
remove-double-neg77.4%
sub-neg77.4%
div-sub77.4%
*-inverses77.4%
Simplified77.4%
if -2.70000000000000017e-34 < y < -2.2e-225Initial program 100.0%
Taylor expanded in z around inf 82.9%
if -2.2e-225 < y < 5.1999999999999998e143Initial program 100.0%
Taylor expanded in x around inf 84.4%
if 5.1999999999999998e143 < y Initial program 99.9%
Taylor expanded in x around 0 96.1%
neg-mul-196.1%
distribute-neg-frac296.1%
sub-neg96.1%
+-commutative96.1%
distribute-neg-in96.1%
remove-double-neg96.1%
sub-neg96.1%
Simplified96.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e-11) (not (<= y 1.15e+130))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-11) || !(y <= 1.15e+130)) {
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 <= (-2.1d-11)) .or. (.not. (y <= 1.15d+130))) 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 <= -2.1e-11) || !(y <= 1.15e+130)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e-11) or not (y <= 1.15e+130): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e-11) || !(y <= 1.15e+130)) 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 <= -2.1e-11) || ~((y <= 1.15e+130))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e-11], N[Not[LessEqual[y, 1.15e+130]], $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 -2.1 \cdot 10^{-11} \lor \neg \left(y \leq 1.15 \cdot 10^{+130}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -2.0999999999999999e-11 or 1.15000000000000011e130 < y Initial program 99.9%
Taylor expanded in z around 0 79.0%
associate-*r/79.0%
neg-mul-179.0%
sub-neg79.0%
+-commutative79.0%
distribute-neg-in79.0%
remove-double-neg79.0%
sub-neg79.0%
div-sub79.0%
*-inverses79.0%
Simplified79.0%
if -2.0999999999999999e-11 < y < 1.15000000000000011e130Initial program 100.0%
Taylor expanded in x around inf 81.0%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e-35) (not (<= y 1.35e-19))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-35) || !(y <= 1.35e-19)) {
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.3d-35)) .or. (.not. (y <= 1.35d-19))) 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.3e-35) || !(y <= 1.35e-19)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e-35) or not (y <= 1.35e-19): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-35) || !(y <= 1.35e-19)) 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.3e-35) || ~((y <= 1.35e-19))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e-35], N[Not[LessEqual[y, 1.35e-19]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-35} \lor \neg \left(y \leq 1.35 \cdot 10^{-19}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.2999999999999999e-35 or 1.35e-19 < y Initial program 99.9%
Taylor expanded in z around 0 73.2%
associate-*r/73.2%
neg-mul-173.2%
sub-neg73.2%
+-commutative73.2%
distribute-neg-in73.2%
remove-double-neg73.2%
sub-neg73.2%
div-sub73.2%
*-inverses73.2%
Simplified73.2%
if -2.2999999999999999e-35 < y < 1.35e-19Initial program 100.0%
Taylor expanded in y around 0 77.4%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e-11) (- 1.0 (/ x y)) (if (<= y 5.2e+143) (/ x (- z y)) (/ y (- y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-11) {
tmp = 1.0 - (x / y);
} else if (y <= 5.2e+143) {
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 (y <= (-7.5d-11)) then
tmp = 1.0d0 - (x / y)
else if (y <= 5.2d+143) 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 (y <= -7.5e-11) {
tmp = 1.0 - (x / y);
} else if (y <= 5.2e+143) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e-11: tmp = 1.0 - (x / y) elif y <= 5.2e+143: tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e-11) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 5.2e+143) 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 (y <= -7.5e-11) tmp = 1.0 - (x / y); elseif (y <= 5.2e+143) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e-11], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.2e+143], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-11}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+143}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -7.5e-11Initial program 100.0%
Taylor expanded in z around 0 78.4%
associate-*r/78.4%
neg-mul-178.4%
sub-neg78.4%
+-commutative78.4%
distribute-neg-in78.4%
remove-double-neg78.4%
sub-neg78.4%
div-sub78.4%
*-inverses78.4%
Simplified78.4%
if -7.5e-11 < y < 5.1999999999999998e143Initial program 100.0%
Taylor expanded in x around inf 80.2%
if 5.1999999999999998e143 < y Initial program 99.9%
Taylor expanded in x around 0 96.1%
neg-mul-196.1%
distribute-neg-frac296.1%
sub-neg96.1%
+-commutative96.1%
distribute-neg-in96.1%
remove-double-neg96.1%
sub-neg96.1%
Simplified96.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.3e-11) 1.0 (if (<= y 1.7e+71) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.3e-11) {
tmp = 1.0;
} else if (y <= 1.7e+71) {
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 <= (-5.3d-11)) then
tmp = 1.0d0
else if (y <= 1.7d+71) 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 <= -5.3e-11) {
tmp = 1.0;
} else if (y <= 1.7e+71) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.3e-11: tmp = 1.0 elif y <= 1.7e+71: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.3e-11) tmp = 1.0; elseif (y <= 1.7e+71) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.3e-11) tmp = 1.0; elseif (y <= 1.7e+71) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.3e-11], 1.0, If[LessEqual[y, 1.7e+71], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.3 \cdot 10^{-11}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.2999999999999998e-11 or 1.6999999999999999e71 < y Initial program 100.0%
Taylor expanded in y around inf 61.4%
if -5.2999999999999998e-11 < y < 1.6999999999999999e71Initial program 100.0%
Taylor expanded in y around 0 69.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 34.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 2024149
(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)))