
(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 7 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 (if (or (<= y -1.35e-20) (not (<= y 1.45e-22))) (* (- z x) y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-20) || !(y <= 1.45e-22)) {
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 <= (-1.35d-20)) .or. (.not. (y <= 1.45d-22))) 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 <= -1.35e-20) || !(y <= 1.45e-22)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-20) or not (y <= 1.45e-22): tmp = (z - x) * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-20) || !(y <= 1.45e-22)) 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 <= -1.35e-20) || ~((y <= 1.45e-22))) tmp = (z - x) * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-20], N[Not[LessEqual[y, 1.45e-22]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-20} \lor \neg \left(y \leq 1.45 \cdot 10^{-22}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1.35e-20 or 1.4500000000000001e-22 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.5
Applied rewrites95.5%
if -1.35e-20 < y < 1.4500000000000001e-22Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.5
Applied rewrites70.5%
Taylor expanded in y around 0
Applied rewrites70.5%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-91) (not (<= x 3.2e-62))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-91) || !(x <= 3.2e-62)) {
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 <= (-9d-91)) .or. (.not. (x <= 3.2d-62))) 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 <= -9e-91) || !(x <= 3.2e-62)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-91) or not (x <= 3.2e-62): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-91) || !(x <= 3.2e-62)) 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 <= -9e-91) || ~((x <= 3.2e-62))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-91], N[Not[LessEqual[x, 3.2e-62]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-91} \lor \neg \left(x \leq 3.2 \cdot 10^{-62}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -8.99999999999999952e-91 or 3.20000000000000021e-62 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6481.5
Applied rewrites81.5%
if -8.99999999999999952e-91 < x < 3.20000000000000021e-62Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
Final simplification77.2%
(FPCore (x y z) :precision binary64 (if (<= x -9e-91) (* (- 1.0 y) x) (if (<= x 3.2e-62) (* z y) (fma (- y) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9e-91) {
tmp = (1.0 - y) * x;
} else if (x <= 3.2e-62) {
tmp = z * y;
} else {
tmp = fma(-y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -9e-91) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 3.2e-62) tmp = Float64(z * y); else tmp = fma(Float64(-y), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -9e-91], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 3.2e-62], N[(z * y), $MachinePrecision], N[((-y) * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-91}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-62}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\end{array}
\end{array}
if x < -8.99999999999999952e-91Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.7
Applied rewrites75.7%
if -8.99999999999999952e-91 < x < 3.20000000000000021e-62Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
if 3.20000000000000021e-62 < x Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6487.6
Applied rewrites87.6%
Applied rewrites87.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-20) (not (<= y 1.25e-22))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-20) || !(y <= 1.25e-22)) {
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 <= (-1.35d-20)) .or. (.not. (y <= 1.25d-22))) 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 <= -1.35e-20) || !(y <= 1.25e-22)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-20) or not (y <= 1.25e-22): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-20) || !(y <= 1.25e-22)) 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 <= -1.35e-20) || ~((y <= 1.25e-22))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-20], N[Not[LessEqual[y, 1.25e-22]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-20} \lor \neg \left(y \leq 1.25 \cdot 10^{-22}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1.35e-20 or 1.24999999999999988e-22 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.9
Applied rewrites52.9%
if -1.35e-20 < y < 1.24999999999999988e-22Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.5
Applied rewrites70.5%
Taylor expanded in y around 0
Applied rewrites70.5%
Final simplification60.7%
(FPCore (x y z) :precision binary64 (if (<= y -0.0031) (* (- y) x) (if (<= y 1.25e-22) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.0031) {
tmp = -y * x;
} else if (y <= 1.25e-22) {
tmp = 1.0 * 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 <= (-0.0031d0)) then
tmp = -y * x
else if (y <= 1.25d-22) then
tmp = 1.0d0 * 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 <= -0.0031) {
tmp = -y * x;
} else if (y <= 1.25e-22) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.0031: tmp = -y * x elif y <= 1.25e-22: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.0031) tmp = Float64(Float64(-y) * x); elseif (y <= 1.25e-22) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.0031) tmp = -y * x; elseif (y <= 1.25e-22) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.0031], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 1.25e-22], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0031:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-22}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -0.00309999999999999989Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6465.6
Applied rewrites65.6%
Taylor expanded in y around inf
Applied rewrites63.5%
if -0.00309999999999999989 < y < 1.24999999999999988e-22Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6469.8
Applied rewrites69.8%
Taylor expanded in y around 0
Applied rewrites68.9%
if 1.24999999999999988e-22 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6461.3
Applied rewrites61.3%
(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.1
Applied rewrites43.1%
herbie shell --seed 2024317
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))