
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.55e+127)
1.0
(if (<= y -1.1e+82)
(/ y (- z))
(if (<= y -17500000.0) 1.0 (if (<= y 1.9e+43) (/ x z) 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+127) {
tmp = 1.0;
} else if (y <= -1.1e+82) {
tmp = y / -z;
} else if (y <= -17500000.0) {
tmp = 1.0;
} else if (y <= 1.9e+43) {
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.55d+127)) then
tmp = 1.0d0
else if (y <= (-1.1d+82)) then
tmp = y / -z
else if (y <= (-17500000.0d0)) then
tmp = 1.0d0
else if (y <= 1.9d+43) 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.55e+127) {
tmp = 1.0;
} else if (y <= -1.1e+82) {
tmp = y / -z;
} else if (y <= -17500000.0) {
tmp = 1.0;
} else if (y <= 1.9e+43) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e+127: tmp = 1.0 elif y <= -1.1e+82: tmp = y / -z elif y <= -17500000.0: tmp = 1.0 elif y <= 1.9e+43: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e+127) tmp = 1.0; elseif (y <= -1.1e+82) tmp = Float64(y / Float64(-z)); elseif (y <= -17500000.0) tmp = 1.0; elseif (y <= 1.9e+43) 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.55e+127) tmp = 1.0; elseif (y <= -1.1e+82) tmp = y / -z; elseif (y <= -17500000.0) tmp = 1.0; elseif (y <= 1.9e+43) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e+127], 1.0, If[LessEqual[y, -1.1e+82], N[(y / (-z)), $MachinePrecision], If[LessEqual[y, -17500000.0], 1.0, If[LessEqual[y, 1.9e+43], N[(x / z), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+127}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.1 \cdot 10^{+82}:\\
\;\;\;\;\frac{y}{-z}\\
\mathbf{elif}\;y \leq -17500000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+43}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.5500000000000001e127 or -1.1000000000000001e82 < y < -1.75e7 or 1.90000000000000004e43 < y Initial program 100.0%
Taylor expanded in y around inf 67.8%
if -1.5500000000000001e127 < y < -1.1000000000000001e82Initial program 100.0%
Taylor expanded in x around inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
*-commutative93.4%
Simplified93.4%
Taylor expanded in z around inf 45.9%
Taylor expanded in x around 0 41.7%
neg-mul-141.7%
Simplified41.7%
if -1.75e7 < y < 1.90000000000000004e43Initial program 100.0%
Taylor expanded in y around 0 67.5%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.85e-76) (not (<= y 1.22e-113))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.85e-76) || !(y <= 1.22e-113)) {
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 <= (-3.85d-76)) .or. (.not. (y <= 1.22d-113))) 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 <= -3.85e-76) || !(y <= 1.22e-113)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.85e-76) or not (y <= 1.22e-113): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.85e-76) || !(y <= 1.22e-113)) 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 <= -3.85e-76) || ~((y <= 1.22e-113))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.85e-76], N[Not[LessEqual[y, 1.22e-113]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.85 \cdot 10^{-76} \lor \neg \left(y \leq 1.22 \cdot 10^{-113}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -3.84999999999999991e-76 or 1.21999999999999995e-113 < y Initial program 100.0%
Taylor expanded in z around 0 71.3%
div-sub71.3%
sub-neg71.3%
*-inverses71.3%
metadata-eval71.3%
distribute-lft-in71.3%
metadata-eval71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
Simplified71.3%
if -3.84999999999999991e-76 < y < 1.21999999999999995e-113Initial program 100.0%
Taylor expanded in y around 0 78.9%
Final simplification74.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e+19) (not (<= y 1.95e+40))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e+19) || !(y <= 1.95e+40)) {
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 <= (-7.2d+19)) .or. (.not. (y <= 1.95d+40))) 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 <= -7.2e+19) || !(y <= 1.95e+40)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2e+19) or not (y <= 1.95e+40): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e+19) || !(y <= 1.95e+40)) 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 <= -7.2e+19) || ~((y <= 1.95e+40))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e+19], N[Not[LessEqual[y, 1.95e+40]], $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 -7.2 \cdot 10^{+19} \lor \neg \left(y \leq 1.95 \cdot 10^{+40}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -7.2e19 or 1.95e40 < y Initial program 100.0%
Taylor expanded in z around 0 76.9%
div-sub76.9%
sub-neg76.9%
*-inverses76.9%
metadata-eval76.9%
distribute-lft-in76.9%
metadata-eval76.9%
+-commutative76.9%
mul-1-neg76.9%
unsub-neg76.9%
Simplified76.9%
if -7.2e19 < y < 1.95e40Initial program 100.0%
Taylor expanded in x around inf 80.7%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.55e-31) (not (<= z 1.55e+92))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.55e-31) || !(z <= 1.55e+92)) {
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.55d-31)) .or. (.not. (z <= 1.55d+92))) 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.55e-31) || !(z <= 1.55e+92)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.55e-31) or not (z <= 1.55e+92): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.55e-31) || !(z <= 1.55e+92)) 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.55e-31) || ~((z <= 1.55e+92))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.55e-31], N[Not[LessEqual[z, 1.55e+92]], $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.55 \cdot 10^{-31} \lor \neg \left(z \leq 1.55 \cdot 10^{+92}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.55e-31 or 1.5500000000000001e92 < z Initial program 100.0%
Taylor expanded in z around inf 83.6%
if -1.55e-31 < z < 1.5500000000000001e92Initial program 100.0%
Taylor expanded in z around 0 80.6%
div-sub80.6%
sub-neg80.6%
*-inverses80.6%
metadata-eval80.6%
distribute-lft-in80.6%
metadata-eval80.6%
+-commutative80.6%
mul-1-neg80.6%
unsub-neg80.6%
Simplified80.6%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1700.0) (not (<= x 7.2e+113))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1700.0) || !(x <= 7.2e+113)) {
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 ((x <= (-1700.0d0)) .or. (.not. (x <= 7.2d+113))) 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 ((x <= -1700.0) || !(x <= 7.2e+113)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1700.0) or not (x <= 7.2e+113): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1700.0) || !(x <= 7.2e+113)) 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 ((x <= -1700.0) || ~((x <= 7.2e+113))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1700.0], N[Not[LessEqual[x, 7.2e+113]], $MachinePrecision]], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1700 \lor \neg \left(x \leq 7.2 \cdot 10^{+113}\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -1700 or 7.19999999999999984e113 < x Initial program 100.0%
Taylor expanded in x around inf 84.7%
if -1700 < x < 7.19999999999999984e113Initial program 100.0%
Taylor expanded in x around 0 82.5%
neg-mul-182.5%
distribute-neg-frac82.5%
Simplified82.5%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (<= y -98000000000.0) 1.0 (if (<= y 4.5e+42) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -98000000000.0) {
tmp = 1.0;
} else if (y <= 4.5e+42) {
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 <= (-98000000000.0d0)) then
tmp = 1.0d0
else if (y <= 4.5d+42) 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 <= -98000000000.0) {
tmp = 1.0;
} else if (y <= 4.5e+42) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -98000000000.0: tmp = 1.0 elif y <= 4.5e+42: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -98000000000.0) tmp = 1.0; elseif (y <= 4.5e+42) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -98000000000.0) tmp = 1.0; elseif (y <= 4.5e+42) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -98000000000.0], 1.0, If[LessEqual[y, 4.5e+42], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -98000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+42}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9.8e10 or 4.50000000000000012e42 < y Initial program 100.0%
Taylor expanded in y around inf 61.2%
if -9.8e10 < y < 4.50000000000000012e42Initial program 100.0%
Taylor expanded in y around 0 67.5%
Final simplification64.4%
(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.0%
Final simplification35.0%
(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 2024059
(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)))