
(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 (<= y -1.92e-31) (not (<= y 4e-33))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.92e-31) || !(y <= 4e-33)) {
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 <= (-1.92d-31)) .or. (.not. (y <= 4d-33))) 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 <= -1.92e-31) || !(y <= 4e-33)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.92e-31) or not (y <= 4e-33): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.92e-31) || !(y <= 4e-33)) 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 <= -1.92e-31) || ~((y <= 4e-33))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.92e-31], N[Not[LessEqual[y, 4e-33]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.92 \cdot 10^{-31} \lor \neg \left(y \leq 4 \cdot 10^{-33}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -1.9200000000000001e-31 or 4.0000000000000002e-33 < y Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in z around 0 80.5%
div-sub80.5%
*-inverses80.5%
Simplified80.5%
if -1.9200000000000001e-31 < y < 4.0000000000000002e-33Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around 0 74.5%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00156) (not (<= y 2.85e-33))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00156) || !(y <= 2.85e-33)) {
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 <= (-0.00156d0)) .or. (.not. (y <= 2.85d-33))) 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 <= -0.00156) || !(y <= 2.85e-33)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00156) or not (y <= 2.85e-33): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00156) || !(y <= 2.85e-33)) 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 <= -0.00156) || ~((y <= 2.85e-33))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00156], N[Not[LessEqual[y, 2.85e-33]], $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 -0.00156 \lor \neg \left(y \leq 2.85 \cdot 10^{-33}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -0.00155999999999999997 or 2.85000000000000013e-33 < y Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in z around 0 82.5%
div-sub82.5%
*-inverses82.5%
Simplified82.5%
if -0.00155999999999999997 < y < 2.85000000000000013e-33Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 86.8%
neg-mul-186.8%
distribute-neg-frac86.8%
Simplified86.8%
Taylor expanded in x around 0 86.8%
associate-*r/86.8%
associate-*l/86.5%
metadata-eval86.5%
associate-/r*86.5%
neg-mul-186.5%
associate-*l/86.8%
*-lft-identity86.8%
neg-sub086.8%
sub-neg86.8%
+-commutative86.8%
associate--r+86.8%
neg-sub086.8%
remove-double-neg86.8%
Simplified86.8%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (<= y -0.0017) (- 1.0 (/ (- x z) y)) (if (<= y 4.4e-33) (/ x (- z y)) (- 1.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.0017) {
tmp = 1.0 - ((x - z) / y);
} else if (y <= 4.4e-33) {
tmp = x / (z - y);
} 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 (y <= (-0.0017d0)) then
tmp = 1.0d0 - ((x - z) / y)
else if (y <= 4.4d-33) then
tmp = x / (z - y)
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 (y <= -0.0017) {
tmp = 1.0 - ((x - z) / y);
} else if (y <= 4.4e-33) {
tmp = x / (z - y);
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.0017: tmp = 1.0 - ((x - z) / y) elif y <= 4.4e-33: tmp = x / (z - y) else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.0017) tmp = Float64(1.0 - Float64(Float64(x - z) / y)); elseif (y <= 4.4e-33) tmp = Float64(x / Float64(z - y)); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.0017) tmp = 1.0 - ((x - z) / y); elseif (y <= 4.4e-33) tmp = x / (z - y); else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.0017], N[(1.0 - N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.4e-33], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0017:\\
\;\;\;\;1 - \frac{x - z}{y}\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{-33}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if y < -0.00169999999999999991Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around inf 82.7%
mul-1-neg82.7%
associate--l+82.7%
mul-1-neg82.7%
distribute-lft-out--82.7%
div-sub82.7%
mul-1-neg82.7%
unsub-neg82.7%
Simplified82.7%
if -0.00169999999999999991 < y < 4.40000000000000011e-33Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 86.8%
neg-mul-186.8%
distribute-neg-frac86.8%
Simplified86.8%
Taylor expanded in x around 0 86.8%
associate-*r/86.8%
associate-*l/86.5%
metadata-eval86.5%
associate-/r*86.5%
neg-mul-186.5%
associate-*l/86.8%
*-lft-identity86.8%
neg-sub086.8%
sub-neg86.8%
+-commutative86.8%
associate--r+86.8%
neg-sub086.8%
remove-double-neg86.8%
Simplified86.8%
if 4.40000000000000011e-33 < y Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in z around 0 82.9%
div-sub82.9%
*-inverses82.9%
Simplified82.9%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (if (<= y -0.00156) 1.0 (if (<= y 2.9e-33) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.00156) {
tmp = 1.0;
} else if (y <= 2.9e-33) {
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 <= (-0.00156d0)) then
tmp = 1.0d0
else if (y <= 2.9d-33) 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 <= -0.00156) {
tmp = 1.0;
} else if (y <= 2.9e-33) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.00156: tmp = 1.0 elif y <= 2.9e-33: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.00156) tmp = 1.0; elseif (y <= 2.9e-33) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.00156) tmp = 1.0; elseif (y <= 2.9e-33) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.00156], 1.0, If[LessEqual[y, 2.9e-33], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00156:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-33}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.00155999999999999997 or 2.90000000000000003e-33 < y Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around inf 63.9%
if -0.00155999999999999997 < y < 2.90000000000000003e-33Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around 0 72.6%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (<= y -0.00092) (+ 1.0 (/ z y)) (if (<= y 3.6e-33) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.00092) {
tmp = 1.0 + (z / y);
} else if (y <= 3.6e-33) {
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 <= (-0.00092d0)) then
tmp = 1.0d0 + (z / y)
else if (y <= 3.6d-33) 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 <= -0.00092) {
tmp = 1.0 + (z / y);
} else if (y <= 3.6e-33) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.00092: tmp = 1.0 + (z / y) elif y <= 3.6e-33: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.00092) tmp = Float64(1.0 + Float64(z / y)); elseif (y <= 3.6e-33) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.00092) tmp = 1.0 + (z / y); elseif (y <= 3.6e-33) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.00092], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e-33], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00092:\\
\;\;\;\;1 + \frac{z}{y}\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-33}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9.2000000000000003e-4Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 76.6%
Taylor expanded in y around inf 66.6%
if -9.2000000000000003e-4 < y < 3.60000000000000034e-33Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around 0 72.6%
if 3.60000000000000034e-33 < y Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around inf 61.6%
Final simplification68.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%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in y around inf 38.6%
Final simplification38.6%
(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 2023230
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:herbie-target
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))