
(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 -1.6e-165) (not (<= z 1e-136))) (+ (/ x z) (* (- 1.0 (/ x z)) y)) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e-165) || !(z <= 1e-136)) {
tmp = (x / z) + ((1.0 - (x / z)) * y);
} 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 <= (-1.6d-165)) .or. (.not. (z <= 1d-136))) then
tmp = (x / z) + ((1.0d0 - (x / z)) * y)
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 <= -1.6e-165) || !(z <= 1e-136)) {
tmp = (x / z) + ((1.0 - (x / z)) * y);
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.6e-165) or not (z <= 1e-136): tmp = (x / z) + ((1.0 - (x / z)) * y) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.6e-165) || !(z <= 1e-136)) tmp = Float64(Float64(x / z) + Float64(Float64(1.0 - Float64(x / z)) * y)); 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 <= -1.6e-165) || ~((z <= 1e-136))) tmp = (x / z) + ((1.0 - (x / z)) * y); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.6e-165], N[Not[LessEqual[z, 1e-136]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] + N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $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 -1.6 \cdot 10^{-165} \lor \neg \left(z \leq 10^{-136}\right):\\
\;\;\;\;\frac{x}{z} + \left(1 - \frac{x}{z}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -1.60000000000000006e-165 or 1e-136 < z Initial program 85.3%
Taylor expanded in y around 0 99.9%
if -1.60000000000000006e-165 < z < 1e-136Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -7000000000.0) (/ y (/ z (- z x))) (if (<= y 27000.0) (/ (+ x (* y (- z x))) z) (* (- 1.0 (/ x z)) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7000000000.0) {
tmp = y / (z / (z - x));
} else if (y <= 27000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = (1.0 - (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 (y <= (-7000000000.0d0)) then
tmp = y / (z / (z - x))
else if (y <= 27000.0d0) then
tmp = (x + (y * (z - x))) / z
else
tmp = (1.0d0 - (x / z)) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7000000000.0) {
tmp = y / (z / (z - x));
} else if (y <= 27000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = (1.0 - (x / z)) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7000000000.0: tmp = y / (z / (z - x)) elif y <= 27000.0: tmp = (x + (y * (z - x))) / z else: tmp = (1.0 - (x / z)) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7000000000.0) tmp = Float64(y / Float64(z / Float64(z - x))); elseif (y <= 27000.0) tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); else tmp = Float64(Float64(1.0 - Float64(x / z)) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7000000000.0) tmp = y / (z / (z - x)); elseif (y <= 27000.0) tmp = (x + (y * (z - x))) / z; else tmp = (1.0 - (x / z)) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7000000000.0], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 27000.0], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7000000000:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{elif}\;y \leq 27000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\
\end{array}
\end{array}
if y < -7e9Initial program 79.8%
Taylor expanded in y around inf 79.8%
associate-/l*99.9%
Simplified99.9%
if -7e9 < y < 27000Initial program 100.0%
if 27000 < y Initial program 78.1%
Taylor expanded in y around 0 94.1%
Taylor expanded in y around inf 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -440000000000.0) (not (<= y 1.55e-14))) (* (- 1.0 (/ x z)) y) (+ (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -440000000000.0) || !(y <= 1.55e-14)) {
tmp = (1.0 - (x / z)) * y;
} 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 ((y <= (-440000000000.0d0)) .or. (.not. (y <= 1.55d-14))) then
tmp = (1.0d0 - (x / z)) * y
else
tmp = (x / z) + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -440000000000.0) || !(y <= 1.55e-14)) {
tmp = (1.0 - (x / z)) * y;
} else {
tmp = (x / z) + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -440000000000.0) or not (y <= 1.55e-14): tmp = (1.0 - (x / z)) * y else: tmp = (x / z) + y return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -440000000000.0) || !(y <= 1.55e-14)) tmp = Float64(Float64(1.0 - Float64(x / z)) * y); else tmp = Float64(Float64(x / z) + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -440000000000.0) || ~((y <= 1.55e-14))) tmp = (1.0 - (x / z)) * y; else tmp = (x / z) + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -440000000000.0], N[Not[LessEqual[y, 1.55e-14]], $MachinePrecision]], N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -440000000000 \lor \neg \left(y \leq 1.55 \cdot 10^{-14}\right):\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} + y\\
\end{array}
\end{array}
if y < -4.4e11 or 1.55000000000000002e-14 < y Initial program 79.7%
Taylor expanded in y around 0 96.2%
Taylor expanded in y around inf 99.5%
if -4.4e11 < y < 1.55000000000000002e-14Initial program 100.0%
Taylor expanded in y around 0 91.8%
Taylor expanded in x around 0 99.3%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= y -440000000000.0) (/ y (/ z (- z x))) (if (<= y 1.55e-14) (+ (/ x z) y) (* (- 1.0 (/ x z)) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -440000000000.0) {
tmp = y / (z / (z - x));
} else if (y <= 1.55e-14) {
tmp = (x / z) + y;
} else {
tmp = (1.0 - (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 (y <= (-440000000000.0d0)) then
tmp = y / (z / (z - x))
else if (y <= 1.55d-14) then
tmp = (x / z) + y
else
tmp = (1.0d0 - (x / z)) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -440000000000.0) {
tmp = y / (z / (z - x));
} else if (y <= 1.55e-14) {
tmp = (x / z) + y;
} else {
tmp = (1.0 - (x / z)) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -440000000000.0: tmp = y / (z / (z - x)) elif y <= 1.55e-14: tmp = (x / z) + y else: tmp = (1.0 - (x / z)) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -440000000000.0) tmp = Float64(y / Float64(z / Float64(z - x))); elseif (y <= 1.55e-14) tmp = Float64(Float64(x / z) + y); else tmp = Float64(Float64(1.0 - Float64(x / z)) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -440000000000.0) tmp = y / (z / (z - x)); elseif (y <= 1.55e-14) tmp = (x / z) + y; else tmp = (1.0 - (x / z)) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -440000000000.0], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.55e-14], N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision], N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -440000000000:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{z} + y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\
\end{array}
\end{array}
if y < -4.4e11Initial program 79.1%
Taylor expanded in y around inf 79.1%
associate-/l*99.9%
Simplified99.9%
if -4.4e11 < y < 1.55000000000000002e-14Initial program 100.0%
Taylor expanded in y around 0 91.8%
Taylor expanded in x around 0 99.3%
if 1.55000000000000002e-14 < y Initial program 80.1%
Taylor expanded in y around 0 93.3%
Taylor expanded in y around inf 99.1%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= y -3.0) y (if (<= y 1.7e-16) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.0) {
tmp = y;
} else if (y <= 1.7e-16) {
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 <= (-3.0d0)) then
tmp = y
else if (y <= 1.7d-16) 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 <= -3.0) {
tmp = y;
} else if (y <= 1.7e-16) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.0: tmp = y elif y <= 1.7e-16: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.0) tmp = y; elseif (y <= 1.7e-16) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.0) tmp = y; elseif (y <= 1.7e-16) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.0], y, If[LessEqual[y, 1.7e-16], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-16}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3 or 1.7e-16 < y Initial program 80.0%
Taylor expanded in x around 0 57.8%
if -3 < y < 1.7e-16Initial program 100.0%
Taylor expanded in y around 0 80.9%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (if (<= y -3.0) (* z (/ y z)) (if (<= y 1.75e-17) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.0) {
tmp = z * (y / z);
} else if (y <= 1.75e-17) {
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 <= (-3.0d0)) then
tmp = z * (y / z)
else if (y <= 1.75d-17) 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 <= -3.0) {
tmp = z * (y / z);
} else if (y <= 1.75e-17) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.0: tmp = z * (y / z) elif y <= 1.75e-17: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.0) tmp = Float64(z * Float64(y / z)); elseif (y <= 1.75e-17) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.0) tmp = z * (y / z); elseif (y <= 1.75e-17) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.0], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.75e-17], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-17}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3Initial program 79.8%
Taylor expanded in y around inf 79.8%
Taylor expanded in z around inf 39.7%
associate-/l*55.3%
associate-/r/58.2%
Applied egg-rr58.2%
if -3 < y < 1.7500000000000001e-17Initial program 100.0%
Taylor expanded in y around 0 80.9%
if 1.7500000000000001e-17 < y Initial program 80.1%
Taylor expanded in x around 0 59.7%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (if (<= y 1.55e-14) (+ (/ x z) y) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.55e-14) {
tmp = (x / z) + y;
} 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.55d-14) then
tmp = (x / z) + y
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.55e-14) {
tmp = (x / z) + y;
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.55e-14: tmp = (x / z) + y else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.55e-14) tmp = Float64(Float64(x / z) + y); else tmp = Float64(y - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.55e-14) tmp = (x / z) + y; else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.55e-14], N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.55 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{z} + y\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 1.55000000000000002e-14Initial program 93.2%
Taylor expanded in y around 0 94.4%
Taylor expanded in x around 0 88.6%
if 1.55000000000000002e-14 < y Initial program 80.1%
Taylor expanded in y around 0 93.3%
Taylor expanded in x around 0 59.2%
div-inv59.2%
add-sqr-sqrt26.8%
sqrt-unprod62.2%
sqr-neg62.2%
sqrt-unprod37.0%
add-sqr-sqrt67.1%
cancel-sign-sub-inv67.1%
div-inv67.1%
Applied egg-rr67.1%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (+ (/ x z) y))
double code(double x, double y, double z) {
return (x / z) + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / z) + y
end function
public static double code(double x, double y, double z) {
return (x / z) + y;
}
def code(x, y, z): return (x / z) + y
function code(x, y, z) return Float64(Float64(x / z) + y) end
function tmp = code(x, y, z) tmp = (x / z) + y; end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z} + y
\end{array}
Initial program 89.3%
Taylor expanded in y around 0 94.1%
Taylor expanded in x around 0 79.9%
Final simplification79.9%
(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 89.3%
Taylor expanded in x around 0 40.6%
Final simplification40.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 2023268
(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))