
(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
(if (or (<= x -1.3e+68)
(and (not (<= x -1.53e+41)) (or (<= x -9.6e-45) (not (<= x 0.01)))))
(/ x (- z y))
(/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e+68) || (!(x <= -1.53e+41) && ((x <= -9.6e-45) || !(x <= 0.01)))) {
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.3d+68)) .or. (.not. (x <= (-1.53d+41))) .and. (x <= (-9.6d-45)) .or. (.not. (x <= 0.01d0))) 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.3e+68) || (!(x <= -1.53e+41) && ((x <= -9.6e-45) || !(x <= 0.01)))) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e+68) or (not (x <= -1.53e+41) and ((x <= -9.6e-45) or not (x <= 0.01))): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e+68) || (!(x <= -1.53e+41) && ((x <= -9.6e-45) || !(x <= 0.01)))) 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.3e+68) || (~((x <= -1.53e+41)) && ((x <= -9.6e-45) || ~((x <= 0.01))))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e+68], And[N[Not[LessEqual[x, -1.53e+41]], $MachinePrecision], Or[LessEqual[x, -9.6e-45], N[Not[LessEqual[x, 0.01]], $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.3 \cdot 10^{+68} \lor \neg \left(x \leq -1.53 \cdot 10^{+41}\right) \land \left(x \leq -9.6 \cdot 10^{-45} \lor \neg \left(x \leq 0.01\right)\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -1.2999999999999999e68 or -1.52999999999999997e41 < x < -9.5999999999999996e-45 or 0.0100000000000000002 < x Initial program 100.0%
Taylor expanded in x around inf 81.4%
if -1.2999999999999999e68 < x < -1.52999999999999997e41 or -9.5999999999999996e-45 < x < 0.0100000000000000002Initial program 100.0%
clear-num99.3%
associate-/r/99.6%
Applied egg-rr99.6%
associate-*l/100.0%
*-un-lft-identity100.0%
clear-num99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 85.6%
mul-1-neg85.6%
distribute-neg-frac285.6%
neg-sub085.6%
associate-+l-85.6%
neg-sub085.6%
+-commutative85.6%
unsub-neg85.6%
Simplified85.6%
Final simplification83.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -4.1e-11)
t_0
(if (<= y 1.1e-130)
(/ x z)
(if (or (<= y 2.6e+18) (not (<= y 8.8e+61))) t_0 (/ y (- z)))))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -4.1e-11) {
tmp = t_0;
} else if (y <= 1.1e-130) {
tmp = x / z;
} else if ((y <= 2.6e+18) || !(y <= 8.8e+61)) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (y <= (-4.1d-11)) then
tmp = t_0
else if (y <= 1.1d-130) then
tmp = x / z
else if ((y <= 2.6d+18) .or. (.not. (y <= 8.8d+61))) then
tmp = t_0
else
tmp = y / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -4.1e-11) {
tmp = t_0;
} else if (y <= 1.1e-130) {
tmp = x / z;
} else if ((y <= 2.6e+18) || !(y <= 8.8e+61)) {
tmp = t_0;
} else {
tmp = y / -z;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -4.1e-11: tmp = t_0 elif y <= 1.1e-130: tmp = x / z elif (y <= 2.6e+18) or not (y <= 8.8e+61): tmp = t_0 else: tmp = y / -z return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -4.1e-11) tmp = t_0; elseif (y <= 1.1e-130) tmp = Float64(x / z); elseif ((y <= 2.6e+18) || !(y <= 8.8e+61)) tmp = t_0; else tmp = Float64(y / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -4.1e-11) tmp = t_0; elseif (y <= 1.1e-130) tmp = x / z; elseif ((y <= 2.6e+18) || ~((y <= 8.8e+61))) tmp = t_0; else tmp = y / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.1e-11], t$95$0, If[LessEqual[y, 1.1e-130], N[(x / z), $MachinePrecision], If[Or[LessEqual[y, 2.6e+18], N[Not[LessEqual[y, 8.8e+61]], $MachinePrecision]], t$95$0, N[(y / (-z)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-130}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+18} \lor \neg \left(y \leq 8.8 \cdot 10^{+61}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{-z}\\
\end{array}
\end{array}
if y < -4.1000000000000001e-11 or 1.0999999999999999e-130 < y < 2.6e18 or 8.8000000000000001e61 < y Initial program 100.0%
Taylor expanded in z around 0 73.0%
div-sub73.0%
sub-neg73.0%
*-inverses73.0%
metadata-eval73.0%
distribute-lft-in73.0%
metadata-eval73.0%
+-commutative73.0%
mul-1-neg73.0%
unsub-neg73.0%
Simplified73.0%
if -4.1000000000000001e-11 < y < 1.0999999999999999e-130Initial program 100.0%
Taylor expanded in y around 0 73.4%
if 2.6e18 < y < 8.8000000000000001e61Initial program 100.0%
Taylor expanded in z around inf 85.9%
Taylor expanded in x around 0 71.8%
neg-mul-171.8%
distribute-neg-frac271.8%
Simplified71.8%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.3e+113) 1.0 (if (<= y -1.6e-13) (/ x (- y)) (if (<= y 2e-10) (/ x z) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e+113) {
tmp = 1.0;
} else if (y <= -1.6e-13) {
tmp = x / -y;
} else if (y <= 2e-10) {
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 <= (-2.3d+113)) then
tmp = 1.0d0
else if (y <= (-1.6d-13)) then
tmp = x / -y
else if (y <= 2d-10) 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 <= -2.3e+113) {
tmp = 1.0;
} else if (y <= -1.6e-13) {
tmp = x / -y;
} else if (y <= 2e-10) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.3e+113: tmp = 1.0 elif y <= -1.6e-13: tmp = x / -y elif y <= 2e-10: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.3e+113) tmp = 1.0; elseif (y <= -1.6e-13) tmp = Float64(x / Float64(-y)); elseif (y <= 2e-10) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.3e+113) tmp = 1.0; elseif (y <= -1.6e-13) tmp = x / -y; elseif (y <= 2e-10) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.3e+113], 1.0, If[LessEqual[y, -1.6e-13], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, 2e-10], N[(x / z), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+113}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.29999999999999997e113 or 2.00000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 61.7%
if -2.29999999999999997e113 < y < -1.6e-13Initial program 99.9%
Taylor expanded in x around inf 53.4%
Taylor expanded in z around 0 45.7%
associate-*r/45.7%
neg-mul-145.7%
Simplified45.7%
if -1.6e-13 < y < 2.00000000000000007e-10Initial program 100.0%
Taylor expanded in y around 0 67.2%
Final simplification62.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.3e-6) (not (<= y 6.2e-9))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-6) || !(y <= 6.2e-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.3d-6)) .or. (.not. (y <= 6.2d-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.3e-6) || !(y <= 6.2e-9)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.3e-6) or not (y <= 6.2e-9): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.3e-6) || !(y <= 6.2e-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.3e-6) || ~((y <= 6.2e-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.3e-6], N[Not[LessEqual[y, 6.2e-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.3 \cdot 10^{-6} \lor \neg \left(y \leq 6.2 \cdot 10^{-9}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.3000000000000001e-6 or 6.2000000000000001e-9 < y Initial program 100.0%
Taylor expanded in z around 0 72.9%
div-sub72.9%
sub-neg72.9%
*-inverses72.9%
metadata-eval72.9%
distribute-lft-in72.9%
metadata-eval72.9%
+-commutative72.9%
mul-1-neg72.9%
unsub-neg72.9%
Simplified72.9%
if -5.3000000000000001e-6 < y < 6.2000000000000001e-9Initial program 100.0%
Taylor expanded in x around inf 82.1%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= y -3.6e-6) 1.0 (if (<= y 1.3e-9) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e-6) {
tmp = 1.0;
} else if (y <= 1.3e-9) {
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 <= (-3.6d-6)) then
tmp = 1.0d0
else if (y <= 1.3d-9) 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 <= -3.6e-6) {
tmp = 1.0;
} else if (y <= 1.3e-9) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.6e-6: tmp = 1.0 elif y <= 1.3e-9: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.6e-6) tmp = 1.0; elseif (y <= 1.3e-9) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.6e-6) tmp = 1.0; elseif (y <= 1.3e-9) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.6e-6], 1.0, If[LessEqual[y, 1.3e-9], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-6}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-9}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.59999999999999984e-6 or 1.3000000000000001e-9 < y Initial program 100.0%
Taylor expanded in y around inf 54.9%
if -3.59999999999999984e-6 < y < 1.3000000000000001e-9Initial program 100.0%
Taylor expanded in y around 0 66.3%
(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 31.9%
(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 2024091
(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)))