Faulhaber's formula: Difference between revisions

Content deleted Content added
m added a Wiki reference.
Hout (talk | contribs)
Line 899:
import Data.Char (isSpace)
import Data.Monoid ((<>))
import Data.Bool (bool)
 
-- FAULHABER -------------------------------------------------------------------
faulhaber :: [[Rational]]
faulhaber =
Line 911 ⟶ 912:
[0 ..]
 
-- EXPRESSION STRINGS ----------------------------------------------------------
polynomials :: [[(String, String)]]
polynomials = fmap ((ratioPower =<<) . reverse . flip zip [1 ..]) faulhaber
Line 943 ⟶ 944:
| otherwise = intercalate "/" [show num, show den]
s = sr <> sn
in ifbool [(sn, sr)] [] (null s)
then []
else [(sn, sr)]
 
-- Rows of uneven length -> All rows padded to length of longest
Line 963 ⟶ 962:
, " -> "
, foldr
(\s a -> concat [s, bool " + " " " (blank a || head a == '-'), a])
concat[]
[ s
, if blank a || head a == '-'
then " "
else " + "
, a
])
""
(polyTerm <$> row)
]
Line 997 ⟶ 989:
unsignedLength xs =
let l = length xs
in bool (bool l (l - 1) ('-' == head xs)) 0 (0 == l)
in case l of
0 -> 0
_ ->
case head xs of
'-' -> l - 1
_ -> l
 
-- TEST ------------------------------------------------------------------------
main :: IO ()
main = (putStrLn . unlines . expressionTable . take 10) polynomials</lang>