
(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 -1.8e-9) (* z y) (if (<= y 1.0) (* 1.0 x) (if (<= y 5.3e+203) (* (- y) x) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e-9) {
tmp = z * y;
} else if (y <= 1.0) {
tmp = 1.0 * x;
} else if (y <= 5.3e+203) {
tmp = -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 (y <= (-1.8d-9)) then
tmp = z * y
else if (y <= 1.0d0) then
tmp = 1.0d0 * x
else if (y <= 5.3d+203) then
tmp = -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 (y <= -1.8e-9) {
tmp = z * y;
} else if (y <= 1.0) {
tmp = 1.0 * x;
} else if (y <= 5.3e+203) {
tmp = -y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.8e-9: tmp = z * y elif y <= 1.0: tmp = 1.0 * x elif y <= 5.3e+203: tmp = -y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.8e-9) tmp = Float64(z * y); elseif (y <= 1.0) tmp = Float64(1.0 * x); elseif (y <= 5.3e+203) tmp = Float64(Float64(-y) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.8e-9) tmp = z * y; elseif (y <= 1.0) tmp = 1.0 * x; elseif (y <= 5.3e+203) tmp = -y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.8e-9], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 5.3e+203], N[((-y) * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-9}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 5.3 \cdot 10^{+203}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -1.8e-9 or 5.29999999999999987e203 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6467.7
Applied rewrites67.7%
if -1.8e-9 < y < 1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in y around 0
Applied rewrites75.5%
if 1 < y < 5.29999999999999987e203Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6468.0
Applied rewrites68.0%
Taylor expanded in y around inf
Applied rewrites59.9%
Final simplification70.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e-7) (not (<= y 5500000.0))) (* (- z x) y) (fma (- x) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-7) || !(y <= 5500000.0)) {
tmp = (z - x) * y;
} else {
tmp = fma(-x, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e-7) || !(y <= 5500000.0)) 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, -2.1e-7], N[Not[LessEqual[y, 5500000.0]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[((-x) * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-7} \lor \neg \left(y \leq 5500000\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\end{array}
\end{array}
if y < -2.1e-7 or 5.5e6 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f6497.0
Applied rewrites97.0%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6499.8
Applied rewrites99.8%
if -2.1e-7 < y < 5.5e6Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.3
Applied rewrites77.3%
Applied rewrites77.3%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -42.0) (not (<= x 9e-44))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -42.0) || !(x <= 9e-44)) {
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 <= (-42.0d0)) .or. (.not. (x <= 9d-44))) 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 <= -42.0) || !(x <= 9e-44)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -42.0) or not (x <= 9e-44): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -42.0) || !(x <= 9e-44)) 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 <= -42.0) || ~((x <= 9e-44))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -42.0], N[Not[LessEqual[x, 9e-44]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -42 \lor \neg \left(x \leq 9 \cdot 10^{-44}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -42 or 8.9999999999999997e-44 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6486.5
Applied rewrites86.5%
if -42 < x < 8.9999999999999997e-44Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (<= x -42.0) (* (- 1.0 y) x) (if (<= x 9e-44) (* z y) (fma (- x) y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -42.0) {
tmp = (1.0 - y) * x;
} else if (x <= 9e-44) {
tmp = z * y;
} else {
tmp = fma(-x, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -42.0) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 9e-44) tmp = Float64(z * y); else tmp = fma(Float64(-x), y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -42.0], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 9e-44], N[(z * y), $MachinePrecision], N[((-x) * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -42:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-44}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\end{array}
\end{array}
if x < -42Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6485.3
Applied rewrites85.3%
if -42 < x < 8.9999999999999997e-44Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
if 8.9999999999999997e-44 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6487.4
Applied rewrites87.4%
Applied rewrites87.5%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-9) (not (<= y 7.5e-56))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-9) || !(y <= 7.5e-56)) {
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.8d-9)) .or. (.not. (y <= 7.5d-56))) 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.8e-9) || !(y <= 7.5e-56)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-9) or not (y <= 7.5e-56): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-9) || !(y <= 7.5e-56)) 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.8e-9) || ~((y <= 7.5e-56))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-9], N[Not[LessEqual[y, 7.5e-56]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-9} \lor \neg \left(y \leq 7.5 \cdot 10^{-56}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1.8e-9 or 7.50000000000000041e-56 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.0
Applied rewrites59.0%
if -1.8e-9 < y < 7.50000000000000041e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.8
Applied rewrites78.8%
Taylor expanded in y around 0
Applied rewrites78.3%
Final simplification67.5%
(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-*.f6443.5
Applied rewrites43.5%
Final simplification43.5%
herbie shell --seed 2024313
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))