
(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}
(FPCore (x y z)
:precision binary64
(if (<= y -1.4e-47)
(* y x)
(if (<= y 9.5e-135)
z
(if (or (<= y 1.06e+26)
(and (not (<= y 2.25e+95))
(or (<= y 1.1e+140) (not (<= y 3.5e+214)))))
(* y x)
(* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-47) {
tmp = y * x;
} else if (y <= 9.5e-135) {
tmp = z;
} else if ((y <= 1.06e+26) || (!(y <= 2.25e+95) && ((y <= 1.1e+140) || !(y <= 3.5e+214)))) {
tmp = y * x;
} else {
tmp = z * -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 <= (-1.4d-47)) then
tmp = y * x
else if (y <= 9.5d-135) then
tmp = z
else if ((y <= 1.06d+26) .or. (.not. (y <= 2.25d+95)) .and. (y <= 1.1d+140) .or. (.not. (y <= 3.5d+214))) then
tmp = y * x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-47) {
tmp = y * x;
} else if (y <= 9.5e-135) {
tmp = z;
} else if ((y <= 1.06e+26) || (!(y <= 2.25e+95) && ((y <= 1.1e+140) || !(y <= 3.5e+214)))) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-47: tmp = y * x elif y <= 9.5e-135: tmp = z elif (y <= 1.06e+26) or (not (y <= 2.25e+95) and ((y <= 1.1e+140) or not (y <= 3.5e+214))): tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-47) tmp = Float64(y * x); elseif (y <= 9.5e-135) tmp = z; elseif ((y <= 1.06e+26) || (!(y <= 2.25e+95) && ((y <= 1.1e+140) || !(y <= 3.5e+214)))) tmp = Float64(y * x); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-47) tmp = y * x; elseif (y <= 9.5e-135) tmp = z; elseif ((y <= 1.06e+26) || (~((y <= 2.25e+95)) && ((y <= 1.1e+140) || ~((y <= 3.5e+214))))) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-47], N[(y * x), $MachinePrecision], If[LessEqual[y, 9.5e-135], z, If[Or[LessEqual[y, 1.06e+26], And[N[Not[LessEqual[y, 2.25e+95]], $MachinePrecision], Or[LessEqual[y, 1.1e+140], N[Not[LessEqual[y, 3.5e+214]], $MachinePrecision]]]], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-47}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-135}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+26} \lor \neg \left(y \leq 2.25 \cdot 10^{+95}\right) \land \left(y \leq 1.1 \cdot 10^{+140} \lor \neg \left(y \leq 3.5 \cdot 10^{+214}\right)\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1.55e-46) (not (<= y 5.1e-135))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-46) || !(y <= 5.1e-135)) {
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.55d-46)) .or. (.not. (y <= 5.1d-135))) 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.55e-46) || !(y <= 5.1e-135)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.55e-46) or not (y <= 5.1e-135): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.55e-46) || !(y <= 5.1e-135)) 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.55e-46) || ~((y <= 5.1e-135))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e-46], N[Not[LessEqual[y, 5.1e-135]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-46} \lor \neg \left(y \leq 5.1 \cdot 10^{-135}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -120000000.0) (not (<= y 3.3e-18))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -120000000.0) || !(y <= 3.3e-18)) {
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 <= (-120000000.0d0)) .or. (.not. (y <= 3.3d-18))) 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 <= -120000000.0) || !(y <= 3.3e-18)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -120000000.0) or not (y <= 3.3e-18): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -120000000.0) || !(y <= 3.3e-18)) 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 <= -120000000.0) || ~((y <= 3.3e-18))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -120000000.0], N[Not[LessEqual[y, 3.3e-18]], $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 -120000000 \lor \neg \left(y \leq 3.3 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e-48) (not (<= y 9.5e-135))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e-48) || !(y <= 9.5e-135)) {
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 <= (-2.6d-48)) .or. (.not. (y <= 9.5d-135))) 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 <= -2.6e-48) || !(y <= 9.5e-135)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e-48) or not (y <= 9.5e-135): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e-48) || !(y <= 9.5e-135)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.6e-48) || ~((y <= 9.5e-135))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e-48], N[Not[LessEqual[y, 9.5e-135]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-48} \lor \neg \left(y \leq 9.5 \cdot 10^{-135}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\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}
(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}
(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 2023343
(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))))