
(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 (- 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 (fma (- 0.0 y) x x))) (if (<= x -5.8e+113) t_0 (if (<= x 3.2e-152) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((0.0 - y), x, x);
double tmp;
if (x <= -5.8e+113) {
tmp = t_0;
} else if (x <= 3.2e-152) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(0.0 - y), x, x) tmp = 0.0 if (x <= -5.8e+113) tmp = t_0; elseif (x <= 3.2e-152) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(0.0 - y), $MachinePrecision] * x + x), $MachinePrecision]}, If[LessEqual[x, -5.8e+113], t$95$0, If[LessEqual[x, 3.2e-152], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0 - y, x, x\right)\\
\mathbf{if}\;x \leq -5.8 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-152}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.79999999999999968e113 or 3.20000000000000013e-152 < x Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f64100.0
Applied egg-rr100.0%
*-commutativeN/A
sub-negN/A
distribute-lft-inN/A
*-commutativeN/A
sub0-negN/A
+-commutativeN/A
associate-+l+N/A
sub0-negN/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub0-negN/A
--lowering--.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6497.2
Applied egg-rr97.2%
*-commutativeN/A
sub0-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
accelerator-lowering-fma.f6497.2
Applied egg-rr97.2%
Taylor expanded in z around 0
Simplified86.9%
if -5.79999999999999968e113 < x < 3.20000000000000013e-152Initial program 100.0%
Taylor expanded in z around inf
Simplified88.3%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6488.3
Applied egg-rr88.3%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (<= y -2.3e-28) (* z y) (if (<= y 2e-42) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e-28) {
tmp = z * y;
} else if (y <= 2e-42) {
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.3d-28)) then
tmp = z * y
else if (y <= 2d-42) 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.3e-28) {
tmp = z * y;
} else if (y <= 2e-42) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.3e-28: tmp = z * y elif y <= 2e-42: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.3e-28) tmp = Float64(z * y); elseif (y <= 2e-42) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.3e-28) tmp = z * y; elseif (y <= 2e-42) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.3e-28], N[(z * y), $MachinePrecision], If[LessEqual[y, 2e-42], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-28}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-42}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.29999999999999986e-28 or 2.00000000000000008e-42 < y Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6452.5
Simplified52.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6452.5
Applied egg-rr52.5%
if -2.29999999999999986e-28 < y < 2.00000000000000008e-42Initial program 100.0%
Taylor expanded in y around 0
Simplified77.8%
(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
Simplified74.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6474.0
Applied egg-rr74.0%
(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
Simplified36.1%
herbie shell --seed 2024198
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))