
(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 (<= y -3.7e+56)
(* y (/ (- z x) z))
(if (<= y 1250000000000.0)
(/ (+ x (* y (- z x))) z)
(* y (- 1.0 (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e+56) {
tmp = y * ((z - x) / z);
} else if (y <= 1250000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y * (1.0 - (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 <= (-3.7d+56)) then
tmp = y * ((z - x) / z)
else if (y <= 1250000000000.0d0) then
tmp = (x + (y * (z - x))) / z
else
tmp = y * (1.0d0 - (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e+56) {
tmp = y * ((z - x) / z);
} else if (y <= 1250000000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.7e+56: tmp = y * ((z - x) / z) elif y <= 1250000000000.0: tmp = (x + (y * (z - x))) / z else: tmp = y * (1.0 - (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.7e+56) tmp = Float64(y * Float64(Float64(z - x) / z)); elseif (y <= 1250000000000.0) tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); else tmp = Float64(y * Float64(1.0 - Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.7e+56) tmp = y * ((z - x) / z); elseif (y <= 1250000000000.0) tmp = (x + (y * (z - x))) / z; else tmp = y * (1.0 - (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.7e+56], N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1250000000000.0], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+56}:\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{elif}\;y \leq 1250000000000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -3.69999999999999997e56Initial program 71.2%
Taylor expanded in y around inf 71.2%
associate-/l*99.9%
Simplified99.9%
if -3.69999999999999997e56 < y < 1.25e12Initial program 99.9%
if 1.25e12 < y Initial program 62.7%
Taylor expanded in y around inf 62.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 62.6%
associate-/l*99.8%
remove-double-neg99.8%
distribute-neg-frac299.8%
distribute-neg-frac99.8%
distribute-neg-frac299.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
div-sub99.8%
*-inverses99.8%
Simplified99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(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 <= (-1.0d0)) .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 <= -1.0) || !(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 <= -1.0) 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 <= -1.0) || !(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 <= -1.0) || ~((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, -1.0], 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 -1 \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 < -1 or 1 < y Initial program 70.8%
Taylor expanded in y around inf 68.6%
associate-/l*97.7%
Simplified97.7%
Taylor expanded in y around 0 68.6%
associate-/l*97.7%
remove-double-neg97.7%
distribute-neg-frac297.7%
distribute-neg-frac97.7%
distribute-neg-frac297.7%
distribute-frac-neg97.7%
remove-double-neg97.7%
div-sub97.7%
*-inverses97.7%
Simplified97.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 96.3%
Taylor expanded in x around 0 98.3%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.02e+47) (not (<= x 1.45e+83))) (* x (/ (- 1.0 y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e+47) || !(x <= 1.45e+83)) {
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 <= (-1.02d+47)) .or. (.not. (x <= 1.45d+83))) 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 <= -1.02e+47) || !(x <= 1.45e+83)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.02e+47) or not (x <= 1.45e+83): tmp = x * ((1.0 - y) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.02e+47) || !(x <= 1.45e+83)) 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 <= -1.02e+47) || ~((x <= 1.45e+83))) tmp = x * ((1.0 - y) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.02e+47], N[Not[LessEqual[x, 1.45e+83]], $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 -1.02 \cdot 10^{+47} \lor \neg \left(x \leq 1.45 \cdot 10^{+83}\right):\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -1.0199999999999999e47 or 1.45e83 < x Initial program 91.4%
Taylor expanded in x around inf 89.2%
associate-/l*90.1%
mul-1-neg90.1%
unsub-neg90.1%
Simplified90.1%
if -1.0199999999999999e47 < x < 1.45e83Initial program 83.2%
Taylor expanded in y around 0 99.4%
Taylor expanded in x around 0 88.2%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* y (/ (- z x) z)) (if (<= y 1.0) (+ y (/ x z)) (* y (- 1.0 (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * ((z - x) / z);
} else if (y <= 1.0) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (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)) then
tmp = y * ((z - x) / z)
else if (y <= 1.0d0) then
tmp = y + (x / z)
else
tmp = y * (1.0d0 - (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * ((z - x) / z);
} else if (y <= 1.0) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = y * ((z - x) / z) elif y <= 1.0: tmp = y + (x / z) else: tmp = y * (1.0 - (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(Float64(z - x) / z)); elseif (y <= 1.0) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(1.0 - Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = y * ((z - x) / z); elseif (y <= 1.0) tmp = y + (x / z); else tmp = y * (1.0 - (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \frac{z - x}{z}\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -1Initial program 75.6%
Taylor expanded in y around inf 74.4%
associate-/l*98.7%
Simplified98.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 96.3%
Taylor expanded in x around 0 98.3%
if 1 < y Initial program 65.2%
Taylor expanded in y around inf 62.0%
associate-/l*96.6%
Simplified96.6%
Taylor expanded in y around 0 62.0%
associate-/l*96.6%
remove-double-neg96.6%
distribute-neg-frac296.6%
distribute-neg-frac96.6%
distribute-neg-frac296.6%
distribute-frac-neg96.6%
remove-double-neg96.6%
div-sub96.6%
*-inverses96.6%
Simplified96.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-26) (not (<= y 1.06e-80))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-26) || !(y <= 1.06e-80)) {
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 <= (-2.5d-26)) .or. (.not. (y <= 1.06d-80))) 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 <= -2.5e-26) || !(y <= 1.06e-80)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-26) or not (y <= 1.06e-80): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-26) || !(y <= 1.06e-80)) 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 <= -2.5e-26) || ~((y <= 1.06e-80))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-26], N[Not[LessEqual[y, 1.06e-80]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-26} \lor \neg \left(y \leq 1.06 \cdot 10^{-80}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.5000000000000001e-26 or 1.0600000000000001e-80 < y Initial program 75.7%
Taylor expanded in z around inf 49.5%
Taylor expanded in x around 0 36.7%
*-commutative36.7%
associate-/l*60.0%
Applied egg-rr60.0%
if -2.5000000000000001e-26 < y < 1.0600000000000001e-80Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (<= y -3e-27) y (if (<= y 7.2e-81) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e-27) {
tmp = y;
} else if (y <= 7.2e-81) {
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-27)) then
tmp = y
else if (y <= 7.2d-81) 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-27) {
tmp = y;
} else if (y <= 7.2e-81) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e-27: tmp = y elif y <= 7.2e-81: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e-27) tmp = y; elseif (y <= 7.2e-81) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e-27) tmp = y; elseif (y <= 7.2e-81) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e-27], y, If[LessEqual[y, 7.2e-81], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-27}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-81}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.0000000000000001e-27 or 7.1999999999999997e-81 < y Initial program 75.7%
Taylor expanded in x around 0 57.8%
if -3.0000000000000001e-27 < y < 7.1999999999999997e-81Initial program 100.0%
Taylor expanded in y around 0 76.8%
(FPCore (x y z) :precision binary64 (+ (/ x z) (* y (- 1.0 (/ x z)))))
double code(double x, double y, double z) {
return (x / z) + (y * (1.0 - (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 / z) + (y * (1.0d0 - (x / z)))
end function
public static double code(double x, double y, double z) {
return (x / z) + (y * (1.0 - (x / z)));
}
def code(x, y, z): return (x / z) + (y * (1.0 - (x / z)))
function code(x, y, z) return Float64(Float64(x / z) + Float64(y * Float64(1.0 - Float64(x / z)))) end
function tmp = code(x, y, z) tmp = (x / z) + (y * (1.0 - (x / z))); end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right)
\end{array}
Initial program 86.0%
Taylor expanded in y around 0 97.2%
Final simplification97.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 86.0%
Taylor expanded in y around 0 97.2%
Taylor expanded in x around 0 83.1%
(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.0%
Taylor expanded in x around 0 44.0%
(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 2024084
(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))