
(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 6 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 (+ 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
(if (<= y -1.85e+264)
(* y z)
(if (or (<= y -1.08e+164) (and (not (<= y -2.25e+98)) (<= y -1.06e+17)))
(* y (- x))
(+ x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e+264) {
tmp = y * z;
} else if ((y <= -1.08e+164) || (!(y <= -2.25e+98) && (y <= -1.06e+17))) {
tmp = y * -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 <= (-1.85d+264)) then
tmp = y * z
else if ((y <= (-1.08d+164)) .or. (.not. (y <= (-2.25d+98))) .and. (y <= (-1.06d+17))) then
tmp = y * -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 <= -1.85e+264) {
tmp = y * z;
} else if ((y <= -1.08e+164) || (!(y <= -2.25e+98) && (y <= -1.06e+17))) {
tmp = y * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e+264: tmp = y * z elif (y <= -1.08e+164) or (not (y <= -2.25e+98) and (y <= -1.06e+17)): tmp = y * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e+264) tmp = Float64(y * z); elseif ((y <= -1.08e+164) || (!(y <= -2.25e+98) && (y <= -1.06e+17))) tmp = Float64(y * Float64(-x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.85e+264) tmp = y * z; elseif ((y <= -1.08e+164) || (~((y <= -2.25e+98)) && (y <= -1.06e+17))) tmp = y * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e+264], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -1.08e+164], And[N[Not[LessEqual[y, -2.25e+98]], $MachinePrecision], LessEqual[y, -1.06e+17]]], N[(y * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{+264}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.08 \cdot 10^{+164} \lor \neg \left(y \leq -2.25 \cdot 10^{+98}\right) \land y \leq -1.06 \cdot 10^{+17}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.85e264Initial program 100.0%
Taylor expanded in z around inf 88.9%
Taylor expanded in x around 0 88.9%
if -1.85e264 < y < -1.08e164 or -2.2500000000000001e98 < y < -1.06e17Initial program 100.0%
Taylor expanded in z around 0 73.7%
mul-1-neg73.7%
distribute-lft-neg-out73.7%
*-commutative73.7%
Simplified73.7%
Taylor expanded in y around inf 73.7%
associate-*r*73.7%
mul-1-neg73.7%
Simplified73.7%
if -1.08e164 < y < -2.2500000000000001e98 or -1.06e17 < y Initial program 100.0%
Taylor expanded in z around inf 86.3%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (<= x -2.15e-11) x (if (<= x 2e+35) (* y z) (if (<= x 3.1e+181) x (* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-11) {
tmp = x;
} else if (x <= 2e+35) {
tmp = y * z;
} else if (x <= 3.1e+181) {
tmp = x;
} else {
tmp = 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 (x <= (-2.15d-11)) then
tmp = x
else if (x <= 2d+35) then
tmp = y * z
else if (x <= 3.1d+181) then
tmp = x
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-11) {
tmp = x;
} else if (x <= 2e+35) {
tmp = y * z;
} else if (x <= 3.1e+181) {
tmp = x;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.15e-11: tmp = x elif x <= 2e+35: tmp = y * z elif x <= 3.1e+181: tmp = x else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.15e-11) tmp = x; elseif (x <= 2e+35) tmp = Float64(y * z); elseif (x <= 3.1e+181) tmp = x; else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.15e-11) tmp = x; elseif (x <= 2e+35) tmp = y * z; elseif (x <= 3.1e+181) tmp = x; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.15e-11], x, If[LessEqual[x, 2e+35], N[(y * z), $MachinePrecision], If[LessEqual[x, 3.1e+181], x, N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+35}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+181}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -2.15000000000000001e-11 or 1.9999999999999999e35 < x < 3.09999999999999989e181Initial program 100.0%
Taylor expanded in z around inf 71.0%
Taylor expanded in x around inf 57.4%
if -2.15000000000000001e-11 < x < 1.9999999999999999e35Initial program 100.0%
Taylor expanded in z around inf 88.6%
Taylor expanded in x around 0 71.4%
if 3.09999999999999989e181 < x Initial program 100.0%
Taylor expanded in z around 0 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 62.3%
associate-*r*62.3%
mul-1-neg62.3%
Simplified62.3%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e+44) (not (<= x 1.1e+107))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e+44) || !(x <= 1.1e+107)) {
tmp = x - (x * 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 <= (-2.1d+44)) .or. (.not. (x <= 1.1d+107))) then
tmp = x - (x * 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 <= -2.1e+44) || !(x <= 1.1e+107)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e+44) or not (x <= 1.1e+107): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e+44) || !(x <= 1.1e+107)) tmp = Float64(x - Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1e+44) || ~((x <= 1.1e+107))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e+44], N[Not[LessEqual[x, 1.1e+107]], $MachinePrecision]], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+44} \lor \neg \left(x \leq 1.1 \cdot 10^{+107}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.09999999999999987e44 or 1.1e107 < x Initial program 100.0%
Taylor expanded in z around 0 94.7%
mul-1-neg94.7%
distribute-lft-neg-out94.7%
*-commutative94.7%
Simplified94.7%
*-commutative94.7%
distribute-lft-neg-out94.7%
unsub-neg94.7%
Applied egg-rr94.7%
if -2.09999999999999987e44 < x < 1.1e107Initial program 100.0%
Taylor expanded in z around inf 88.7%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (<= x -7.8e-13) x (if (<= x 2e+35) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.8e-13) {
tmp = x;
} else if (x <= 2e+35) {
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 <= (-7.8d-13)) then
tmp = x
else if (x <= 2d+35) 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 <= -7.8e-13) {
tmp = x;
} else if (x <= 2e+35) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.8e-13: tmp = x elif x <= 2e+35: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.8e-13) tmp = x; elseif (x <= 2e+35) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.8e-13) tmp = x; elseif (x <= 2e+35) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.8e-13], x, If[LessEqual[x, 2e+35], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+35}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.80000000000000009e-13 or 1.9999999999999999e35 < x Initial program 100.0%
Taylor expanded in z around inf 66.7%
Taylor expanded in x around inf 54.2%
if -7.80000000000000009e-13 < x < 1.9999999999999999e35Initial program 100.0%
Taylor expanded in z around inf 88.6%
Taylor expanded in x around 0 71.4%
Final simplification63.6%
(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 z around inf 78.7%
Taylor expanded in x around inf 34.9%
Final simplification34.9%
herbie shell --seed 2024067
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))