
(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 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 (<= y -7.5e+38) (* y (- x)) (if (or (<= y -2.7e-28) (not (<= y 1.75e-13))) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+38) {
tmp = y * -x;
} else if ((y <= -2.7e-28) || !(y <= 1.75e-13)) {
tmp = y * z;
} else {
tmp = 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 <= (-7.5d+38)) then
tmp = y * -x
else if ((y <= (-2.7d-28)) .or. (.not. (y <= 1.75d-13))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+38) {
tmp = y * -x;
} else if ((y <= -2.7e-28) || !(y <= 1.75e-13)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e+38: tmp = y * -x elif (y <= -2.7e-28) or not (y <= 1.75e-13): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e+38) tmp = Float64(y * Float64(-x)); elseif ((y <= -2.7e-28) || !(y <= 1.75e-13)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.5e+38) tmp = y * -x; elseif ((y <= -2.7e-28) || ~((y <= 1.75e-13))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+38], N[(y * (-x)), $MachinePrecision], If[Or[LessEqual[y, -2.7e-28], N[Not[LessEqual[y, 1.75e-13]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+38}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-28} \lor \neg \left(y \leq 1.75 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.4999999999999999e38Initial program 100.0%
Taylor expanded in x around inf 58.0%
mul-1-neg58.0%
unsub-neg58.0%
Simplified58.0%
Taylor expanded in y around inf 58.0%
associate-*r*58.0%
mul-1-neg58.0%
Simplified58.0%
if -7.4999999999999999e38 < y < -2.6999999999999999e-28 or 1.7500000000000001e-13 < y Initial program 100.0%
Taylor expanded in z around inf 61.4%
Taylor expanded in x around 0 60.1%
if -2.6999999999999999e-28 < y < 1.7500000000000001e-13Initial program 100.0%
Taylor expanded in y around 0 77.1%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.3e-66) (not (<= x 4.6e-135))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-66) || !(x <= 4.6e-135)) {
tmp = x * (1.0 - y);
} 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 ((x <= (-4.3d-66)) .or. (.not. (x <= 4.6d-135))) then
tmp = x * (1.0d0 - y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-66) || !(x <= 4.6e-135)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e-66) or not (x <= 4.6e-135): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e-66) || !(x <= 4.6e-135)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.3e-66) || ~((x <= 4.6e-135))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e-66], N[Not[LessEqual[x, 4.6e-135]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{-66} \lor \neg \left(x \leq 4.6 \cdot 10^{-135}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.30000000000000013e-66 or 4.5999999999999998e-135 < x Initial program 100.0%
Taylor expanded in x around inf 83.6%
mul-1-neg83.6%
unsub-neg83.6%
Simplified83.6%
if -4.30000000000000013e-66 < x < 4.5999999999999998e-135Initial program 100.0%
Taylor expanded in z around inf 92.6%
Taylor expanded in x around 0 71.5%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -122.0) (not (<= z 8.8e-32))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -122.0) || !(z <= 8.8e-32)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - 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 ((z <= (-122.0d0)) .or. (.not. (z <= 8.8d-32))) then
tmp = x + (y * z)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -122.0) || !(z <= 8.8e-32)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -122.0) or not (z <= 8.8e-32): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -122.0) || !(z <= 8.8e-32)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -122.0) || ~((z <= 8.8e-32))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -122.0], N[Not[LessEqual[z, 8.8e-32]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -122 \lor \neg \left(z \leq 8.8 \cdot 10^{-32}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -122 or 8.7999999999999999e-32 < z Initial program 100.0%
Taylor expanded in z around inf 90.2%
if -122 < z < 8.7999999999999999e-32Initial program 100.0%
Taylor expanded in x around inf 87.5%
mul-1-neg87.5%
unsub-neg87.5%
Simplified87.5%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.95e-27) (not (<= y 3.2e-15))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.95e-27) || !(y <= 3.2e-15)) {
tmp = y * z;
} else {
tmp = 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.95d-27)) .or. (.not. (y <= 3.2d-15))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.95e-27) || !(y <= 3.2e-15)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.95e-27) or not (y <= 3.2e-15): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.95e-27) || !(y <= 3.2e-15)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.95e-27) || ~((y <= 3.2e-15))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.95e-27], N[Not[LessEqual[y, 3.2e-15]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-27} \lor \neg \left(y \leq 3.2 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.94999999999999986e-27 or 3.1999999999999999e-15 < y Initial program 100.0%
Taylor expanded in z around inf 53.5%
Taylor expanded in x around 0 52.3%
if -1.94999999999999986e-27 < y < 3.1999999999999999e-15Initial program 100.0%
Taylor expanded in y around 0 77.1%
Final simplification64.3%
(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)
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.4%
Final simplification39.4%
herbie shell --seed 2023309
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))