
(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 6 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 (+ y (* (/ x z) (- 1.0 y))))
double code(double x, double y, double z) {
return y + ((x / z) * (1.0 - 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 + ((x / z) * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return y + ((x / z) * (1.0 - y));
}
def code(x, y, z): return y + ((x / z) * (1.0 - y))
function code(x, y, z) return Float64(y + Float64(Float64(x / z) * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = y + ((x / z) * (1.0 - y)); end
code[x_, y_, z_] := N[(y + N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \frac{x}{z} \cdot \left(1 - y\right)
\end{array}
Initial program 86.8%
Taylor expanded in x around 0 95.7%
Taylor expanded in y around -inf 93.7%
+-commutative93.7%
mul-1-neg93.7%
unsub-neg93.7%
sub-neg93.7%
metadata-eval93.7%
Simplified93.7%
Taylor expanded in x around 0 95.7%
div-sub95.8%
associate-*r/94.1%
associate-*l/99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.1e-11))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.1e-11)) {
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 <= (-1.0d0)) .or. (.not. (y <= 1.1d-11))) 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 <= -1.0) || !(y <= 1.1e-11)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.1e-11): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.1e-11)) 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 <= -1.0) || ~((y <= 1.1e-11))) tmp = y * (1.0 - (x / z)); 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.1e-11]], $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 -1 \lor \neg \left(y \leq 1.1 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1.1000000000000001e-11 < y Initial program 73.5%
Taylor expanded in x around 0 91.8%
Taylor expanded in y around inf 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
if -1 < y < 1.1000000000000001e-11Initial program 99.9%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around 0 99.3%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.52e-77) y (if (<= z 9e+67) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.52e-77) {
tmp = y;
} else if (z <= 9e+67) {
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 (z <= (-1.52d-77)) then
tmp = y
else if (z <= 9d+67) 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 (z <= -1.52e-77) {
tmp = y;
} else if (z <= 9e+67) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.52e-77: tmp = y elif z <= 9e+67: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.52e-77) tmp = y; elseif (z <= 9e+67) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.52e-77) tmp = y; elseif (z <= 9e+67) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.52e-77], y, If[LessEqual[z, 9e+67], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.52 \cdot 10^{-77}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+67}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -1.52e-77 or 8.9999999999999997e67 < z Initial program 75.0%
Taylor expanded in x around 0 67.5%
if -1.52e-77 < z < 8.9999999999999997e67Initial program 98.5%
Taylor expanded in y around 0 58.4%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (if (<= y -8.5e-75) (* z (/ y z)) (if (<= y 1e-11) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e-75) {
tmp = z * (y / z);
} else if (y <= 1e-11) {
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 <= (-8.5d-75)) then
tmp = z * (y / z)
else if (y <= 1d-11) 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 <= -8.5e-75) {
tmp = z * (y / z);
} else if (y <= 1e-11) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e-75: tmp = z * (y / z) elif y <= 1e-11: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e-75) tmp = Float64(z * Float64(y / z)); elseif (y <= 1e-11) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.5e-75) tmp = z * (y / z); elseif (y <= 1e-11) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e-75], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e-11], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-75}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 10^{-11}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -8.5000000000000001e-75Initial program 72.0%
Taylor expanded in y around inf 67.1%
Taylor expanded in z around inf 30.3%
associate-/l*52.0%
associate-/r/56.0%
Applied egg-rr56.0%
if -8.5000000000000001e-75 < y < 9.99999999999999939e-12Initial program 100.0%
Taylor expanded in y around 0 74.9%
if 9.99999999999999939e-12 < y Initial program 84.6%
Taylor expanded in x around 0 53.5%
Final simplification63.7%
(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 86.8%
Taylor expanded in x around 0 95.7%
Taylor expanded in y around 0 78.2%
Final simplification78.2%
(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 86.8%
Taylor expanded in x around 0 42.1%
Final simplification42.1%
(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 2024041
(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))