
(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 7 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 -6.2e+14) (not (<= y 8.6e-5))) (* y (/ (- z x) z)) (+ (/ x z) (/ (* y (- z x)) z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e+14) || !(y <= 8.6e-5)) {
tmp = y * ((z - x) / z);
} else {
tmp = (x / z) + ((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 <= (-6.2d+14)) .or. (.not. (y <= 8.6d-5))) then
tmp = y * ((z - x) / z)
else
tmp = (x / z) + ((y * (z - x)) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e+14) || !(y <= 8.6e-5)) {
tmp = y * ((z - x) / z);
} else {
tmp = (x / z) + ((y * (z - x)) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e+14) or not (y <= 8.6e-5): tmp = y * ((z - x) / z) else: tmp = (x / z) + ((y * (z - x)) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e+14) || !(y <= 8.6e-5)) tmp = Float64(y * Float64(Float64(z - x) / z)); else tmp = Float64(Float64(x / z) + Float64(Float64(y * Float64(z - x)) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e+14) || ~((y <= 8.6e-5))) tmp = y * ((z - x) / z); else tmp = (x / z) + ((y * (z - x)) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e+14], N[Not[LessEqual[y, 8.6e-5]], $MachinePrecision]], N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+14} \lor \neg \left(y \leq 8.6 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} + \frac{y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -6.2e14 or 8.6000000000000003e-5 < y Initial program 78.9%
Taylor expanded in y around inf 78.9%
*-lft-identity78.9%
associate-*l/78.8%
*-commutative78.8%
associate-*l*99.8%
associate-*r/100.0%
*-rgt-identity100.0%
Simplified100.0%
if -6.2e14 < y < 8.6000000000000003e-5Initial program 99.9%
Taylor expanded in y around inf 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e+14) (not (<= y 9.5e+45))) (* y (/ (- z x) z)) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e+14) || !(y <= 9.5e+45)) {
tmp = y * ((z - 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 <= (-9d+14)) .or. (.not. (y <= 9.5d+45))) then
tmp = y * ((z - 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 <= -9e+14) || !(y <= 9.5e+45)) {
tmp = y * ((z - x) / z);
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e+14) or not (y <= 9.5e+45): tmp = y * ((z - x) / z) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e+14) || !(y <= 9.5e+45)) tmp = Float64(y * Float64(Float64(z - 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 <= -9e+14) || ~((y <= 9.5e+45))) tmp = y * ((z - x) / z); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e+14], N[Not[LessEqual[y, 9.5e+45]], $MachinePrecision]], N[(y * N[(N[(z - x), $MachinePrecision] / z), $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 -9 \cdot 10^{+14} \lor \neg \left(y \leq 9.5 \cdot 10^{+45}\right):\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -9e14 or 9.4999999999999998e45 < y Initial program 77.8%
Taylor expanded in y around inf 77.8%
*-lft-identity77.8%
associate-*l/77.7%
*-commutative77.7%
associate-*l*99.8%
associate-*r/100.0%
*-rgt-identity100.0%
Simplified100.0%
if -9e14 < y < 9.4999999999999998e45Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e+15) (not (<= y 8.6e-5))) (* y (/ (- z x) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e+15) || !(y <= 8.6e-5)) {
tmp = y * ((z - 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.1d+15)) .or. (.not. (y <= 8.6d-5))) then
tmp = y * ((z - 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.1e+15) || !(y <= 8.6e-5)) {
tmp = y * ((z - x) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e+15) or not (y <= 8.6e-5): tmp = y * ((z - x) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e+15) || !(y <= 8.6e-5)) tmp = Float64(y * Float64(Float64(z - 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.1e+15) || ~((y <= 8.6e-5))) tmp = y * ((z - x) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e+15], N[Not[LessEqual[y, 8.6e-5]], $MachinePrecision]], N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+15} \lor \neg \left(y \leq 8.6 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.1e15 or 8.6000000000000003e-5 < y Initial program 78.8%
Taylor expanded in y around inf 78.8%
*-lft-identity78.8%
associate-*l/78.7%
*-commutative78.7%
associate-*l*99.8%
associate-*r/100.0%
*-rgt-identity100.0%
Simplified100.0%
if -1.1e15 < y < 8.6000000000000003e-5Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in z around inf 98.8%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.8e-244) (not (<= z 1.3e-233))) (+ y (/ x z)) (* y (/ (- x) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-244) || !(z <= 1.3e-233)) {
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 ((z <= (-7.8d-244)) .or. (.not. (z <= 1.3d-233))) 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 ((z <= -7.8e-244) || !(z <= 1.3e-233)) {
tmp = y + (x / z);
} else {
tmp = y * (-x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.8e-244) or not (z <= 1.3e-233): tmp = y + (x / z) else: tmp = y * (-x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.8e-244) || !(z <= 1.3e-233)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(Float64(-x) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.8e-244) || ~((z <= 1.3e-233))) tmp = y + (x / z); else tmp = y * (-x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.8e-244], N[Not[LessEqual[z, 1.3e-233]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[((-x) / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-244} \lor \neg \left(z \leq 1.3 \cdot 10^{-233}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{-x}{z}\\
\end{array}
\end{array}
if z < -7.7999999999999998e-244 or 1.2999999999999999e-233 < z Initial program 87.6%
Taylor expanded in y around inf 86.3%
Taylor expanded in z around inf 82.7%
if -7.7999999999999998e-244 < z < 1.2999999999999999e-233Initial program 100.0%
Taylor expanded in y around inf 82.8%
*-lft-identity82.8%
associate-*l/82.8%
*-commutative82.8%
associate-*l*86.2%
associate-*r/86.2%
*-rgt-identity86.2%
Simplified86.2%
Taylor expanded in z around 0 82.6%
associate-*r/82.6%
mul-1-neg82.6%
Simplified82.6%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (<= x -5.2e-65) (/ x z) (if (<= x 2.05e-10) y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e-65) {
tmp = x / z;
} else if (x <= 2.05e-10) {
tmp = y;
} 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 (x <= (-5.2d-65)) then
tmp = x / z
else if (x <= 2.05d-10) then
tmp = y
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e-65) {
tmp = x / z;
} else if (x <= 2.05e-10) {
tmp = y;
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.2e-65: tmp = x / z elif x <= 2.05e-10: tmp = y else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.2e-65) tmp = Float64(x / z); elseif (x <= 2.05e-10) tmp = y; else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.2e-65) tmp = x / z; elseif (x <= 2.05e-10) tmp = y; else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.2e-65], N[(x / z), $MachinePrecision], If[LessEqual[x, 2.05e-10], y, N[(x / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-65}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-10}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if x < -5.20000000000000019e-65 or 2.0499999999999999e-10 < x Initial program 91.3%
Taylor expanded in y around 0 58.1%
if -5.20000000000000019e-65 < x < 2.0499999999999999e-10Initial program 86.0%
Taylor expanded in x around 0 69.7%
Final simplification63.3%
(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 88.9%
Taylor expanded in y around inf 86.6%
Taylor expanded in z around inf 80.3%
Final simplification80.3%
(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 88.9%
Taylor expanded in x around 0 43.4%
Final simplification43.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 2023297
(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))