
(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 9 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 99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -620000000000.0) (not (<= z 3.8e-74))) (/ (- x y) z) (+ 1.0 (/ (- z x) y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -620000000000.0) || !(z <= 3.8e-74)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 + ((z - 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 <= (-620000000000.0d0)) .or. (.not. (z <= 3.8d-74))) then
tmp = (x - y) / z
else
tmp = 1.0d0 + ((z - x) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -620000000000.0) || !(z <= 3.8e-74)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 + ((z - x) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -620000000000.0) or not (z <= 3.8e-74): tmp = (x - y) / z else: tmp = 1.0 + ((z - x) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -620000000000.0) || !(z <= 3.8e-74)) tmp = Float64(Float64(x - y) / z); else tmp = Float64(1.0 + Float64(Float64(z - x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -620000000000.0) || ~((z <= 3.8e-74))) tmp = (x - y) / z; else tmp = 1.0 + ((z - x) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -620000000000.0], N[Not[LessEqual[z, 3.8e-74]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(1.0 + N[(N[(z - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -620000000000 \lor \neg \left(z \leq 3.8 \cdot 10^{-74}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{z - x}{y}\\
\end{array}
\end{array}
if z < -6.2e11 or 3.7999999999999996e-74 < z Initial program 99.9%
Taylor expanded in z around inf 78.4%
if -6.2e11 < z < 3.7999999999999996e-74Initial program 99.9%
Taylor expanded in y around inf 83.8%
associate--l+83.8%
distribute-lft-out--83.8%
div-sub83.8%
mul-1-neg83.8%
unsub-neg83.8%
Simplified83.8%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.88) (not (<= z 5.1e-70))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.88) || !(z <= 5.1e-70)) {
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 <= (-0.88d0)) .or. (.not. (z <= 5.1d-70))) 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 <= -0.88) || !(z <= 5.1e-70)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.88) or not (z <= 5.1e-70): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.88) || !(z <= 5.1e-70)) 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 <= -0.88) || ~((z <= 5.1e-70))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.88], N[Not[LessEqual[z, 5.1e-70]], $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 -0.88 \lor \neg \left(z \leq 5.1 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -0.880000000000000004 or 5.10000000000000025e-70 < z Initial program 99.9%
Taylor expanded in z around inf 78.4%
if -0.880000000000000004 < z < 5.10000000000000025e-70Initial program 99.9%
Taylor expanded in z around 0 83.7%
associate-*r/83.7%
neg-mul-183.7%
sub-neg83.7%
+-commutative83.7%
distribute-neg-in83.7%
remove-double-neg83.7%
sub-neg83.7%
div-sub83.7%
*-inverses83.7%
Simplified83.7%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e+98) (not (<= x 6.1e+131))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e+98) || !(x <= 6.1e+131)) {
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 <= (-1.25d+98)) .or. (.not. (x <= 6.1d+131))) 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 <= -1.25e+98) || !(x <= 6.1e+131)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e+98) or not (x <= 6.1e+131): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e+98) || !(x <= 6.1e+131)) 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 <= -1.25e+98) || ~((x <= 6.1e+131))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e+98], N[Not[LessEqual[x, 6.1e+131]], $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 -1.25 \cdot 10^{+98} \lor \neg \left(x \leq 6.1 \cdot 10^{+131}\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -1.25e98 or 6.0999999999999999e131 < x Initial program 100.0%
Taylor expanded in x around inf 87.9%
if -1.25e98 < x < 6.0999999999999999e131Initial program 99.9%
Taylor expanded in x around 0 75.4%
neg-mul-175.4%
distribute-neg-frac275.4%
sub-neg75.4%
+-commutative75.4%
distribute-neg-in75.4%
remove-double-neg75.4%
sub-neg75.4%
Simplified75.4%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.5e+46) (not (<= y 6e-38))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+46) || !(y <= 6e-38)) {
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 <= (-8.5d+46)) .or. (.not. (y <= 6d-38))) 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 <= -8.5e+46) || !(y <= 6e-38)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e+46) or not (y <= 6e-38): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e+46) || !(y <= 6e-38)) 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 <= -8.5e+46) || ~((y <= 6e-38))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e+46], N[Not[LessEqual[y, 6e-38]], $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 -8.5 \cdot 10^{+46} \lor \neg \left(y \leq 6 \cdot 10^{-38}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -8.4999999999999996e46 or 5.99999999999999977e-38 < y Initial program 100.0%
Taylor expanded in z around 0 71.4%
associate-*r/71.4%
neg-mul-171.4%
sub-neg71.4%
+-commutative71.4%
distribute-neg-in71.4%
remove-double-neg71.4%
sub-neg71.4%
div-sub71.4%
*-inverses71.4%
Simplified71.4%
if -8.4999999999999996e46 < y < 5.99999999999999977e-38Initial program 99.9%
Taylor expanded in x around inf 75.3%
Final simplification73.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e-61) (not (<= y 1.12e-38))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-61) || !(y <= 1.12e-38)) {
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 <= (-5.5d-61)) .or. (.not. (y <= 1.12d-38))) 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 <= -5.5e-61) || !(y <= 1.12e-38)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e-61) or not (y <= 1.12e-38): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e-61) || !(y <= 1.12e-38)) 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 <= -5.5e-61) || ~((y <= 1.12e-38))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e-61], N[Not[LessEqual[y, 1.12e-38]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-61} \lor \neg \left(y \leq 1.12 \cdot 10^{-38}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -5.4999999999999997e-61 or 1.1200000000000001e-38 < 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.2%
*-inverses68.2%
Simplified68.2%
if -5.4999999999999997e-61 < y < 1.1200000000000001e-38Initial program 99.9%
Taylor expanded in y around 0 72.0%
Final simplification69.9%
(FPCore (x y z) :precision binary64 (if (<= y -8e+45) 1.0 (if (<= y 7e-39) (/ x z) (+ 1.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+45) {
tmp = 1.0;
} else if (y <= 7e-39) {
tmp = x / z;
} else {
tmp = 1.0 + (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 <= (-8d+45)) then
tmp = 1.0d0
else if (y <= 7d-39) then
tmp = x / z
else
tmp = 1.0d0 + (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8e+45) {
tmp = 1.0;
} else if (y <= 7e-39) {
tmp = x / z;
} else {
tmp = 1.0 + (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e+45: tmp = 1.0 elif y <= 7e-39: tmp = x / z else: tmp = 1.0 + (z / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e+45) tmp = 1.0; elseif (y <= 7e-39) tmp = Float64(x / z); else tmp = Float64(1.0 + Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e+45) tmp = 1.0; elseif (y <= 7e-39) tmp = x / z; else tmp = 1.0 + (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e+45], 1.0, If[LessEqual[y, 7e-39], N[(x / z), $MachinePrecision], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+45}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-39}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{z}{y}\\
\end{array}
\end{array}
if y < -7.9999999999999994e45Initial program 99.9%
Taylor expanded in y around inf 66.0%
if -7.9999999999999994e45 < y < 6.99999999999999999e-39Initial program 99.9%
Taylor expanded in y around 0 66.1%
if 6.99999999999999999e-39 < y Initial program 100.0%
Taylor expanded in x around 0 72.1%
neg-mul-172.1%
distribute-neg-frac272.1%
sub-neg72.1%
+-commutative72.1%
distribute-neg-in72.1%
remove-double-neg72.1%
sub-neg72.1%
Simplified72.1%
Taylor expanded in y around inf 51.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.35e+46) 1.0 (if (<= y 6e-38) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.35e+46) {
tmp = 1.0;
} else if (y <= 6e-38) {
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.35d+46)) then
tmp = 1.0d0
else if (y <= 6d-38) 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.35e+46) {
tmp = 1.0;
} else if (y <= 6e-38) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.35e+46: tmp = 1.0 elif y <= 6e-38: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.35e+46) tmp = 1.0; elseif (y <= 6e-38) 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.35e+46) tmp = 1.0; elseif (y <= 6e-38) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.35e+46], 1.0, If[LessEqual[y, 6e-38], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+46}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-38}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.3500000000000001e46 or 5.99999999999999977e-38 < y Initial program 100.0%
Taylor expanded in y around inf 57.7%
if -1.3500000000000001e46 < y < 5.99999999999999977e-38Initial program 99.9%
Taylor expanded in y around 0 66.1%
(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 99.9%
Taylor expanded in y around inf 35.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 2024181
(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)))