
(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 -9.6e+210) (* (- y) x) (if (or (<= y -5.2e-18) (not (<= y 4e-31))) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.6e+210) {
tmp = -y * x;
} else if ((y <= -5.2e-18) || !(y <= 4e-31)) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -9.6e+210) tmp = Float64(Float64(-y) * x); elseif ((y <= -5.2e-18) || !(y <= 4e-31)) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -9.6e+210], N[((-y) * x), $MachinePrecision], If[Or[LessEqual[y, -5.2e-18], N[Not[LessEqual[y, 4e-31]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.6 \cdot 10^{+210}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq -5.2 \cdot 10^{-18} \lor \neg \left(y \leq 4 \cdot 10^{-31}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -9.59999999999999953e210Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6467.4
Applied rewrites67.4%
Taylor expanded in y around inf
Applied rewrites67.4%
if -9.59999999999999953e210 < y < -5.2000000000000001e-18 or 4e-31 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6462.5
Applied rewrites62.5%
if -5.2000000000000001e-18 < y < 4e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.6
Applied rewrites79.6%
Applied rewrites79.6%
Applied rewrites79.6%
Final simplification70.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-19) (not (<= y 5.1e-31))) (* (- z x) y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-19) || !(y <= 5.1e-31)) {
tmp = (z - x) * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-19) || !(y <= 5.1e-31)) tmp = Float64(Float64(z - x) * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-19], N[Not[LessEqual[y, 5.1e-31]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-19} \lor \neg \left(y \leq 5.1 \cdot 10^{-31}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -2.80000000000000003e-19 or 5.0999999999999997e-31 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.6
Applied rewrites97.6%
if -2.80000000000000003e-19 < y < 5.0999999999999997e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.6
Applied rewrites79.6%
Applied rewrites79.6%
Applied rewrites79.6%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-10) (not (<= x 3.2e-208))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-10) || !(x <= 3.2e-208)) {
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 <= (-1.3d-10)) .or. (.not. (x <= 3.2d-208))) 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 <= -1.3e-10) || !(x <= 3.2e-208)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e-10) or not (x <= 3.2e-208): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-10) || !(x <= 3.2e-208)) 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 <= -1.3e-10) || ~((x <= 3.2e-208))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-10], N[Not[LessEqual[x, 3.2e-208]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-10} \lor \neg \left(x \leq 3.2 \cdot 10^{-208}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -1.29999999999999991e-10 or 3.2000000000000001e-208 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6481.8
Applied rewrites81.8%
if -1.29999999999999991e-10 < x < 3.2000000000000001e-208Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6483.1
Applied rewrites83.1%
Final simplification82.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-18) (not (<= y 4e-31))) (* z y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-18) || !(y <= 4e-31)) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-18) || !(y <= 4e-31)) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-18], N[Not[LessEqual[y, 4e-31]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-18} \lor \neg \left(y \leq 4 \cdot 10^{-31}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -5.2000000000000001e-18 or 4e-31 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
if -5.2000000000000001e-18 < y < 4e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.6
Applied rewrites79.6%
Applied rewrites79.6%
Applied rewrites79.6%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-18) (not (<= y 4e-31))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-18) || !(y <= 4e-31)) {
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.2d-18)) .or. (.not. (y <= 4d-31))) 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.2e-18) || !(y <= 4e-31)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-18) or not (y <= 4e-31): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-18) || !(y <= 4e-31)) 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.2e-18) || ~((y <= 4e-31))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-18], N[Not[LessEqual[y, 4e-31]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-18} \lor \neg \left(y \leq 4 \cdot 10^{-31}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -5.2000000000000001e-18 or 4e-31 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
if -5.2000000000000001e-18 < y < 4e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.6
Applied rewrites79.6%
Taylor expanded in y around 0
Applied rewrites79.6%
Final simplification68.1%
(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-*.f6444.3
Applied rewrites44.3%
herbie shell --seed 2024318
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))