
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -8.5e+25)
(not
(or (<= x -3.8e-26) (and (not (<= x -4.7e-57)) (<= x 1550000.0)))))
(/ x (- z y))
(/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e+25) || !((x <= -3.8e-26) || (!(x <= -4.7e-57) && (x <= 1550000.0)))) {
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 <= (-8.5d+25)) .or. (.not. (x <= (-3.8d-26)) .or. (.not. (x <= (-4.7d-57))) .and. (x <= 1550000.0d0))) 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 <= -8.5e+25) || !((x <= -3.8e-26) || (!(x <= -4.7e-57) && (x <= 1550000.0)))) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e+25) or not ((x <= -3.8e-26) or (not (x <= -4.7e-57) and (x <= 1550000.0))): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e+25) || !((x <= -3.8e-26) || (!(x <= -4.7e-57) && (x <= 1550000.0)))) 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 <= -8.5e+25) || ~(((x <= -3.8e-26) || (~((x <= -4.7e-57)) && (x <= 1550000.0))))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e+25], N[Not[Or[LessEqual[x, -3.8e-26], And[N[Not[LessEqual[x, -4.7e-57]], $MachinePrecision], LessEqual[x, 1550000.0]]]], $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 -8.5 \cdot 10^{+25} \lor \neg \left(x \leq -3.8 \cdot 10^{-26} \lor \neg \left(x \leq -4.7 \cdot 10^{-57}\right) \land x \leq 1550000\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -8.5000000000000007e25 or -3.80000000000000015e-26 < x < -4.6999999999999998e-57 or 1.55e6 < x Initial program 100.0%
Taylor expanded in x around inf 80.6%
if -8.5000000000000007e25 < x < -3.80000000000000015e-26 or -4.6999999999999998e-57 < x < 1.55e6Initial program 99.9%
Taylor expanded in x around 0 83.8%
neg-mul-183.8%
distribute-neg-frac83.8%
Simplified83.8%
frac-2neg83.8%
div-inv83.6%
remove-double-neg83.6%
sub-neg83.6%
distribute-neg-in83.6%
remove-double-neg83.6%
Applied egg-rr83.6%
associate-*r/83.8%
*-rgt-identity83.8%
+-commutative83.8%
unsub-neg83.8%
Simplified83.8%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-58) (not (<= y 6.8e-54))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-58) || !(y <= 6.8e-54)) {
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.5d-58)) .or. (.not. (y <= 6.8d-54))) 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.5e-58) || !(y <= 6.8e-54)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-58) or not (y <= 6.8e-54): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-58) || !(y <= 6.8e-54)) 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.5e-58) || ~((y <= 6.8e-54))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-58], N[Not[LessEqual[y, 6.8e-54]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-58} \lor \neg \left(y \leq 6.8 \cdot 10^{-54}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.49999999999999989e-58 or 6.79999999999999975e-54 < y Initial program 99.9%
Taylor expanded in z around 0 70.8%
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 -2.49999999999999989e-58 < y < 6.79999999999999975e-54Initial program 100.0%
Taylor expanded in y around 0 77.0%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+63) (not (<= y 7.5e-54))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+63) || !(y <= 7.5e-54)) {
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.5d+63)) .or. (.not. (y <= 7.5d-54))) 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.5e+63) || !(y <= 7.5e-54)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e+63) or not (y <= 7.5e-54): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+63) || !(y <= 7.5e-54)) 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.5e+63) || ~((y <= 7.5e-54))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+63], N[Not[LessEqual[y, 7.5e-54]], $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.5 \cdot 10^{+63} \lor \neg \left(y \leq 7.5 \cdot 10^{-54}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -7.5000000000000005e63 or 7.5000000000000005e-54 < y Initial program 99.9%
Taylor expanded in z around 0 77.1%
div-sub77.1%
sub-neg77.1%
*-inverses77.1%
metadata-eval77.1%
distribute-lft-in77.1%
metadata-eval77.1%
+-commutative77.1%
mul-1-neg77.1%
unsub-neg77.1%
Simplified77.1%
if -7.5000000000000005e63 < y < 7.5000000000000005e-54Initial program 100.0%
Taylor expanded in x around inf 77.8%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.9e-36) (not (<= z 8.8e+47))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e-36) || !(z <= 8.8e+47)) {
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 <= (-2.9d-36)) .or. (.not. (z <= 8.8d+47))) 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 <= -2.9e-36) || !(z <= 8.8e+47)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.9e-36) or not (z <= 8.8e+47): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.9e-36) || !(z <= 8.8e+47)) 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 <= -2.9e-36) || ~((z <= 8.8e+47))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.9e-36], N[Not[LessEqual[z, 8.8e+47]], $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 -2.9 \cdot 10^{-36} \lor \neg \left(z \leq 8.8 \cdot 10^{+47}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -2.90000000000000013e-36 or 8.7999999999999997e47 < z Initial program 100.0%
Taylor expanded in z around inf 82.8%
if -2.90000000000000013e-36 < z < 8.7999999999999997e47Initial program 100.0%
Taylor expanded in z around 0 77.0%
div-sub77.0%
sub-neg77.0%
*-inverses77.0%
metadata-eval77.0%
distribute-lft-in77.0%
metadata-eval77.0%
+-commutative77.0%
mul-1-neg77.0%
unsub-neg77.0%
Simplified77.0%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (<= y -3e+63) 1.0 (if (<= y 2.6e-51) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+63) {
tmp = 1.0;
} else if (y <= 2.6e-51) {
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 <= (-3d+63)) then
tmp = 1.0d0
else if (y <= 2.6d-51) 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 <= -3e+63) {
tmp = 1.0;
} else if (y <= 2.6e-51) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+63: tmp = 1.0 elif y <= 2.6e-51: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+63) tmp = 1.0; elseif (y <= 2.6e-51) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e+63) tmp = 1.0; elseif (y <= 2.6e-51) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+63], 1.0, If[LessEqual[y, 2.6e-51], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+63}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-51}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.99999999999999999e63 or 2.6e-51 < y Initial program 99.9%
Taylor expanded in y around inf 60.2%
if -2.99999999999999999e63 < y < 2.6e-51Initial program 100.0%
Taylor expanded in y around 0 66.1%
Final simplification63.5%
(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 32.3%
Final simplification32.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 2024082
(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)))