
(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 (or (<= y -3.8e+74) (not (<= y 8.8e-33))) (/ y (- y z)) (/ (- x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+74) || !(y <= 8.8e-33)) {
tmp = y / (y - z);
} else {
tmp = (x - 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.8d+74)) .or. (.not. (y <= 8.8d-33))) then
tmp = y / (y - z)
else
tmp = (x - y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+74) || !(y <= 8.8e-33)) {
tmp = y / (y - z);
} else {
tmp = (x - y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e+74) or not (y <= 8.8e-33): tmp = y / (y - z) else: tmp = (x - y) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+74) || !(y <= 8.8e-33)) tmp = Float64(y / Float64(y - z)); else tmp = Float64(Float64(x - y) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.8e+74) || ~((y <= 8.8e-33))) tmp = y / (y - z); else tmp = (x - y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+74], N[Not[LessEqual[y, 8.8e-33]], $MachinePrecision]], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+74} \lor \neg \left(y \leq 8.8 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{z}\\
\end{array}
\end{array}
if y < -3.7999999999999998e74 or 8.80000000000000022e-33 < y Initial program 99.9%
Taylor expanded in x around 0 80.6%
neg-mul-180.6%
distribute-neg-frac280.6%
sub-neg80.6%
+-commutative80.6%
distribute-neg-in80.6%
remove-double-neg80.6%
sub-neg80.6%
Simplified80.6%
if -3.7999999999999998e74 < y < 8.80000000000000022e-33Initial program 100.0%
Taylor expanded in z around inf 78.1%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+74) (not (<= y 3.9e+17))) (/ y (- y z)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+74) || !(y <= 3.9e+17)) {
tmp = y / (y - z);
} 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 <= (-7.5d+74)) .or. (.not. (y <= 3.9d+17))) then
tmp = y / (y - z)
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 <= -7.5e+74) || !(y <= 3.9e+17)) {
tmp = y / (y - z);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e+74) or not (y <= 3.9e+17): tmp = y / (y - z) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+74) || !(y <= 3.9e+17)) tmp = Float64(y / Float64(y - z)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.5e+74) || ~((y <= 3.9e+17))) tmp = y / (y - z); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+74], N[Not[LessEqual[y, 3.9e+17]], $MachinePrecision]], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+74} \lor \neg \left(y \leq 3.9 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -7.5e74 or 3.9e17 < y Initial program 99.9%
Taylor expanded in x around 0 84.1%
neg-mul-184.1%
distribute-neg-frac284.1%
sub-neg84.1%
+-commutative84.1%
distribute-neg-in84.1%
remove-double-neg84.1%
sub-neg84.1%
Simplified84.1%
if -7.5e74 < y < 3.9e17Initial program 100.0%
Taylor expanded in x around inf 72.7%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e+36) (not (<= y 6e-74))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e+36) || !(y <= 6e-74)) {
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.1d+36)) .or. (.not. (y <= 6d-74))) 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.1e+36) || !(y <= 6e-74)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e+36) or not (y <= 6e-74): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e+36) || !(y <= 6e-74)) 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.1e+36) || ~((y <= 6e-74))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e+36], N[Not[LessEqual[y, 6e-74]], $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.1 \cdot 10^{+36} \lor \neg \left(y \leq 6 \cdot 10^{-74}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -1.1e36 or 6.00000000000000014e-74 < y Initial program 99.9%
Taylor expanded in z around 0 73.4%
associate-*r/73.4%
neg-mul-173.4%
sub-neg73.4%
+-commutative73.4%
distribute-neg-in73.4%
remove-double-neg73.4%
sub-neg73.4%
div-sub73.4%
*-inverses73.4%
Simplified73.4%
if -1.1e36 < y < 6.00000000000000014e-74Initial program 100.0%
Taylor expanded in x around inf 76.6%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e-82) (not (<= y 3.1e-118))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-82) || !(y <= 3.1e-118)) {
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.4d-82)) .or. (.not. (y <= 3.1d-118))) 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.4e-82) || !(y <= 3.1e-118)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e-82) or not (y <= 3.1e-118): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e-82) || !(y <= 3.1e-118)) 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.4e-82) || ~((y <= 3.1e-118))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e-82], N[Not[LessEqual[y, 3.1e-118]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-82} \lor \neg \left(y \leq 3.1 \cdot 10^{-118}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -4.39999999999999971e-82 or 3.1000000000000001e-118 < y Initial program 99.9%
Taylor expanded in z around 0 68.2%
associate-*r/68.2%
neg-mul-168.2%
sub-neg68.2%
+-commutative68.2%
distribute-neg-in68.2%
remove-double-neg68.2%
sub-neg68.2%
div-sub68.3%
*-inverses68.3%
Simplified68.3%
if -4.39999999999999971e-82 < y < 3.1000000000000001e-118Initial program 100.0%
Taylor expanded in y around 0 80.0%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.2e+37) 1.0 (if (<= y 1.8e-35) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.2e+37) {
tmp = 1.0;
} else if (y <= 1.8e-35) {
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.2d+37)) then
tmp = 1.0d0
else if (y <= 1.8d-35) 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.2e+37) {
tmp = 1.0;
} else if (y <= 1.8e-35) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.2e+37: tmp = 1.0 elif y <= 1.8e-35: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.2e+37) tmp = 1.0; elseif (y <= 1.8e-35) 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.2e+37) tmp = 1.0; elseif (y <= 1.8e-35) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.2e+37], 1.0, If[LessEqual[y, 1.8e-35], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+37}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-35}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.2e37 or 1.80000000000000009e-35 < y Initial program 100.0%
Taylor expanded in y around inf 59.8%
if -1.2e37 < y < 1.80000000000000009e-35Initial program 99.9%
Taylor expanded in y around 0 66.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 36.9%
(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 2024176
(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)))