
(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 (- (* x y))))
(if (<= y -3.5e+135)
(fma z y x)
(if (<= y -7e+41) t_0 (if (<= y 1450000.0) (fma z y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -(x * y);
double tmp;
if (y <= -3.5e+135) {
tmp = fma(z, y, x);
} else if (y <= -7e+41) {
tmp = t_0;
} else if (y <= 1450000.0) {
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 <= -3.5e+135) tmp = fma(z, y, x); elseif (y <= -7e+41) tmp = t_0; elseif (y <= 1450000.0) 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, -3.5e+135], N[(z * y + x), $MachinePrecision], If[LessEqual[y, -7e+41], t$95$0, If[LessEqual[y, 1450000.0], N[(z * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -x \cdot y\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+135}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;y \leq -7 \cdot 10^{+41}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1450000:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.5000000000000003e135 or -6.9999999999999998e41 < y < 1.45e6Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6493.5
Simplified93.5%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6493.5
Applied egg-rr93.5%
if -3.5000000000000003e135 < y < -6.9999999999999998e41 or 1.45e6 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6466.7
Simplified66.7%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -76000.0) t_0 (if (<= y 8.6e-10) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -76000.0) {
tmp = t_0;
} else if (y <= 8.6e-10) {
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 <= -76000.0) tmp = t_0; elseif (y <= 8.6e-10) 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, -76000.0], t$95$0, If[LessEqual[y, 8.6e-10], 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 -76000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -76000 or 8.60000000000000029e-10 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6498.6
Simplified98.6%
if -76000 < y < 8.60000000000000029e-10Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6499.6
Simplified99.6%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.6
Applied egg-rr99.6%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e-83) (* z y) (if (<= y 5.5e-53) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e-83) {
tmp = z * y;
} else if (y <= 5.5e-53) {
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.5d-83)) then
tmp = z * y
else if (y <= 5.5d-53) 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.5e-83) {
tmp = z * y;
} else if (y <= 5.5e-53) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e-83: tmp = z * y elif y <= 5.5e-53: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e-83) tmp = Float64(z * y); elseif (y <= 5.5e-53) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.5e-83) tmp = z * y; elseif (y <= 5.5e-53) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e-83], N[(z * y), $MachinePrecision], If[LessEqual[y, 5.5e-53], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-83}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.5e-83 or 5.50000000000000023e-53 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6452.6
Simplified52.6%
if -2.5e-83 < y < 5.50000000000000023e-53Initial program 100.0%
Taylor expanded in y around 0
Simplified76.1%
Final simplification62.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
*-lowering-*.f6475.3
Simplified75.3%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6475.3
Applied egg-rr75.3%
(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
Simplified35.9%
herbie shell --seed 2024199
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))