From dfe8a8034e3d4fec57cf61b7a9521eae956a262d Mon Sep 17 00:00:00 2001 From: Robert Dodier Date: Sat, 11 Mar 2023 18:54:29 -0800 Subject: [PATCH] Ensure parentheses are output for (n!)! by decreasing right-binding power of MFACTORIAL. Fixes SF bug #4092: "Repeated factorial (n!)! displayed the same as double factorial n!!" --- src/grind.lisp | 1 + tests/rtest9a.mac | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/grind.lisp b/src/grind.lisp index ac2ac62c5..a5814deec 100644 --- a/src/grind.lisp +++ b/src/grind.lisp @@ -387,6 +387,7 @@ (defprop mfactorial msize-postfix grind) (defprop mfactorial 160. lbp) +(defprop mfactorial 159. rbp) (defprop mexpt msz-mexpt grind) (defprop mexpt 140. lbp) diff --git a/tests/rtest9a.mac b/tests/rtest9a.mac index 5f8e96aab..5b5ca068a 100644 --- a/tests/rtest9a.mac +++ b/tests/rtest9a.mac @@ -524,3 +524,55 @@ print_string_2d (-((a + b)/c)); string (-((a + b)/c)); "-((b+a)/c)"; + +/* SF bug #4092: "Repeated factorial (n!)! displayed the same as double factorial n!!" */ + +(kill (n), printf (false, "~m", (n!)!)); +"(n!)! +"; + +printf (false, "~a", (n!)!); +"(n!)!"; + +tex1 ((n!)!); +"\\left(n!\\right)!"; + +/* verify that "!" continues to interact correctly with other operators */ + +(kill (m, o), 0); +0; + +n! + m! + o!; +(n!) + (m!) + (o!); + +(n! * m! * o!); +(n!) * (m!) * (o!); + +'(n! := if n = 0 then 1 else n*(n - 1)!); +(n!) := (if (n = 0) then 1 else (n*((n - 1)!))); + +'(n! : m!); +(n!) : (m!); + +'(n! : m! : o!); +(n!) : ((m!) : (o!)); + +'(n! := m! : o!); +(n!) := ((m!) : (o!)); + +/* verify double factorial symbol continues to work the same */ + +n!!; +genfact(n, n/2, 2); + +n!!!; +genfact(n, n/2, 2)!; + +n!!!!; +genfact(genfact(n, n/2, 2), genfact(n, n/2, 2)/2, 2); + +(n!)!!; +genfact(n!, n!/2, 2); + +n!!*m!!; +genfact(m, m/2, 2)*genfact(n, n/2, 2); -- 2.11.4.GIT