
(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 (<= y -7.0) (not (<= y 19000000000000.0))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.0) || !(y <= 19000000000000.0)) {
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 <= (-7.0d0)) .or. (.not. (y <= 19000000000000.0d0))) 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 <= -7.0) || !(y <= 19000000000000.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.0) or not (y <= 19000000000000.0): 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 <= -7.0) || !(y <= 19000000000000.0)) 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 <= -7.0) || ~((y <= 19000000000000.0))) 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, -7.0], N[Not[LessEqual[y, 19000000000000.0]], $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 -7 \lor \neg \left(y \leq 19000000000000\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 < -7 or 1.9e13 < y Initial program 71.5%
Taylor expanded in y around inf 71.5%
associate-/l*99.8%
div-sub99.8%
*-inverses99.8%
Simplified99.8%
if -7 < y < 1.9e13Initial program 100.0%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e+23) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e+23) || !(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 <= (-8d+23)) .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 <= -8e+23) || !(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 <= -8e+23) 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 <= -8e+23) || !(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 <= -8e+23) || ~((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, -8e+23], 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 -8 \cdot 10^{+23} \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 < -7.9999999999999993e23 or 1 < y Initial program 71.1%
Taylor expanded in y around inf 70.8%
associate-/l*99.5%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
if -7.9999999999999993e23 < y < 1Initial program 100.0%
Taylor expanded in y around 0 94.4%
Taylor expanded in x around 0 97.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.1e-50) (not (<= z 3e-51))) (+ y (/ x z)) (* x (/ (- 1.0 y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e-50) || !(z <= 3e-51)) {
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 <= (-4.1d-50)) .or. (.not. (z <= 3d-51))) 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 <= -4.1e-50) || !(z <= 3e-51)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.1e-50) or not (z <= 3e-51): tmp = y + (x / z) else: tmp = x * ((1.0 - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.1e-50) || !(z <= 3e-51)) 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 <= -4.1e-50) || ~((z <= 3e-51))) tmp = y + (x / z); else tmp = x * ((1.0 - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.1e-50], N[Not[LessEqual[z, 3e-51]], $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 -4.1 \cdot 10^{-50} \lor \neg \left(z \leq 3 \cdot 10^{-51}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\end{array}
\end{array}
if z < -4.09999999999999985e-50 or 3.00000000000000002e-51 < z Initial program 73.9%
Taylor expanded in y around 0 99.2%
Taylor expanded in x around 0 87.2%
if -4.09999999999999985e-50 < z < 3.00000000000000002e-51Initial program 99.9%
Taylor expanded in x around inf 89.1%
associate-/l*84.2%
mul-1-neg84.2%
unsub-neg84.2%
Simplified84.2%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (<= x 4.5e+103) (+ (/ x z) (* y (- 1.0 (/ x z)))) (* x (+ (/ (- 1.0 y) z) (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 4.5e+103) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = x * (((1.0 - y) / z) + (y / 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 (x <= 4.5d+103) then
tmp = (x / z) + (y * (1.0d0 - (x / z)))
else
tmp = x * (((1.0d0 - y) / z) + (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 4.5e+103) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = x * (((1.0 - y) / z) + (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 4.5e+103: tmp = (x / z) + (y * (1.0 - (x / z))) else: tmp = x * (((1.0 - y) / z) + (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 4.5e+103) tmp = Float64(Float64(x / z) + Float64(y * Float64(1.0 - Float64(x / z)))); else tmp = Float64(x * Float64(Float64(Float64(1.0 - y) / z) + Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 4.5e+103) tmp = (x / z) + (y * (1.0 - (x / z))); else tmp = x * (((1.0 - y) / z) + (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 4.5e+103], N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision] + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.5 \cdot 10^{+103}:\\
\;\;\;\;\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\frac{1 - y}{z} + \frac{y}{x}\right)\\
\end{array}
\end{array}
if x < 4.50000000000000001e103Initial program 86.4%
Taylor expanded in y around 0 99.0%
if 4.50000000000000001e103 < x Initial program 79.3%
Taylor expanded in x around inf 99.8%
associate-+r+99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
div-sub99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-9) (not (<= y 7.5e-21))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-9) || !(y <= 7.5e-21)) {
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-9)) .or. (.not. (y <= 7.5d-21))) 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-9) || !(y <= 7.5e-21)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e-9) or not (y <= 7.5e-21): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-9) || !(y <= 7.5e-21)) 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-9) || ~((y <= 7.5e-21))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-9], N[Not[LessEqual[y, 7.5e-21]], $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^{-9} \lor \neg \left(y \leq 7.5 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -9.5000000000000007e-9 or 7.50000000000000072e-21 < y Initial program 74.1%
Taylor expanded in z around inf 37.1%
Taylor expanded in x around 0 30.4%
*-commutative30.4%
associate-/l*58.0%
Applied egg-rr58.0%
if -9.5000000000000007e-9 < y < 7.50000000000000072e-21Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (if (<= y -3e-8) y (if (<= y 5.1e-14) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e-8) {
tmp = y;
} else if (y <= 5.1e-14) {
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 <= (-3d-8)) then
tmp = y
else if (y <= 5.1d-14) 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 <= -3e-8) {
tmp = y;
} else if (y <= 5.1e-14) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e-8: tmp = y elif y <= 5.1e-14: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e-8) tmp = y; elseif (y <= 5.1e-14) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e-8) tmp = y; elseif (y <= 5.1e-14) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e-8], y, If[LessEqual[y, 5.1e-14], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-8}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.99999999999999973e-8 or 5.0999999999999997e-14 < y Initial program 74.1%
Taylor expanded in x around 0 53.3%
if -2.99999999999999973e-8 < y < 5.0999999999999997e-14Initial program 100.0%
Taylor expanded in y around 0 76.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 85.3%
Taylor expanded in y around 0 96.0%
Taylor expanded in x around 0 77.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 85.3%
Taylor expanded in x around 0 41.4%
(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 2024089
(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))