
(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 99.9%
+-commutative99.9%
fma-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+145) (* x (- y)) (if (or (<= y -3.7e-135) (not (<= y 3.2e-93))) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+145) {
tmp = x * -y;
} else if ((y <= -3.7e-135) || !(y <= 3.2e-93)) {
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.1d+145)) then
tmp = x * -y
else if ((y <= (-3.7d-135)) .or. (.not. (y <= 3.2d-93))) 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.1e+145) {
tmp = x * -y;
} else if ((y <= -3.7e-135) || !(y <= 3.2e-93)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e+145: tmp = x * -y elif (y <= -3.7e-135) or not (y <= 3.2e-93): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+145) tmp = Float64(x * Float64(-y)); elseif ((y <= -3.7e-135) || !(y <= 3.2e-93)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e+145) tmp = x * -y; elseif ((y <= -3.7e-135) || ~((y <= 3.2e-93))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+145], N[(x * (-y)), $MachinePrecision], If[Or[LessEqual[y, -3.7e-135], N[Not[LessEqual[y, 3.2e-93]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+145}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{-135} \lor \neg \left(y \leq 3.2 \cdot 10^{-93}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.10000000000000004e145Initial program 100.0%
Taylor expanded in x around inf 60.1%
mul-1-neg60.1%
unsub-neg60.1%
Simplified60.1%
Taylor expanded in y around inf 60.1%
neg-mul-160.1%
Simplified60.1%
if -1.10000000000000004e145 < y < -3.6999999999999997e-135 or 3.1999999999999999e-93 < y Initial program 99.9%
Taylor expanded in z around inf 68.1%
Taylor expanded in y around inf 66.7%
Taylor expanded in z around inf 54.5%
if -3.6999999999999997e-135 < y < 3.1999999999999999e-93Initial program 100.0%
Taylor expanded in y around 0 82.7%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e+14) (not (<= x 1.65e+31))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+14) || !(x <= 1.65e+31)) {
tmp = x * (1.0 - y);
} 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 ((x <= (-1.6d+14)) .or. (.not. (x <= 1.65d+31))) then
tmp = x * (1.0d0 - y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+14) || !(x <= 1.65e+31)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+14) or not (x <= 1.65e+31): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+14) || !(x <= 1.65e+31)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e+14) || ~((x <= 1.65e+31))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+14], N[Not[LessEqual[x, 1.65e+31]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+14} \lor \neg \left(x \leq 1.65 \cdot 10^{+31}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.6e14 or 1.64999999999999996e31 < x Initial program 99.9%
Taylor expanded in x around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
if -1.6e14 < x < 1.64999999999999996e31Initial program 99.9%
Taylor expanded in z around inf 89.7%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e-79) (not (<= x 1.6e-52))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e-79) || !(x <= 1.6e-52)) {
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 <= (-1.25d-79)) .or. (.not. (x <= 1.6d-52))) 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 <= -1.25e-79) || !(x <= 1.6e-52)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e-79) or not (x <= 1.6e-52): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e-79) || !(x <= 1.6e-52)) 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 <= -1.25e-79) || ~((x <= 1.6e-52))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e-79], N[Not[LessEqual[x, 1.6e-52]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-79} \lor \neg \left(x \leq 1.6 \cdot 10^{-52}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.25e-79 or 1.60000000000000005e-52 < x Initial program 100.0%
Taylor expanded in x around inf 82.9%
mul-1-neg82.9%
unsub-neg82.9%
Simplified82.9%
if -1.25e-79 < x < 1.60000000000000005e-52Initial program 99.9%
Taylor expanded in z around inf 92.1%
Taylor expanded in y around inf 92.1%
Taylor expanded in z around inf 76.3%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-135) (not (<= y 1.02e-88))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-135) || !(y <= 1.02e-88)) {
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 <= (-5.2d-135)) .or. (.not. (y <= 1.02d-88))) 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 <= -5.2e-135) || !(y <= 1.02e-88)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-135) or not (y <= 1.02e-88): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-135) || !(y <= 1.02e-88)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.2e-135) || ~((y <= 1.02e-88))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-135], N[Not[LessEqual[y, 1.02e-88]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-135} \lor \neg \left(y \leq 1.02 \cdot 10^{-88}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.20000000000000008e-135 or 1.02000000000000001e-88 < y Initial program 99.9%
Taylor expanded in z around inf 62.7%
Taylor expanded in y around inf 61.7%
Taylor expanded in z around inf 52.3%
if -5.20000000000000008e-135 < y < 1.02000000000000001e-88Initial program 100.0%
Taylor expanded in y around 0 82.7%
Final simplification62.0%
(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 99.9%
(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 99.9%
Taylor expanded in y around 0 34.8%
herbie shell --seed 2024136
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))