
(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 8 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 (<= y -1.4e-49)
1.0
(if (<= y 3.5e-109)
(/ x z)
(if (<= y 5.6e-71) (/ (- x) y) (if (<= y 1.06e-20) (/ x z) 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-49) {
tmp = 1.0;
} else if (y <= 3.5e-109) {
tmp = x / z;
} else if (y <= 5.6e-71) {
tmp = -x / y;
} else if (y <= 1.06e-20) {
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.4d-49)) then
tmp = 1.0d0
else if (y <= 3.5d-109) then
tmp = x / z
else if (y <= 5.6d-71) then
tmp = -x / y
else if (y <= 1.06d-20) 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.4e-49) {
tmp = 1.0;
} else if (y <= 3.5e-109) {
tmp = x / z;
} else if (y <= 5.6e-71) {
tmp = -x / y;
} else if (y <= 1.06e-20) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-49: tmp = 1.0 elif y <= 3.5e-109: tmp = x / z elif y <= 5.6e-71: tmp = -x / y elif y <= 1.06e-20: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-49) tmp = 1.0; elseif (y <= 3.5e-109) tmp = Float64(x / z); elseif (y <= 5.6e-71) tmp = Float64(Float64(-x) / y); elseif (y <= 1.06e-20) 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.4e-49) tmp = 1.0; elseif (y <= 3.5e-109) tmp = x / z; elseif (y <= 5.6e-71) tmp = -x / y; elseif (y <= 1.06e-20) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-49], 1.0, If[LessEqual[y, 3.5e-109], N[(x / z), $MachinePrecision], If[LessEqual[y, 5.6e-71], N[((-x) / y), $MachinePrecision], If[LessEqual[y, 1.06e-20], N[(x / z), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-49}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-71}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{-20}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.39999999999999999e-49 or 1.06e-20 < y Initial program 100.0%
Taylor expanded in y around inf 65.9%
if -1.39999999999999999e-49 < y < 3.5e-109 or 5.60000000000000001e-71 < y < 1.06e-20Initial program 100.0%
Taylor expanded in y around 0 73.4%
if 3.5e-109 < y < 5.60000000000000001e-71Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 78.3%
associate-*r/78.3%
neg-mul-178.3%
Simplified78.3%
Final simplification69.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (- y z))))
(if (<= y -2.05e-48)
t_0
(if (<= y 6.4e-127) (/ (- x y) z) (if (<= y 2100.0) (/ x (- z y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -2.05e-48) {
tmp = t_0;
} else if (y <= 6.4e-127) {
tmp = (x - y) / z;
} else if (y <= 2100.0) {
tmp = x / (z - y);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = y / (y - z)
if (y <= (-2.05d-48)) then
tmp = t_0
else if (y <= 6.4d-127) then
tmp = (x - y) / z
else if (y <= 2100.0d0) then
tmp = x / (z - y)
else
tmp = t_0
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 <= -2.05e-48) {
tmp = t_0;
} else if (y <= 6.4e-127) {
tmp = (x - y) / z;
} else if (y <= 2100.0) {
tmp = x / (z - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) tmp = 0 if y <= -2.05e-48: tmp = t_0 elif y <= 6.4e-127: tmp = (x - y) / z elif y <= 2100.0: tmp = x / (z - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) tmp = 0.0 if (y <= -2.05e-48) tmp = t_0; elseif (y <= 6.4e-127) tmp = Float64(Float64(x - y) / z); elseif (y <= 2100.0) tmp = Float64(x / Float64(z - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); tmp = 0.0; if (y <= -2.05e-48) tmp = t_0; elseif (y <= 6.4e-127) tmp = (x - y) / z; elseif (y <= 2100.0) tmp = x / (z - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.05e-48], t$95$0, If[LessEqual[y, 6.4e-127], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 2100.0], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
\mathbf{if}\;y \leq -2.05 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{-127}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;y \leq 2100:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.05000000000000007e-48 or 2100 < y Initial program 100.0%
Taylor expanded in x around 0 81.1%
neg-mul-181.1%
distribute-neg-frac81.1%
Simplified81.1%
frac-2neg81.1%
div-inv81.0%
remove-double-neg81.0%
sub-neg81.0%
distribute-neg-in81.0%
remove-double-neg81.0%
Applied egg-rr81.0%
associate-*r/81.1%
*-rgt-identity81.1%
+-commutative81.1%
unsub-neg81.1%
Simplified81.1%
if -2.05000000000000007e-48 < y < 6.40000000000000035e-127Initial program 100.0%
Taylor expanded in z around inf 90.3%
if 6.40000000000000035e-127 < y < 2100Initial program 100.0%
Taylor expanded in x around inf 79.9%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e-51) (not (<= y 1.2e-109))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-51) || !(y <= 1.2e-109)) {
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 <= (-4.4d-51)) .or. (.not. (y <= 1.2d-109))) 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 <= -4.4e-51) || !(y <= 1.2e-109)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e-51) or not (y <= 1.2e-109): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e-51) || !(y <= 1.2e-109)) 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 <= -4.4e-51) || ~((y <= 1.2e-109))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e-51], N[Not[LessEqual[y, 1.2e-109]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-51} \lor \neg \left(y \leq 1.2 \cdot 10^{-109}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -4.4e-51 or 1.19999999999999994e-109 < y Initial program 100.0%
Taylor expanded in z around 0 74.1%
div-sub74.1%
sub-neg74.1%
*-inverses74.1%
metadata-eval74.1%
distribute-lft-in74.1%
metadata-eval74.1%
+-commutative74.1%
mul-1-neg74.1%
unsub-neg74.1%
Simplified74.1%
if -4.4e-51 < y < 1.19999999999999994e-109Initial program 100.0%
Taylor expanded in y around 0 76.0%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.15e-47) (not (<= y 2.3e-23))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.15e-47) || !(y <= 2.3e-23)) {
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 <= (-4.15d-47)) .or. (.not. (y <= 2.3d-23))) 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 <= -4.15e-47) || !(y <= 2.3e-23)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.15e-47) or not (y <= 2.3e-23): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.15e-47) || !(y <= 2.3e-23)) 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 <= -4.15e-47) || ~((y <= 2.3e-23))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.15e-47], N[Not[LessEqual[y, 2.3e-23]], $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 -4.15 \cdot 10^{-47} \lor \neg \left(y \leq 2.3 \cdot 10^{-23}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -4.1499999999999998e-47 or 2.3000000000000001e-23 < y Initial program 100.0%
Taylor expanded in z around 0 77.8%
div-sub77.8%
sub-neg77.8%
*-inverses77.8%
metadata-eval77.8%
distribute-lft-in77.8%
metadata-eval77.8%
+-commutative77.8%
mul-1-neg77.8%
unsub-neg77.8%
Simplified77.8%
if -4.1499999999999998e-47 < y < 2.3000000000000001e-23Initial program 100.0%
Taylor expanded in x around inf 83.1%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-33) (not (<= y 2400.0))) (/ y (- y z)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-33) || !(y <= 2400.0)) {
tmp = y / (y - z);
} 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.2d-33)) .or. (.not. (y <= 2400.0d0))) then
tmp = y / (y - z)
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.2e-33) || !(y <= 2400.0)) {
tmp = y / (y - z);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-33) or not (y <= 2400.0): tmp = y / (y - z) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-33) || !(y <= 2400.0)) tmp = Float64(y / Float64(y - z)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.2e-33) || ~((y <= 2400.0))) tmp = y / (y - z); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-33], N[Not[LessEqual[y, 2400.0]], $MachinePrecision]], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-33} \lor \neg \left(y \leq 2400\right):\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.19999999999999988e-33 or 2400 < y Initial program 100.0%
Taylor expanded in x around 0 82.1%
neg-mul-182.1%
distribute-neg-frac82.1%
Simplified82.1%
frac-2neg82.1%
div-inv81.9%
remove-double-neg81.9%
sub-neg81.9%
distribute-neg-in81.9%
remove-double-neg81.9%
Applied egg-rr81.9%
associate-*r/82.1%
*-rgt-identity82.1%
+-commutative82.1%
unsub-neg82.1%
Simplified82.1%
if -5.19999999999999988e-33 < y < 2400Initial program 100.0%
Taylor expanded in x around inf 81.1%
Final simplification81.6%
(FPCore (x y z) :precision binary64 (if (<= y -6.3e-47) 1.0 (if (<= y 6.4e-22) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.3e-47) {
tmp = 1.0;
} else if (y <= 6.4e-22) {
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 <= (-6.3d-47)) then
tmp = 1.0d0
else if (y <= 6.4d-22) 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 <= -6.3e-47) {
tmp = 1.0;
} else if (y <= 6.4e-22) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.3e-47: tmp = 1.0 elif y <= 6.4e-22: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.3e-47) tmp = 1.0; elseif (y <= 6.4e-22) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.3e-47) tmp = 1.0; elseif (y <= 6.4e-22) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.3e-47], 1.0, If[LessEqual[y, 6.4e-22], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.3 \cdot 10^{-47}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{-22}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.3000000000000002e-47 or 6.39999999999999975e-22 < y Initial program 100.0%
Taylor expanded in y around inf 65.9%
if -6.3000000000000002e-47 < y < 6.39999999999999975e-22Initial program 100.0%
Taylor expanded in y around 0 69.3%
Final simplification67.4%
(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 38.8%
Final simplification38.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 2024095
(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)))