diff --git a/mathics/builtin/intfns/combinatorial.py b/mathics/builtin/intfns/combinatorial.py
index 3843283b0..19126e40b 100644
--- a/mathics/builtin/intfns/combinatorial.py
+++ b/mathics/builtin/intfns/combinatorial.py
@@ -11,7 +11,7 @@
biology to computer science, etc.
"""
-
+from abc import ABC
from itertools import combinations
from mathics.core.atoms import Integer, Integer1
@@ -71,7 +71,7 @@ def eval(self, z, evaluation: Evaluation):
return super().eval(z, evaluation)
-class _BooleanDissimilarity(Builtin):
+class _BooleanDissimilarity(Builtin, ABC):
@staticmethod
def _to_bool_vector(u):
def generate():
@@ -97,7 +97,10 @@ def generate():
except _NoBoolVector:
return None
- def eval(self, u, v, evaluation):
+ def _compute(self, n, c_ff, c_ft, c_tf, c_tt) -> Expression:
+ raise NotImplementedError
+
+ def eval(self, u, v, evaluation: Evaluation):
"%(name)s[u_List, v_List]"
if len(u.elements) != len(v.elements):
return
@@ -199,7 +202,7 @@ class DiceDissimilarity(_BooleanDissimilarity):
https://reference.wolfram.com/language/ref/DiceDissimilarity.html)
- 'DiceDissimilarity'[$u$, $v$]
-
- returns the Dice dissimilarity between the two boolean 1-D lists $u$ and $v$.
+
- returns the Dice dissimilarity between the two Boolean 1-D lists $u$ and $v$.
This is defined as ($c_tf$ + $c_ft$) / (2 * $c_tt$ + $c_ft$ + c_tf).
$n$ is len($u$) and $c_ij$ is the number of occurrences of $u$[$k$]=$i$ and $v$[$k$]=$j$ for $k$ < $n$.
@@ -210,7 +213,7 @@ class DiceDissimilarity(_BooleanDissimilarity):
summary_text = "Dice dissimilarity"
- def _compute(self, n, c_ff, c_ft, c_tf, c_tt):
+ def _compute(self, n, c_ff, c_ft, c_tf, c_tt) -> Expression:
return Expression(
SymbolDivide, Integer(c_tf + c_ft), Integer(2 * c_tt + c_ft + c_tf)
)
@@ -262,11 +265,11 @@ class JaccardDissimilarity(_BooleanDissimilarity):
https://reference.wolfram.com/language/ref/JaccardDissimilarity.html)
- 'JaccardDissimilarity'[$u$, $v$]
-
- returns the Jaccard-Needham dissimilarity between the two boolean \
+
- returns the Jaccard-Needham dissimilarity between the two Boolean \
1-D lists $u$ and $v$, which is defined as \
- ($c_tf$ + $c_ft$) / ($c_tt$ + $c_ft$ + $c_tf$), where $n$ is \
+ $(c_tf + c_ft) / (c_tt + c_ft + c_tf)$, where $n$ is \
len($u$) and $c_ij$ is the number of occurrences of \
- $u$[$k$]=$i$ and $v$[$k$]=$j$ for $k$ < $n$.
+ $u[k]=i$ and $v[k]=j$ for $k < n$.
>> JaccardDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]
@@ -297,7 +300,7 @@ class LucasL(SympyFunction):
gives the $n$th Lucas number.
'LucasL'[$n$, $x$]
- gives the $n$th Lucas polynomial $L$_($x$).
+ gives the $n$th Lucas polynomial $L_(x)$.
A list of the first five Lucas numbers:
@@ -332,10 +335,10 @@ class MatchingDissimilarity(_BooleanDissimilarity):
- 'MatchingDissimilarity'[$u$, $v$]
-
- returns the Matching dissimilarity between the two boolean \
- 1-D lists $u$ and $v$, which is defined as ($c_tf$ + $c_ft$) / $n$, \
+
- returns the Matching dissimilarity between the two Boolean \
+ 1-D lists $u$ and $v$, which is defined as $(c_tf + c_ft) / n$, \
where $n$ is len($u$) and $c_ij$ is the number of occurrences of \
- $u$[$k$]=$i$ and $v$[$k$]=$j$ for $k$ < $n$.
+ $u[k]=i$ and $v[k]=j$ for $k < n$.
>> MatchingDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]
@@ -356,7 +359,7 @@ class Multinomial(Builtin):
:WMA: https://reference.wolfram.com/language/ref/Multinomial.html)
- 'Multinomial'[$n_1$, $n_2$, ...]
-
- gives the multinomial coefficient '($n_1$+$n_2$+...)!/($n_1$!$n_2$!...)'.
+
- gives the multinomial coefficient $(n_1+n_2+...)!/(n_1!n_2!...)$.
>> Multinomial[2, 3, 4, 5]
@@ -369,6 +372,10 @@ class Multinomial(Builtin):
'Multinomial[$n$-$k$, $k$]' is equivalent to 'Binomial[$n$, $k$]'.
>> Multinomial[2, 3]
= 10
+
+ See also
+ :'Binomial':
+ /doc/reference-of-built-in-symbols/integer-functions/combinatorial-functions/binomial/.
"""
attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_ORDERLESS | A_PROTECTED
@@ -431,17 +438,19 @@ class PolygonalNumber(Builtin):
class RogersTanimotoDissimilarity(_BooleanDissimilarity):
"""
-
- :WMA link:
- https://reference.wolfram.com/language/ref/RogersTanimotoDissimilarity.html
+ :Rogers Tanimoto coefficient:
+ https://en.wikipedia.org/wiki/Qualitative_variation#Rogers%E2%80%93Tanimoto_coefficient
+ (
+ :WMA:
+ https://reference.wolfram.com/language/ref/RogersTanimotoDissimilarity.html)
- 'RogersTanimotoDissimilarity'[$u$, $v$]
-
- returns the Rogers-Tanimoto dissimilarity between the two boolean \
+
- returns the Rogers-Tanimoto dissimilarity between the two Boolean \
1-D lists $u$ and $v$, which is defined as \
- $R$ / (c_tt + c_ff + $R$) where $n$ is len($u$), c_ij is \
- the number of occurrences of $u$[$k$]=$i$ and $v$[$k]$=$j$ for $k$
>> RogersTanimotoDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]
@@ -457,16 +466,17 @@ def _compute(self, n, c_ff, c_ft, c_tf, c_tt):
class RussellRaoDissimilarity(_BooleanDissimilarity):
"""
-
- :WMA link:
- https://reference.wolfram.com/language/ref/RusselRaoDissimilarity.html
+ :Russel-Rao coefficient:
+ https://en.wikipedia.org/wiki/Qualitative_variation#Russel%E2%80%93Rao_coefficient (
+ :WMA:
+ https://reference.wolfram.com/language/ref/RusselRaoDissimilarity.html)
- 'RussellRaoDissimilarity'[$u$, $v$]
-
- returns the Russell-Rao dissimilarity between the two boolean \
- 1-D lists $u$ and $v$, which is defined as ($n$ - $c_tt$) / $c_tt$ \
- where $n$ is len($u$) and $c_ij$ is \
- the number of occurrences of $u$[k]=i and $v$[$k$]=$j$ for $k$ < $n$.
+
- returns the Russell-Rao dissimilarity between the two Boolean \
+ 1-D lists $u$ and $v$, which is defined as $(n - c_tt) / c_tt$ \
+ where $n$ is $len(u)$, $c_ij$ is \
+ the number of occurrences of $u[k]=i$ and $v[k]=j$ for $k < n$.
>> RussellRaoDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]
@@ -481,17 +491,19 @@ def _compute(self, n, c_ff, c_ft, c_tf, c_tt):
class SokalSneathDissimilarity(_BooleanDissimilarity):
"""
-
- :WMA link:
- https://reference.wolfram.com/language/ref/SokalSneathDissimilarity.html
+
+ :Snokal-Sneath coefficient:
+ https://en.wikipedia.org/wiki/Qualitative_variation#Sokal%E2%80%93Sneath_coefficient (
+ :WMA:
+ https://reference.wolfram.com/language/ref/SokalSneathDissimilarity.html)
- 'SokalSneathDissimilarity'[$u$, $v$]
-
- returns the Sokal-Sneath dissimilarity between the two boolean \
- 1-D lists $u$ and $v$, which is defined as $R$ / (c_tt + $R$) where \
- $n$ is len($u$), $c_ij$ is the number of occurrences of \
- $u$[$k$]=$i$ and $v$[k]=$j$ for $k$ < $n$, \
- and $R$ = 2 * ($c_tf$ + $c_ft$).
+
- returns the Sokal-Sneath dissimilarity between the two Boolean \
+ 1-D lists $u$ and $v$, which is defined as $R / (c_tt + R)$ where \
+ $n$ is $len(u)$, $c_ij$ is the number of occurrences of \
+ $u[k]=i$, $v[k]=j$ for $k < n$, \
+ and $R = 2 (c_tf + c_ft)$.
>> SokalSneathDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]
@@ -702,11 +714,11 @@ class YuleDissimilarity(_BooleanDissimilarity):
- 'YuleDissimilarity'[$u$, $v$]
-
- returns the Yule dissimilarity between the two boolean 1-D lists $u$ \
- and $v$, which is defined as $R$ / ($c_tt$ * $c_ff$ + $R$ / 2) \
- where $n$ is len($u$), $c_ij$ is the number of occurrences of \
- $u$[$k$]=$i$ and $v$[$k$]=$j$ for $k$<$n$, \
- and $R$ = 2 * $c_tf$ * $c_ft$.
+
- returns the Yule dissimilarity between the two Boolean 1-D lists $u$ \
+ and $v$, which is defined as $R / (c_tt c_ff + R / 2)$ \
+ where $n$ is $len(u)$, $c_ij$ is the number of occurrences of \
+ $u[k]=i$, $v[k]=j$ for $k
>> YuleDissimilarity[{1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 0, 0, 0, 1}]