
(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%
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.4) (not (<= y 5.5e-52))) (* (- z x) y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4) || !(y <= 5.5e-52)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - 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 ((y <= (-1.4d0)) .or. (.not. (y <= 5.5d-52))) then
tmp = (z - x) * y
else
tmp = (1.0d0 - y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4) || !(y <= 5.5e-52)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4) or not (y <= 5.5e-52): tmp = (z - x) * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4) || !(y <= 5.5e-52)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.4) || ~((y <= 5.5e-52))) tmp = (z - x) * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4], N[Not[LessEqual[y, 5.5e-52]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \lor \neg \left(y \leq 5.5 \cdot 10^{-52}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if y < -1.3999999999999999 or 5.5e-52 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.4
Applied rewrites59.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -1.3999999999999999 < y < 5.5e-52Initial 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--.f6477.7
Applied rewrites77.7%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e+52) (not (<= z 4.2e+39))) (* z y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e+52) || !(z <= 4.2e+39)) {
tmp = z * y;
} else {
tmp = (1.0 - 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 <= (-8.5d+52)) .or. (.not. (z <= 4.2d+39))) then
tmp = z * y
else
tmp = (1.0d0 - y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e+52) || !(z <= 4.2e+39)) {
tmp = z * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e+52) or not (z <= 4.2e+39): tmp = z * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e+52) || !(z <= 4.2e+39)) tmp = Float64(z * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e+52) || ~((z <= 4.2e+39))) tmp = z * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e+52], N[Not[LessEqual[z, 4.2e+39]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+52} \lor \neg \left(z \leq 4.2 \cdot 10^{+39}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if z < -8.49999999999999994e52 or 4.1999999999999997e39 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6472.0
Applied rewrites72.0%
if -8.49999999999999994e52 < z < 4.1999999999999997e39Initial 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--.f6488.3
Applied rewrites88.3%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0013) (not (<= y 6.5e-54))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0013) || !(y <= 6.5e-54)) {
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 <= (-0.0013d0)) .or. (.not. (y <= 6.5d-54))) 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 <= -0.0013) || !(y <= 6.5e-54)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0013) or not (y <= 6.5e-54): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0013) || !(y <= 6.5e-54)) 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 <= -0.0013) || ~((y <= 6.5e-54))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0013], N[Not[LessEqual[y, 6.5e-54]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0013 \lor \neg \left(y \leq 6.5 \cdot 10^{-54}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -0.0012999999999999999 or 6.49999999999999991e-54 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6459.4
Applied rewrites59.4%
if -0.0012999999999999999 < y < 6.49999999999999991e-54Initial 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--.f6477.7
Applied rewrites77.7%
Taylor expanded in y around 0
Applied rewrites77.2%
Final simplification68.2%
(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-*.f6441.5
Applied rewrites41.5%
herbie shell --seed 2024338
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))