
(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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y) x)))
(if (<= y -7.5e+232)
t_0
(if (<= y -3e-57) (* z y) (if (<= y 1.0) (* 1.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -7.5e+232) {
tmp = t_0;
} else if (y <= -3e-57) {
tmp = z * y;
} else if (y <= 1.0) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -y * x
if (y <= (-7.5d+232)) then
tmp = t_0
else if (y <= (-3d-57)) then
tmp = z * y
else if (y <= 1.0d0) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -7.5e+232) {
tmp = t_0;
} else if (y <= -3e-57) {
tmp = z * y;
} else if (y <= 1.0) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -y * x tmp = 0 if y <= -7.5e+232: tmp = t_0 elif y <= -3e-57: tmp = z * y elif y <= 1.0: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (y <= -7.5e+232) tmp = t_0; elseif (y <= -3e-57) tmp = Float64(z * y); elseif (y <= 1.0) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y * x; tmp = 0.0; if (y <= -7.5e+232) tmp = t_0; elseif (y <= -3e-57) tmp = z * y; elseif (y <= 1.0) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[y, -7.5e+232], t$95$0, If[LessEqual[y, -3e-57], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;y \leq -7.5 \cdot 10^{+232}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-57}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.50000000000000035e232 or 1 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6468.6
Applied rewrites68.6%
Taylor expanded in y around inf
Applied rewrites67.0%
if -7.50000000000000035e232 < y < -3.00000000000000001e-57Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6465.2
Applied rewrites65.2%
if -3.00000000000000001e-57 < y < 1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6467.9
Applied rewrites67.9%
Taylor expanded in y around 0
Applied rewrites67.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e-57) (not (<= y 3e-28))) (* (- z x) y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-57) || !(y <= 3e-28)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * 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 ((y <= (-3d-57)) .or. (.not. (y <= 3d-28))) then
tmp = (z - x) * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-57) || !(y <= 3e-28)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e-57) or not (y <= 3e-28): tmp = (z - x) * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e-57) || !(y <= 3e-28)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3e-57) || ~((y <= 3e-28))) tmp = (z - x) * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e-57], N[Not[LessEqual[y, 3e-28]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-57} \lor \neg \left(y \leq 3 \cdot 10^{-28}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -3.00000000000000001e-57 or 3.00000000000000003e-28 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6453.1
Applied rewrites53.1%
Taylor expanded in y around 0
Applied rewrites6.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.6
Applied rewrites95.6%
if -3.00000000000000001e-57 < y < 3.00000000000000003e-28Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6469.0
Applied rewrites69.0%
Taylor expanded in y around 0
Applied rewrites69.0%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e-83) (not (<= x 6e-82))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-83) || !(x <= 6e-82)) {
tmp = (1.0 - y) * 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 ((x <= (-1.1d-83)) .or. (.not. (x <= 6d-82))) then
tmp = (1.0d0 - y) * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-83) || !(x <= 6e-82)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-83) or not (x <= 6e-82): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-83) || !(x <= 6e-82)) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e-83) || ~((x <= 6e-82))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-83], N[Not[LessEqual[x, 6e-82]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-83} \lor \neg \left(x \leq 6 \cdot 10^{-82}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -1.10000000000000004e-83 or 5.9999999999999998e-82 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6482.5
Applied rewrites82.5%
if -1.10000000000000004e-83 < x < 5.9999999999999998e-82Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6478.5
Applied rewrites78.5%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e-57) (not (<= y 3.4e-40))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-57) || !(y <= 3.4e-40)) {
tmp = z * y;
} else {
tmp = 1.0 * 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 ((y <= (-3d-57)) .or. (.not. (y <= 3.4d-40))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-57) || !(y <= 3.4e-40)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e-57) or not (y <= 3.4e-40): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e-57) || !(y <= 3.4e-40)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3e-57) || ~((y <= 3.4e-40))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e-57], N[Not[LessEqual[y, 3.4e-40]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-57} \lor \neg \left(y \leq 3.4 \cdot 10^{-40}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -3.00000000000000001e-57 or 3.39999999999999984e-40 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6450.7
Applied rewrites50.7%
if -3.00000000000000001e-57 < y < 3.39999999999999984e-40Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6469.3
Applied rewrites69.3%
Taylor expanded in y around 0
Applied rewrites69.3%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6443.4
Applied rewrites43.4%
herbie shell --seed 2024339
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))