
(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
(let* ((t_0 (* x (- y))))
(if (<= y -3e+121)
(* y z)
(if (<= y -1.45e+31)
t_0
(if (<= y -8.5e-19)
(* y z)
(if (<= y 5.8e-18)
x
(if (or (<= y 2.2e+65) (and (not (<= y 3.8e+156)) (<= y 3.8e+197)))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -3e+121) {
tmp = y * z;
} else if (y <= -1.45e+31) {
tmp = t_0;
} else if (y <= -8.5e-19) {
tmp = y * z;
} else if (y <= 5.8e-18) {
tmp = x;
} else if ((y <= 2.2e+65) || (!(y <= 3.8e+156) && (y <= 3.8e+197))) {
tmp = y * z;
} else {
tmp = t_0;
}
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 = x * -y
if (y <= (-3d+121)) then
tmp = y * z
else if (y <= (-1.45d+31)) then
tmp = t_0
else if (y <= (-8.5d-19)) then
tmp = y * z
else if (y <= 5.8d-18) then
tmp = x
else if ((y <= 2.2d+65) .or. (.not. (y <= 3.8d+156)) .and. (y <= 3.8d+197)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -3e+121) {
tmp = y * z;
} else if (y <= -1.45e+31) {
tmp = t_0;
} else if (y <= -8.5e-19) {
tmp = y * z;
} else if (y <= 5.8e-18) {
tmp = x;
} else if ((y <= 2.2e+65) || (!(y <= 3.8e+156) && (y <= 3.8e+197))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -3e+121: tmp = y * z elif y <= -1.45e+31: tmp = t_0 elif y <= -8.5e-19: tmp = y * z elif y <= 5.8e-18: tmp = x elif (y <= 2.2e+65) or (not (y <= 3.8e+156) and (y <= 3.8e+197)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -3e+121) tmp = Float64(y * z); elseif (y <= -1.45e+31) tmp = t_0; elseif (y <= -8.5e-19) tmp = Float64(y * z); elseif (y <= 5.8e-18) tmp = x; elseif ((y <= 2.2e+65) || (!(y <= 3.8e+156) && (y <= 3.8e+197))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -3e+121) tmp = y * z; elseif (y <= -1.45e+31) tmp = t_0; elseif (y <= -8.5e-19) tmp = y * z; elseif (y <= 5.8e-18) tmp = x; elseif ((y <= 2.2e+65) || (~((y <= 3.8e+156)) && (y <= 3.8e+197))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -3e+121], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.45e+31], t$95$0, If[LessEqual[y, -8.5e-19], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.8e-18], x, If[Or[LessEqual[y, 2.2e+65], And[N[Not[LessEqual[y, 3.8e+156]], $MachinePrecision], LessEqual[y, 3.8e+197]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3 \cdot 10^{+121}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.45 \cdot 10^{+31}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+65} \lor \neg \left(y \leq 3.8 \cdot 10^{+156}\right) \land y \leq 3.8 \cdot 10^{+197}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.0000000000000002e121 or -1.45e31 < y < -8.50000000000000003e-19 or 5.8e-18 < y < 2.1999999999999998e65 or 3.80000000000000024e156 < y < 3.8000000000000001e197Initial program 100.0%
Taylor expanded in z around inf 70.3%
Taylor expanded in x around 0 66.6%
if -3.0000000000000002e121 < y < -1.45e31 or 2.1999999999999998e65 < y < 3.80000000000000024e156 or 3.8000000000000001e197 < y Initial program 100.0%
Taylor expanded in z around 0 75.3%
mul-1-neg75.3%
distribute-lft-neg-out75.3%
*-commutative75.3%
Simplified75.3%
Taylor expanded in y around inf 75.3%
associate-*r*75.3%
mul-1-neg75.3%
Simplified75.3%
if -8.50000000000000003e-19 < y < 5.8e-18Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 78.0%
Final simplification73.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* y z))) (t_1 (* x (- y))))
(if (<= y -9e+120)
t_0
(if (<= y -1.5e+31)
t_1
(if (<= y 5.7e+63)
t_0
(if (or (<= y 3.7e+156) (not (<= y 3e+197))) t_1 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x + (y * z);
double t_1 = x * -y;
double tmp;
if (y <= -9e+120) {
tmp = t_0;
} else if (y <= -1.5e+31) {
tmp = t_1;
} else if (y <= 5.7e+63) {
tmp = t_0;
} else if ((y <= 3.7e+156) || !(y <= 3e+197)) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = x + (y * z)
t_1 = x * -y
if (y <= (-9d+120)) then
tmp = t_0
else if (y <= (-1.5d+31)) then
tmp = t_1
else if (y <= 5.7d+63) then
tmp = t_0
else if ((y <= 3.7d+156) .or. (.not. (y <= 3d+197))) then
tmp = t_1
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y * z);
double t_1 = x * -y;
double tmp;
if (y <= -9e+120) {
tmp = t_0;
} else if (y <= -1.5e+31) {
tmp = t_1;
} else if (y <= 5.7e+63) {
tmp = t_0;
} else if ((y <= 3.7e+156) || !(y <= 3e+197)) {
tmp = t_1;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y * z) t_1 = x * -y tmp = 0 if y <= -9e+120: tmp = t_0 elif y <= -1.5e+31: tmp = t_1 elif y <= 5.7e+63: tmp = t_0 elif (y <= 3.7e+156) or not (y <= 3e+197): tmp = t_1 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y * z)) t_1 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -9e+120) tmp = t_0; elseif (y <= -1.5e+31) tmp = t_1; elseif (y <= 5.7e+63) tmp = t_0; elseif ((y <= 3.7e+156) || !(y <= 3e+197)) tmp = t_1; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y * z); t_1 = x * -y; tmp = 0.0; if (y <= -9e+120) tmp = t_0; elseif (y <= -1.5e+31) tmp = t_1; elseif (y <= 5.7e+63) tmp = t_0; elseif ((y <= 3.7e+156) || ~((y <= 3e+197))) tmp = t_1; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -9e+120], t$95$0, If[LessEqual[y, -1.5e+31], t$95$1, If[LessEqual[y, 5.7e+63], t$95$0, If[Or[LessEqual[y, 3.7e+156], N[Not[LessEqual[y, 3e+197]], $MachinePrecision]], t$95$1, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + y \cdot z\\
t_1 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -9 \cdot 10^{+120}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{+31}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+156} \lor \neg \left(y \leq 3 \cdot 10^{+197}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -8.99999999999999953e120 or -1.49999999999999995e31 < y < 5.7000000000000002e63Initial program 100.0%
Taylor expanded in z around inf 89.2%
if -8.99999999999999953e120 < y < -1.49999999999999995e31 or 5.7000000000000002e63 < y < 3.70000000000000001e156 or 3.0000000000000002e197 < y Initial program 100.0%
Taylor expanded in z around 0 75.3%
mul-1-neg75.3%
distribute-lft-neg-out75.3%
*-commutative75.3%
Simplified75.3%
Taylor expanded in y around inf 75.3%
associate-*r*75.3%
mul-1-neg75.3%
Simplified75.3%
if 3.70000000000000001e156 < y < 3.0000000000000002e197Initial program 100.0%
Taylor expanded in z around inf 70.9%
Taylor expanded in x around 0 71.2%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e+18) (not (<= x 7e-39))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e+18) || !(x <= 7e-39)) {
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 <= (-8.2d+18)) .or. (.not. (x <= 7d-39))) 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 <= -8.2e+18) || !(x <= 7e-39)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e+18) or not (x <= 7e-39): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e+18) || !(x <= 7e-39)) 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 <= -8.2e+18) || ~((x <= 7e-39))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e+18], N[Not[LessEqual[x, 7e-39]], $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 -8.2 \cdot 10^{+18} \lor \neg \left(x \leq 7 \cdot 10^{-39}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -8.2e18 or 6.99999999999999999e-39 < x Initial program 100.0%
Taylor expanded in z around 0 92.2%
mul-1-neg92.2%
distribute-lft-neg-out92.2%
*-commutative92.2%
Simplified92.2%
Taylor expanded in x around 0 92.2%
neg-mul-192.2%
distribute-rgt-in92.2%
*-lft-identity92.2%
cancel-sign-sub-inv92.2%
Simplified92.2%
if -8.2e18 < x < 6.99999999999999999e-39Initial program 100.0%
Taylor expanded in z around inf 86.7%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e-19) (* y z) (if (<= y 9e-18) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-19) {
tmp = y * z;
} else if (y <= 9e-18) {
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 <= (-8.4d-19)) then
tmp = y * z
else if (y <= 9d-18) 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 <= -8.4e-19) {
tmp = y * z;
} else if (y <= 9e-18) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e-19: tmp = y * z elif y <= 9e-18: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e-19) tmp = Float64(y * z); elseif (y <= 9e-18) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.4e-19) tmp = y * z; elseif (y <= 9e-18) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e-19], N[(y * z), $MachinePrecision], If[LessEqual[y, 9e-18], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -8.3999999999999996e-19 or 8.99999999999999987e-18 < y Initial program 100.0%
Taylor expanded in z around inf 54.6%
Taylor expanded in x around 0 52.2%
if -8.3999999999999996e-19 < y < 8.99999999999999987e-18Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 78.0%
Final simplification64.3%
(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 75.9%
Taylor expanded in x around inf 39.0%
Final simplification39.0%
herbie shell --seed 2023275
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))