
(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.06e-64) (* y z) (if (<= y 1.55e-13) (* 1.0 x) (if (<= y 2.8e+124) (* y z) (* (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e-64) {
tmp = y * z;
} else if (y <= 1.55e-13) {
tmp = 1.0 * x;
} else if (y <= 2.8e+124) {
tmp = y * z;
} else {
tmp = -x * 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.06d-64)) then
tmp = y * z
else if (y <= 1.55d-13) then
tmp = 1.0d0 * x
else if (y <= 2.8d+124) then
tmp = y * z
else
tmp = -x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e-64) {
tmp = y * z;
} else if (y <= 1.55e-13) {
tmp = 1.0 * x;
} else if (y <= 2.8e+124) {
tmp = y * z;
} else {
tmp = -x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.06e-64: tmp = y * z elif y <= 1.55e-13: tmp = 1.0 * x elif y <= 2.8e+124: tmp = y * z else: tmp = -x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.06e-64) tmp = Float64(y * z); elseif (y <= 1.55e-13) tmp = Float64(1.0 * x); elseif (y <= 2.8e+124) tmp = Float64(y * z); else tmp = Float64(Float64(-x) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.06e-64) tmp = y * z; elseif (y <= 1.55e-13) tmp = 1.0 * x; elseif (y <= 2.8e+124) tmp = y * z; else tmp = -x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.06e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.55e-13], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 2.8e+124], N[(y * z), $MachinePrecision], N[((-x) * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-13}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+124}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot y\\
\end{array}
\end{array}
if y < -1.06000000000000007e-64 or 1.55e-13 < y < 2.8e124Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.3
Applied rewrites52.3%
if -1.06000000000000007e-64 < y < 1.55e-13Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6473.3
Applied rewrites73.3%
Taylor expanded in y around 0
Applied rewrites73.3%
if 2.8e124 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites55.4%
Final simplification61.9%
herbie shell --seed 2024230
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))