
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (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 = (x * y) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (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 = (x * y) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (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 = z + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 97.3%
+-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.2%
*-lft-identity97.2%
associate-+l+97.3%
+-commutative97.3%
*-commutative97.3%
neg-mul-197.3%
associate-*r*97.3%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -8.6e-58)
(* y x)
(if (<= y 1.3e-14)
z
(if (<= y 2.75e+59)
(* y x)
(if (or (<= y 6e+147) (and (not (<= y 2.8e+239)) (<= y 3.95e+300)))
(* z (- y))
(* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e-58) {
tmp = y * x;
} else if (y <= 1.3e-14) {
tmp = z;
} else if (y <= 2.75e+59) {
tmp = y * x;
} else if ((y <= 6e+147) || (!(y <= 2.8e+239) && (y <= 3.95e+300))) {
tmp = z * -y;
} else {
tmp = y * x;
}
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.6d-58)) then
tmp = y * x
else if (y <= 1.3d-14) then
tmp = z
else if (y <= 2.75d+59) then
tmp = y * x
else if ((y <= 6d+147) .or. (.not. (y <= 2.8d+239)) .and. (y <= 3.95d+300)) then
tmp = z * -y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e-58) {
tmp = y * x;
} else if (y <= 1.3e-14) {
tmp = z;
} else if (y <= 2.75e+59) {
tmp = y * x;
} else if ((y <= 6e+147) || (!(y <= 2.8e+239) && (y <= 3.95e+300))) {
tmp = z * -y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.6e-58: tmp = y * x elif y <= 1.3e-14: tmp = z elif y <= 2.75e+59: tmp = y * x elif (y <= 6e+147) or (not (y <= 2.8e+239) and (y <= 3.95e+300)): tmp = z * -y else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.6e-58) tmp = Float64(y * x); elseif (y <= 1.3e-14) tmp = z; elseif (y <= 2.75e+59) tmp = Float64(y * x); elseif ((y <= 6e+147) || (!(y <= 2.8e+239) && (y <= 3.95e+300))) tmp = Float64(z * Float64(-y)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.6e-58) tmp = y * x; elseif (y <= 1.3e-14) tmp = z; elseif (y <= 2.75e+59) tmp = y * x; elseif ((y <= 6e+147) || (~((y <= 2.8e+239)) && (y <= 3.95e+300))) tmp = z * -y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.6e-58], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.3e-14], z, If[LessEqual[y, 2.75e+59], N[(y * x), $MachinePrecision], If[Or[LessEqual[y, 6e+147], And[N[Not[LessEqual[y, 2.8e+239]], $MachinePrecision], LessEqual[y, 3.95e+300]]], N[(z * (-y)), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{-58}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+59}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+147} \lor \neg \left(y \leq 2.8 \cdot 10^{+239}\right) \land y \leq 3.95 \cdot 10^{+300}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.5999999999999999e-58 or 1.29999999999999998e-14 < y < 2.74999999999999995e59 or 5.99999999999999987e147 < y < 2.80000000000000002e239 or 3.95000000000000006e300 < y Initial program 97.6%
Taylor expanded in x around inf 64.0%
if -8.5999999999999999e-58 < y < 1.29999999999999998e-14Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 2.74999999999999995e59 < y < 5.99999999999999987e147 or 2.80000000000000002e239 < y < 3.95000000000000006e300Initial program 86.2%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 66.2%
mul-1-neg66.2%
*-commutative66.2%
distribute-rgt-neg-in66.2%
Simplified66.2%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.3e-55) (not (<= y 9.8e-14))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e-55) || !(y <= 9.8e-14)) {
tmp = y * (x - z);
} else {
tmp = 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.3d-55)) .or. (.not. (y <= 9.8d-14))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e-55) || !(y <= 9.8e-14)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.3e-55) or not (y <= 9.8e-14): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.3e-55) || !(y <= 9.8e-14)) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.3e-55) || ~((y <= 9.8e-14))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.3e-55], N[Not[LessEqual[y, 9.8e-14]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-55} \lor \neg \left(y \leq 9.8 \cdot 10^{-14}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.2999999999999999e-55 or 9.79999999999999989e-14 < y Initial program 95.4%
Taylor expanded in y around inf 96.2%
mul-1-neg96.2%
+-commutative96.2%
sub-neg96.2%
Simplified96.2%
if -3.2999999999999999e-55 < y < 9.79999999999999989e-14Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 5e-13))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 5e-13)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
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 <= 5d-13))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 5e-13)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 5e-13): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 5e-13)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 5e-13))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 5e-13]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 4.9999999999999999e-13 < y Initial program 95.2%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
+-commutative98.4%
sub-neg98.4%
Simplified98.4%
if -1 < y < 4.9999999999999999e-13Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 99.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -4.3e-57) (* y x) (if (<= y 4e-14) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.3e-57) {
tmp = y * x;
} else if (y <= 4e-14) {
tmp = z;
} else {
tmp = y * x;
}
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 <= (-4.3d-57)) then
tmp = y * x
else if (y <= 4d-14) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.3e-57) {
tmp = y * x;
} else if (y <= 4e-14) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.3e-57: tmp = y * x elif y <= 4e-14: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.3e-57) tmp = Float64(y * x); elseif (y <= 4e-14) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.3e-57) tmp = y * x; elseif (y <= 4e-14) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.3e-57], N[(y * x), $MachinePrecision], If[LessEqual[y, 4e-14], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-57}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.30000000000000022e-57 or 4e-14 < y Initial program 95.4%
Taylor expanded in x around inf 58.2%
if -4.30000000000000022e-57 < y < 4e-14Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification64.6%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 97.3%
Taylor expanded in y around 0 32.5%
Final simplification32.5%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - x) * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2023207
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))