
(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 9 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 -8e+14) (not (<= y 1e+15))) (* y (- 1.0 (/ x z))) (/ (fma y (- z x) x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e+14) || !(y <= 1e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = fma(y, (z - x), x) / z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -8e+14) || !(y <= 1e+15)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(fma(y, Float64(z - x), x) / z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e+14], N[Not[LessEqual[y, 1e+15]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+14} \lor \neg \left(y \leq 10^{+15}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\
\end{array}
\end{array}
if y < -8e14 or 1e15 < y Initial program 70.0%
Taylor expanded in y around inf 70.0%
associate-/l*99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
if -8e14 < y < 1e15Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x 1.85e-73) (and (not (<= x 5.5e-39)) (<= x 8.2e+269))) (+ y (/ x z)) (* x (/ y (- z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= 1.85e-73) || (!(x <= 5.5e-39) && (x <= 8.2e+269))) {
tmp = y + (x / z);
} else {
tmp = x * (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 <= 1.85d-73) .or. (.not. (x <= 5.5d-39)) .and. (x <= 8.2d+269)) then
tmp = y + (x / z)
else
tmp = x * (y / -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= 1.85e-73) || (!(x <= 5.5e-39) && (x <= 8.2e+269))) {
tmp = y + (x / z);
} else {
tmp = x * (y / -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= 1.85e-73) or (not (x <= 5.5e-39) and (x <= 8.2e+269)): tmp = y + (x / z) else: tmp = x * (y / -z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= 1.85e-73) || (!(x <= 5.5e-39) && (x <= 8.2e+269))) tmp = Float64(y + Float64(x / z)); else tmp = Float64(x * Float64(y / Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= 1.85e-73) || (~((x <= 5.5e-39)) && (x <= 8.2e+269))) tmp = y + (x / z); else tmp = x * (y / -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, 1.85e-73], And[N[Not[LessEqual[x, 5.5e-39]], $MachinePrecision], LessEqual[x, 8.2e+269]]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.85 \cdot 10^{-73} \lor \neg \left(x \leq 5.5 \cdot 10^{-39}\right) \land x \leq 8.2 \cdot 10^{+269}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{-z}\\
\end{array}
\end{array}
if x < 1.85e-73 or 5.50000000000000018e-39 < x < 8.20000000000000015e269Initial program 85.5%
Taylor expanded in z around inf 71.2%
Taylor expanded in x around 0 83.0%
if 1.85e-73 < x < 5.50000000000000018e-39 or 8.20000000000000015e269 < x Initial program 88.3%
Taylor expanded in x around inf 88.0%
associate-/l*93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
Taylor expanded in y around inf 78.6%
mul-1-neg78.6%
distribute-neg-frac278.6%
associate-*r/84.6%
Simplified84.6%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.3e+14) (not (<= y 1.22e+15))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.3e+14) || !(y <= 1.22e+15)) {
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 <= (-4.3d+14)) .or. (.not. (y <= 1.22d+15))) 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 <= -4.3e+14) || !(y <= 1.22e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.3e+14) or not (y <= 1.22e+15): 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 <= -4.3e+14) || !(y <= 1.22e+15)) 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 <= -4.3e+14) || ~((y <= 1.22e+15))) 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, -4.3e+14], N[Not[LessEqual[y, 1.22e+15]], $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 -4.3 \cdot 10^{+14} \lor \neg \left(y \leq 1.22 \cdot 10^{+15}\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 < -4.3e14 or 1.22e15 < y Initial program 70.0%
Taylor expanded in y around inf 70.0%
associate-/l*99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
if -4.3e14 < y < 1.22e15Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.45e-31) (not (<= z 2.9e-135))) (+ y (/ x z)) (* x (/ (- 1.0 y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.45e-31) || !(z <= 2.9e-135)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - 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.45d-31)) .or. (.not. (z <= 2.9d-135))) then
tmp = y + (x / z)
else
tmp = x * ((1.0d0 - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.45e-31) || !(z <= 2.9e-135)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.45e-31) or not (z <= 2.9e-135): tmp = y + (x / z) else: tmp = x * ((1.0 - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.45e-31) || !(z <= 2.9e-135)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(x * Float64(Float64(1.0 - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.45e-31) || ~((z <= 2.9e-135))) tmp = y + (x / z); else tmp = x * ((1.0 - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.45e-31], N[Not[LessEqual[z, 2.9e-135]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{-31} \lor \neg \left(z \leq 2.9 \cdot 10^{-135}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\end{array}
\end{array}
if z < -2.45000000000000012e-31 or 2.9000000000000002e-135 < z Initial program 77.6%
Taylor expanded in z around inf 67.8%
Taylor expanded in x around 0 85.7%
if -2.45000000000000012e-31 < z < 2.9000000000000002e-135Initial program 99.9%
Taylor expanded in x around inf 94.7%
associate-/l*92.5%
mul-1-neg92.5%
unsub-neg92.5%
Simplified92.5%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 3.1e-9))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 3.1e-9)) {
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 <= (-1.0d0)) .or. (.not. (y <= 3.1d-9))) 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 <= -1.0) || !(y <= 3.1e-9)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 3.1e-9): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 3.1e-9)) 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 <= -1.0) || ~((y <= 3.1e-9))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 3.1e-9]], $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 -1 \lor \neg \left(y \leq 3.1 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 3.10000000000000005e-9 < y Initial program 71.8%
Taylor expanded in y around inf 70.9%
associate-/l*98.9%
div-sub99.0%
*-inverses99.0%
Simplified99.0%
if -1 < y < 3.10000000000000005e-9Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 100.0%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-11) (not (<= y 7.5e-56))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-11) || !(y <= 7.5e-56)) {
tmp = z * (y / z);
} 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 <= (-9.5d-11)) .or. (.not. (y <= 7.5d-56))) then
tmp = z * (y / z)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-11) || !(y <= 7.5e-56)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e-11) or not (y <= 7.5e-56): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-11) || !(y <= 7.5e-56)) tmp = Float64(z * Float64(y / z)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.5e-11) || ~((y <= 7.5e-56))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-11], N[Not[LessEqual[y, 7.5e-56]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-11} \lor \neg \left(y \leq 7.5 \cdot 10^{-56}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -9.49999999999999951e-11 or 7.50000000000000041e-56 < y Initial program 74.4%
Taylor expanded in y around inf 74.3%
Taylor expanded in z around inf 35.8%
*-commutative35.8%
Simplified35.8%
associate-/l*60.6%
*-commutative60.6%
Applied egg-rr60.6%
if -9.49999999999999951e-11 < y < 7.50000000000000041e-56Initial program 99.9%
Taylor expanded in y around 0 76.0%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (<= y -4.3e-13) y (if (<= y 2e-59) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.3e-13) {
tmp = y;
} else if (y <= 2e-59) {
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 <= (-4.3d-13)) then
tmp = y
else if (y <= 2d-59) 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 <= -4.3e-13) {
tmp = y;
} else if (y <= 2e-59) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.3e-13: tmp = y elif y <= 2e-59: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.3e-13) tmp = y; elseif (y <= 2e-59) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.3e-13) tmp = y; elseif (y <= 2e-59) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.3e-13], y, If[LessEqual[y, 2e-59], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-13}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-59}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.2999999999999999e-13 or 2.0000000000000001e-59 < y Initial program 74.4%
Taylor expanded in x around 0 56.3%
if -4.2999999999999999e-13 < y < 2.0000000000000001e-59Initial program 99.9%
Taylor expanded in y around 0 76.0%
Final simplification65.0%
(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 85.6%
Taylor expanded in z around inf 67.7%
Taylor expanded in x around 0 79.1%
Final simplification79.1%
(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 85.6%
Taylor expanded in x around 0 42.7%
Final simplification42.7%
(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 2024076
(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))