diff --git a/Rules/Languages/de/SharedRules/general.yaml b/Rules/Languages/de/SharedRules/general.yaml
index 4058dd43..c0cbaaed 100644
--- a/Rules/Languages/de/SharedRules/general.yaml
+++ b/Rules/Languages/de/SharedRules/general.yaml
@@ -571,13 +571,11 @@
- name: identity-matrix
tag: matrix
- # select all the non-zero entries...if they are not on the diagonal, or are != 1
- # if there are any of them, then this isn't an identity matrix
+ # every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- - "count(*) = count(*[1]/*) and "
- - "not( */*/*[not(self::m:mn and .= 0)]"
- - " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- - " )"
+ - "count(*) = count(*[1]/*) and " # matrix is square
+ - "not( */*[count(preceding-sibling::*) = count(../preceding-sibling::*)]/*[not(self::m:mn and .= 1)] ) and " # on-diagonal
+ - "not( */*[count(preceding-sibling::*) != count(../preceding-sibling::*)]/*[not(self::m:mn and .= 0)] )" # off-diagonal
replace:
- T: "die" # phrase('the' 1 by 2 matrix M)
- x: count(*)
diff --git a/Rules/Languages/en/SharedRules/general.yaml b/Rules/Languages/en/SharedRules/general.yaml
index aece2074..d6feca1d 100644
--- a/Rules/Languages/en/SharedRules/general.yaml
+++ b/Rules/Languages/en/SharedRules/general.yaml
@@ -595,13 +595,11 @@
- name: identity-matrix
tag: matrix
- # select all the non-zero entries...if they are not on the diagonal, or are != 1
- # if there are any of them, then this isn't an identity matrix
+ # every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- - "count(*) = count(*[1]/*) and "
- - "not( */*/*[not(self::m:mn and .= 0)]"
- - " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- - " )"
+ - "count(*) = count(*[1]/*) and " # matrix is square
+ - "not( */*[count(preceding-sibling::*) = count(../preceding-sibling::*)]/*[not(self::m:mn and .= 1)] ) and " # on-diagonal
+ - "not( */*[count(preceding-sibling::*) != count(../preceding-sibling::*)]/*[not(self::m:mn and .= 0)] )" # off-diagonal
replace:
- t: "the" # phrase('the' 1 by 2 matrix M)
- x: count(*)
diff --git a/Rules/Languages/nb/SharedRules/general.yaml b/Rules/Languages/nb/SharedRules/general.yaml
index 7f0ef37f..f5babe07 100644
--- a/Rules/Languages/nb/SharedRules/general.yaml
+++ b/Rules/Languages/nb/SharedRules/general.yaml
@@ -686,13 +686,11 @@
- name: identity-matrix
tag: matrix
- # select all the non-zero entries...if they are not on the diagonal, or are != 1
- # if there are any of them, then this isn't an identity matrix
+ # every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- - "count(*) = count(*[1]/*) and "
- - "not( */*/*[not(self::m:mn and .= 0)]"
- - " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- - " )"
+ - "count(*) = count(*[1]/*) and " # matrix is square
+ - "not( */*[count(preceding-sibling::*) = count(../preceding-sibling::*)]/*[not(self::m:mn and .= 1)] ) and " # on-diagonal
+ - "not( */*[count(preceding-sibling::*) != count(../preceding-sibling::*)]/*[not(self::m:mn and .= 0)] )" # off-diagonal
replace:
- x: count(*)
- T: "ganger" # phrase(the 1 'by' 2 matrix)
diff --git a/tests/Languages/de/mtable.rs b/tests/Languages/de/mtable.rs
index 472e5868..f542a4e5 100644
--- a/tests/Languages/de/mtable.rs
+++ b/tests/Languages/de/mtable.rs
@@ -1144,3 +1144,48 @@ fn single_line_with_label() -> Result<()> {
return Ok(());
*/
+
+#[test]
+fn identity_matrix() -> Result<()> {
+ let expr = "";
+ test("de", "SimpleSpeak", expr, "die 3 mal 3 identitätsmatrix")?;
+ Ok(())
+}
+
+#[test]
+fn identity_matrix_false_positive_negative_one() -> Result<()> {
+ let expr = "";
+ test_prefs("de", "SimpleSpeak", vec![("Verbosity", "Terse")],
+ expr, "die 2 mal 2 diagonalmatrix; spalte 1; 1; spalte 2; negativ 1")?;
+ Ok(())
+}
+
+#[test]
+fn identity_matrix_false_positive_zero_diagonal() -> Result<()> {
+ let expr = "";
+ test_prefs("de", "SimpleSpeak", vec![("Verbosity", "Terse")],
+ expr, "die 2 mal 2 diagonalmatrix; spalte 1; 1")?;
+ Ok(())
+}
diff --git a/tests/Languages/en/mtable.rs b/tests/Languages/en/mtable.rs
index 0207d6c0..f3c51174 100644
--- a/tests/Languages/en/mtable.rs
+++ b/tests/Languages/en/mtable.rs
@@ -1125,6 +1125,36 @@ fn identity_matrix() -> Result<()> {
return Ok(());
}
+#[test]
+fn identity_matrix_false_positive_negative_one() -> Result<()> {
+ let expr = "";
+ test_prefs("en", "SimpleSpeak", vec![("Verbosity", "Terse")],
+ expr, "the 2 by 2 diagonal matrix; column 1; 1; column 2; negative 1")?;
+ Ok(())
+}
+
+#[test]
+fn identity_matrix_false_positive_zero_diagonal() -> Result<()> {
+ let expr = "";
+ test_prefs("en", "SimpleSpeak", vec![("Verbosity", "Terse")],
+ expr, "the 2 by 2 diagonal matrix; column 1; 1")?;
+ Ok(())
+}
+
#[test]
fn diagonal_matrix() -> Result<()> {
let expr = "