
(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%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -1.0) t_0 (if (<= y 1.0) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
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 <= -1.0) tmp = t_0; elseif (y <= 1.0) 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, -1.0], t$95$0, If[LessEqual[y, 1.0], 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 -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6498.3
Simplified98.3%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6497.9
Simplified97.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6497.9
Applied egg-rr97.9%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.2e-28) (* z y) (if (<= y 1.08e-86) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-28) {
tmp = z * y;
} else if (y <= 1.08e-86) {
tmp = 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 (y <= (-2.2d-28)) then
tmp = z * y
else if (y <= 1.08d-86) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-28) {
tmp = z * y;
} else if (y <= 1.08e-86) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e-28: tmp = z * y elif y <= 1.08e-86: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e-28) tmp = Float64(z * y); elseif (y <= 1.08e-86) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.2e-28) tmp = z * y; elseif (y <= 1.08e-86) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e-28], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.08e-86], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-28}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1.08 \cdot 10^{-86}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.19999999999999996e-28 or 1.07999999999999993e-86 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6450.1
Simplified50.1%
if -2.19999999999999996e-28 < y < 1.07999999999999993e-86Initial program 100.0%
Taylor expanded in y around 0
Simplified80.3%
Final simplification62.6%
(FPCore (x y z) :precision binary64 (if (<= y 31000.0) (fma z y x) (- (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 31000.0) {
tmp = fma(z, y, x);
} else {
tmp = -(x * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 31000.0) tmp = fma(z, y, x); else tmp = Float64(-Float64(x * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 31000.0], N[(z * y + x), $MachinePrecision], (-N[(x * y), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 31000:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;-x \cdot y\\
\end{array}
\end{array}
if y < 31000Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6486.9
Simplified86.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6486.9
Applied egg-rr86.9%
if 31000 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6498.7
Simplified98.7%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6462.1
Simplified62.1%
Final simplification79.2%
(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
*-lowering-*.f6473.4
Simplified73.4%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6473.4
Applied egg-rr73.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Simplified37.1%
herbie shell --seed 2024204
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))