
(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 (- 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}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.58e+69) 1.0 (if (<= y 1.05e-125) (/ x z) (if (<= y 2.02e+18) (/ x (- y)) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.58e+69) {
tmp = 1.0;
} else if (y <= 1.05e-125) {
tmp = x / z;
} else if (y <= 2.02e+18) {
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.58d+69)) then
tmp = 1.0d0
else if (y <= 1.05d-125) then
tmp = x / z
else if (y <= 2.02d+18) 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.58e+69) {
tmp = 1.0;
} else if (y <= 1.05e-125) {
tmp = x / z;
} else if (y <= 2.02e+18) {
tmp = x / -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.58e+69: tmp = 1.0 elif y <= 1.05e-125: tmp = x / z elif y <= 2.02e+18: tmp = x / -y else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.58e+69) tmp = 1.0; elseif (y <= 1.05e-125) tmp = Float64(x / z); elseif (y <= 2.02e+18) 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.58e+69) tmp = 1.0; elseif (y <= 1.05e-125) tmp = x / z; elseif (y <= 2.02e+18) tmp = x / -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.58e+69], 1.0, If[LessEqual[y, 1.05e-125], N[(x / z), $MachinePrecision], If[LessEqual[y, 2.02e+18], N[(x / (-y)), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.58 \cdot 10^{+69}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-125}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 2.02 \cdot 10^{+18}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.58e69 or 2.02e18 < y Initial program 100.0%
Taylor expanded in y around inf 57.9%
if -1.58e69 < y < 1.05e-125Initial program 100.0%
Taylor expanded in y around 0 68.1%
if 1.05e-125 < y < 2.02e18Initial program 100.0%
Taylor expanded in x around inf 69.7%
Taylor expanded in z around 0 50.7%
mul-1-neg50.7%
distribute-neg-frac250.7%
Simplified50.7%
Final simplification61.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.35e-50) (not (<= y 7.2e-158))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.35e-50) || !(y <= 7.2e-158)) {
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.35d-50)) .or. (.not. (y <= 7.2d-158))) 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.35e-50) || !(y <= 7.2e-158)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.35e-50) or not (y <= 7.2e-158): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.35e-50) || !(y <= 7.2e-158)) 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.35e-50) || ~((y <= 7.2e-158))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.35e-50], N[Not[LessEqual[y, 7.2e-158]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.35 \cdot 10^{-50} \lor \neg \left(y \leq 7.2 \cdot 10^{-158}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.3500000000000001e-50 or 7.19999999999999982e-158 < y Initial program 99.9%
Taylor expanded in z around 0 67.7%
div-sub67.7%
sub-neg67.7%
*-inverses67.7%
metadata-eval67.7%
distribute-lft-in67.7%
metadata-eval67.7%
+-commutative67.7%
mul-1-neg67.7%
unsub-neg67.7%
Simplified67.7%
if -2.3500000000000001e-50 < y < 7.19999999999999982e-158Initial program 100.0%
Taylor expanded in y around 0 79.8%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -9800000000.0) (not (<= y 8e-8))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9800000000.0) || !(y <= 8e-8)) {
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 <= (-9800000000.0d0)) .or. (.not. (y <= 8d-8))) 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 <= -9800000000.0) || !(y <= 8e-8)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9800000000.0) or not (y <= 8e-8): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9800000000.0) || !(y <= 8e-8)) 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 <= -9800000000.0) || ~((y <= 8e-8))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9800000000.0], N[Not[LessEqual[y, 8e-8]], $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 -9800000000 \lor \neg \left(y \leq 8 \cdot 10^{-8}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -9.8e9 or 8.0000000000000002e-8 < y Initial program 99.9%
Taylor expanded in z around 0 70.9%
div-sub70.9%
sub-neg70.9%
*-inverses70.9%
metadata-eval70.9%
distribute-lft-in70.9%
metadata-eval70.9%
+-commutative70.9%
mul-1-neg70.9%
unsub-neg70.9%
Simplified70.9%
if -9.8e9 < y < 8.0000000000000002e-8Initial program 100.0%
Taylor expanded in x around inf 83.7%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e+14) (not (<= x 1.4e-74))) (/ x (- z y)) (/ y (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+14) || !(x <= 1.4e-74)) {
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 <= (-3.7d+14)) .or. (.not. (x <= 1.4d-74))) 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 <= -3.7e+14) || !(x <= 1.4e-74)) {
tmp = x / (z - y);
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e+14) or not (x <= 1.4e-74): tmp = x / (z - y) else: tmp = y / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e+14) || !(x <= 1.4e-74)) 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 <= -3.7e+14) || ~((x <= 1.4e-74))) tmp = x / (z - y); else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e+14], N[Not[LessEqual[x, 1.4e-74]], $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 -3.7 \cdot 10^{+14} \lor \neg \left(x \leq 1.4 \cdot 10^{-74}\right):\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
if x < -3.7e14 or 1.39999999999999994e-74 < x Initial program 99.9%
Taylor expanded in x around inf 77.3%
if -3.7e14 < x < 1.39999999999999994e-74Initial program 100.0%
Taylor expanded in x around 0 83.2%
neg-mul-183.2%
distribute-neg-frac83.2%
Simplified83.2%
frac-2neg83.2%
div-inv83.1%
remove-double-neg83.1%
sub-neg83.1%
distribute-neg-in83.1%
remove-double-neg83.1%
Applied egg-rr83.1%
associate-*r/83.2%
*-rgt-identity83.2%
+-commutative83.2%
unsub-neg83.2%
Simplified83.2%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+69) 1.0 (if (<= y 7800000000000.0) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+69) {
tmp = 1.0;
} else if (y <= 7800000000000.0) {
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.5d+69)) then
tmp = 1.0d0
else if (y <= 7800000000000.0d0) 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.5e+69) {
tmp = 1.0;
} else if (y <= 7800000000000.0) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e+69: tmp = 1.0 elif y <= 7800000000000.0: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+69) tmp = 1.0; elseif (y <= 7800000000000.0) 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.5e+69) tmp = 1.0; elseif (y <= 7800000000000.0) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+69], 1.0, If[LessEqual[y, 7800000000000.0], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+69}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7800000000000:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.50000000000000018e69 or 7.8e12 < y Initial program 100.0%
Taylor expanded in y around inf 56.7%
if -2.50000000000000018e69 < y < 7.8e12Initial program 100.0%
Taylor expanded in y around 0 61.6%
Final simplification59.2%
(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 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 34.0%
Final simplification34.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 2024077
(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)))