Not-a-tree

Triangular numbers in Mathematica

Jul 19th, 2017
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Some functions for triangular numbers in Mathematica, sorted by byte count
  2.  
  3. 15: ((2#+1)^2-1)/8&
  4. 17: Tr[Range@#^3]^.5&
  5. 17: ⌊(2#+1)^2/8⌋&
  6. 18: ((#+1)^3-#^3-1)/6&
  7. 19: Sqrt@Tr[Range@#^3]&
  8. 19: -StirlingS1[#+1,#]&
  9. 19: Sum[1,{i,#},{j,i}]&
  10. 20: f@0=0;f@i_:=i+f[i-1]
  11. 20: Tr[{#+1,-#,-1}^3/6]&
  12. 22: ⌊(#+1)^3/(#+2)⌋/2&
  13. 23: Tr@Table[i^3,{i,#}]^.5&
  14. 26: Sqrt@Sum[i*j,{i,#},{j,#}]&
  15. 27: Sum[i^2(-1)^i,{i,#}](-1)^#&
  16. 28: D[x/(1-x)^3,{x,#}]/#!/.x->0&
  17. 28: (For[i=n=0,i<#,n+=i,i++];n)&
  18. 29: n=0;(Do[n+=i,{i,#}];Print@n)&
  19. 29: EdgeCount@CompleteGraph[#+1]&
  20. 29: Length@Expand[(x+y+z)^(#-1)]& (note: doesn't work for 1)
  21. 29: Coefficient[(1+x)^(#+1),x^2]&
  22. 29: ⌊(#+1)/(Exp[2/(#+1)]-1)⌋&
  23. 30: Nest[#+(1+Sqrt[1+8#])/2&,0,#]&
  24. 31: Sum[EulerPhi@k⌊#/k⌋,{k,#}]&
  25. 33: Series[x/(1-x)^3,{x,0,#}][[3,#]]&
  26. 34: Boole[#2>=#]&~Array~{#,#}~Total~2& (thanks to Mark S., https://codegolf.stackexchange.com/questions/133109/sum-of-all-integers-from-1-to-n/133160#comment339998_133160)
  27. 37: SeriesCoefficient[x/(1-x)^3,{x,0,#}]&
  28. 37: Det@Array[Binomial[1+##,#]&,{#,#}-1]& (note: doesn't work for 1)
  29. 39: Length@Solve[0<a<=b<=#,{a,b},Integers]&
  30. 40: UpperTriangularize@Table[1,#,#]~Total~2&
  31. 42: Last@LinearRecurrence[{3,-3,1},{1,3,6},#]&
  32. 42: CellularAutomaton[50,{{1},0},#-1]~Total~2&
  33. 45: 1/Integrate[4Sin@x^(2#-1)Cos@x^3,{x,0,Pi/2}]&
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×