
(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 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%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e-17) (not (<= x 2.35e+126))) (- x (* y x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-17) || !(x <= 2.35e+126)) {
tmp = x - (y * x);
} else {
tmp = x + (y * z);
}
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 ((x <= (-3.3d-17)) .or. (.not. (x <= 2.35d+126))) then
tmp = x - (y * x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-17) || !(x <= 2.35e+126)) {
tmp = x - (y * x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e-17) or not (x <= 2.35e+126): tmp = x - (y * x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e-17) || !(x <= 2.35e+126)) tmp = Float64(x - Float64(y * x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.3e-17) || ~((x <= 2.35e+126))) tmp = x - (y * x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e-17], N[Not[LessEqual[x, 2.35e+126]], $MachinePrecision]], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-17} \lor \neg \left(x \leq 2.35 \cdot 10^{+126}\right):\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.3e-17 or 2.3499999999999999e126 < x Initial program 100.0%
Taylor expanded in x around inf 90.4%
+-commutative90.4%
distribute-rgt1-in90.4%
mul-1-neg90.4%
cancel-sign-sub-inv90.4%
Simplified90.4%
if -3.3e-17 < x < 2.3499999999999999e126Initial program 100.0%
Taylor expanded in z around inf 86.7%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= y -9.8e-57) (* y z) (if (<= y 9.8e-67) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.8e-57) {
tmp = y * z;
} else if (y <= 9.8e-67) {
tmp = x;
} else {
tmp = y * z;
}
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 <= (-9.8d-57)) then
tmp = y * z
else if (y <= 9.8d-67) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.8e-57) {
tmp = y * z;
} else if (y <= 9.8e-67) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.8e-57: tmp = y * z elif y <= 9.8e-67: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.8e-57) tmp = Float64(y * z); elseif (y <= 9.8e-67) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.8e-57) tmp = y * z; elseif (y <= 9.8e-67) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.8e-57], N[(y * z), $MachinePrecision], If[LessEqual[y, 9.8e-67], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{-57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-67}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -9.79999999999999976e-57 or 9.79999999999999987e-67 < y Initial program 100.0%
Taylor expanded in z around inf 64.1%
Taylor expanded in x around 0 56.2%
if -9.79999999999999976e-57 < y < 9.79999999999999987e-67Initial program 100.0%
Taylor expanded in y around 0 78.9%
Final simplification65.7%
(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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (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 = x + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 79.2%
Final simplification79.2%
(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 39.3%
Final simplification39.3%
herbie shell --seed 2023175
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))