
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= x -9.1e+98)
(* z x)
(if (<= x -1.7e+46)
(* y x)
(if (<= x -1.0)
(* z x)
(if (<= x 9.6e-53)
(- z)
(if (or (<= x 2.3e+80) (not (<= x 2e+143))) (* y x) (* z x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.1e+98) {
tmp = z * x;
} else if (x <= -1.7e+46) {
tmp = y * x;
} else if (x <= -1.0) {
tmp = z * x;
} else if (x <= 9.6e-53) {
tmp = -z;
} else if ((x <= 2.3e+80) || !(x <= 2e+143)) {
tmp = y * x;
} else {
tmp = z * 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 (x <= (-9.1d+98)) then
tmp = z * x
else if (x <= (-1.7d+46)) then
tmp = y * x
else if (x <= (-1.0d0)) then
tmp = z * x
else if (x <= 9.6d-53) then
tmp = -z
else if ((x <= 2.3d+80) .or. (.not. (x <= 2d+143))) then
tmp = y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9.1e+98) {
tmp = z * x;
} else if (x <= -1.7e+46) {
tmp = y * x;
} else if (x <= -1.0) {
tmp = z * x;
} else if (x <= 9.6e-53) {
tmp = -z;
} else if ((x <= 2.3e+80) || !(x <= 2e+143)) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.1e+98: tmp = z * x elif x <= -1.7e+46: tmp = y * x elif x <= -1.0: tmp = z * x elif x <= 9.6e-53: tmp = -z elif (x <= 2.3e+80) or not (x <= 2e+143): tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.1e+98) tmp = Float64(z * x); elseif (x <= -1.7e+46) tmp = Float64(y * x); elseif (x <= -1.0) tmp = Float64(z * x); elseif (x <= 9.6e-53) tmp = Float64(-z); elseif ((x <= 2.3e+80) || !(x <= 2e+143)) tmp = Float64(y * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.1e+98) tmp = z * x; elseif (x <= -1.7e+46) tmp = y * x; elseif (x <= -1.0) tmp = z * x; elseif (x <= 9.6e-53) tmp = -z; elseif ((x <= 2.3e+80) || ~((x <= 2e+143))) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.1e+98], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.7e+46], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 9.6e-53], (-z), If[Or[LessEqual[x, 2.3e+80], N[Not[LessEqual[x, 2e+143]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.1 \cdot 10^{+98}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{+46}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{-53}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+80} \lor \neg \left(x \leq 2 \cdot 10^{+143}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e-22) (not (<= x 5.3e-51))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-22) || !(x <= 5.3e-51)) {
tmp = (y + z) * 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 ((x <= (-4.1d-22)) .or. (.not. (x <= 5.3d-51))) then
tmp = (y + z) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-22) || !(x <= 5.3e-51)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e-22) or not (x <= 5.3e-51): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e-22) || !(x <= 5.3e-51)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e-22) || ~((x <= 5.3e-51))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e-22], N[Not[LessEqual[x, 5.3e-51]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{-22} \lor \neg \left(x \leq 5.3 \cdot 10^{-51}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -80000000.0) (not (<= x 5.9e-52))) (* (+ y z) x) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -80000000.0) || !(x <= 5.9e-52)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
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 <= (-80000000.0d0)) .or. (.not. (x <= 5.9d-52))) then
tmp = (y + z) * x
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -80000000.0) || !(x <= 5.9e-52)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -80000000.0) or not (x <= 5.9e-52): tmp = (y + z) * x else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -80000000.0) || !(x <= 5.9e-52)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -80000000.0) || ~((x <= 5.9e-52))) tmp = (y + z) * x; else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -80000000.0], N[Not[LessEqual[x, 5.9e-52]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -80000000 \lor \neg \left(x \leq 5.9 \cdot 10^{-52}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -80000000.0) (not (<= x 1.45e-51))) (* (+ y z) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -80000000.0) || !(x <= 1.45e-51)) {
tmp = (y + z) * x;
} else {
tmp = (z * 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 <= (-80000000.0d0)) .or. (.not. (x <= 1.45d-51))) then
tmp = (y + z) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -80000000.0) || !(x <= 1.45e-51)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -80000000.0) or not (x <= 1.45e-51): tmp = (y + z) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -80000000.0) || !(x <= 1.45e-51)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -80000000.0) || ~((x <= 1.45e-51))) tmp = (y + z) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -80000000.0], N[Not[LessEqual[x, 1.45e-51]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -80000000 \lor \neg \left(x \leq 1.45 \cdot 10^{-51}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-22) (not (<= x 8.6e-51))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-22) || !(x <= 8.6e-51)) {
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 ((x <= (-3.6d-22)) .or. (.not. (x <= 8.6d-51))) 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 ((x <= -3.6e-22) || !(x <= 8.6e-51)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-22) or not (x <= 8.6e-51): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-22) || !(x <= 8.6e-51)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e-22) || ~((x <= 8.6e-51))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-22], N[Not[LessEqual[x, 8.6e-51]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-22} \lor \neg \left(x \leq 8.6 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((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 = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\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 Float64(-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)
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}
herbie shell --seed 2024008
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))