
(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 -115500000.0) (not (<= y 5.3e+14))) (/ y (/ z (- z x))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -115500000.0) || !(y <= 5.3e+14)) {
tmp = y / (z / (z - x));
} 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 <= (-115500000.0d0)) .or. (.not. (y <= 5.3d+14))) then
tmp = y / (z / (z - x))
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 <= -115500000.0) || !(y <= 5.3e+14)) {
tmp = y / (z / (z - x));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -115500000.0) or not (y <= 5.3e+14): tmp = y / (z / (z - x)) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -115500000.0) || !(y <= 5.3e+14)) tmp = Float64(y / Float64(z / Float64(z - x))); 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 <= -115500000.0) || ~((y <= 5.3e+14))) tmp = y / (z / (z - x)); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -115500000.0], N[Not[LessEqual[y, 5.3e+14]], $MachinePrecision]], N[(y / N[(z / N[(z - x), $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 -115500000 \lor \neg \left(y \leq 5.3 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -1.155e8 or 5.3e14 < y Initial program 66.8%
Taylor expanded in y around inf 66.6%
associate-/l*99.4%
Simplified99.4%
if -1.155e8 < y < 5.3e14Initial program 99.9%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= y 5e+16) (+ (/ x z) (* y (- 1.0 (/ x z)))) (/ y (/ z (- z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 5e+16) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = y / (z / (z - x));
}
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 <= 5d+16) then
tmp = (x / z) + (y * (1.0d0 - (x / z)))
else
tmp = y / (z / (z - x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 5e+16) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = y / (z / (z - x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 5e+16: tmp = (x / z) + (y * (1.0 - (x / z))) else: tmp = y / (z / (z - x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 5e+16) tmp = Float64(Float64(x / z) + Float64(y * Float64(1.0 - Float64(x / z)))); else tmp = Float64(y / Float64(z / Float64(z - x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 5e+16) tmp = (x / z) + (y * (1.0 - (x / z))); else tmp = y / (z / (z - x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 5e+16], N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{+16}:\\
\;\;\;\;\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\end{array}
\end{array}
if y < 5e16Initial program 91.8%
Taylor expanded in y around 0 98.3%
if 5e16 < y Initial program 60.9%
Taylor expanded in y around inf 60.9%
associate-/l*99.9%
Simplified99.9%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-61) (not (<= z 3.2e-13))) (+ y (/ x z)) (* (/ x z) (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-61) || !(z <= 3.2e-13)) {
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 ((z <= (-1.75d-61)) .or. (.not. (z <= 3.2d-13))) 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 ((z <= -1.75e-61) || !(z <= 3.2e-13)) {
tmp = y + (x / z);
} else {
tmp = (x / z) * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.75e-61) or not (z <= 3.2e-13): tmp = y + (x / z) else: tmp = (x / z) * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-61) || !(z <= 3.2e-13)) 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 ((z <= -1.75e-61) || ~((z <= 3.2e-13))) tmp = y + (x / z); else tmp = (x / z) * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.75e-61], N[Not[LessEqual[z, 3.2e-13]], $MachinePrecision]], 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}\;z \leq -1.75 \cdot 10^{-61} \lor \neg \left(z \leq 3.2 \cdot 10^{-13}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.7500000000000002e-61 or 3.2e-13 < z Initial program 71.1%
Taylor expanded in y around 0 99.9%
flip--94.6%
associate-*l/93.4%
metadata-eval93.4%
pow293.4%
Applied egg-rr93.4%
Taylor expanded in x around 0 86.8%
if -1.7500000000000002e-61 < z < 3.2e-13Initial program 99.9%
Taylor expanded in x around inf 93.9%
*-commutative93.9%
associate-/l*87.1%
mul-1-neg87.1%
unsub-neg87.1%
Simplified87.1%
associate-/r/93.9%
Applied egg-rr93.9%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (/ y (/ z (- z x))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y / (z / (z - x));
} 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 <= 1.0d0))) then
tmp = y / (z / (z - x))
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 <= 1.0)) {
tmp = y / (z / (z - x));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y / (z / (z - x)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y / Float64(z / Float64(z - x))); 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 <= 1.0))) tmp = y / (z / (z - x)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y / N[(z / N[(z - x), $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 1\right):\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 68.0%
Taylor expanded in y around inf 67.1%
associate-/l*98.6%
Simplified98.6%
if -1 < y < 1Initial program 99.9%
Taylor expanded in y around 0 97.5%
flip--75.2%
associate-*l/75.2%
metadata-eval75.2%
pow275.2%
Applied egg-rr75.2%
Taylor expanded in x around 0 99.2%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-115) (not (<= z 1.82e-183))) (+ y (/ x z)) (* (/ x z) (- y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-115) || !(z <= 1.82e-183)) {
tmp = y + (x / z);
} 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 ((z <= (-1.75d-115)) .or. (.not. (z <= 1.82d-183))) then
tmp = y + (x / z)
else
tmp = (x / z) * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-115) || !(z <= 1.82e-183)) {
tmp = y + (x / z);
} else {
tmp = (x / z) * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.75e-115) or not (z <= 1.82e-183): tmp = y + (x / z) else: tmp = (x / z) * -y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-115) || !(z <= 1.82e-183)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(Float64(x / z) * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.75e-115) || ~((z <= 1.82e-183))) tmp = y + (x / z); else tmp = (x / z) * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.75e-115], N[Not[LessEqual[z, 1.82e-183]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-115} \lor \neg \left(z \leq 1.82 \cdot 10^{-183}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < -1.7500000000000001e-115 or 1.82e-183 < z Initial program 77.3%
Taylor expanded in y around 0 99.4%
flip--87.9%
associate-*l/85.9%
metadata-eval85.9%
pow285.9%
Applied egg-rr85.9%
Taylor expanded in x around 0 84.9%
if -1.7500000000000001e-115 < z < 1.82e-183Initial program 99.9%
Taylor expanded in x around inf 95.8%
+-commutative95.8%
distribute-rgt1-in95.8%
associate-*r*95.8%
mul-1-neg95.8%
unsub-neg95.8%
Simplified95.8%
Taylor expanded in y around inf 64.3%
mul-1-neg64.3%
distribute-rgt-neg-out64.3%
Simplified64.3%
div-inv64.2%
distribute-rgt-neg-out64.2%
remove-double-neg64.2%
distribute-rgt-neg-out64.2%
distribute-lft-neg-out64.2%
distribute-rgt-neg-out64.2%
remove-double-neg64.2%
associate-*r*65.5%
div-inv65.6%
Applied egg-rr65.6%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -15500000.0) (not (<= y 5e-28))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -15500000.0) || !(y <= 5e-28)) {
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 <= (-15500000.0d0)) .or. (.not. (y <= 5d-28))) 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 <= -15500000.0) || !(y <= 5e-28)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -15500000.0) or not (y <= 5e-28): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -15500000.0) || !(y <= 5e-28)) 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 <= -15500000.0) || ~((y <= 5e-28))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -15500000.0], N[Not[LessEqual[y, 5e-28]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15500000 \lor \neg \left(y \leq 5 \cdot 10^{-28}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -1.55e7 or 5.0000000000000002e-28 < y Initial program 68.5%
Taylor expanded in x around 0 25.3%
div-inv25.3%
*-commutative25.3%
associate-*l*56.6%
Applied egg-rr56.6%
associate-*r/56.8%
*-rgt-identity56.8%
Simplified56.8%
if -1.55e7 < y < 5.0000000000000002e-28Initial program 99.9%
Taylor expanded in y around 0 76.7%
Final simplification66.2%
(FPCore (x y z) :precision binary64 (if (<= y -15500000.0) y (if (<= y 1.85e-28) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -15500000.0) {
tmp = y;
} else if (y <= 1.85e-28) {
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 <= (-15500000.0d0)) then
tmp = y
else if (y <= 1.85d-28) 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 <= -15500000.0) {
tmp = y;
} else if (y <= 1.85e-28) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -15500000.0: tmp = y elif y <= 1.85e-28: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -15500000.0) tmp = y; elseif (y <= 1.85e-28) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -15500000.0) tmp = y; elseif (y <= 1.85e-28) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -15500000.0], y, If[LessEqual[y, 1.85e-28], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15500000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{-28}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.55e7 or 1.8500000000000001e-28 < y Initial program 68.5%
Taylor expanded in x around 0 50.4%
if -1.55e7 < y < 1.8500000000000001e-28Initial program 99.9%
Taylor expanded in y around 0 76.7%
Final simplification62.8%
(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 83.4%
Taylor expanded in y around 0 96.4%
flip--81.5%
associate-*l/79.0%
metadata-eval79.0%
pow279.0%
Applied egg-rr79.0%
Taylor expanded in x around 0 75.4%
Final simplification75.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 83.4%
Taylor expanded in x around 0 37.6%
Final simplification37.6%
(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 2023274
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:herbie-target
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))