
(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 (<= z -1.35e+167) (not (<= z 1.7e+85))) (+ y (/ x z)) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e+167) || !(z <= 1.7e+85)) {
tmp = y + (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 ((z <= (-1.35d+167)) .or. (.not. (z <= 1.7d+85))) then
tmp = y + (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 ((z <= -1.35e+167) || !(z <= 1.7e+85)) {
tmp = y + (x / z);
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.35e+167) or not (z <= 1.7e+85): tmp = y + (x / z) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.35e+167) || !(z <= 1.7e+85)) tmp = Float64(y + 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 ((z <= -1.35e+167) || ~((z <= 1.7e+85))) tmp = y + (x / z); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e+167], N[Not[LessEqual[z, 1.7e+85]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+167} \lor \neg \left(z \leq 1.7 \cdot 10^{+85}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -1.35000000000000003e167 or 1.7000000000000002e85 < z Initial program 64.2%
Taylor expanded in z around inf 63.9%
Taylor expanded in x around 0 93.1%
if -1.35000000000000003e167 < z < 1.7000000000000002e85Initial program 97.3%
Final simplification96.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e+91) (not (<= x 1.85e+94))) (* (/ x z) (- 1.0 y)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+91) || !(x <= 1.85e+94)) {
tmp = (x / z) * (1.0 - y);
} 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 ((x <= (-4.1d+91)) .or. (.not. (x <= 1.85d+94))) then
tmp = (x / z) * (1.0d0 - y)
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+91) || !(x <= 1.85e+94)) {
tmp = (x / z) * (1.0 - y);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e+91) or not (x <= 1.85e+94): tmp = (x / z) * (1.0 - y) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e+91) || !(x <= 1.85e+94)) tmp = Float64(Float64(x / z) * Float64(1.0 - y)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e+91) || ~((x <= 1.85e+94))) tmp = (x / z) * (1.0 - y); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+91], N[Not[LessEqual[x, 1.85e+94]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+91} \lor \neg \left(x \leq 1.85 \cdot 10^{+94}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -4.1000000000000002e91 or 1.8500000000000001e94 < x Initial program 84.3%
Taylor expanded in x around inf 84.1%
*-commutative84.1%
associate-/l*94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
if -4.1000000000000002e91 < x < 1.8500000000000001e94Initial program 87.5%
Taylor expanded in z around inf 75.2%
Taylor expanded in x around 0 87.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e+90) (not (<= x 1.4e+94))) (* x (/ (- 1.0 y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e+90) || !(x <= 1.4e+94)) {
tmp = x * ((1.0 - y) / 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 ((x <= (-4.5d+90)) .or. (.not. (x <= 1.4d+94))) then
tmp = x * ((1.0d0 - y) / 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 ((x <= -4.5e+90) || !(x <= 1.4e+94)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e+90) or not (x <= 1.4e+94): tmp = x * ((1.0 - y) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e+90) || !(x <= 1.4e+94)) tmp = Float64(x * Float64(Float64(1.0 - y) / z)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e+90) || ~((x <= 1.4e+94))) tmp = x * ((1.0 - y) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e+90], N[Not[LessEqual[x, 1.4e+94]], $MachinePrecision]], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+90} \lor \neg \left(x \leq 1.4 \cdot 10^{+94}\right):\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -4.5e90 or 1.39999999999999999e94 < x Initial program 84.3%
Taylor expanded in x around inf 84.1%
associate-/l*93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
if -4.5e90 < x < 1.39999999999999999e94Initial program 87.5%
Taylor expanded in z around inf 75.2%
Taylor expanded in x around 0 87.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.2e+92) (/ x (/ z (- 1.0 y))) (if (<= x 4.8e+93) (+ y (/ x z)) (* (/ x z) (- 1.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+92) {
tmp = x / (z / (1.0 - y));
} else if (x <= 4.8e+93) {
tmp = y + (x / z);
} else {
tmp = (x / z) * (1.0 - 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 (x <= (-1.2d+92)) then
tmp = x / (z / (1.0d0 - y))
else if (x <= 4.8d+93) then
tmp = y + (x / z)
else
tmp = (x / z) * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+92) {
tmp = x / (z / (1.0 - y));
} else if (x <= 4.8e+93) {
tmp = y + (x / z);
} else {
tmp = (x / z) * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e+92: tmp = x / (z / (1.0 - y)) elif x <= 4.8e+93: tmp = y + (x / z) else: tmp = (x / z) * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e+92) tmp = Float64(x / Float64(z / Float64(1.0 - y))); elseif (x <= 4.8e+93) tmp = Float64(y + Float64(x / z)); else tmp = Float64(Float64(x / z) * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.2e+92) tmp = x / (z / (1.0 - y)); elseif (x <= 4.8e+93) tmp = y + (x / z); else tmp = (x / z) * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e+92], N[(x / N[(z / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.8e+93], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{x}{\frac{z}{1 - y}}\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+93}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -1.20000000000000002e92Initial program 76.6%
div-inv76.5%
+-commutative76.5%
fma-undefine76.5%
Applied egg-rr76.5%
Taylor expanded in z around 0 76.4%
mul-1-neg76.4%
distribute-rgt-neg-out76.4%
*-commutative76.4%
distribute-rgt1-in76.4%
+-commutative76.4%
sub-neg76.4%
associate-*r/89.2%
*-commutative89.2%
associate-/r/89.2%
Simplified89.2%
if -1.20000000000000002e92 < x < 4.80000000000000021e93Initial program 87.5%
Taylor expanded in z around inf 75.2%
Taylor expanded in x around 0 87.7%
if 4.80000000000000021e93 < x Initial program 90.2%
Taylor expanded in x around inf 90.1%
*-commutative90.1%
associate-/l*97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (<= y -2.1e-76) y (if (<= y 2.2e-20) (/ x z) (* z (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.1e-76) {
tmp = y;
} else if (y <= 2.2e-20) {
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 <= (-2.1d-76)) then
tmp = y
else if (y <= 2.2d-20) 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 <= -2.1e-76) {
tmp = y;
} else if (y <= 2.2e-20) {
tmp = x / z;
} else {
tmp = z * (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.1e-76: tmp = y elif y <= 2.2e-20: tmp = x / z else: tmp = z * (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.1e-76) tmp = y; elseif (y <= 2.2e-20) 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 <= -2.1e-76) tmp = y; elseif (y <= 2.2e-20) tmp = x / z; else tmp = z * (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.1e-76], y, If[LessEqual[y, 2.2e-20], N[(x / z), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-76}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-20}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -2.09999999999999992e-76Initial program 80.8%
Taylor expanded in x around 0 54.6%
if -2.09999999999999992e-76 < y < 2.19999999999999991e-20Initial program 100.0%
Taylor expanded in y around 0 81.0%
if 2.19999999999999991e-20 < y Initial program 71.6%
Taylor expanded in y around inf 71.6%
Taylor expanded in z around inf 34.8%
*-commutative34.8%
Simplified34.8%
associate-/l*57.3%
*-commutative57.3%
Applied egg-rr57.3%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.04e-76) y (if (<= y 3.3e-21) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.04e-76) {
tmp = y;
} else if (y <= 3.3e-21) {
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 <= (-1.04d-76)) then
tmp = y
else if (y <= 3.3d-21) 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 <= -1.04e-76) {
tmp = y;
} else if (y <= 3.3e-21) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.04e-76: tmp = y elif y <= 3.3e-21: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.04e-76) tmp = y; elseif (y <= 3.3e-21) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.04e-76) tmp = y; elseif (y <= 3.3e-21) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.04e-76], y, If[LessEqual[y, 3.3e-21], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{-76}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-21}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.04e-76 or 3.30000000000000009e-21 < y Initial program 76.7%
Taylor expanded in x around 0 55.2%
if -1.04e-76 < y < 3.30000000000000009e-21Initial program 100.0%
Taylor expanded in y around 0 81.0%
(FPCore (x y z) :precision binary64 (if (<= y 1.0) (+ y (/ x z)) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.0) {
tmp = y + (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) then
tmp = y + (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) {
tmp = y + (x / z);
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.0: tmp = y + (x / z) else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.0) tmp = Float64(y + 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) tmp = y + (x / z); else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 1Initial program 91.8%
Taylor expanded in z around inf 81.8%
Taylor expanded in x around 0 87.7%
if 1 < y Initial program 69.8%
Taylor expanded in z around inf 33.1%
Taylor expanded in x around 0 55.8%
add-sqr-sqrt35.6%
sqrt-unprod60.8%
sqr-neg60.8%
sqrt-unprod27.1%
add-sqr-sqrt66.2%
distribute-frac-neg266.2%
sub-neg66.2%
Applied egg-rr66.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 86.4%
Taylor expanded in z around inf 70.0%
Taylor expanded in x around 0 80.0%
(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 86.4%
Taylor expanded in x around 0 41.2%
(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 2024180
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))
(/ (+ x (* y (- z x))) z))