
(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 7 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 (fma y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 94.9%
distribute-lft-out--94.9%
*-rgt-identity94.9%
cancel-sign-sub-inv94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -5.6e+259) (* y (- z)) (if (or (<= y -1.02e-52) (not (<= y 5e-61))) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.6e+259) {
tmp = y * -z;
} else if ((y <= -1.02e-52) || !(y <= 5e-61)) {
tmp = y * x;
} 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 <= (-5.6d+259)) then
tmp = y * -z
else if ((y <= (-1.02d-52)) .or. (.not. (y <= 5d-61))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.6e+259) {
tmp = y * -z;
} else if ((y <= -1.02e-52) || !(y <= 5e-61)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.6e+259: tmp = y * -z elif (y <= -1.02e-52) or not (y <= 5e-61): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.6e+259) tmp = Float64(y * Float64(-z)); elseif ((y <= -1.02e-52) || !(y <= 5e-61)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.6e+259) tmp = y * -z; elseif ((y <= -1.02e-52) || ~((y <= 5e-61))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.6e+259], N[(y * (-z)), $MachinePrecision], If[Or[LessEqual[y, -1.02e-52], N[Not[LessEqual[y, 5e-61]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{+259}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq -1.02 \cdot 10^{-52} \lor \neg \left(y \leq 5 \cdot 10^{-61}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.6000000000000001e259Initial program 70.0%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
sub-neg99.8%
Simplified99.8%
Taylor expanded in x around 0 71.4%
associate-*r*71.4%
*-commutative71.4%
neg-mul-171.4%
Simplified71.4%
if -5.6000000000000001e259 < y < -1.02000000000000009e-52 or 4.9999999999999999e-61 < y Initial program 93.0%
Taylor expanded in x around inf 60.5%
*-commutative60.5%
Simplified60.5%
if -1.02000000000000009e-52 < y < 4.9999999999999999e-61Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.3e-52) (not (<= y 2.5e-57))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.3e-52) || !(y <= 2.5e-57)) {
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 <= (-1.3d-52)) .or. (.not. (y <= 2.5d-57))) 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 <= -1.3e-52) || !(y <= 2.5e-57)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.3e-52) or not (y <= 2.5e-57): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.3e-52) || !(y <= 2.5e-57)) 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 <= -1.3e-52) || ~((y <= 2.5e-57))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.3e-52], N[Not[LessEqual[y, 2.5e-57]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-52} \lor \neg \left(y \leq 2.5 \cdot 10^{-57}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.2999999999999999e-52 or 2.5000000000000001e-57 < y Initial program 91.5%
Taylor expanded in y around inf 92.9%
mul-1-neg92.9%
sub-neg92.9%
Simplified92.9%
if -1.2999999999999999e-52 < y < 2.5000000000000001e-57Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 89.9%
Taylor expanded in y around inf 98.5%
mul-1-neg98.5%
sub-neg98.5%
Simplified98.5%
if -1 < y < 1Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.3%
mul-1-neg99.3%
distribute-lft-neg-out99.3%
*-commutative99.3%
Simplified99.3%
*-commutative99.3%
cancel-sign-sub99.3%
*-commutative99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.2e-49) (not (<= y 8.2e-56))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-49) || !(y <= 8.2e-56)) {
tmp = y * x;
} 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.2d-49)) .or. (.not. (y <= 8.2d-56))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-49) || !(y <= 8.2e-56)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.2e-49) or not (y <= 8.2e-56): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.2e-49) || !(y <= 8.2e-56)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.2e-49) || ~((y <= 8.2e-56))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e-49], N[Not[LessEqual[y, 8.2e-56]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-49} \lor \neg \left(y \leq 8.2 \cdot 10^{-56}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.20000000000000002e-49 or 8.2000000000000003e-56 < y Initial program 91.5%
Taylor expanded in x around inf 58.2%
*-commutative58.2%
Simplified58.2%
if -3.20000000000000002e-49 < y < 8.2000000000000003e-56Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification65.4%
(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 94.9%
+-commutative94.9%
+-lft-identity94.9%
cancel-sign-sub94.9%
cancel-sign-sub94.9%
+-lft-identity94.9%
distribute-lft-out--94.9%
*-rgt-identity94.9%
associate-+l-94.9%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(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 94.9%
Taylor expanded in y around 0 34.8%
Final simplification34.8%
(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 2024053
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))