Skip to content

Commit

Permalink
fix corner case in PolynomialGcd()
Browse files Browse the repository at this point in the history
Task #144 - PolynomialGcd() fails for 0
  • Loading branch information
grzegorzmazur committed Nov 11, 2015
1 parent 3ada818 commit be6284e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/stubs.rep/code.ys
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ Sqrt(xlist_IsList) <-- MapSingle("Sqrt",xlist);
PolynomialGcd(n, m, VarList(n*m)[1]);
];

30 # PolynomialGcd(n_CanBeUni, m_CanBeUni, x_IsVariable) <--
40 # PolynomialGcd(0, m_CanBeUni, x_IsVariable) <-- m;
40 # PolynomialGcd(n_CanBeUni, 0, x_IsVariable) <-- n;

50 # PolynomialGcd(n_CanBeUni, m_CanBeUni, x_IsVariable) <--
[
Local(vars);
vars:=VarList(n*m);
Expand Down
2 changes: 2 additions & 0 deletions tests/poly.yts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Verify(Gcd(2*x+2,4*x+4), 2*x+2);
Verify(Gcd(x^2+7*x+6,x^2-5*x-6), x+1);
Verify(Gcd(x^8+x^6-3*x^4-3*x^3+8*x^2+2*x-5,3*x^6+5*x^4-4*x^2-9*x+21), 1);

Verify(PolynomialGcd(0, x, x), x);
Verify(PolynomialGcd(x, 0, x), x);
Verify(PolynomialGcd(2, 1/4, x), 1/4);
Verify(PolynomialGcd(2*x+2, 4*x+4, x), 2*x+2);
Verify(PolynomialGcd(x^2+7*x+6, x^2-5*x-6, x), x+1);
Expand Down

0 comments on commit be6284e

Please sign in to comment.