
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= y -5.5e-7)
(* y z)
(if (<= y 0.00016)
x
(if (or (<= y 7.8e+94) (and (not (<= y 5.2e+139)) (<= y 1.55e+214)))
(* y z)
(* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e-7) {
tmp = y * z;
} else if (y <= 0.00016) {
tmp = x;
} else if ((y <= 7.8e+94) || (!(y <= 5.2e+139) && (y <= 1.55e+214))) {
tmp = y * 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 <= (-5.5d-7)) then
tmp = y * z
else if (y <= 0.00016d0) then
tmp = x
else if ((y <= 7.8d+94) .or. (.not. (y <= 5.2d+139)) .and. (y <= 1.55d+214)) then
tmp = y * 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 <= -5.5e-7) {
tmp = y * z;
} else if (y <= 0.00016) {
tmp = x;
} else if ((y <= 7.8e+94) || (!(y <= 5.2e+139) && (y <= 1.55e+214))) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e-7: tmp = y * z elif y <= 0.00016: tmp = x elif (y <= 7.8e+94) or (not (y <= 5.2e+139) and (y <= 1.55e+214)): tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e-7) tmp = Float64(y * z); elseif (y <= 0.00016) tmp = x; elseif ((y <= 7.8e+94) || (!(y <= 5.2e+139) && (y <= 1.55e+214))) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.5e-7) tmp = y * z; elseif (y <= 0.00016) tmp = x; elseif ((y <= 7.8e+94) || (~((y <= 5.2e+139)) && (y <= 1.55e+214))) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e-7], N[(y * z), $MachinePrecision], If[LessEqual[y, 0.00016], x, If[Or[LessEqual[y, 7.8e+94], And[N[Not[LessEqual[y, 5.2e+139]], $MachinePrecision], LessEqual[y, 1.55e+214]]], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 0.00016:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+94} \lor \neg \left(y \leq 5.2 \cdot 10^{+139}\right) \land y \leq 1.55 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e-20) (not (<= x 4.6e-70))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-20) || !(x <= 4.6e-70)) {
tmp = x * (1.0 - y);
} else {
tmp = y * 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 <= (-2.3d-20)) .or. (.not. (x <= 4.6d-70))) then
tmp = x * (1.0d0 - y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-20) || !(x <= 4.6e-70)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e-20) or not (x <= 4.6e-70): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e-20) || !(x <= 4.6e-70)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3e-20) || ~((x <= 4.6e-70))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e-20], N[Not[LessEqual[x, 4.6e-70]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-20} \lor \neg \left(x \leq 4.6 \cdot 10^{-70}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e+49) (not (<= x 3.8e-70))) (* x (- 1.0 y)) (* y (- z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e+49) || !(x <= 3.8e-70)) {
tmp = x * (1.0 - y);
} else {
tmp = y * (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 <= (-3.2d+49)) .or. (.not. (x <= 3.8d-70))) then
tmp = x * (1.0d0 - y)
else
tmp = y * (z - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e+49) || !(x <= 3.8e-70)) {
tmp = x * (1.0 - y);
} else {
tmp = y * (z - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e+49) or not (x <= 3.8e-70): tmp = x * (1.0 - y) else: tmp = y * (z - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e+49) || !(x <= 3.8e-70)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * Float64(z - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.2e+49) || ~((x <= 3.8e-70))) tmp = x * (1.0 - y); else tmp = y * (z - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e+49], N[Not[LessEqual[x, 3.8e-70]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+49} \lor \neg \left(x \leq 3.8 \cdot 10^{-70}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z - x\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= x -5.2e+49) (* x (- 1.0 y)) (if (<= x 4.4e-72) (* y (- z x)) (- x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+49) {
tmp = x * (1.0 - y);
} else if (x <= 4.4e-72) {
tmp = y * (z - x);
} else {
tmp = x - (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 (x <= (-5.2d+49)) then
tmp = x * (1.0d0 - y)
else if (x <= 4.4d-72) then
tmp = y * (z - x)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+49) {
tmp = x * (1.0 - y);
} else if (x <= 4.4e-72) {
tmp = y * (z - x);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.2e+49: tmp = x * (1.0 - y) elif x <= 4.4e-72: tmp = y * (z - x) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.2e+49) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 4.4e-72) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.2e+49) tmp = x * (1.0 - y); elseif (x <= 4.4e-72) tmp = y * (z - x); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.2e+49], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.4e-72], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+49}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-72}:\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -4.5e-6) (not (<= y 0.000165))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e-6) || !(y <= 0.000165)) {
tmp = y * z;
} else {
tmp = 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.5d-6)) .or. (.not. (y <= 0.000165d0))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e-6) || !(y <= 0.000165)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.5e-6) or not (y <= 0.000165): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.5e-6) || !(y <= 0.000165)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.5e-6) || ~((y <= 0.000165))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.5e-6], N[Not[LessEqual[y, 0.000165]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-6} \lor \neg \left(y \leq 0.000165\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
herbie shell --seed 2023343
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))