
(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 5 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 y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-rgt-identityN/A
associate-+l+N/A
mul-1-negN/A
unsub-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-fma.f64N/A
lower--.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -1.0) t_0 (if (<= y 2.35e-12) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.35e-12) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 2.35e-12) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 2.35e-12], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 2.34999999999999988e-12 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6498.0
Simplified98.0%
if -1 < y < 2.34999999999999988e-12Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.6
Simplified98.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.6
Simplified98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y x)))) (if (<= y -3.5e+253) t_0 (if (<= y 1.2e+194) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * x);
double tmp;
if (y <= -3.5e+253) {
tmp = t_0;
} else if (y <= 1.2e+194) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-Float64(y * x)) tmp = 0.0 if (y <= -3.5e+253) tmp = t_0; elseif (y <= 1.2e+194) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * x), $MachinePrecision])}, If[LessEqual[y, -3.5e+253], t$95$0, If[LessEqual[y, 1.2e+194], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot x\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+253}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+194}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.49999999999999978e253 or 1.2e194 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Simplified100.0%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6476.4
Simplified76.4%
if -3.49999999999999978e253 < y < 1.2e194Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6480.9
Simplified80.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6480.9
Simplified80.9%
Final simplification80.4%
(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-*.f6475.1
Simplified75.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6475.1
Simplified75.1%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6436.0
Simplified36.0%
herbie shell --seed 2024215
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))