
(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 (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
return (x / (z - y)) + (y / (y - z));
}
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 / (y - z))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) + (y / (y - z));
}
def code(x, y, z): return (x / (z - y)) + (y / (y - z))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) + Float64(y / Float64(y - z))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) + (y / (y - z)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] + N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} + \frac{y}{y - z}
\end{array}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e-21) 1.0 (if (<= y 9.5e-71) (/ x z) (if (<= y 75000000000000.0) (/ y (- z)) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-21) {
tmp = 1.0;
} else if (y <= 9.5e-71) {
tmp = x / z;
} else if (y <= 75000000000000.0) {
tmp = y / -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.65d-21)) then
tmp = 1.0d0
else if (y <= 9.5d-71) then
tmp = x / z
else if (y <= 75000000000000.0d0) then
tmp = y / -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.65e-21) {
tmp = 1.0;
} else if (y <= 9.5e-71) {
tmp = x / z;
} else if (y <= 75000000000000.0) {
tmp = y / -z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-21: tmp = 1.0 elif y <= 9.5e-71: tmp = x / z elif y <= 75000000000000.0: tmp = y / -z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-21) tmp = 1.0; elseif (y <= 9.5e-71) tmp = Float64(x / z); elseif (y <= 75000000000000.0) tmp = Float64(y / Float64(-z)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e-21) tmp = 1.0; elseif (y <= 9.5e-71) tmp = x / z; elseif (y <= 75000000000000.0) tmp = y / -z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-21], 1.0, If[LessEqual[y, 9.5e-71], N[(x / z), $MachinePrecision], If[LessEqual[y, 75000000000000.0], N[(y / (-z)), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-21}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-71}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 75000000000000:\\
\;\;\;\;\frac{y}{-z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.65000000000000004e-21 or 7.5e13 < y Initial program 100.0%
Taylor expanded in y around inf 63.3%
if -1.65000000000000004e-21 < y < 9.4999999999999994e-71Initial program 100.0%
Taylor expanded in y around 0 74.8%
if 9.4999999999999994e-71 < y < 7.5e13Initial program 99.9%
Taylor expanded in x around 0 56.7%
neg-mul-156.7%
distribute-neg-frac256.7%
sub-neg56.7%
+-commutative56.7%
distribute-neg-in56.7%
remove-double-neg56.7%
sub-neg56.7%
Simplified56.7%
Taylor expanded in y around 0 52.2%
associate-*r/52.2%
neg-mul-152.2%
Simplified52.2%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e-21) 1.0 (if (<= y 1.7e-49) (/ x z) (if (<= y 5.6e+36) (/ x (- y)) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-21) {
tmp = 1.0;
} else if (y <= 1.7e-49) {
tmp = x / z;
} else if (y <= 5.6e+36) {
tmp = x / -y;
} 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.4d-21)) then
tmp = 1.0d0
else if (y <= 1.7d-49) then
tmp = x / z
else if (y <= 5.6d+36) then
tmp = x / -y
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.4e-21) {
tmp = 1.0;
} else if (y <= 1.7e-49) {
tmp = x / z;
} else if (y <= 5.6e+36) {
tmp = x / -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-21: tmp = 1.0 elif y <= 1.7e-49: tmp = x / z elif y <= 5.6e+36: tmp = x / -y else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-21) tmp = 1.0; elseif (y <= 1.7e-49) tmp = Float64(x / z); elseif (y <= 5.6e+36) tmp = Float64(x / Float64(-y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-21) tmp = 1.0; elseif (y <= 1.7e-49) tmp = x / z; elseif (y <= 5.6e+36) tmp = x / -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-21], 1.0, If[LessEqual[y, 1.7e-49], N[(x / z), $MachinePrecision], If[LessEqual[y, 5.6e+36], N[(x / (-y)), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-21}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-49}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{+36}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.40000000000000002e-21 or 5.6000000000000001e36 < y Initial program 100.0%
Taylor expanded in y around inf 66.3%
if -1.40000000000000002e-21 < y < 1.70000000000000002e-49Initial program 100.0%
Taylor expanded in y around 0 72.1%
if 1.70000000000000002e-49 < y < 5.6000000000000001e36Initial program 100.0%
Taylor expanded in x around inf 61.8%
Taylor expanded in z around 0 46.6%
mul-1-neg46.6%
distribute-frac-neg246.6%
Simplified46.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-26) (not (<= y 4e+32))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-26) || !(y <= 4e+32)) {
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 <= (-5d-26)) .or. (.not. (y <= 4d+32))) 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 <= -5e-26) || !(y <= 4e+32)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-26) or not (y <= 4e+32): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-26) || !(y <= 4e+32)) 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 <= -5e-26) || ~((y <= 4e+32))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-26], N[Not[LessEqual[y, 4e+32]], $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 \cdot 10^{-26} \lor \neg \left(y \leq 4 \cdot 10^{+32}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.00000000000000019e-26 or 4.00000000000000021e32 < y Initial program 100.0%
Taylor expanded in z around 0 81.5%
associate-*r/81.5%
neg-mul-181.5%
sub-neg81.5%
+-commutative81.5%
distribute-neg-in81.5%
remove-double-neg81.5%
sub-neg81.5%
div-sub81.6%
*-inverses81.6%
Simplified81.6%
if -5.00000000000000019e-26 < y < 4.00000000000000021e32Initial program 100.0%
Taylor expanded in x around inf 79.1%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-126) (not (<= y 1.85e-49))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-126) || !(y <= 1.85e-49)) {
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-126)) .or. (.not. (y <= 1.85d-49))) 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-126) || !(y <= 1.85e-49)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-126) or not (y <= 1.85e-49): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-126) || !(y <= 1.85e-49)) 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-126) || ~((y <= 1.85e-49))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-126], N[Not[LessEqual[y, 1.85e-49]], $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^{-126} \lor \neg \left(y \leq 1.85 \cdot 10^{-49}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.50000000000000003e-126 or 1.85e-49 < y Initial program 100.0%
Taylor expanded in z around 0 73.2%
associate-*r/73.2%
neg-mul-173.2%
sub-neg73.2%
+-commutative73.2%
distribute-neg-in73.2%
remove-double-neg73.2%
sub-neg73.2%
div-sub73.2%
*-inverses73.2%
Simplified73.2%
if -2.50000000000000003e-126 < y < 1.85e-49Initial program 100.0%
Taylor expanded in y around 0 80.4%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (<= y -2.15e-101) (/ y (- y z)) (if (<= y 4e+32) (/ x (- z y)) (- 1.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.15e-101) {
tmp = y / (y - z);
} else if (y <= 4e+32) {
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 <= (-2.15d-101)) then
tmp = y / (y - z)
else if (y <= 4d+32) 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 <= -2.15e-101) {
tmp = y / (y - z);
} else if (y <= 4e+32) {
tmp = x / (z - y);
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.15e-101: tmp = y / (y - z) elif y <= 4e+32: tmp = x / (z - y) else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.15e-101) tmp = Float64(y / Float64(y - z)); elseif (y <= 4e+32) 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 <= -2.15e-101) tmp = y / (y - z); elseif (y <= 4e+32) tmp = x / (z - y); else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.15e-101], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e+32], 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 -2.15 \cdot 10^{-101}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+32}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if y < -2.1499999999999999e-101Initial program 100.0%
Taylor expanded in x around 0 74.0%
neg-mul-174.0%
distribute-neg-frac274.0%
sub-neg74.0%
+-commutative74.0%
distribute-neg-in74.0%
remove-double-neg74.0%
sub-neg74.0%
Simplified74.0%
if -2.1499999999999999e-101 < y < 4.00000000000000021e32Initial program 100.0%
Taylor expanded in x around inf 85.6%
if 4.00000000000000021e32 < y Initial program 99.9%
Taylor expanded in z around 0 85.7%
associate-*r/85.7%
neg-mul-185.7%
sub-neg85.7%
+-commutative85.7%
distribute-neg-in85.7%
remove-double-neg85.7%
sub-neg85.7%
div-sub85.7%
*-inverses85.7%
Simplified85.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e-25) 1.0 (if (<= y 5.2e+34) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-25) {
tmp = 1.0;
} else if (y <= 5.2e+34) {
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.85d-25)) then
tmp = 1.0d0
else if (y <= 5.2d+34) 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.85e-25) {
tmp = 1.0;
} else if (y <= 5.2e+34) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e-25: tmp = 1.0 elif y <= 5.2e+34: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e-25) tmp = 1.0; elseif (y <= 5.2e+34) 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.85e-25) tmp = 1.0; elseif (y <= 5.2e+34) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e-25], 1.0, If[LessEqual[y, 5.2e+34], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-25}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+34}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.85000000000000004e-25 or 5.19999999999999995e34 < y Initial program 100.0%
Taylor expanded in y around inf 66.3%
if -1.85000000000000004e-25 < y < 5.19999999999999995e34Initial program 100.0%
Taylor expanded in y around 0 64.1%
(FPCore (x y z) :precision binary64 (/ (- y x) (- y z)))
double code(double x, double y, double z) {
return (y - x) / (y - z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y - x) / (y - z)
end function
public static double code(double x, double y, double z) {
return (y - x) / (y - z);
}
def code(x, y, z): return (y - x) / (y - z)
function code(x, y, z) return Float64(Float64(y - x) / Float64(y - z)) end
function tmp = code(x, y, z) tmp = (y - x) / (y - z); end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y - x}{y - z}
\end{array}
Initial program 100.0%
Final simplification100.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%
Taylor expanded in y around inf 36.8%
(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 2024170
(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)))