
(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 8 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 (<= z -2.8e-47) (not (<= z 2e-65))) (+ x (* y z)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-47) || !(z <= 2e-65)) {
tmp = x + (y * z);
} else {
tmp = x - (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 <= (-2.8d-47)) .or. (.not. (z <= 2d-65))) then
tmp = x + (y * z)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-47) || !(z <= 2e-65)) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-47) or not (z <= 2e-65): tmp = x + (y * z) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-47) || !(z <= 2e-65)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e-47) || ~((z <= 2e-65))) tmp = x + (y * z); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-47], N[Not[LessEqual[z, 2e-65]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-47} \lor \neg \left(z \leq 2 \cdot 10^{-65}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if z < -2.79999999999999993e-47 or 1.99999999999999985e-65 < z Initial program 100.0%
Taylor expanded in z around inf 88.4%
if -2.79999999999999993e-47 < z < 1.99999999999999985e-65Initial program 100.0%
Taylor expanded in x around inf 89.8%
mul-1-neg89.8%
unsub-neg89.8%
Simplified89.8%
sub-neg89.8%
distribute-rgt-in89.8%
*-un-lft-identity89.8%
distribute-lft-neg-in89.8%
unsub-neg89.8%
Applied egg-rr89.8%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -5e-45) (not (<= z 7.5e-64))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5e-45) || !(z <= 7.5e-64)) {
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 <= (-5d-45)) .or. (.not. (z <= 7.5d-64))) 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 <= -5e-45) || !(z <= 7.5e-64)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5e-45) or not (z <= 7.5e-64): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5e-45) || !(z <= 7.5e-64)) 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 <= -5e-45) || ~((z <= 7.5e-64))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5e-45], N[Not[LessEqual[z, 7.5e-64]], $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 -5 \cdot 10^{-45} \lor \neg \left(z \leq 7.5 \cdot 10^{-64}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -4.99999999999999976e-45 or 7.49999999999999949e-64 < z Initial program 100.0%
Taylor expanded in z around inf 88.4%
if -4.99999999999999976e-45 < z < 7.49999999999999949e-64Initial program 100.0%
Taylor expanded in x around inf 89.8%
mul-1-neg89.8%
unsub-neg89.8%
Simplified89.8%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-78) (not (<= x 4.2e-132))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-78) || !(x <= 4.2e-132)) {
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.05d-78)) .or. (.not. (x <= 4.2d-132))) 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.05e-78) || !(x <= 4.2e-132)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-78) or not (x <= 4.2e-132): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-78) || !(x <= 4.2e-132)) 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.05e-78) || ~((x <= 4.2e-132))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-78], N[Not[LessEqual[x, 4.2e-132]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-78} \lor \neg \left(x \leq 4.2 \cdot 10^{-132}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.05e-78 or 4.2000000000000002e-132 < x Initial program 100.0%
Taylor expanded in x around inf 80.6%
mul-1-neg80.6%
unsub-neg80.6%
Simplified80.6%
if -1.05e-78 < x < 4.2000000000000002e-132Initial program 100.0%
Taylor expanded in z around inf 94.5%
Taylor expanded in z around inf 94.5%
Taylor expanded in y around inf 82.1%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.6e-32) (* y z) (if (<= y 1.0) x (* x (- y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e-32) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * -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 <= (-1.6d-32)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e-32) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.6e-32: tmp = y * z elif y <= 1.0: tmp = x else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.6e-32) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.6e-32) tmp = y * z; elseif (y <= 1.0) tmp = x; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.6e-32], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * (-y)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.6000000000000001e-32Initial program 100.0%
Taylor expanded in z around inf 61.1%
Taylor expanded in z around inf 64.1%
Taylor expanded in y around inf 55.9%
if -1.6000000000000001e-32 < y < 1Initial program 100.0%
Taylor expanded in y around 0 70.5%
if 1 < y Initial program 100.0%
Taylor expanded in x around inf 52.8%
mul-1-neg52.8%
unsub-neg52.8%
Simplified52.8%
Taylor expanded in y around inf 52.8%
neg-mul-152.8%
Simplified52.8%
Final simplification62.3%
(FPCore (x y z) :precision binary64 (if (<= x -2.08e-10) x (if (<= x 0.00037) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.08e-10) {
tmp = x;
} else if (x <= 0.00037) {
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 (x <= (-2.08d-10)) then
tmp = x
else if (x <= 0.00037d0) 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 (x <= -2.08e-10) {
tmp = x;
} else if (x <= 0.00037) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.08e-10: tmp = x elif x <= 0.00037: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.08e-10) tmp = x; elseif (x <= 0.00037) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.08e-10) tmp = x; elseif (x <= 0.00037) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.08e-10], x, If[LessEqual[x, 0.00037], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.08 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 0.00037:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.0800000000000001e-10 or 3.6999999999999999e-4 < x Initial program 100.0%
Taylor expanded in y around 0 54.8%
if -2.0800000000000001e-10 < x < 3.6999999999999999e-4Initial program 100.0%
Taylor expanded in z around inf 86.5%
Taylor expanded in z around inf 86.5%
Taylor expanded in y around inf 69.4%
Final simplification62.2%
(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 36.9%
herbie shell --seed 2024185
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))