Mathematica is a functional language. A program that calculates n!, n factorial looks like this:
f[n_] := Apply[Times, Range[n]]
The function f[5] yields 120 = 5!
Explanation of the code:
- Range[5] by itself yields {1, 2, 3, 4, 5}
- Times[a,b] yields a*b.
- Apply[Times, {1,2,3,4,5}] yields Times[Times[Times[Times[1, 2], 3], 4], 5]
Functional programming goes back to the 1950's when the programming language Lisp was developed. Since then Lisp has always been in use ( in some dialect ) for the development of highly complicated systems like Artificial Intelligence (AI) systems. But unexpectedly for the time the first Yahoo Store web application has been built in Lisp also.
2-2024 Quran and mathematics
7 months ago
No comments:
Post a Comment