
(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 10 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) (+ y -1.0))))
double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
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 + (-1.0d0)))
end function
public static double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
def code(x, y, z): return y - ((x / z) * (y + -1.0))
function code(x, y, z) return Float64(y - Float64(Float64(x / z) * Float64(y + -1.0))) end
function tmp = code(x, y, z) tmp = y - ((x / z) * (y + -1.0)); end
code[x_, y_, z_] := N[(y - N[(N[(x / z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - \frac{x}{z} \cdot \left(y + -1\right)
\end{array}
Initial program 88.6%
Taylor expanded in x around -inf 96.3%
mul-1-neg96.3%
unsub-neg96.3%
associate-/l*97.7%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.3e+46) (not (<= x 3.2e+30))) (* x (/ (- 1.0 y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.3e+46) || !(x <= 3.2e+30)) {
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 <= (-8.3d+46)) .or. (.not. (x <= 3.2d+30))) 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 <= -8.3e+46) || !(x <= 3.2e+30)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.3e+46) or not (x <= 3.2e+30): tmp = x * ((1.0 - y) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.3e+46) || !(x <= 3.2e+30)) 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 <= -8.3e+46) || ~((x <= 3.2e+30))) tmp = x * ((1.0 - y) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.3e+46], N[Not[LessEqual[x, 3.2e+30]], $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 -8.3 \cdot 10^{+46} \lor \neg \left(x \leq 3.2 \cdot 10^{+30}\right):\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -8.29999999999999951e46 or 3.19999999999999973e30 < x Initial program 92.9%
Taylor expanded in x around -inf 92.9%
mul-1-neg92.9%
unsub-neg92.9%
associate-/l*99.9%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 91.7%
div-sub91.7%
Simplified91.7%
if -8.29999999999999951e46 < x < 3.19999999999999973e30Initial program 84.7%
Taylor expanded in z around inf 75.9%
Taylor expanded in x around 0 91.1%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.15e+46) (not (<= x 2.7e+28))) (* (/ x z) (- 1.0 y)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.15e+46) || !(x <= 2.7e+28)) {
tmp = (x / z) * (1.0 - 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 ((x <= (-4.15d+46)) .or. (.not. (x <= 2.7d+28))) then
tmp = (x / z) * (1.0d0 - 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 ((x <= -4.15e+46) || !(x <= 2.7e+28)) {
tmp = (x / z) * (1.0 - y);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.15e+46) or not (x <= 2.7e+28): tmp = (x / z) * (1.0 - y) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.15e+46) || !(x <= 2.7e+28)) tmp = Float64(Float64(x / z) * Float64(1.0 - y)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.15e+46) || ~((x <= 2.7e+28))) tmp = (x / z) * (1.0 - y); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.15e+46], N[Not[LessEqual[x, 2.7e+28]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.15 \cdot 10^{+46} \lor \neg \left(x \leq 2.7 \cdot 10^{+28}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -4.14999999999999976e46 or 2.7000000000000002e28 < x Initial program 92.9%
Taylor expanded in x around inf 87.5%
associate-/l*91.8%
associate-/r/91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
if -4.14999999999999976e46 < x < 2.7000000000000002e28Initial program 84.7%
Taylor expanded in z around inf 75.9%
Taylor expanded in x around 0 91.1%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.22e-5))) (* (/ y z) (- z x)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.22e-5)) {
tmp = (y / z) * (z - x);
} 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.22d-5))) then
tmp = (y / z) * (z - x)
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.22e-5)) {
tmp = (y / z) * (z - x);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.22e-5): tmp = (y / z) * (z - x) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.22e-5)) tmp = Float64(Float64(y / z) * Float64(z - x)); 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.22e-5))) tmp = (y / z) * (z - x); 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.22e-5]], $MachinePrecision]], N[(N[(y / z), $MachinePrecision] * N[(z - x), $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.22 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{y}{z} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1.22000000000000001e-5 < y Initial program 77.1%
Taylor expanded in y around inf 76.4%
associate-/l*99.1%
associate-/r/94.7%
Simplified94.7%
if -1 < y < 1.22000000000000001e-5Initial program 99.9%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around 0 99.6%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.22e-5))) (- y (* y (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.22e-5)) {
tmp = y - (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 ((y <= (-1.0d0)) .or. (.not. (y <= 1.22d-5))) then
tmp = y - (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 ((y <= -1.0) || !(y <= 1.22e-5)) {
tmp = y - (y * (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.22e-5): tmp = y - (y * (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.22e-5)) tmp = Float64(y - Float64(y * 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.22e-5))) tmp = y - (y * (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.22e-5]], $MachinePrecision]], N[(y - N[(y * 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.22 \cdot 10^{-5}\right):\\
\;\;\;\;y - y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1.22000000000000001e-5 < y Initial program 77.1%
Taylor expanded in x around -inf 92.5%
mul-1-neg92.5%
unsub-neg92.5%
associate-/l*95.4%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 91.7%
associate-*l/99.2%
*-commutative99.2%
Simplified99.2%
if -1 < y < 1.22000000000000001e-5Initial program 99.9%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around 0 99.6%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e+54) (not (<= x 9000000000000.0))) (/ x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e+54) || !(x <= 9000000000000.0)) {
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 <= (-1.3d+54)) .or. (.not. (x <= 9000000000000.0d0))) 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 <= -1.3e+54) || !(x <= 9000000000000.0)) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e+54) or not (x <= 9000000000000.0): tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e+54) || !(x <= 9000000000000.0)) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.3e+54) || ~((x <= 9000000000000.0))) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e+54], N[Not[LessEqual[x, 9000000000000.0]], $MachinePrecision]], N[(x / z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+54} \lor \neg \left(x \leq 9000000000000\right):\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.30000000000000003e54 or 9e12 < x Initial program 92.2%
Taylor expanded in y around 0 58.2%
if -1.30000000000000003e54 < x < 9e12Initial program 85.4%
Taylor expanded in x around 0 71.7%
Final simplification65.3%
(FPCore (x y z) :precision binary64 (if (<= x 3.1e+99) (+ y (/ x z)) (* y (/ (- x) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.1e+99) {
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 (x <= 3.1d+99) 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 (x <= 3.1e+99) {
tmp = y + (x / z);
} else {
tmp = y * (-x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.1e+99: tmp = y + (x / z) else: tmp = y * (-x / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.1e+99) 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 (x <= 3.1e+99) tmp = y + (x / z); else tmp = y * (-x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.1e+99], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[((-x) / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1 \cdot 10^{+99}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{-x}{z}\\
\end{array}
\end{array}
if x < 3.1000000000000001e99Initial program 87.7%
Taylor expanded in z around inf 75.3%
Taylor expanded in x around 0 85.7%
if 3.1000000000000001e99 < x Initial program 92.2%
Taylor expanded in x around inf 92.2%
associate-/l*97.3%
associate-/r/97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
Taylor expanded in y around inf 55.5%
mul-1-neg55.5%
associate-*l/66.3%
distribute-rgt-neg-out66.3%
Simplified66.3%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (<= y 1.22e-5) (+ y (/ x z)) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.22e-5) {
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 (y <= 1.22d-5) 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 (y <= 1.22e-5) {
tmp = y + (x / z);
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.22e-5: tmp = y + (x / z) else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.22e-5) tmp = Float64(y + 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.22e-5) tmp = y + (x / z); else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.22e-5], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.22 \cdot 10^{-5}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 1.22000000000000001e-5Initial program 93.9%
Taylor expanded in z around inf 84.8%
Taylor expanded in x around 0 88.9%
if 1.22000000000000001e-5 < y Initial program 74.5%
Taylor expanded in z around inf 32.5%
Taylor expanded in x around 0 52.6%
add-sqr-sqrt18.8%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod38.8%
add-sqr-sqrt62.8%
distribute-frac-neg62.8%
sub-neg62.8%
Applied egg-rr62.8%
Final simplification81.8%
(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.6%
Taylor expanded in z around inf 70.5%
Taylor expanded in x around 0 79.0%
Final simplification79.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 88.6%
Taylor expanded in x around 0 42.7%
Final simplification42.7%
(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 2024034
(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))