{"id":2084,"date":"2020-08-16T16:21:35","date_gmt":"2020-08-16T10:51:35","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2084"},"modified":"2020-08-16T20:24:42","modified_gmt":"2020-08-16T14:54:42","slug":"pattern-matching-comparing-elixir-and-mathematica","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/","title":{"rendered":"Pattern Matching: Comparing Elixir and Mathematica"},"content":{"rendered":"<p>One of the things I like about <a href=\"https:\/\/elixir-lang.org\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>Elixir<\/strong><\/em><\/a>\u00a0is its support for patterns at the core language level, not through library functions as in most other languages. This contributes to writing cleaner code, in my opinion. <span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Another environment that I am familiar with, namely <a href=\"https:\/\/www.wolfram.com\/mathematica\/\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>Mathematica<\/strong><\/em><\/a>, boasts of (arguably) the most powerful symbolic programming language called <em><strong>&#8220;Wolfram Language&#8221;<\/strong><\/em>. <em><strong>Mathematica<\/strong><\/em> is primarily used in mathematical and scientific programming. Patterns and Rules are all-pervasive in this language.<\/p>\n<p>It is not fair to compare these two languages since each addresses a different kind of problem. <em><strong>Elixir<\/strong><\/em> is meant for highly scalable and fault tolerant general-purpose computing, whereas <em><strong>Mathematica<\/strong><\/em> excels in complex symbolic (and numeric) computations, and over the years has been extended to include Neural Networks, Machine Learning, Natural Language Understanding, and so on.<\/p>\n<p>In this article, I am going to compare the pattern matching ideas supported by <em><strong>Elixir<\/strong><\/em> and <em><strong>Mathematica<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0 <\/span>Even this is a vast topic to address, so I will limit the discussion to the most striking aspects of pattern matching.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>In the following sections, when I use the term <em><strong>&#8220;Mathematica&#8221;<\/strong><\/em>, I actually mean <em><strong>&#8220;Wolfram Language&#8221;<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<h3><span style=\"color: #0000ff;\">The \u201c=\u201d Operator<\/span><\/h3>\n<p>Let us start with a simple idea. In <em><strong>Elixir<\/strong><\/em>, the operator <em><strong>\u201c=\u201d<\/strong><\/em> is called <em><strong>\u201cPattern Matching\u201d<\/strong><\/em> operator, not an <em><strong>\u201cAssignment Operator\u201d<\/strong><\/em>, although the operation can involve assignment. Look at the following example:<\/p>\n<figure id=\"attachment_2085\" aria-describedby=\"caption-attachment-2085\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2085\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/assign1-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg\" data-orig-size=\"845,236\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597563530&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Pattern Matching Operator\" data-image-description=\"&lt;p&gt;Pattern Matching Operator&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Pattern Matching Operator&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg\" class=\"wp-image-2085\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg?resize=600%2C168&#038;ssl=1\" alt=\"Pattern Matching Operator\" width=\"600\" height=\"168\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg?w=845&amp;ssl=1 845w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg?resize=300%2C84&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-elixir.jpg?resize=768%2C214&amp;ssl=1 768w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2085\" class=\"wp-caption-text\"><strong>Pattern Matching Operator<\/strong><\/figcaption><\/figure>\n<p>Here, the two patterns will match only if <em><strong>X, Y, <\/strong><\/em>and<em><strong> Z\u00a0<\/strong><\/em>are bound respectively to 1, 2 and 3. This causes the values to be bound to the variables. The operator, in this case, behaves like the assignment operator.<\/p>\n<p>Here is a slight variation:<\/p>\n<figure id=\"attachment_2086\" aria-describedby=\"caption-attachment-2086\" style=\"width: 384px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2086\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/assign2-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg\" data-orig-size=\"384,174\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597563600&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Pattern Matching (Contd.)\" data-image-description=\"&lt;p&gt;Pattern Matching (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Pattern Matching (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg\" class=\"size-full wp-image-2086\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg?resize=384%2C174&#038;ssl=1\" alt=\"Pattern Matching (Contd.)\" width=\"384\" height=\"174\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg?w=384&amp;ssl=1 384w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-elixir.jpg?resize=300%2C136&amp;ssl=1 300w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><figcaption id=\"caption-attachment-2086\" class=\"wp-caption-text\"><strong>Pattern Matching (Contd.)<\/strong><\/figcaption><\/figure>\n<p>In this case, the first value of the LHS tuple is a constant and hence for the pattern to succeed, the RHS must have the same first element. The match succeeds since this is true, and <em><strong>Y<\/strong><\/em> and <em><strong>Z<\/strong><\/em> are bound as before.<\/p>\n<p>What happens if there is a pattern mismatch? The following example shows this.<\/p>\n<figure id=\"attachment_2087\" aria-describedby=\"caption-attachment-2087\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2087\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/assign3-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg\" data-orig-size=\"680,102\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597569543&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Pattern Mismatch\" data-image-description=\"&lt;p&gt;Pattern Mismatch&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Pattern Mismatch&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg\" class=\"wp-image-2087\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg?resize=600%2C90&#038;ssl=1\" alt=\"Pattern Mismatch\" width=\"600\" height=\"90\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg?resize=300%2C45&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign3-elixir.jpg?resize=675%2C102&amp;ssl=1 675w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2087\" class=\"wp-caption-text\"><strong>Pattern Mismatch<\/strong><\/figcaption><\/figure>\n<p>I hope you understand what is going on. There are other interesting variations of the pattern matching operator in <em><strong>Elixir<\/strong><\/em>, but we will not get into those here.<\/p>\n<p>Coming to <em><strong>Mathematica<\/strong><\/em>, the <em><strong>\u201c=\u201d<\/strong><\/em> operator is the traditional <em><strong>\u201cAssignment\u201d<\/strong><\/em> operator. No pattern matching is occurs here. The following example is similar to what we tried in <em><strong>Elixir<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2088\" aria-describedby=\"caption-attachment-2088\" style=\"width: 548px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2088\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/assign1-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png\" data-orig-size=\"548,230\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Assignment in Mathematica\" data-image-description=\"&lt;p&gt;Assignment in Mathematica&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Assignment in Mathematica&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png\" class=\"size-full wp-image-2088\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png?resize=548%2C230&#038;ssl=1\" alt=\"Assignment in Mathematica\" width=\"548\" height=\"230\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png?w=548&amp;ssl=1 548w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign1-mm.png?resize=300%2C126&amp;ssl=1 300w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/a><figcaption id=\"caption-attachment-2088\" class=\"wp-caption-text\"><strong>Assignment in Mathematica<\/strong><\/figcaption><\/figure>\n<p>There is no surprise here since it merely involves assignment to the 3 variables on LHS. Now consider this:<\/p>\n<figure id=\"attachment_2090\" aria-describedby=\"caption-attachment-2090\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2090\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/assign2-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png\" data-orig-size=\"552,100\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Invalid Assignment\" data-image-description=\"&lt;p&gt;Invalid Assignment&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Invalid Assignment&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png\" class=\"size-full wp-image-2090\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png?resize=552%2C100&#038;ssl=1\" alt=\"Invalid Assignment\" width=\"552\" height=\"100\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png?w=552&amp;ssl=1 552w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/assign2-mm.png?resize=300%2C54&amp;ssl=1 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/a><figcaption id=\"caption-attachment-2090\" class=\"wp-caption-text\"><strong>Invalid Assignment<\/strong><\/figcaption><\/figure>\n<p>Since we cannot assign to a constant on the LHS, the above fails. There is no attempt to <em><strong>\u201cpattern match\u201d<\/strong><\/em> in this case.<\/p>\n<p>As the above examples show, the <em><strong>\u201c=\u201d<\/strong><\/em> operator in <em><strong>Elixir<\/strong><\/em> is more general than<em><strong> Mathematica\u2019s<\/strong><\/em> assignment operator.<\/p>\n<h3><span style=\"color: #0000ff;\">Case Statement<\/span><\/h3>\n<p><em><strong>Elixir<\/strong><\/em> differs from most other programming languages in that it supports patterns (instead of simple conditions) in the <em><strong>\u201ccase\u201d<\/strong><\/em> statement. Here is an example:<\/p>\n<figure id=\"attachment_2091\" aria-describedby=\"caption-attachment-2091\" style=\"width: 572px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2091\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/case1-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg\" data-orig-size=\"572,190\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597567904&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Case Statement in Elixir\" data-image-description=\"&lt;p&gt;Case Statement in Elixir&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Case Statement in Elixir&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg\" class=\"size-full wp-image-2091\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg?resize=572%2C190&#038;ssl=1\" alt=\"Case Statement in Elixir\" width=\"572\" height=\"190\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg?w=572&amp;ssl=1 572w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case1-elixir.jpg?resize=300%2C100&amp;ssl=1 300w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/a><figcaption id=\"caption-attachment-2091\" class=\"wp-caption-text\"><strong>Case Statement in Elixir<\/strong><\/figcaption><\/figure>\n<p>Notice how we use a <em><strong>\u201cguard\u201d<\/strong><\/em> along with the first pattern to check if the second element of the list is greater than 10. The second pattern matches any element in the second position of the list. The third pattern only checks if the expression is a list without considering its internal structure. The last condition will match anything that hasn\u2019t matched the earlier three patterns. In this case, the given list <em><strong>\u201c[1, 11, 3]\u201d<\/strong><\/em> matches the first pattern.<\/p>\n<p>Here is the same code as above but with the expression <em><strong>\u201c[1, 9, 3]\u201d<\/strong><\/em>. It matches the second pattern.<\/p>\n<figure id=\"attachment_2092\" aria-describedby=\"caption-attachment-2092\" style=\"width: 576px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2092\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/case2-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg\" data-orig-size=\"576,190\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597567984&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Case Statement (Contd.)\" data-image-description=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg\" class=\"size-full wp-image-2092\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg?resize=576%2C190&#038;ssl=1\" alt=\"Case Statement (Contd.)\" width=\"576\" height=\"190\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg?w=576&amp;ssl=1 576w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case2-elixir.jpg?resize=300%2C99&amp;ssl=1 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><figcaption id=\"caption-attachment-2092\" class=\"wp-caption-text\"><strong>Case Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p>What is the result if we pass a 4-element list instead of a 3-element list? The third <em><strong>&#8220;qualified&#8221;<\/strong><\/em> pattern matches.<\/p>\n<figure id=\"attachment_2093\" aria-describedby=\"caption-attachment-2093\" style=\"width: 581px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2093\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/case3-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg\" data-orig-size=\"581,190\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597568038&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Case Statement (Contd.)\" data-image-description=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg\" class=\"size-full wp-image-2093\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg?resize=581%2C190&#038;ssl=1\" alt=\"Case Statement (Contd.)\" width=\"581\" height=\"190\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg?w=581&amp;ssl=1 581w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case3-elixir.jpg?resize=300%2C98&amp;ssl=1 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/a><figcaption id=\"caption-attachment-2093\" class=\"wp-caption-text\"><strong>Case Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p>Finally, we pass a <em><strong>\u201cstring\u201d<\/strong> <\/em>instead of a list. In this case, the <em><strong>\u201ccatch all\u201d<\/strong><\/em> pattern matches!<\/p>\n<figure id=\"attachment_2094\" aria-describedby=\"caption-attachment-2094\" style=\"width: 584px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2094\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/case4-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg\" data-orig-size=\"584,188\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597568096&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Case Statement (Contd.)\" data-image-description=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Case Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg\" class=\"size-full wp-image-2094\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg?resize=584%2C188&#038;ssl=1\" alt=\"Case Statement (Contd.)\" width=\"584\" height=\"188\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg?w=584&amp;ssl=1 584w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/case4-elixir.jpg?resize=300%2C97&amp;ssl=1 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/a><figcaption id=\"caption-attachment-2094\" class=\"wp-caption-text\"><strong>Case Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p><em><strong>Mathematica<\/strong><\/em> uses <em><strong>\u201cSwitch\u201d<\/strong><\/em> instead of <em><strong>\u201ccase\u201d<\/strong><\/em>. Otherwise, the structure is quite similar. The following examples correspond to the above <em><strong>Elixir<\/strong><\/em> examples:<\/p>\n<figure id=\"attachment_2095\" aria-describedby=\"caption-attachment-2095\" style=\"width: 549px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2095\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/switch1-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png\" data-orig-size=\"549,190\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Mathematica Switch Statement\" data-image-description=\"&lt;p&gt;Mathematica Switch Statement&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Mathematica Switch Statement&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png\" class=\"size-full wp-image-2095\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png?resize=549%2C190&#038;ssl=1\" alt=\"Mathematica Switch Statement\" width=\"549\" height=\"190\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png?w=549&amp;ssl=1 549w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch1-mm.png?resize=300%2C104&amp;ssl=1 300w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/a><figcaption id=\"caption-attachment-2095\" class=\"wp-caption-text\"><strong>Mathematica Switch Statement<\/strong><\/figcaption><\/figure>\n<p>The operator <em><strong>&#8220;\/;&#8221;<\/strong><\/em> puts constraints on the associated pattern. The following matches the second condition.<\/p>\n<figure id=\"attachment_2096\" aria-describedby=\"caption-attachment-2096\" style=\"width: 544px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2096\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/switch2-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png\" data-orig-size=\"544,196\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Switch Statement (Contd.)\" data-image-description=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png\" class=\"size-full wp-image-2096\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png?resize=544%2C196&#038;ssl=1\" alt=\"Switch Statement (Contd.)\" width=\"544\" height=\"196\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png?w=544&amp;ssl=1 544w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch2-mm.png?resize=300%2C108&amp;ssl=1 300w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/a><figcaption id=\"caption-attachment-2096\" class=\"wp-caption-text\"><strong>Switch Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p>The following matches the third condition, a pattern that matches any <em><strong>&#8220;List&#8221;<\/strong><\/em>.<\/p>\n<figure id=\"attachment_2097\" aria-describedby=\"caption-attachment-2097\" style=\"width: 549px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2097\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/switch3-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png\" data-orig-size=\"549,196\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Switch Statement (Contd.)\" data-image-description=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png\" class=\"size-full wp-image-2097\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png?resize=549%2C196&#038;ssl=1\" alt=\"Switch Statement (Contd.)\" width=\"549\" height=\"196\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png?w=549&amp;ssl=1 549w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch3-mm.png?resize=300%2C107&amp;ssl=1 300w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/a><figcaption id=\"caption-attachment-2097\" class=\"wp-caption-text\"><strong>Switch Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p>The last case corresponds to a &#8220;<em><strong>non-List&#8221;<\/strong><\/em> expression.<\/p>\n<figure id=\"attachment_2098\" aria-describedby=\"caption-attachment-2098\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2098\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/switch4-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png\" data-orig-size=\"550,192\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Switch Statement (Contd.)\" data-image-description=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Switch Statement (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png\" class=\"size-full wp-image-2098\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png?resize=550%2C192&#038;ssl=1\" alt=\"Switch Statement (Contd.)\" width=\"550\" height=\"192\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png?w=550&amp;ssl=1 550w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/switch4-mm.png?resize=300%2C105&amp;ssl=1 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2098\" class=\"wp-caption-text\"><strong>Switch Statement (Contd.)<\/strong><\/figcaption><\/figure>\n<p>As you can observe, the behaviour is quite similar to <em><strong>Elixir<\/strong><\/em>.<\/p>\n<h3><span style=\"color: #0000ff;\">Patterns and Guards in Functions<\/span><\/h3>\n<p>Both <em><strong>Elixir<\/strong><\/em> and <em><strong>Mathematica<\/strong><\/em> allow <em><strong>\u201cguards\u201d<\/strong><\/em> (or conditions) to be associated with function definitions. This is quite powerful. Let us go through an example to see how this is done.<\/p>\n<p>Suppose that we want to compute the <em><strong>n<sup>th<\/sup><\/strong> <strong>\u201cFibonacci\u201d<\/strong><\/em> number. Here is one way to do this in <em><strong>Elixir<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2099\" aria-describedby=\"caption-attachment-2099\" style=\"width: 469px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2099\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib1-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg\" data-orig-size=\"469,218\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597508926&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Computing Fibonacci Number\" data-image-description=\"&lt;p&gt;Computing Fibonacci Number&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Computing Fibonacci Number&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg\" class=\"size-full wp-image-2099\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg?resize=469%2C218&#038;ssl=1\" alt=\"Computing Fibonacci Number\" width=\"469\" height=\"218\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg?w=469&amp;ssl=1 469w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-elixir.jpg?resize=300%2C139&amp;ssl=1 300w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/a><figcaption id=\"caption-attachment-2099\" class=\"wp-caption-text\"><strong>Computing Fibonacci Number<\/strong><\/figcaption><\/figure>\n<p>Instead of coding the different trivial cases in a single function, we split the logic across multiple definitions. Notice also, how we are able to associate a <em><strong>\u201cguard\u201d<\/strong><\/em> or condition with the third definition to check if the passed argument is an integer (we take for granted that the argument is positive).<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Here is yet another way. We have merged the first two definitions by introducing a <em><strong>\u201cguard\u201d<\/strong><\/em>.<\/p>\n<figure id=\"attachment_2100\" aria-describedby=\"caption-attachment-2100\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2100\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib2-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg\" data-orig-size=\"550,187\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597509171&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Fibonacci (Contd.)\" data-image-description=\"&lt;p&gt;Fibonacci (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fibonacci (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg\" class=\"size-full wp-image-2100\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg?resize=550%2C187&#038;ssl=1\" alt=\"Fibonacci (Contd.)\" width=\"550\" height=\"187\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg?w=550&amp;ssl=1 550w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-elixir.jpg?resize=300%2C102&amp;ssl=1 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2100\" class=\"wp-caption-text\"><strong>Fibonacci (Contd.)<\/strong><\/figcaption><\/figure>\n<p>It is important to keep in mind that <em><strong>Elixir<\/strong><\/em> tries the functions in the order of definition. So, if we change the order as in the following case, it will not work.<\/p>\n<figure id=\"attachment_2101\" aria-describedby=\"caption-attachment-2101\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2101\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib3-invalid-elixir\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg\" data-orig-size=\"540,191\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1597509473&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Invalid Definition Order\" data-image-description=\"&lt;p&gt;Invalid Definition Order&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Invalid Definition Order&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg\" class=\"size-full wp-image-2101\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg?resize=540%2C191&#038;ssl=1\" alt=\"Invalid Definition Order\" width=\"540\" height=\"191\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg?w=540&amp;ssl=1 540w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-invalid-elixir.jpg?resize=300%2C106&amp;ssl=1 300w\" sizes=\"(max-width: 540px) 100vw, 540px\" \/><\/a><figcaption id=\"caption-attachment-2101\" class=\"wp-caption-text\"><strong>Invalid Definition Order<\/strong><\/figcaption><\/figure>\n<p>How do we write this function in <em><strong>Mathematica<\/strong><\/em>? The following implementation corresponds to the first version we wrote in <em><strong>Elixir<\/strong><\/em>.<\/p>\n<figure id=\"attachment_2102\" aria-describedby=\"caption-attachment-2102\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2102\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib1-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png\" data-orig-size=\"531,119\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Fibonacci Function in Mathematica\" data-image-description=\"&lt;p&gt;Fibonacci Function in Mathematica&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fibonacci Function in Mathematica&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png\" class=\"size-full wp-image-2102\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png?resize=531%2C119&#038;ssl=1\" alt=\"Fibonacci Function in Mathematica\" width=\"531\" height=\"119\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png?w=531&amp;ssl=1 531w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib1-mm.png?resize=300%2C67&amp;ssl=1 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-2102\" class=\"wp-caption-text\"><strong>Fibonacci Function in Mathematica<\/strong><\/figcaption><\/figure>\n<p><em><strong>Mathematica<\/strong><\/em> too allows us to use <em><strong>\u201cconditions\u201d<\/strong> <\/em>as part of function definition. The code given below matches the second version we wrote in <em><strong>Elixir<\/strong><\/em>.<\/p>\n<figure id=\"attachment_2103\" aria-describedby=\"caption-attachment-2103\" style=\"width: 539px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2103\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib2-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png\" data-orig-size=\"539,127\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Fibonacci (Contd.)\" data-image-description=\"&lt;p&gt;Fibonacci (Contd.)&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fibonacci (Contd.)&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png\" class=\"size-full wp-image-2103\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png?resize=539%2C127&#038;ssl=1\" alt=\"Fibonacci (Contd.)\" width=\"539\" height=\"127\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png?w=539&amp;ssl=1 539w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib2-mm.png?resize=300%2C71&amp;ssl=1 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/a><figcaption id=\"caption-attachment-2103\" class=\"wp-caption-text\"><strong>Fibonacci (Contd.)<\/strong><\/figcaption><\/figure>\n<p>A nice thing about <em><strong>Mathematica<\/strong><\/em> is that there is no restriction on the order in which the definitions must be provided. So, even the following will work correctly.<\/p>\n<figure id=\"attachment_2104\" aria-describedby=\"caption-attachment-2104\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2104\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/fib3-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png\" data-orig-size=\"547,125\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Order is not Important\" data-image-description=\"&lt;p&gt;Order is not Important&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Order is not Important&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png\" class=\"size-full wp-image-2104\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png?resize=547%2C125&#038;ssl=1\" alt=\"Order is not Important\" width=\"547\" height=\"125\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png?w=547&amp;ssl=1 547w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/fib3-mm.png?resize=300%2C69&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><figcaption id=\"caption-attachment-2104\" class=\"wp-caption-text\"><strong>Order is not Important<\/strong><span style=\"font-size: 16px;\">\u00a0<\/span><\/figcaption><\/figure>\n<h4><span style=\"color: #0000ff;\">Arbitrary Pattern-based Transformations in Mathematica<\/span><\/h4>\n<p>Unlike <em><strong>Elixir<\/strong><\/em>, <em><strong>Mathematica<\/strong><\/em> allows us to define functions that work with symbolic expressions. Take a look at the following snippet:<\/p>\n<figure id=\"attachment_2106\" aria-describedby=\"caption-attachment-2106\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2106\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/pattern-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png\" data-orig-size=\"547,241\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Symbolic Expressions\" data-image-description=\"&lt;p&gt;Symbolic Expressions&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Symbolic Expressions&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png\" class=\"size-full wp-image-2106\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?resize=547%2C241&#038;ssl=1\" alt=\"Symbolic Expressions\" width=\"547\" height=\"241\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?w=547&amp;ssl=1 547w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?resize=300%2C132&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><figcaption id=\"caption-attachment-2106\" class=\"wp-caption-text\"><strong>Working with Symbolic Expressions<\/strong><\/figcaption><\/figure>\n<p>The first line above defines a function that takes two arguments. The first argument can be anything as denoted by the pattern <em><strong>\u201cx_\u201d<\/strong><\/em>. The second argument must be an expression of the form <em><strong>\u201cx_ raised to the power of anything\u201d<\/strong><\/em>. Given two arguments like this, this function applies another function <strong>\u201cp\u201d<\/strong> to <em><strong>2 times \u201cx\u201d<\/strong><\/em> (remember <em><strong>\u201cx\u201d<\/strong><\/em> refers to the first argument).<\/p>\n<p>The second and third lines show what happens when this function is called with <em><strong>\u201c(m+n)\u201d<\/strong><\/em> and <strong><em>\u201c(m+n)<\/em> <sup>3<\/sup>\u201d<\/strong>. The fourth and fifth lines show another valid invocation example. In both these cases, the <em><strong>argument structure<\/strong><\/em> is maintained and hence the expected transformation takes place. The last two lines show what happens when the second argument does not satisfy the required structure (it uses <em><strong>\u201cn\u201d<\/strong><\/em> instead of <em><strong>\u201cm\u201d<\/strong><\/em>).<\/p>\n<p>As the final example of pattern transformations, <em><strong>Mathematica<\/strong><\/em> has a special <em><strong>\u201csubstitution\u201d<\/strong><\/em> operator <em><strong>\u201c\/\/.\u201d<\/strong><\/em>\u00a0that can be applied to an arbitrary expression to transform it into another expression. Here is an example:<\/p>\n<figure id=\"attachment_2107\" aria-describedby=\"caption-attachment-2107\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2107\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/transform-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png\" data-orig-size=\"547,69\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Substitution Operator\" data-image-description=\"&lt;p&gt;Substitution Operator&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Substitution Operator&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png\" class=\"size-full wp-image-2107\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png?resize=547%2C69&#038;ssl=1\" alt=\"Substitution Operator\" width=\"547\" height=\"69\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png?w=547&amp;ssl=1 547w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform-mm.png?resize=300%2C38&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><figcaption id=\"caption-attachment-2107\" class=\"wp-caption-text\"><strong>Substitution Operator<\/strong><\/figcaption><\/figure>\n<p>Here, the expression to the left of <em><strong>\u201c\/\/.\u201d<\/strong><\/em> Is <em><strong>\u201cX<sup>2<\/sup> + Y<sup>2 <\/sup>+ Z\u201d<\/strong><\/em>. To the right of <em><strong>\u201c\/\/.\u201d<\/strong><\/em> we have a list of substitutions to apply. The substitution operator <em><strong>repeatedly<\/strong><\/em> applies the given values to the LHS expression until it changes no more. Finally, we get the answer <em><strong>\u201c16\u201d<\/strong><\/em>.<\/p>\n<p>Of course, the substitution can also be symbolic. Look at this:<\/p>\n<figure id=\"attachment_2108\" aria-describedby=\"caption-attachment-2108\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2108\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/transform2-mm\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png\" data-orig-size=\"547,104\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Symbolic Substitution\" data-image-description=\"&lt;p&gt;Symbolic Substitution&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Symbolic Substitution&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png\" class=\"size-full wp-image-2108\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png?resize=547%2C104&#038;ssl=1\" alt=\"Symbolic Substitution\" width=\"547\" height=\"104\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png?w=547&amp;ssl=1 547w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/transform2-mm.png?resize=300%2C57&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><figcaption id=\"caption-attachment-2108\" class=\"wp-caption-text\"><strong>Symbolic Substitution<\/strong><\/figcaption><\/figure>\n<p>Here we transform one symbolic expression to another. Such transformations are quite common in the domain of <em><strong>Mathematica<\/strong><\/em>.<\/p>\n<p>In my view, <em><strong>Mathematica\u2019s<\/strong><\/em> pattern matching capabilities are richer and more powerful than <em><strong>Elixir<\/strong><\/em>. What I have covered is just a tiny part of what\u00a0<em><strong>Mathematica<\/strong><\/em>\u00a0allows.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Hope you enjoyed reading this article. Have a nice weekend and a wonderful week ahead!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the things I like about Elixir\u00a0is its support for patterns at the core language level, not through library functions as in most other languages. This contributes to writing cleaner code, in my opinion. \u00a0 Another environment that I am familiar with, namely Mathematica, boasts of (arguably) the most powerful symbolic programming language called [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[242,72,17],"tags":[243,43,62],"class_list":["post-2084","post","type-post","status-publish","format-standard","hentry","category-elixir","category-mathematica","category-programming","tag-elixir","tag-mathematica","tag-pattern-matching"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-xC","jetpack-related-posts":[{"id":409,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/11\/02\/working-with-linguistic-data-in-mathematica\/","url_meta":{"origin":2084,"position":0},"title":"Working with Linguistic Data in Mathematica","author":"admin","date":"November 2, 2016","format":false,"excerpt":"There are many interesting functions in Mathematica for working with language data, not just in English but in many other languages too. The DictionaryLookup[] function is a good starting point. Let us see what languages are supported as part of dictionary lookup: That is a good collection. It is nice\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Supported Languages","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/11\/dict-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/11\/dict-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/11\/dict-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":328,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/09\/11\/natural-language-processing-in-mathematica\/","url_meta":{"origin":2084,"position":1},"title":"Natural Language Processing in Mathematica","author":"admin","date":"September 11, 2016","format":false,"excerpt":"Welcome back. Today I am going to share with you some of the nice capabilities of Mathematica in the area of Natural Language Processing (NLP). Let us start with words. What if we wish to know\u00a0the various definitions of the word image?\u00a0Here is the answer. Mathematica gives the various senses\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Word Definition","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/09\/word-data1-1024x238.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/09\/word-data1-1024x238.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/09\/word-data1-1024x238.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/09\/word-data1-1024x238.png?resize=700%2C400 2x"},"classes":[]},{"id":1594,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/06\/08\/using-nodejs-in-mathematica-12\/","url_meta":{"origin":2084,"position":2},"title":"Using NodeJS in Mathematica 12","author":"admin","date":"June 8, 2019","format":false,"excerpt":"In an earlier article, I had described Python integration in Mathematica 12. In addition to Python, NodeJS is also supported as a default \u201cexternal\u201d language. In today\u2019s article, I will focus on NodeJS integration. By the way, NodeJS support was introduced in Mathematica 11.2. Before using NodeJS with Mathematica 12,\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"NodeJS Session Continued","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/06\/Session2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/06\/Session2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/06\/Session2.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/06\/Session2.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1560,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/05\/05\/python-integration-in-mathematica-12\/","url_meta":{"origin":2084,"position":3},"title":"Python Integration in Mathematica 12","author":"admin","date":"May 5, 2019","format":false,"excerpt":"Mathematica has had Python support since ver 11.2 through ExternalEvaluate[]. In ver 11.3 it was possible to input Python expression in a cell by beginning with \u201c>\u201d character. The good news is that Mathematica 12 has significantly enhanced this integration. Python Cells Let us start with the simplest way to\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Function References","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/05\/External-Evaluate-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/05\/External-Evaluate-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/05\/External-Evaluate-4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2947,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/11\/24\/using-julia-from-mathematica\/","url_meta":{"origin":2084,"position":4},"title":"Using Julia from Mathematica","author":"admin","date":"November 24, 2022","format":false,"excerpt":"In an earlier article, I had shown how it is possible to interact with Mathematica from Julia. In today\u2019s article, I will share the details of how to interact with Julia from within Mathematica. Why would somebody want to execute Julia code inside Mathematica? Although Mathematica is a great symbolic\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"Installing Julia","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1581,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/05\/19\/currying-in-mathematica\/","url_meta":{"origin":2084,"position":5},"title":"Currying in Mathematica","author":"admin","date":"May 19, 2019","format":false,"excerpt":"One of the more recent additions to the core Wolfram Language is the \u201cCurry\u201d function. It was introduced in Mathematica ver 11.3 and is still (as of ver 12.0) considered Experimental. In this post, I would like to go over this function briefly. Non-curried functions in Mathematica have to be\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Lisp Currying Examples","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/05\/Lisp-Usage.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2084"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2084\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}