
(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
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -9.2e+16) t_0 (if (<= y 0.0105) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -9.2e+16) {
tmp = t_0;
} else if (y <= 0.0105) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -9.2e+16) tmp = t_0; elseif (y <= 0.0105) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -9.2e+16], t$95$0, If[LessEqual[y, 0.0105], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.2e16 or 0.0105000000000000007 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -9.2e16 < y < 0.0105000000000000007Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.7
Applied rewrites98.7%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.7
Applied rewrites98.7%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e+229) (fma z y x) (if (<= y -3.7e+28) (* x (- y)) (fma z y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e+229) {
tmp = fma(z, y, x);
} else if (y <= -3.7e+28) {
tmp = x * -y;
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8.4e+229) tmp = fma(z, y, x); elseif (y <= -3.7e+28) tmp = Float64(x * Float64(-y)); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8.4e+229], N[(z * y + x), $MachinePrecision], If[LessEqual[y, -3.7e+28], N[(x * (-y)), $MachinePrecision], N[(z * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{+229}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{+28}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if y < -8.3999999999999995e229 or -3.6999999999999999e28 < y Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6482.9
Applied rewrites82.9%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6482.9
Applied rewrites82.9%
if -8.3999999999999995e229 < y < -3.6999999999999999e28Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6467.0
Applied rewrites67.0%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6476.1
Applied rewrites76.1%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.1
Applied rewrites76.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
lower-*.f6443.6
Applied rewrites43.6%
Final simplification43.6%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6466.9
Applied rewrites66.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6427.6
Applied rewrites27.6%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
distribute-neg-fracN/A
flip3--N/A
neg-sub0N/A
remove-double-negN/A
Applied rewrites5.6%
Final simplification5.6%
herbie shell --seed 2024216
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))