
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3.05e+165)
(* y z)
(if (<= y -9e+95)
t_0
(if (<= y -2.2e-51)
(* y z)
(if (<= y 13000.0) x (if (<= y 3.8e+275) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.05e+165) {
tmp = y * z;
} else if (y <= -9e+95) {
tmp = t_0;
} else if (y <= -2.2e-51) {
tmp = y * z;
} else if (y <= 13000.0) {
tmp = x;
} else if (y <= 3.8e+275) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-3.05d+165)) then
tmp = y * z
else if (y <= (-9d+95)) then
tmp = t_0
else if (y <= (-2.2d-51)) then
tmp = y * z
else if (y <= 13000.0d0) then
tmp = x
else if (y <= 3.8d+275) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.05e+165) {
tmp = y * z;
} else if (y <= -9e+95) {
tmp = t_0;
} else if (y <= -2.2e-51) {
tmp = y * z;
} else if (y <= 13000.0) {
tmp = x;
} else if (y <= 3.8e+275) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.05e+165: tmp = y * z elif y <= -9e+95: tmp = t_0 elif y <= -2.2e-51: tmp = y * z elif y <= 13000.0: tmp = x elif y <= 3.8e+275: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -3.05e+165) tmp = Float64(y * z); elseif (y <= -9e+95) tmp = t_0; elseif (y <= -2.2e-51) tmp = Float64(y * z); elseif (y <= 13000.0) tmp = x; elseif (y <= 3.8e+275) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -3.05e+165) tmp = y * z; elseif (y <= -9e+95) tmp = t_0; elseif (y <= -2.2e-51) tmp = y * z; elseif (y <= 13000.0) tmp = x; elseif (y <= 3.8e+275) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -3.05e+165], N[(y * z), $MachinePrecision], If[LessEqual[y, -9e+95], t$95$0, If[LessEqual[y, -2.2e-51], N[(y * z), $MachinePrecision], If[LessEqual[y, 13000.0], x, If[LessEqual[y, 3.8e+275], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.05 \cdot 10^{+165}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -9 \cdot 10^{+95}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{-51}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 13000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+275}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -3.04999999999999983e165 or -9.00000000000000033e95 < y < -2.2e-51 or 3.80000000000000012e275 < y Initial program 99.9%
Taylor expanded in z around inf 74.0%
Taylor expanded in x around 0 66.9%
if -3.04999999999999983e165 < y < -9.00000000000000033e95 or 13000 < y < 3.80000000000000012e275Initial program 100.0%
Taylor expanded in x around inf 67.9%
*-commutative67.9%
mul-1-neg67.9%
Simplified67.9%
Taylor expanded in y around inf 67.4%
mul-1-neg67.4%
distribute-rgt-neg-in67.4%
Simplified67.4%
if -2.2e-51 < y < 13000Initial program 100.0%
Taylor expanded in y around 0 77.8%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e+86) (not (<= x 5.8e+73))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+86) || !(x <= 5.8e+73)) {
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 <= (-2.4d+86)) .or. (.not. (x <= 5.8d+73))) 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 <= -2.4e+86) || !(x <= 5.8e+73)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e+86) or not (x <= 5.8e+73): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e+86) || !(x <= 5.8e+73)) 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 <= -2.4e+86) || ~((x <= 5.8e+73))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e+86], N[Not[LessEqual[x, 5.8e+73]], $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 -2.4 \cdot 10^{+86} \lor \neg \left(x \leq 5.8 \cdot 10^{+73}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.4e86 or 5.8000000000000005e73 < x Initial program 100.0%
Taylor expanded in x around inf 91.5%
*-commutative91.5%
mul-1-neg91.5%
Simplified91.5%
Taylor expanded in x around 0 91.5%
if -2.4e86 < x < 5.8000000000000005e73Initial program 100.0%
Taylor expanded in z around inf 87.1%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.6e+122) (* y z) (if (<= z 135000000000.0) (* x (- 1.0 y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e+122) {
tmp = y * z;
} else if (z <= 135000000000.0) {
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 (z <= (-1.6d+122)) then
tmp = y * z
else if (z <= 135000000000.0d0) 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 (z <= -1.6e+122) {
tmp = y * z;
} else if (z <= 135000000000.0) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.6e+122: tmp = y * z elif z <= 135000000000.0: tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.6e+122) tmp = Float64(y * z); elseif (z <= 135000000000.0) 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 (z <= -1.6e+122) tmp = y * z; elseif (z <= 135000000000.0) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.6e+122], N[(y * z), $MachinePrecision], If[LessEqual[z, 135000000000.0], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+122}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 135000000000:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.60000000000000006e122 or 1.35e11 < z Initial program 100.0%
Taylor expanded in z around inf 90.8%
Taylor expanded in x around 0 71.6%
if -1.60000000000000006e122 < z < 1.35e11Initial program 100.0%
Taylor expanded in x around inf 78.4%
*-commutative78.4%
mul-1-neg78.4%
Simplified78.4%
Taylor expanded in x around 0 78.4%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e+88) (- x (* y x)) (if (<= x 4.6e+73) (+ x (* y z)) (* x (- 1.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e+88) {
tmp = x - (y * x);
} else if (x <= 4.6e+73) {
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 (x <= (-1.4d+88)) then
tmp = x - (y * x)
else if (x <= 4.6d+73) 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 (x <= -1.4e+88) {
tmp = x - (y * x);
} else if (x <= 4.6e+73) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.4e+88: tmp = x - (y * x) elif x <= 4.6e+73: tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.4e+88) tmp = Float64(x - Float64(y * x)); elseif (x <= 4.6e+73) 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 (x <= -1.4e+88) tmp = x - (y * x); elseif (x <= 4.6e+73) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.4e+88], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.6e+73], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+88}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+73}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -1.39999999999999994e88Initial program 100.0%
Taylor expanded in x around inf 92.7%
+-commutative92.7%
distribute-rgt1-in92.7%
mul-1-neg92.7%
cancel-sign-sub-inv92.7%
Simplified92.7%
if -1.39999999999999994e88 < x < 4.6e73Initial program 100.0%
Taylor expanded in z around inf 87.1%
if 4.6e73 < x Initial program 100.0%
Taylor expanded in x around inf 90.3%
*-commutative90.3%
mul-1-neg90.3%
Simplified90.3%
Taylor expanded in x around 0 90.3%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e-50) (* y z) (if (<= y 1e-5) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e-50) {
tmp = y * z;
} else if (y <= 1e-5) {
tmp = x;
} 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 (y <= (-2.5d-50)) then
tmp = y * z
else if (y <= 1d-5) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e-50) {
tmp = y * z;
} else if (y <= 1e-5) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e-50: tmp = y * z elif y <= 1e-5: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e-50) tmp = Float64(y * z); elseif (y <= 1e-5) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.5e-50) tmp = y * z; elseif (y <= 1e-5) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e-50], N[(y * z), $MachinePrecision], If[LessEqual[y, 1e-5], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-50}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.49999999999999984e-50 or 1.00000000000000008e-5 < y Initial program 100.0%
Taylor expanded in z around inf 58.5%
Taylor expanded in x around 0 54.3%
if -2.49999999999999984e-50 < y < 1.00000000000000008e-5Initial program 100.0%
Taylor expanded in y around 0 79.1%
Final simplification65.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%
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 38.3%
Final simplification38.3%
herbie shell --seed 2023240
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))