
(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 -1.65e+130)
(* z y)
(if (<= y -3.6e+58)
(* (- y) x)
(if (or (<= y -3.6e-52) (not (<= y 7.5e-126))) (* z y) (* 1.0 x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e+130) {
tmp = z * y;
} else if (y <= -3.6e+58) {
tmp = -y * x;
} else if ((y <= -3.6e-52) || !(y <= 7.5e-126)) {
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 <= (-1.65d+130)) then
tmp = z * y
else if (y <= (-3.6d+58)) then
tmp = -y * x
else if ((y <= (-3.6d-52)) .or. (.not. (y <= 7.5d-126))) 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 <= -1.65e+130) {
tmp = z * y;
} else if (y <= -3.6e+58) {
tmp = -y * x;
} else if ((y <= -3.6e-52) || !(y <= 7.5e-126)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e+130: tmp = z * y elif y <= -3.6e+58: tmp = -y * x elif (y <= -3.6e-52) or not (y <= 7.5e-126): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e+130) tmp = Float64(z * y); elseif (y <= -3.6e+58) tmp = Float64(Float64(-y) * x); elseif ((y <= -3.6e-52) || !(y <= 7.5e-126)) 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 <= -1.65e+130) tmp = z * y; elseif (y <= -3.6e+58) tmp = -y * x; elseif ((y <= -3.6e-52) || ~((y <= 7.5e-126))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e+130], N[(z * y), $MachinePrecision], If[LessEqual[y, -3.6e+58], N[((-y) * x), $MachinePrecision], If[Or[LessEqual[y, -3.6e-52], N[Not[LessEqual[y, 7.5e-126]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+130}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{+58}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-52} \lor \neg \left(y \leq 7.5 \cdot 10^{-126}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1.65e130 or -3.59999999999999996e58 < y < -3.59999999999999988e-52 or 7.49999999999999976e-126 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.8
Applied rewrites55.8%
if -1.65e130 < y < -3.59999999999999996e58Initial 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--.f6480.4
Applied rewrites80.4%
Taylor expanded in y around inf
Applied rewrites80.4%
if -3.59999999999999988e-52 < y < 7.49999999999999976e-126Initial 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--.f6482.3
Applied rewrites82.3%
Taylor expanded in y around 0
Applied rewrites82.3%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e-52) (not (<= y 46000000.0))) (* (- z x) y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e-52) || !(y <= 46000000.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 <= (-3.6d-52)) .or. (.not. (y <= 46000000.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 <= -3.6e-52) || !(y <= 46000000.0)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e-52) or not (y <= 46000000.0): tmp = (z - x) * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e-52) || !(y <= 46000000.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 <= -3.6e-52) || ~((y <= 46000000.0))) tmp = (z - x) * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e-52], N[Not[LessEqual[y, 46000000.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 -3.6 \cdot 10^{-52} \lor \neg \left(y \leq 46000000\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if y < -3.59999999999999988e-52 or 4.6e7 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.6
Applied rewrites53.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.6
Applied rewrites95.6%
if -3.59999999999999988e-52 < y < 4.6e7Initial 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--.f6477.5
Applied rewrites77.5%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e+160) (not (<= z 5.1e+70))) (* z y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+160) || !(z <= 5.1e+70)) {
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 <= (-2.4d+160)) .or. (.not. (z <= 5.1d+70))) 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 <= -2.4e+160) || !(z <= 5.1e+70)) {
tmp = z * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e+160) or not (z <= 5.1e+70): tmp = z * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+160) || !(z <= 5.1e+70)) 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 <= -2.4e+160) || ~((z <= 5.1e+70))) tmp = z * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e+160], N[Not[LessEqual[z, 5.1e+70]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+160} \lor \neg \left(z \leq 5.1 \cdot 10^{+70}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.4000000000000001e160 or 5.10000000000000014e70 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6478.6
Applied rewrites78.6%
if -2.4000000000000001e160 < z < 5.10000000000000014e70Initial 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.3
Applied rewrites81.3%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e-52) (not (<= y 7.5e-126))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e-52) || !(y <= 7.5e-126)) {
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.6d-52)) .or. (.not. (y <= 7.5d-126))) 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.6e-52) || !(y <= 7.5e-126)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e-52) or not (y <= 7.5e-126): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e-52) || !(y <= 7.5e-126)) 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.6e-52) || ~((y <= 7.5e-126))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e-52], N[Not[LessEqual[y, 7.5e-126]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-52} \lor \neg \left(y \leq 7.5 \cdot 10^{-126}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -3.59999999999999988e-52 or 7.49999999999999976e-126 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.6
Applied rewrites52.6%
if -3.59999999999999988e-52 < y < 7.49999999999999976e-126Initial 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--.f6482.3
Applied rewrites82.3%
Taylor expanded in y around 0
Applied rewrites82.3%
Final simplification64.0%
(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 2024320
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))