
(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 8 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 -7.5e-73) (not (<= z 2.1e-185))) (+ (/ x z) (* y (- 1.0 (/ x z)))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e-73) || !(z <= 2.1e-185)) {
tmp = (x / z) + (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 ((z <= (-7.5d-73)) .or. (.not. (z <= 2.1d-185))) then
tmp = (x / z) + (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 ((z <= -7.5e-73) || !(z <= 2.1e-185)) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.5e-73) or not (z <= 2.1e-185): tmp = (x / z) + (y * (1.0 - (x / z))) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.5e-73) || !(z <= 2.1e-185)) tmp = Float64(Float64(x / z) + 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 ((z <= -7.5e-73) || ~((z <= 2.1e-185))) tmp = (x / z) + (y * (1.0 - (x / z))); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e-73], N[Not[LessEqual[z, 2.1e-185]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $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 -7.5 \cdot 10^{-73} \lor \neg \left(z \leq 2.1 \cdot 10^{-185}\right):\\
\;\;\;\;\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -7.5e-73 or 2.1e-185 < z Initial program 81.1%
Taylor expanded in y around 0 100.0%
if -7.5e-73 < z < 2.1e-185Initial program 99.9%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.2e+37) (* y (- 1.0 (/ x z))) (if (<= y 20000000000000.0) (/ (+ x (* y (- z x))) z) (- y (* y (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e+37) {
tmp = y * (1.0 - (x / z));
} else if (y <= 20000000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y - (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.2d+37)) then
tmp = y * (1.0d0 - (x / z))
else if (y <= 20000000000000.0d0) then
tmp = (x + (y * (z - x))) / z
else
tmp = y - (y * (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e+37) {
tmp = y * (1.0 - (x / z));
} else if (y <= 20000000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y - (y * (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e+37: tmp = y * (1.0 - (x / z)) elif y <= 20000000000000.0: tmp = (x + (y * (z - x))) / z else: tmp = y - (y * (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e+37) tmp = Float64(y * Float64(1.0 - Float64(x / z))); elseif (y <= 20000000000000.0) tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); else tmp = Float64(y - Float64(y * Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.2e+37) tmp = y * (1.0 - (x / z)); elseif (y <= 20000000000000.0) tmp = (x + (y * (z - x))) / z; else tmp = y - (y * (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e+37], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 20000000000000.0], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(y - N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+37}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{elif}\;y \leq 20000000000000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.2000000000000001e37Initial program 65.7%
Taylor expanded in y around inf 65.7%
associate-/l*100.0%
div-sub100.0%
sub-neg100.0%
*-inverses100.0%
sub-neg100.0%
Simplified100.0%
if -2.2000000000000001e37 < y < 2e13Initial program 99.9%
if 2e13 < y Initial program 74.3%
Taylor expanded in y around inf 74.3%
associate-/l*99.9%
div-sub99.9%
sub-neg99.9%
*-inverses99.9%
sub-neg99.9%
Simplified99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
*-commutative99.9%
associate-*r/88.3%
add-sqr-sqrt45.7%
sqrt-unprod62.2%
sqr-neg62.2%
sqrt-unprod21.4%
add-sqr-sqrt41.3%
associate-*r/46.8%
*-commutative46.8%
cancel-sign-sub46.8%
distribute-frac-neg246.8%
*-commutative46.8%
associate-*r/41.3%
add-sqr-sqrt19.9%
sqrt-unprod57.9%
sqr-neg57.9%
sqrt-unprod42.6%
add-sqr-sqrt88.3%
associate-*r/99.9%
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+32) (not (<= y 0.0155))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+32) || !(y <= 0.0155)) {
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 <= (-5.2d+32)) .or. (.not. (y <= 0.0155d0))) 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 <= -5.2e+32) || !(y <= 0.0155)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e+32) or not (y <= 0.0155): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e+32) || !(y <= 0.0155)) 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 <= -5.2e+32) || ~((y <= 0.0155))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e+32], N[Not[LessEqual[y, 0.0155]], $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 -5.2 \cdot 10^{+32} \lor \neg \left(y \leq 0.0155\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.2000000000000004e32 or 0.0155 < y Initial program 71.6%
Taylor expanded in y around inf 71.3%
associate-/l*99.5%
div-sub99.6%
sub-neg99.6%
*-inverses99.6%
sub-neg99.6%
Simplified99.6%
if -5.2000000000000004e32 < y < 0.0155Initial program 99.9%
Taylor expanded in y around 0 91.2%
Taylor expanded in x around 0 99.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+32) (* y (- 1.0 (/ x z))) (if (<= y 0.0155) (+ y (/ x z)) (- y (* y (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+32) {
tmp = y * (1.0 - (x / z));
} else if (y <= 0.0155) {
tmp = y + (x / z);
} else {
tmp = y - (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 <= (-5.2d+32)) then
tmp = y * (1.0d0 - (x / z))
else if (y <= 0.0155d0) then
tmp = y + (x / z)
else
tmp = y - (y * (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+32) {
tmp = y * (1.0 - (x / z));
} else if (y <= 0.0155) {
tmp = y + (x / z);
} else {
tmp = y - (y * (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+32: tmp = y * (1.0 - (x / z)) elif y <= 0.0155: tmp = y + (x / z) else: tmp = y - (y * (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+32) tmp = Float64(y * Float64(1.0 - Float64(x / z))); elseif (y <= 0.0155) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y - Float64(y * Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+32) tmp = y * (1.0 - (x / z)); elseif (y <= 0.0155) tmp = y + (x / z); else tmp = y - (y * (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+32], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0155], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+32}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{elif}\;y \leq 0.0155:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.2000000000000004e32Initial program 67.0%
Taylor expanded in y around inf 67.0%
associate-/l*99.9%
div-sub99.9%
sub-neg99.9%
*-inverses99.9%
sub-neg99.9%
Simplified99.9%
if -5.2000000000000004e32 < y < 0.0155Initial program 99.9%
Taylor expanded in y around 0 91.2%
Taylor expanded in x around 0 99.0%
if 0.0155 < y Initial program 75.0%
Taylor expanded in y around inf 74.4%
associate-/l*99.3%
div-sub99.3%
sub-neg99.3%
*-inverses99.3%
sub-neg99.3%
Simplified99.3%
sub-neg99.3%
distribute-rgt-in99.3%
*-un-lft-identity99.3%
distribute-neg-frac299.3%
Applied egg-rr99.3%
*-commutative99.3%
associate-*r/88.0%
add-sqr-sqrt45.2%
sqrt-unprod62.7%
sqr-neg62.7%
sqrt-unprod22.3%
add-sqr-sqrt41.6%
associate-*r/46.9%
*-commutative46.9%
cancel-sign-sub46.9%
distribute-frac-neg246.9%
*-commutative46.9%
associate-*r/41.6%
add-sqr-sqrt19.3%
sqrt-unprod57.7%
sqr-neg57.7%
sqrt-unprod42.8%
add-sqr-sqrt88.0%
associate-*r/99.3%
Applied egg-rr99.3%
(FPCore (x y z) :precision binary64 (if (<= y -5.5e-14) y (if (<= y 4.2e-18) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e-14) {
tmp = y;
} else if (y <= 4.2e-18) {
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 <= (-5.5d-14)) then
tmp = y
else if (y <= 4.2d-18) 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 <= -5.5e-14) {
tmp = y;
} else if (y <= 4.2e-18) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e-14: tmp = y elif y <= 4.2e-18: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e-14) tmp = y; elseif (y <= 4.2e-18) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.5e-14) tmp = y; elseif (y <= 4.2e-18) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e-14], y, If[LessEqual[y, 4.2e-18], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-18}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.49999999999999991e-14 or 4.19999999999999999e-18 < y Initial program 74.2%
Taylor expanded in x around 0 52.6%
if -5.49999999999999991e-14 < y < 4.19999999999999999e-18Initial program 99.9%
Taylor expanded in y around 0 73.8%
(FPCore (x y z) :precision binary64 (if (<= y 0.0155) (+ y (/ x z)) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.0155) {
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 <= 0.0155d0) 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 <= 0.0155) {
tmp = y + (x / z);
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.0155: tmp = y + (x / z) else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.0155) 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 <= 0.0155) tmp = y + (x / z); else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.0155], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0155:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 0.0155Initial program 91.0%
Taylor expanded in y around 0 93.6%
Taylor expanded in x around 0 90.2%
if 0.0155 < y Initial program 75.0%
Taylor expanded in y around 0 86.6%
Taylor expanded in x around 0 47.4%
add-sqr-sqrt24.5%
sqrt-unprod54.1%
sqr-neg54.1%
sqrt-unprod28.0%
add-sqr-sqrt61.9%
distribute-frac-neg261.9%
sub-neg61.9%
Applied egg-rr61.9%
(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.8%
Taylor expanded in y around 0 91.8%
Taylor expanded in x around 0 78.8%
(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.8%
Taylor expanded in x around 0 41.1%
(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 2024170
(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))