
(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 (<= z -1.36e-135) (not (<= z 3.4e+68))) (+ x (* y z)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.36e-135) || !(z <= 3.4e+68)) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
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 ((z <= (-1.36d-135)) .or. (.not. (z <= 3.4d+68))) then
tmp = x + (y * z)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.36e-135) || !(z <= 3.4e+68)) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.36e-135) or not (z <= 3.4e+68): tmp = x + (y * z) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.36e-135) || !(z <= 3.4e+68)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.36e-135) || ~((z <= 3.4e+68))) tmp = x + (y * z); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.36e-135], N[Not[LessEqual[z, 3.4e+68]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.36 \cdot 10^{-135} \lor \neg \left(z \leq 3.4 \cdot 10^{+68}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if z < -1.36e-135 or 3.40000000000000015e68 < z Initial program 100.0%
Taylor expanded in z around inf 94.0%
if -1.36e-135 < z < 3.40000000000000015e68Initial program 100.0%
Taylor expanded in x around inf 85.4%
+-commutative85.4%
distribute-rgt1-in85.4%
mul-1-neg85.4%
cancel-sign-sub-inv85.4%
Simplified85.4%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -6.3e-38) (* y z) (if (<= y 6.5e-11) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.3e-38) {
tmp = y * z;
} else if (y <= 6.5e-11) {
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 <= (-6.3d-38)) then
tmp = y * z
else if (y <= 6.5d-11) 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 <= -6.3e-38) {
tmp = y * z;
} else if (y <= 6.5e-11) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.3e-38: tmp = y * z elif y <= 6.5e-11: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.3e-38) tmp = Float64(y * z); elseif (y <= 6.5e-11) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.3e-38) tmp = y * z; elseif (y <= 6.5e-11) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.3e-38], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.5e-11], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.3 \cdot 10^{-38}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -6.2999999999999996e-38 or 6.49999999999999953e-11 < y Initial program 100.0%
Taylor expanded in z around inf 60.8%
Taylor expanded in x around 0 59.6%
if -6.2999999999999996e-38 < y < 6.49999999999999953e-11Initial program 100.0%
Taylor expanded in y around 0 75.4%
Final simplification67.2%
(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.5%
Final simplification79.5%
(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 38.2%
Final simplification38.2%
herbie shell --seed 2023199
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))