
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.35e-67)
(/ x z)
(if (<= z 2.4e-51)
(- 1.0 (/ x y))
(if (or (<= z 9e+191) (not (<= z 1.8e+295))) (/ x z) (/ y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.35e-67) {
tmp = x / z;
} else if (z <= 2.4e-51) {
tmp = 1.0 - (x / y);
} else if ((z <= 9e+191) || !(z <= 1.8e+295)) {
tmp = x / z;
} 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) :: tmp
if (z <= (-2.35d-67)) then
tmp = x / z
else if (z <= 2.4d-51) then
tmp = 1.0d0 - (x / y)
else if ((z <= 9d+191) .or. (.not. (z <= 1.8d+295))) then
tmp = x / z
else
tmp = y / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.35e-67) {
tmp = x / z;
} else if (z <= 2.4e-51) {
tmp = 1.0 - (x / y);
} else if ((z <= 9e+191) || !(z <= 1.8e+295)) {
tmp = x / z;
} else {
tmp = y / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.35e-67: tmp = x / z elif z <= 2.4e-51: tmp = 1.0 - (x / y) elif (z <= 9e+191) or not (z <= 1.8e+295): tmp = x / z else: tmp = y / -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.35e-67) tmp = Float64(x / z); elseif (z <= 2.4e-51) tmp = Float64(1.0 - Float64(x / y)); elseif ((z <= 9e+191) || !(z <= 1.8e+295)) tmp = Float64(x / z); else tmp = Float64(y / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.35e-67) tmp = x / z; elseif (z <= 2.4e-51) tmp = 1.0 - (x / y); elseif ((z <= 9e+191) || ~((z <= 1.8e+295))) tmp = x / z; else tmp = y / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.35e-67], N[(x / z), $MachinePrecision], If[LessEqual[z, 2.4e-51], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, 9e+191], N[Not[LessEqual[z, 1.8e+295]], $MachinePrecision]], N[(x / z), $MachinePrecision], N[(y / (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.35 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-51}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+191} \lor \neg \left(z \leq 1.8 \cdot 10^{+295}\right):\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{-z}\\
\end{array}
\end{array}
if z < -2.35000000000000002e-67 or 2.4e-51 < z < 9.0000000000000005e191 or 1.79999999999999992e295 < z Initial program 100.0%
Taylor expanded in y around 0 58.3%
if -2.35000000000000002e-67 < z < 2.4e-51Initial program 99.9%
Taylor expanded in z around 0 87.0%
div-sub87.0%
sub-neg87.0%
*-inverses87.0%
metadata-eval87.0%
distribute-lft-in87.0%
metadata-eval87.0%
+-commutative87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
if 9.0000000000000005e191 < z < 1.79999999999999992e295Initial program 100.0%
Taylor expanded in z around inf 89.2%
Taylor expanded in x around 0 63.8%
neg-mul-163.8%
distribute-neg-frac263.8%
Simplified63.8%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e+42) (not (<= y 2.4e+82))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e+42) || !(y <= 2.4e+82)) {
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 <= (-3d+42)) .or. (.not. (y <= 2.4d+82))) 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 <= -3e+42) || !(y <= 2.4e+82)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e+42) or not (y <= 2.4e+82): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e+42) || !(y <= 2.4e+82)) 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 <= -3e+42) || ~((y <= 2.4e+82))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e+42], N[Not[LessEqual[y, 2.4e+82]], $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 -3 \cdot 10^{+42} \lor \neg \left(y \leq 2.4 \cdot 10^{+82}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -3.00000000000000029e42 or 2.39999999999999998e82 < y Initial program 99.9%
Taylor expanded in z around 0 72.0%
div-sub72.0%
sub-neg72.0%
*-inverses72.0%
metadata-eval72.0%
distribute-lft-in72.0%
metadata-eval72.0%
+-commutative72.0%
mul-1-neg72.0%
unsub-neg72.0%
Simplified72.0%
if -3.00000000000000029e42 < y < 2.39999999999999998e82Initial program 100.0%
Taylor expanded in x around inf 82.6%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-70) (not (<= z 2.6e-51))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-70) || !(z <= 2.6e-51)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / 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 ((z <= (-1.25d-70)) .or. (.not. (z <= 2.6d-51))) then
tmp = (x - y) / z
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-70) || !(z <= 2.6e-51)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-70) or not (z <= 2.6e-51): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-70) || !(z <= 2.6e-51)) tmp = Float64(Float64(x - y) / z); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-70) || ~((z <= 2.6e-51))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-70], N[Not[LessEqual[z, 2.6e-51]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-70} \lor \neg \left(z \leq 2.6 \cdot 10^{-51}\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if z < -1.25e-70 or 2.6e-51 < z Initial program 100.0%
Taylor expanded in z around inf 80.8%
if -1.25e-70 < z < 2.6e-51Initial program 99.9%
Taylor expanded in z around 0 87.0%
div-sub87.0%
sub-neg87.0%
*-inverses87.0%
metadata-eval87.0%
distribute-lft-in87.0%
metadata-eval87.0%
+-commutative87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (<= y -8.6e+41) 1.0 (if (<= y 2.1e+82) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+41) {
tmp = 1.0;
} else if (y <= 2.1e+82) {
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 <= (-8.6d+41)) then
tmp = 1.0d0
else if (y <= 2.1d+82) 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 <= -8.6e+41) {
tmp = 1.0;
} else if (y <= 2.1e+82) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.6e+41: tmp = 1.0 elif y <= 2.1e+82: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.6e+41) tmp = 1.0; elseif (y <= 2.1e+82) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.6e+41) tmp = 1.0; elseif (y <= 2.1e+82) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.6e+41], 1.0, If[LessEqual[y, 2.1e+82], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{+41}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+82}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.60000000000000048e41 or 2.1e82 < y Initial program 99.9%
Taylor expanded in y around inf 64.8%
if -8.60000000000000048e41 < y < 2.1e82Initial program 100.0%
Taylor expanded in y around 0 64.1%
Final simplification64.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 29.2%
Final simplification29.2%
(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 2024079
(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)))