
(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 -180000000.0) t_0 (if (<= y 0.0003) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -180000000.0) {
tmp = t_0;
} else if (y <= 0.0003) {
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 <= -180000000.0) tmp = t_0; elseif (y <= 0.0003) 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, -180000000.0], t$95$0, If[LessEqual[y, 0.0003], 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 -180000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0003:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8e8 or 2.99999999999999974e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6499.3
Applied rewrites99.3%
if -1.8e8 < y < 2.99999999999999974e-4Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x y)))) (if (<= y -1.8e+233) t_0 (if (<= y 4.5e+184) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = -(x * y);
double tmp;
if (y <= -1.8e+233) {
tmp = t_0;
} else if (y <= 4.5e+184) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-Float64(x * y)) tmp = 0.0 if (y <= -1.8e+233) tmp = t_0; elseif (y <= 4.5e+184) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(x * y), $MachinePrecision])}, If[LessEqual[y, -1.8e+233], t$95$0, If[LessEqual[y, 4.5e+184], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -x \cdot y\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{+233}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+184}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.7999999999999999e233 or 4.50000000000000036e184 < y Initial 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.f6473.6
Applied rewrites73.6%
if -1.7999999999999999e233 < y < 4.50000000000000036e184Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.0
Applied rewrites88.0%
Final simplification85.5%
(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-*.f6480.5
Applied rewrites80.5%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.5
Applied rewrites80.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
lower-*.f6446.9
Applied rewrites46.9%
Final simplification46.9%
(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.2
Applied rewrites66.2%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6425.9
Applied rewrites25.9%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
pow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow1N/A
Applied rewrites4.4%
Final simplification4.4%
herbie shell --seed 2024214
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))