
(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
(let* ((t_0 (/ y (- y z))))
(if (<= y -7.2e+71)
t_0
(if (<= y 0.00035)
(/ x (- z y))
(if (<= y 1.35e+167) t_0 (- 1.0 (/ x y)))))))
double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -7.2e+71) {
tmp = t_0;
} else if (y <= 0.00035) {
tmp = x / (z - y);
} else if (y <= 1.35e+167) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y / (y - z)
if (y <= (-7.2d+71)) then
tmp = t_0
else if (y <= 0.00035d0) then
tmp = x / (z - y)
else if (y <= 1.35d+167) then
tmp = t_0
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -7.2e+71) {
tmp = t_0;
} else if (y <= 0.00035) {
tmp = x / (z - y);
} else if (y <= 1.35e+167) {
tmp = t_0;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) tmp = 0 if y <= -7.2e+71: tmp = t_0 elif y <= 0.00035: tmp = x / (z - y) elif y <= 1.35e+167: tmp = t_0 else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) tmp = 0.0 if (y <= -7.2e+71) tmp = t_0; elseif (y <= 0.00035) tmp = Float64(x / Float64(z - y)); elseif (y <= 1.35e+167) tmp = t_0; else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); tmp = 0.0; if (y <= -7.2e+71) tmp = t_0; elseif (y <= 0.00035) tmp = x / (z - y); elseif (y <= 1.35e+167) tmp = t_0; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.2e+71], t$95$0, If[LessEqual[y, 0.00035], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e+167], t$95$0, N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
\mathbf{if}\;y \leq -7.2 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00035:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+167}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if y < -7.1999999999999999e71 or 3.49999999999999996e-4 < y < 1.35000000000000003e167Initial program 100.0%
Taylor expanded in x around 0 72.7%
neg-mul-172.7%
distribute-neg-frac272.7%
sub-neg72.7%
+-commutative72.7%
distribute-neg-in72.7%
remove-double-neg72.7%
sub-neg72.7%
Simplified72.7%
if -7.1999999999999999e71 < y < 3.49999999999999996e-4Initial program 100.0%
Taylor expanded in x around inf 81.5%
if 1.35000000000000003e167 < y Initial program 99.9%
Taylor expanded in z around 0 89.0%
associate-*r/89.0%
neg-mul-189.0%
sub-neg89.0%
+-commutative89.0%
distribute-neg-in89.0%
remove-double-neg89.0%
sub-neg89.0%
div-sub89.0%
*-inverses89.0%
Simplified89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e+65) (not (<= z 3.8e-44))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e+65) || !(z <= 3.8e-44)) {
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.8d+65)) .or. (.not. (z <= 3.8d-44))) 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.8e+65) || !(z <= 3.8e-44)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e+65) or not (z <= 3.8e-44): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e+65) || !(z <= 3.8e-44)) 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.8e+65) || ~((z <= 3.8e-44))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e+65], N[Not[LessEqual[z, 3.8e-44]], $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.8 \cdot 10^{+65} \lor \neg \left(z \leq 3.8 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -2.7999999999999999e65 or 3.8000000000000001e-44 < z Initial program 100.0%
Taylor expanded in z around inf 78.4%
if -2.7999999999999999e65 < z < 3.8000000000000001e-44Initial program 99.9%
Taylor expanded in z around 0 77.8%
associate-*r/77.8%
neg-mul-177.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-in77.8%
remove-double-neg77.8%
sub-neg77.8%
div-sub77.8%
*-inverses77.8%
Simplified77.8%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e+71) (not (<= y 1.35e-9))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e+71) || !(y <= 1.35e-9)) {
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 <= (-5.5d+71)) .or. (.not. (y <= 1.35d-9))) 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 <= -5.5e+71) || !(y <= 1.35e-9)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e+71) or not (y <= 1.35e-9): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e+71) || !(y <= 1.35e-9)) 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 <= -5.5e+71) || ~((y <= 1.35e-9))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e+71], N[Not[LessEqual[y, 1.35e-9]], $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 -5.5 \cdot 10^{+71} \lor \neg \left(y \leq 1.35 \cdot 10^{-9}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.5e71 or 1.3500000000000001e-9 < y Initial program 99.9%
Taylor expanded in z around 0 70.0%
associate-*r/70.0%
neg-mul-170.0%
sub-neg70.0%
+-commutative70.0%
distribute-neg-in70.0%
remove-double-neg70.0%
sub-neg70.0%
div-sub70.1%
*-inverses70.1%
Simplified70.1%
if -5.5e71 < y < 1.3500000000000001e-9Initial program 100.0%
Taylor expanded in x around inf 81.2%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.95e-7) (not (<= y 1.9e-7))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.95e-7) || !(y <= 1.9e-7)) {
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.95d-7)) .or. (.not. (y <= 1.9d-7))) 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.95e-7) || !(y <= 1.9e-7)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.95e-7) or not (y <= 1.9e-7): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.95e-7) || !(y <= 1.9e-7)) 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.95e-7) || ~((y <= 1.9e-7))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.95e-7], N[Not[LessEqual[y, 1.9e-7]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.95 \cdot 10^{-7} \lor \neg \left(y \leq 1.9 \cdot 10^{-7}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.94999999999999981e-7 or 1.90000000000000007e-7 < y Initial program 99.9%
Taylor expanded in z around 0 67.8%
associate-*r/67.8%
neg-mul-167.8%
sub-neg67.8%
+-commutative67.8%
distribute-neg-in67.8%
remove-double-neg67.8%
sub-neg67.8%
div-sub67.9%
*-inverses67.9%
Simplified67.9%
if -2.94999999999999981e-7 < y < 1.90000000000000007e-7Initial program 100.0%
Taylor expanded in y around 0 71.8%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (<= y -4e+70) 1.0 (if (<= y 2.3e-46) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+70) {
tmp = 1.0;
} else if (y <= 2.3e-46) {
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 <= (-4d+70)) then
tmp = 1.0d0
else if (y <= 2.3d-46) 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 <= -4e+70) {
tmp = 1.0;
} else if (y <= 2.3e-46) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e+70: tmp = 1.0 elif y <= 2.3e-46: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e+70) tmp = 1.0; elseif (y <= 2.3e-46) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e+70) tmp = 1.0; elseif (y <= 2.3e-46) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e+70], 1.0, If[LessEqual[y, 2.3e-46], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+70}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-46}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.00000000000000029e70 or 2.2999999999999999e-46 < y Initial program 99.9%
Taylor expanded in y around inf 55.7%
if -4.00000000000000029e70 < y < 2.2999999999999999e-46Initial program 100.0%
Taylor expanded in y around 0 69.2%
(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 33.7%
(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 2024137
(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)))