
(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 6 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 (<= y -9e-9) (- 1.0 (/ x y)) (if (<= y 4.9e+53) (/ (- x y) z) (/ y (- y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-9) {
tmp = 1.0 - (x / y);
} else if (y <= 4.9e+53) {
tmp = (x - y) / z;
} 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 (y <= (-9d-9)) then
tmp = 1.0d0 - (x / y)
else if (y <= 4.9d+53) then
tmp = (x - y) / z
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9e-9) {
tmp = 1.0 - (x / y);
} else if (y <= 4.9e+53) {
tmp = (x - y) / z;
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e-9: tmp = 1.0 - (x / y) elif y <= 4.9e+53: tmp = (x - y) / z else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e-9) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 4.9e+53) tmp = Float64(Float64(x - y) / z); else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9e-9) tmp = 1.0 - (x / y); elseif (y <= 4.9e+53) tmp = (x - y) / z; else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e-9], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.9e+53], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-9}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+53}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -8.99999999999999953e-9Initial program 99.9%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6481.3%
Simplified81.3%
if -8.99999999999999953e-9 < y < 4.90000000000000018e53Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in z around inf
associate-*r/N/A
/-lowering-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f6481.0%
Simplified81.0%
if 4.90000000000000018e53 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
--lowering--.f6481.0%
Simplified81.0%
(FPCore (x y z) :precision binary64 (if (<= y -9.6e-12) (- 1.0 (/ x y)) (if (<= y 3.65e+22) (/ x z) (/ y (- y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.6e-12) {
tmp = 1.0 - (x / y);
} else if (y <= 3.65e+22) {
tmp = x / z;
} 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 (y <= (-9.6d-12)) then
tmp = 1.0d0 - (x / y)
else if (y <= 3.65d+22) then
tmp = x / z
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.6e-12) {
tmp = 1.0 - (x / y);
} else if (y <= 3.65e+22) {
tmp = x / z;
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.6e-12: tmp = 1.0 - (x / y) elif y <= 3.65e+22: tmp = x / z else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.6e-12) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 3.65e+22) tmp = Float64(x / z); else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.6e-12) tmp = 1.0 - (x / y); elseif (y <= 3.65e+22) tmp = x / z; else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.6e-12], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.65e+22], N[(x / z), $MachinePrecision], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.6 \cdot 10^{-12}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 3.65 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if y < -9.59999999999999948e-12Initial program 99.9%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6481.3%
Simplified81.3%
if -9.59999999999999948e-12 < y < 3.6499999999999999e22Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6466.5%
Simplified66.5%
if 3.6499999999999999e22 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
--lowering--.f6477.8%
Simplified77.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (/ x y)))) (if (<= y -9.5e-12) t_0 (if (<= y 1.05e+34) (/ x z) t_0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -9.5e-12) {
tmp = t_0;
} else if (y <= 1.05e+34) {
tmp = x / z;
} 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 = 1.0d0 - (x / y)
if (y <= (-9.5d-12)) then
tmp = t_0
else if (y <= 1.05d+34) then
tmp = x / z
else
tmp = t_0
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 <= -9.5e-12) {
tmp = t_0;
} else if (y <= 1.05e+34) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -9.5e-12: tmp = t_0 elif y <= 1.05e+34: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -9.5e-12) tmp = t_0; elseif (y <= 1.05e+34) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -9.5e-12) tmp = t_0; elseif (y <= 1.05e+34) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.5e-12], t$95$0, If[LessEqual[y, 1.05e+34], N[(x / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+34}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.4999999999999995e-12 or 1.05000000000000009e34 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in z around 0
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6479.0%
Simplified79.0%
if -9.4999999999999995e-12 < y < 1.05000000000000009e34Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6465.8%
Simplified65.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.55e-10) 1.0 (if (<= y 5.5e+53) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e-10) {
tmp = 1.0;
} else if (y <= 5.5e+53) {
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.55d-10)) then
tmp = 1.0d0
else if (y <= 5.5d+53) 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.55e-10) {
tmp = 1.0;
} else if (y <= 5.5e+53) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e-10: tmp = 1.0 elif y <= 5.5e+53: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e-10) tmp = 1.0; elseif (y <= 5.5e+53) 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.55e-10) tmp = 1.0; elseif (y <= 5.5e+53) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e-10], 1.0, If[LessEqual[y, 5.5e+53], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-10}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+53}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.55000000000000008e-10 or 5.49999999999999975e53 < y Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
Simplified67.0%
if -1.55000000000000008e-10 < y < 5.49999999999999975e53Initial program 100.0%
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
/-lowering-/.f6463.7%
Simplified63.7%
(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-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
sub-negN/A
+-commutativeN/A
distribute-neg-outN/A
remove-double-negN/A
sub-negN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
Simplified37.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 2024152
(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)))