
(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-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e+15) (not (<= y 0.195))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e+15) || !(y <= 0.195)) {
tmp = y * (z - x);
} else {
tmp = x + (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 <= (-3d+15)) .or. (.not. (y <= 0.195d0))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3e+15) || !(y <= 0.195)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e+15) or not (y <= 0.195): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e+15) || !(y <= 0.195)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3e+15) || ~((y <= 0.195))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e+15], N[Not[LessEqual[y, 0.195]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+15} \lor \neg \left(y \leq 0.195\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -3e15 or 0.19500000000000001 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.5%
if -3e15 < y < 0.19500000000000001Initial program 100.0%
Taylor expanded in z around inf 99.1%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-96) (not (<= y 4.9e-11))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-96) || !(y <= 4.9e-11)) {
tmp = y * (z - x);
} 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 ((y <= (-5d-96)) .or. (.not. (y <= 4.9d-11))) then
tmp = y * (z - x)
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 ((y <= -5e-96) || !(y <= 4.9e-11)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-96) or not (y <= 4.9e-11): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-96) || !(y <= 4.9e-11)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5e-96) || ~((y <= 4.9e-11))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-96], N[Not[LessEqual[y, 4.9e-11]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-96} \lor \neg \left(y \leq 4.9 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -4.99999999999999995e-96 or 4.8999999999999999e-11 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
Taylor expanded in z around inf 94.1%
if -4.99999999999999995e-96 < y < 4.8999999999999999e-11Initial program 100.0%
Taylor expanded in x around inf 71.2%
mul-1-neg71.2%
unsub-neg71.2%
Simplified71.2%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5e-163) (not (<= x 1.05e-50))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e-163) || !(x <= 1.05e-50)) {
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 <= (-5d-163)) .or. (.not. (x <= 1.05d-50))) 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 <= -5e-163) || !(x <= 1.05e-50)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e-163) or not (x <= 1.05e-50): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e-163) || !(x <= 1.05e-50)) 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 <= -5e-163) || ~((x <= 1.05e-50))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e-163], N[Not[LessEqual[x, 1.05e-50]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-163} \lor \neg \left(x \leq 1.05 \cdot 10^{-50}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.99999999999999977e-163 or 1.05e-50 < x Initial program 100.0%
Taylor expanded in x around inf 78.4%
mul-1-neg78.4%
unsub-neg78.4%
Simplified78.4%
if -4.99999999999999977e-163 < x < 1.05e-50Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 75.1%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2e-73) (not (<= y 1.6e-11))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-73) || !(y <= 1.6e-11)) {
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 <= (-2d-73)) .or. (.not. (y <= 1.6d-11))) 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 <= -2e-73) || !(y <= 1.6e-11)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e-73) or not (y <= 1.6e-11): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e-73) || !(y <= 1.6e-11)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2e-73) || ~((y <= 1.6e-11))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e-73], N[Not[LessEqual[y, 1.6e-11]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-73} \lor \neg \left(y \leq 1.6 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.99999999999999999e-73 or 1.59999999999999997e-11 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
Taylor expanded in z around inf 60.5%
if -1.99999999999999999e-73 < y < 1.59999999999999997e-11Initial program 100.0%
Taylor expanded in y around 0 70.3%
Final simplification64.8%
(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%
(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 34.7%
herbie shell --seed 2024170
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))