
(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 6 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 -3.35e+96) (* z y) (if (or (<= y -60000000000.0) (not (<= y 1.0))) (* (- y) x) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.35e+96) {
tmp = z * y;
} else if ((y <= -60000000000.0) || !(y <= 1.0)) {
tmp = -y * x;
} 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 <= (-3.35d+96)) then
tmp = z * y
else if ((y <= (-60000000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = -y * x
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 <= -3.35e+96) {
tmp = z * y;
} else if ((y <= -60000000000.0) || !(y <= 1.0)) {
tmp = -y * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.35e+96: tmp = z * y elif (y <= -60000000000.0) or not (y <= 1.0): tmp = -y * x else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.35e+96) tmp = Float64(z * y); elseif ((y <= -60000000000.0) || !(y <= 1.0)) tmp = Float64(Float64(-y) * x); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.35e+96) tmp = z * y; elseif ((y <= -60000000000.0) || ~((y <= 1.0))) tmp = -y * x; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.35e+96], N[(z * y), $MachinePrecision], If[Or[LessEqual[y, -60000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.35 \cdot 10^{+96}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq -60000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -3.35000000000000021e96Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6470.0
Applied rewrites70.0%
if -3.35000000000000021e96 < y < -6e10 or 1 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6459.9
Applied rewrites59.9%
Taylor expanded in y around inf
Applied rewrites58.0%
if -6e10 < y < 1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6474.0
Applied rewrites74.0%
Taylor expanded in y around 0
Applied rewrites73.2%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.8e-11) (not (<= y 520.0))) (* (- z x) y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.8e-11) || !(y <= 520.0)) {
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 <= (-8.8d-11)) .or. (.not. (y <= 520.0d0))) 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 <= -8.8e-11) || !(y <= 520.0)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.8e-11) or not (y <= 520.0): tmp = (z - x) * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.8e-11) || !(y <= 520.0)) 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 <= -8.8e-11) || ~((y <= 520.0))) tmp = (z - x) * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.8e-11], N[Not[LessEqual[y, 520.0]], $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 -8.8 \cdot 10^{-11} \lor \neg \left(y \leq 520\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if y < -8.8000000000000006e-11 or 520 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6456.7
Applied rewrites56.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.9
Applied rewrites99.9%
if -8.8000000000000006e-11 < y < 520Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6475.4
Applied rewrites75.4%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e+77) (not (<= z 4.6e+109))) (* z y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e+77) || !(z <= 4.6e+109)) {
tmp = z * 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 ((z <= (-3d+77)) .or. (.not. (z <= 4.6d+109))) then
tmp = z * 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 ((z <= -3e+77) || !(z <= 4.6e+109)) {
tmp = z * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e+77) or not (z <= 4.6e+109): tmp = z * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e+77) || !(z <= 4.6e+109)) tmp = Float64(z * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e+77) || ~((z <= 4.6e+109))) tmp = z * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e+77], N[Not[LessEqual[z, 4.6e+109]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+77} \lor \neg \left(z \leq 4.6 \cdot 10^{+109}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.9999999999999998e77 or 4.60000000000000021e109 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
if -2.9999999999999998e77 < z < 4.60000000000000021e109Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6481.2
Applied rewrites81.2%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.9e-12) (not (<= y 3.5e-32))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.9e-12) || !(y <= 3.5e-32)) {
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 <= (-3.9d-12)) .or. (.not. (y <= 3.5d-32))) 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 <= -3.9e-12) || !(y <= 3.5e-32)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.9e-12) or not (y <= 3.5e-32): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.9e-12) || !(y <= 3.5e-32)) 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 <= -3.9e-12) || ~((y <= 3.5e-32))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.9e-12], N[Not[LessEqual[y, 3.5e-32]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{-12} \lor \neg \left(y \leq 3.5 \cdot 10^{-32}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -3.89999999999999994e-12 or 3.4999999999999999e-32 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.8
Applied rewrites55.8%
if -3.89999999999999994e-12 < y < 3.4999999999999999e-32Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6476.2
Applied rewrites76.2%
Taylor expanded in y around 0
Applied rewrites76.1%
Final simplification65.6%
(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-*.f6441.2
Applied rewrites41.2%
herbie shell --seed 2024326
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))