
(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 (/ (- x y) z)))
(if (<= z -7.2e+96)
t_0
(if (<= z -1.45e-44)
(/ y (- y z))
(if (<= z -6.8e-140)
(/ x (- z y))
(if (<= z 1.35e+17) (/ (- y x) y) t_0))))))
double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (z <= -7.2e+96) {
tmp = t_0;
} else if (z <= -1.45e-44) {
tmp = y / (y - z);
} else if (z <= -6.8e-140) {
tmp = x / (z - y);
} else if (z <= 1.35e+17) {
tmp = (y - x) / 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 = (x - y) / z
if (z <= (-7.2d+96)) then
tmp = t_0
else if (z <= (-1.45d-44)) then
tmp = y / (y - z)
else if (z <= (-6.8d-140)) then
tmp = x / (z - y)
else if (z <= 1.35d+17) then
tmp = (y - x) / y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (z <= -7.2e+96) {
tmp = t_0;
} else if (z <= -1.45e-44) {
tmp = y / (y - z);
} else if (z <= -6.8e-140) {
tmp = x / (z - y);
} else if (z <= 1.35e+17) {
tmp = (y - x) / y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / z tmp = 0 if z <= -7.2e+96: tmp = t_0 elif z <= -1.45e-44: tmp = y / (y - z) elif z <= -6.8e-140: tmp = x / (z - y) elif z <= 1.35e+17: tmp = (y - x) / y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / z) tmp = 0.0 if (z <= -7.2e+96) tmp = t_0; elseif (z <= -1.45e-44) tmp = Float64(y / Float64(y - z)); elseif (z <= -6.8e-140) tmp = Float64(x / Float64(z - y)); elseif (z <= 1.35e+17) tmp = Float64(Float64(y - x) / y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / z; tmp = 0.0; if (z <= -7.2e+96) tmp = t_0; elseif (z <= -1.45e-44) tmp = y / (y - z); elseif (z <= -6.8e-140) tmp = x / (z - y); elseif (z <= 1.35e+17) tmp = (y - x) / y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[z, -7.2e+96], t$95$0, If[LessEqual[z, -1.45e-44], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -6.8e-140], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.35e+17], N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{z}\\
\mathbf{if}\;z \leq -7.2 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.45 \cdot 10^{-44}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;z \leq -6.8 \cdot 10^{-140}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+17}:\\
\;\;\;\;\frac{y - x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.20000000000000026e96 or 1.35e17 < z Initial program 100.0%
Taylor expanded in z around inf 89.6%
if -7.20000000000000026e96 < z < -1.4500000000000001e-44Initial program 100.0%
Taylor expanded in x around 0 73.2%
neg-mul-173.2%
distribute-neg-frac273.2%
sub-neg73.2%
+-commutative73.2%
distribute-neg-in73.2%
remove-double-neg73.2%
sub-neg73.2%
Simplified73.2%
if -1.4500000000000001e-44 < z < -6.80000000000000017e-140Initial program 99.9%
Taylor expanded in x around inf 74.9%
if -6.80000000000000017e-140 < z < 1.35e17Initial program 100.0%
Taylor expanded in z around 0 84.0%
associate-*r/84.0%
neg-mul-184.0%
sub-neg84.0%
+-commutative84.0%
distribute-neg-in84.0%
remove-double-neg84.0%
sub-neg84.0%
Simplified84.0%
(FPCore (x y z) :precision binary64 (if (<= y -6.9e+15) 1.0 (if (<= y 1.4e-98) (/ x z) (if (<= y 3.7e-28) (/ (- x) y) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.9e+15) {
tmp = 1.0;
} else if (y <= 1.4e-98) {
tmp = x / z;
} else if (y <= 3.7e-28) {
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 <= (-6.9d+15)) then
tmp = 1.0d0
else if (y <= 1.4d-98) then
tmp = x / z
else if (y <= 3.7d-28) 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 <= -6.9e+15) {
tmp = 1.0;
} else if (y <= 1.4e-98) {
tmp = x / z;
} else if (y <= 3.7e-28) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.9e+15: tmp = 1.0 elif y <= 1.4e-98: tmp = x / z elif y <= 3.7e-28: tmp = -x / y else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.9e+15) tmp = 1.0; elseif (y <= 1.4e-98) tmp = Float64(x / z); elseif (y <= 3.7e-28) tmp = Float64(Float64(-x) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.9e+15) tmp = 1.0; elseif (y <= 1.4e-98) tmp = x / z; elseif (y <= 3.7e-28) tmp = -x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.9e+15], 1.0, If[LessEqual[y, 1.4e-98], N[(x / z), $MachinePrecision], If[LessEqual[y, 3.7e-28], N[((-x) / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.9 \cdot 10^{+15}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-98}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-28}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.9e15 or 3.7000000000000002e-28 < y Initial program 100.0%
Taylor expanded in y around inf 59.3%
if -6.9e15 < y < 1.3999999999999999e-98Initial program 100.0%
Taylor expanded in y around 0 68.3%
if 1.3999999999999999e-98 < y < 3.7000000000000002e-28Initial program 99.9%
Taylor expanded in x around inf 66.2%
Taylor expanded in z around 0 48.1%
mul-1-neg48.1%
distribute-frac-neg48.1%
Simplified48.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.6e-34) (not (<= y 1.08e-27))) (/ y (- y z)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.6e-34) || !(y <= 1.08e-27)) {
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.6d-34)) .or. (.not. (y <= 1.08d-27))) 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.6e-34) || !(y <= 1.08e-27)) {
tmp = y / (y - z);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.6e-34) or not (y <= 1.08e-27): tmp = y / (y - z) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.6e-34) || !(y <= 1.08e-27)) 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.6e-34) || ~((y <= 1.08e-27))) tmp = y / (y - z); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.6e-34], N[Not[LessEqual[y, 1.08e-27]], $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.6 \cdot 10^{-34} \lor \neg \left(y \leq 1.08 \cdot 10^{-27}\right):\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.59999999999999994e-34 or 1.08e-27 < y Initial program 99.9%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
distribute-neg-frac276.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-in76.8%
remove-double-neg76.8%
sub-neg76.8%
Simplified76.8%
if -5.59999999999999994e-34 < y < 1.08e-27Initial program 100.0%
Taylor expanded in x around inf 83.1%
Final simplification80.0%
(FPCore (x y z) :precision binary64 (if (<= y -5.9e+110) 1.0 (if (<= y 1.2e-27) (/ x (- z y)) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.9e+110) {
tmp = 1.0;
} else if (y <= 1.2e-27) {
tmp = x / (z - 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 <= (-5.9d+110)) then
tmp = 1.0d0
else if (y <= 1.2d-27) then
tmp = x / (z - 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 <= -5.9e+110) {
tmp = 1.0;
} else if (y <= 1.2e-27) {
tmp = x / (z - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.9e+110: tmp = 1.0 elif y <= 1.2e-27: tmp = x / (z - y) else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.9e+110) tmp = 1.0; elseif (y <= 1.2e-27) tmp = Float64(x / Float64(z - y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.9e+110) tmp = 1.0; elseif (y <= 1.2e-27) tmp = x / (z - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.9e+110], 1.0, If[LessEqual[y, 1.2e-27], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.9 \cdot 10^{+110}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-27}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.8999999999999997e110 or 1.20000000000000001e-27 < y Initial program 100.0%
Taylor expanded in y around inf 64.6%
if -5.8999999999999997e110 < y < 1.20000000000000001e-27Initial program 100.0%
Taylor expanded in x around inf 75.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e+15) 1.0 (if (<= y 1.15e-27) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e+15) {
tmp = 1.0;
} else if (y <= 1.15e-27) {
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.7d+15)) then
tmp = 1.0d0
else if (y <= 1.15d-27) 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.7e+15) {
tmp = 1.0;
} else if (y <= 1.15e-27) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e+15: tmp = 1.0 elif y <= 1.15e-27: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e+15) tmp = 1.0; elseif (y <= 1.15e-27) 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.7e+15) tmp = 1.0; elseif (y <= 1.15e-27) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e+15], 1.0, If[LessEqual[y, 1.15e-27], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+15}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-27}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.7e15 or 1.15e-27 < y Initial program 100.0%
Taylor expanded in y around inf 59.8%
if -1.7e15 < y < 1.15e-27Initial program 100.0%
Taylor expanded in y around 0 60.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 32.0%
(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 2024163
(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)))