
(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 -2e-52) (not (<= z 2.5e+31))) (+ (/ x z) (* y (- 1.0 (/ x z)))) (/ (fma y (- z x) x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-52) || !(z <= 2.5e+31)) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = fma(y, (z - x), x) / z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2e-52) || !(z <= 2.5e+31)) tmp = Float64(Float64(x / z) + 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[z, -2e-52], N[Not[LessEqual[z, 2.5e+31]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-52} \lor \neg \left(z \leq 2.5 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{x}{z} + 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 z < -2e-52 or 2.50000000000000013e31 < z Initial program 82.2%
Taylor expanded in y around 0 99.9%
if -2e-52 < z < 2.50000000000000013e31Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e-55) (not (<= z 1.6e+31))) (+ (/ x z) (* y (- 1.0 (/ x z)))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-55) || !(z <= 1.6e+31)) {
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 <= (-2d-55)) .or. (.not. (z <= 1.6d+31))) 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 <= -2e-55) || !(z <= 1.6e+31)) {
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 <= -2e-55) or not (z <= 1.6e+31): 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 <= -2e-55) || !(z <= 1.6e+31)) 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 <= -2e-55) || ~((z <= 1.6e+31))) 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, -2e-55], N[Not[LessEqual[z, 1.6e+31]], $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 -2 \cdot 10^{-55} \lor \neg \left(z \leq 1.6 \cdot 10^{+31}\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 < -1.99999999999999999e-55 or 1.6e31 < z Initial program 82.2%
Taylor expanded in y around 0 99.9%
if -1.99999999999999999e-55 < z < 1.6e31Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.52e+29) (not (<= y 1.05e+16))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.52e+29) || !(y <= 1.05e+16)) {
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 <= (-1.52d+29)) .or. (.not. (y <= 1.05d+16))) 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 <= -1.52e+29) || !(y <= 1.05e+16)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.52e+29) or not (y <= 1.05e+16): 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 <= -1.52e+29) || !(y <= 1.05e+16)) 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 <= -1.52e+29) || ~((y <= 1.05e+16))) 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, -1.52e+29], N[Not[LessEqual[y, 1.05e+16]], $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 -1.52 \cdot 10^{+29} \lor \neg \left(y \leq 1.05 \cdot 10^{+16}\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 < -1.52e29 or 1.05e16 < y Initial program 80.4%
Taylor expanded in y around inf 80.4%
associate-/l*99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
if -1.52e29 < y < 1.05e16Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e+47) (not (<= x 1.7e+42))) (* x (/ (- 1.0 y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+47) || !(x <= 1.7e+42)) {
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 <= (-2.4d+47)) .or. (.not. (x <= 1.7d+42))) 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 <= -2.4e+47) || !(x <= 1.7e+42)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e+47) or not (x <= 1.7e+42): tmp = x * ((1.0 - y) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e+47) || !(x <= 1.7e+42)) 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 <= -2.4e+47) || ~((x <= 1.7e+42))) tmp = x * ((1.0 - y) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e+47], N[Not[LessEqual[x, 1.7e+42]], $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 -2.4 \cdot 10^{+47} \lor \neg \left(x \leq 1.7 \cdot 10^{+42}\right):\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -2.40000000000000019e47 or 1.69999999999999988e42 < x Initial program 89.5%
Taylor expanded in x around inf 86.5%
associate-/l*91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
if -2.40000000000000019e47 < x < 1.69999999999999988e42Initial program 91.0%
Taylor expanded in y around 0 99.3%
Taylor expanded in x around 0 90.1%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.1) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1) || !(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 <= (-3.1d0)) .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 <= -3.1) || !(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 <= -3.1) 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 <= -3.1) || !(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 <= -3.1) || ~((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, -3.1], 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 -3.1 \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 < -3.10000000000000009 or 1 < y Initial program 82.1%
Taylor expanded in y around inf 81.1%
associate-/l*98.9%
div-sub98.9%
*-inverses98.9%
Simplified98.9%
if -3.10000000000000009 < y < 1Initial program 99.9%
Taylor expanded in y around 0 94.9%
Taylor expanded in x around 0 99.4%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e+35) (not (<= x 8.5e+39))) (/ x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+35) || !(x <= 8.5e+39)) {
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 ((x <= (-8d+35)) .or. (.not. (x <= 8.5d+39))) 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 ((x <= -8e+35) || !(x <= 8.5e+39)) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e+35) or not (x <= 8.5e+39): tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e+35) || !(x <= 8.5e+39)) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e+35) || ~((x <= 8.5e+39))) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e+35], N[Not[LessEqual[x, 8.5e+39]], $MachinePrecision]], N[(x / z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+35} \lor \neg \left(x \leq 8.5 \cdot 10^{+39}\right):\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -7.9999999999999997e35 or 8.49999999999999971e39 < x Initial program 89.7%
Taylor expanded in y around 0 58.0%
if -7.9999999999999997e35 < x < 8.49999999999999971e39Initial program 90.9%
Taylor expanded in x around 0 70.2%
Final simplification65.0%
(FPCore (x y z) :precision binary64 (if (<= x -4.4e+244) (* x (/ (- y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e+244) {
tmp = x * (-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.4d+244)) then
tmp = x * (-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.4e+244) {
tmp = x * (-y / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.4e+244: tmp = x * (-y / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.4e+244) tmp = Float64(x * Float64(Float64(-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.4e+244) tmp = x * (-y / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.4e+244], N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+244}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -4.40000000000000003e244Initial program 93.5%
Taylor expanded in x around inf 93.5%
associate-/l*99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in y around inf 81.5%
neg-mul-181.5%
distribute-neg-frac81.5%
Simplified81.5%
if -4.40000000000000003e244 < x Initial program 90.2%
Taylor expanded in y around 0 95.8%
Taylor expanded in x around 0 81.5%
Final simplification81.5%
(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 90.4%
Taylor expanded in y around 0 95.3%
Taylor expanded in x around 0 79.5%
Final simplification79.5%
(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 90.4%
Taylor expanded in x around 0 44.5%
Final simplification44.5%
(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 2024059
(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))