
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
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 - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
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 - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -2e+54) (not (<= y 7.8e+20))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e+54) || !(y <= 7.8e+20)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - 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 <= (-2d+54)) .or. (.not. (y <= 7.8d+20))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = (x + (y * (z - x))) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2e+54) || !(y <= 7.8e+20)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e+54) or not (y <= 7.8e+20): tmp = y * (1.0 - (x / z)) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e+54) || !(y <= 7.8e+20)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2e+54) || ~((y <= 7.8e+20))) tmp = y * (1.0 - (x / z)); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e+54], N[Not[LessEqual[y, 7.8e+20]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+54} \lor \neg \left(y \leq 7.8 \cdot 10^{+20}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -2.0000000000000002e54 or 7.8e20 < y Initial program 74.9%
Taylor expanded in y around inf 74.9%
associate-/l*99.9%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
if -2.0000000000000002e54 < y < 7.8e20Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e+45) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e+45) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (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.7d+45)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e+45) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e+45) or not (y <= 1.0): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e+45) || !(y <= 1.0)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.7e+45) || ~((y <= 1.0))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e+45], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+45} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.69999999999999984e45 or 1 < y Initial program 76.0%
Taylor expanded in y around inf 75.7%
associate-/l*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
if -2.69999999999999984e45 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.1%
Taylor expanded in x around 0 99.1%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= y -3.5e-61) y (if (<= y 4.65e-32) (/ x z) (* z (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.5e-61) {
tmp = y;
} else if (y <= 4.65e-32) {
tmp = x / z;
} else {
tmp = z * (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 <= (-3.5d-61)) then
tmp = y
else if (y <= 4.65d-32) then
tmp = x / z
else
tmp = z * (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.5e-61) {
tmp = y;
} else if (y <= 4.65e-32) {
tmp = x / z;
} else {
tmp = z * (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.5e-61: tmp = y elif y <= 4.65e-32: tmp = x / z else: tmp = z * (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.5e-61) tmp = y; elseif (y <= 4.65e-32) tmp = Float64(x / z); else tmp = Float64(z * Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.5e-61) tmp = y; elseif (y <= 4.65e-32) tmp = x / z; else tmp = z * (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.5e-61], y, If[LessEqual[y, 4.65e-32], N[(x / z), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-61}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.65 \cdot 10^{-32}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -3.5000000000000003e-61Initial program 83.7%
Taylor expanded in x around 0 50.1%
if -3.5000000000000003e-61 < y < 4.64999999999999988e-32Initial program 100.0%
Taylor expanded in y around 0 74.0%
if 4.64999999999999988e-32 < y Initial program 76.4%
Taylor expanded in y around inf 72.6%
Taylor expanded in z around inf 38.7%
*-commutative38.7%
associate-/l*63.0%
Applied egg-rr63.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.7e-61) y (if (<= y 3.6e-87) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e-61) {
tmp = y;
} else if (y <= 3.6e-87) {
tmp = x / z;
} else {
tmp = 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 <= (-2.7d-61)) then
tmp = y
else if (y <= 3.6d-87) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e-61) {
tmp = y;
} else if (y <= 3.6e-87) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.7e-61: tmp = y elif y <= 3.6e-87: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.7e-61) tmp = y; elseif (y <= 3.6e-87) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.7e-61) tmp = y; elseif (y <= 3.6e-87) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.7e-61], y, If[LessEqual[y, 3.6e-87], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-61}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-87}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.69999999999999993e-61 or 3.59999999999999993e-87 < y Initial program 81.0%
Taylor expanded in x around 0 54.7%
if -2.69999999999999993e-61 < y < 3.59999999999999993e-87Initial program 100.0%
Taylor expanded in y around 0 76.2%
(FPCore (x y z) :precision binary64 (+ y (/ x z)))
double code(double x, double y, double z) {
return y + (x / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + (x / z)
end function
public static double code(double x, double y, double z) {
return y + (x / z);
}
def code(x, y, z): return y + (x / z)
function code(x, y, z) return Float64(y + Float64(x / z)) end
function tmp = code(x, y, z) tmp = y + (x / z); end
code[x_, y_, z_] := N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \frac{x}{z}
\end{array}
Initial program 88.6%
Taylor expanded in z around inf 70.2%
Taylor expanded in x around 0 79.4%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 88.6%
Taylor expanded in x around 0 42.9%
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z): return (y + (x / z)) - (y / (z / x))
function code(x, y, z) return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (y + (x / z)) - (y / (z / x)); end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}
herbie shell --seed 2024094
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:alt
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))