
(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 7 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 (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4.4e+39) (* (- y) x) (if (or (<= y -5.4e-58) (not (<= y 1.15e-12))) (* z y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+39) {
tmp = -y * x;
} else if ((y <= -5.4e-58) || !(y <= 1.15e-12)) {
tmp = z * y;
} else {
tmp = 1.0 * 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.4d+39)) then
tmp = -y * x
else if ((y <= (-5.4d-58)) .or. (.not. (y <= 1.15d-12))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+39) {
tmp = -y * x;
} else if ((y <= -5.4e-58) || !(y <= 1.15e-12)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.4e+39: tmp = -y * x elif (y <= -5.4e-58) or not (y <= 1.15e-12): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.4e+39) tmp = Float64(Float64(-y) * x); elseif ((y <= -5.4e-58) || !(y <= 1.15e-12)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.4e+39) tmp = -y * x; elseif ((y <= -5.4e-58) || ~((y <= 1.15e-12))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.4e+39], N[((-y) * x), $MachinePrecision], If[Or[LessEqual[y, -5.4e-58], N[Not[LessEqual[y, 1.15e-12]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+39}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq -5.4 \cdot 10^{-58} \lor \neg \left(y \leq 1.15 \cdot 10^{-12}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -4.4000000000000003e39Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6462.4
Applied rewrites62.4%
Taylor expanded in y around inf
Applied rewrites62.4%
if -4.4000000000000003e39 < y < -5.3999999999999998e-58 or 1.14999999999999995e-12 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6462.2
Applied rewrites62.2%
if -5.3999999999999998e-58 < y < 1.14999999999999995e-12Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.6
Applied rewrites74.6%
Taylor expanded in y around 0
Applied rewrites74.5%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e-58) (not (<= y 2.9e-12))) (* (- z x) y) (fma (- x) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-58) || !(y <= 2.9e-12)) {
tmp = (z - x) * y;
} else {
tmp = fma(-x, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e-58) || !(y <= 2.9e-12)) tmp = Float64(Float64(z - x) * y); else tmp = fma(Float64(-x), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e-58], N[Not[LessEqual[y, 2.9e-12]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[((-x) * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-58} \lor \neg \left(y \leq 2.9 \cdot 10^{-12}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\end{array}
\end{array}
if y < -5.3999999999999998e-58 or 2.9000000000000002e-12 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.4
Applied rewrites97.4%
if -5.3999999999999998e-58 < y < 2.9000000000000002e-12Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6474.6
Applied rewrites74.6%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e-58) (not (<= y 2.9e-12))) (* (- z x) y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-58) || !(y <= 2.9e-12)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - 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.4d-58)) .or. (.not. (y <= 2.9d-12))) then
tmp = (z - x) * y
else
tmp = (1.0d0 - y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-58) || !(y <= 2.9e-12)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e-58) or not (y <= 2.9e-12): tmp = (z - x) * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e-58) || !(y <= 2.9e-12)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.4e-58) || ~((y <= 2.9e-12))) tmp = (z - x) * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e-58], N[Not[LessEqual[y, 2.9e-12]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-58} \lor \neg \left(y \leq 2.9 \cdot 10^{-12}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if y < -5.3999999999999998e-58 or 2.9000000000000002e-12 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.4
Applied rewrites97.4%
if -5.3999999999999998e-58 < y < 2.9000000000000002e-12Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.6
Applied rewrites74.6%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-25) (not (<= x 2.4e-102))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-25) || !(x <= 2.4e-102)) {
tmp = (1.0 - 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 ((x <= (-7d-25)) .or. (.not. (x <= 2.4d-102))) then
tmp = (1.0d0 - 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 ((x <= -7e-25) || !(x <= 2.4e-102)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-25) or not (x <= 2.4e-102): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-25) || !(x <= 2.4e-102)) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-25) || ~((x <= 2.4e-102))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-25], N[Not[LessEqual[x, 2.4e-102]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-25} \lor \neg \left(x \leq 2.4 \cdot 10^{-102}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -7.0000000000000004e-25 or 2.4e-102 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6480.1
Applied rewrites80.1%
if -7.0000000000000004e-25 < x < 2.4e-102Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6472.0
Applied rewrites72.0%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e-58) (not (<= y 1.15e-12))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-58) || !(y <= 1.15e-12)) {
tmp = z * y;
} else {
tmp = 1.0 * 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.4d-58)) .or. (.not. (y <= 1.15d-12))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-58) || !(y <= 1.15e-12)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e-58) or not (y <= 1.15e-12): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e-58) || !(y <= 1.15e-12)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.4e-58) || ~((y <= 1.15e-12))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e-58], N[Not[LessEqual[y, 1.15e-12]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-58} \lor \neg \left(y \leq 1.15 \cdot 10^{-12}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -5.3999999999999998e-58 or 1.14999999999999995e-12 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
if -5.3999999999999998e-58 < y < 1.14999999999999995e-12Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.6
Applied rewrites74.6%
Taylor expanded in y around 0
Applied rewrites74.5%
Final simplification63.4%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * 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 * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6440.5
Applied rewrites40.5%
herbie shell --seed 2024307
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))