
(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 (or (<= y -5.8e-19) (not (<= y 5e-21))) (* (- z x) y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-19) || !(y <= 5e-21)) {
tmp = (z - x) * 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.8d-19)) .or. (.not. (y <= 5d-21))) then
tmp = (z - x) * 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.8e-19) || !(y <= 5e-21)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-19) or not (y <= 5e-21): tmp = (z - x) * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-19) || !(y <= 5e-21)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e-19) || ~((y <= 5e-21))) tmp = (z - x) * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-19], N[Not[LessEqual[y, 5e-21]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-19} \lor \neg \left(y \leq 5 \cdot 10^{-21}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -5.8e-19 or 4.99999999999999973e-21 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.0
Applied rewrites98.0%
if -5.8e-19 < y < 4.99999999999999973e-21Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6471.5
Applied rewrites71.5%
Taylor expanded in y around 0
Applied rewrites71.5%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.85e-65) (not (<= x 1.8e-46))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.85e-65) || !(x <= 1.8e-46)) {
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.85d-65)) .or. (.not. (x <= 1.8d-46))) 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.85e-65) || !(x <= 1.8e-46)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.85e-65) or not (x <= 1.8e-46): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.85e-65) || !(x <= 1.8e-46)) 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.85e-65) || ~((x <= 1.8e-46))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.85e-65], N[Not[LessEqual[x, 1.8e-46]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-65} \lor \neg \left(x \leq 1.8 \cdot 10^{-46}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -1.85e-65 or 1.8e-46 < 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.8
Applied rewrites80.8%
if -1.85e-65 < x < 1.8e-46Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6473.9
Applied rewrites73.9%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.85e-65) (* (- 1.0 y) x) (if (<= x 1.8e-46) (* z y) (fma (- y) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e-65) {
tmp = (1.0 - y) * x;
} else if (x <= 1.8e-46) {
tmp = z * y;
} else {
tmp = fma(-y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.85e-65) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 1.8e-46) tmp = Float64(z * y); else tmp = fma(Float64(-y), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.85e-65], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.8e-46], N[(z * y), $MachinePrecision], N[((-y) * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-65}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-46}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\end{array}
\end{array}
if x < -1.85e-65Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6483.7
Applied rewrites83.7%
if -1.85e-65 < x < 1.8e-46Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6473.9
Applied rewrites73.9%
if 1.8e-46 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.0
Applied rewrites77.0%
Applied rewrites77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-19) (not (<= y 5e-21))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-19) || !(y <= 5e-21)) {
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.8d-19)) .or. (.not. (y <= 5d-21))) 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.8e-19) || !(y <= 5e-21)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-19) or not (y <= 5e-21): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-19) || !(y <= 5e-21)) 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.8e-19) || ~((y <= 5e-21))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-19], N[Not[LessEqual[y, 5e-21]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-19} \lor \neg \left(y \leq 5 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -5.8e-19 or 4.99999999999999973e-21 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6456.7
Applied rewrites56.7%
if -5.8e-19 < y < 4.99999999999999973e-21Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6471.5
Applied rewrites71.5%
Taylor expanded in y around 0
Applied rewrites71.5%
Final simplification63.9%
(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.9
Applied rewrites43.9%
herbie shell --seed 2024324
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))