pages tagged wolfram http://meng6net.localhost/tag/wolfram/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Mon, 22 May 2017 20:24:50 +0000 Wolfram http://meng6net.localhost/computing/programming/Wolfram/ http://meng6net.localhost/computing/programming/Wolfram/ Mathematica Wolfram computing note programming Sat, 20 May 2017 21:53:47 +0000 2017-05-21T06:06:00Z <h2>Programming idioms</h2> <h3>Caching the result of a time-comsuming computation in a symbol's <code>DownValue</code></h3> <pre><code>ClearAll[f] f[x_] := f[x] = (Pause[5]; Print["Time consuming definition run!"]; 1); In[31]:= DownValues[f] Out[31]= {HoldPattern[f[x_]]:&gt;(f[x]=(Pause[5];Print[Time consuming definition run!];1))} In[32]:= f[1]//AbsoluteTiming//Timing f[1]//AbsoluteTiming//Timing During evaluation of In[32]:= Time consuming definition run! Out[32]= {0.061456,{5.00291,1}} Out[33]= {7.*10^-6,{1.*10^-6,1}} In[34]:= DownValues[f] Out[34]= {HoldPattern[f[1]]:&gt;1,HoldPattern[f[x_]]:&gt;(f[x]=(Pause[5];Print[Time consuming definition run!];1))} </code></pre> Haskell and Wolfram Language syntax comparison http://meng6net.localhost/computing/programming/Haskell_and_Wolfram_Language_syntax_comparison/ http://meng6net.localhost/computing/programming/Haskell_and_Wolfram_Language_syntax_comparison/ Haskell Mathematica Wolfram computing note programming Fri, 19 May 2017 02:50:12 +0000 2017-05-22T20:24:50Z <table class="datatable"> <thead> <tr> <th>description</th> <th>Haskell</th> <th>Wolfram</th> <th colspan="2">comment</th> </tr> </thead> <tbody> <tr> <td>defining a named function with explicitly named arguments</td> <td> <pre> <code>incrementInteger :: Int -&gt; Int<br />incrementInteger n = n + 1</code></pre></td> <td> <pre><code>incrementInteger[n_Integer] := n + 1;</code></pre></td> <td colspan="2"></td> </tr> <tr> <td>defining a named function with lambda expression</td> <td> <pre> <code>incrementInteger :: Int -&gt; Int<br />incrementInteger = \n -&gt; n + 1</code></pre></td> <td> <pre> <code>incrementInteger = Function[{n}, n + 1];</code></pre></td> <td colspan="2"></td> </tr> <tr> <td>defining a function with a function name as one of the arguments</td> <td> <pre> <code>Prelude&gt; increment = \x -&gt; x+1<br />Prelude&gt; double = \x -&gt; 2*x<br />Prelude&gt; thenDouble someFunc = double . someFunc<br />Prelude&gt; thenDouble increment 3<br />8</code></pre></td> <td> <pre> <code>In[1]:= double = Function[x, 2<em>x];<br />increment = Function[x, x + 1];<br />thenDouble[someFunc_] := Composition[double, someFunc];<br /><br />In[4]:= thenDouble[increment]<br /><br />Out[4]= Function[x, 2 x]@</em>Function[x, x + 1]<br /><br />In[5]:= (thenDouble[increment])[3]<br /><br />Out[5]= 8<br /></code></pre></td> <td colspan="2"></td> </tr> <tr> <td>defining a function with locally definded intermediate functions</td> <td> <pre> <code>Prelude&gt; :{<br />Prelude&gt; myFunc1 x =<br />Prelude&gt; let y = sin x<br />Prelude&gt; in cos y<br />Prelude&gt; :}<br />Prelude&gt; myFunc1 pi<br />1.0<br /><br />Prelude&gt; :{<br />Prelude&gt; myFunc2 x =<br />Prelude&gt; cos y<br />Prelude&gt; where<br />Prelude&gt; y = sin x<br />Prelude&gt; :}<br />Prelude&gt; myFunc2 pi<br />1.0</code></pre></td> <td> <pre> <code>In[1]:= myFunc[x_]:=With[{f=Sin[x]},Cos[f]]<br />myFunc[Pi]<br />Out[2]= 1</code></pre></td> <td colspan="2">Alternatively, instead of using <code>With</code> (for symbolic replacement), <a href= "https://reference.wolfram.com/language/tutorial/BlocksComparedWithModules.html"> use <code>Module</code> (for lexical scoping) or <code>Block</code> (for dynamic scoping)</a>.</td> </tr> </tbody> </table> Wolfram-related Twitter accounts and the alike http://meng6net.localhost/blog/wolfram-related_twitter_accounts_and_the_alike/ http://meng6net.localhost/blog/wolfram-related_twitter_accounts_and_the_alike/ blog mathematica note twitter weibo wolfram Sat, 07 Mar 2015 02:37:38 +0000 2017-05-16T23:59:39Z <ul> <li>news, blogs, comprehensive <ul> <li>Wolfram: <a href= "https://twitter.com/WolframResearch">@WolframResearch</a></li> <li>Wolfram Japan: <a href= "https://twitter.com/WolframJapan">@WolframJapan</a></li> <li>Wolfram China: <a href= "http://www.weibo.com/wolframchina">@WolframChina</a></li> <li>Wolfram Education: <a href= "https://twitter.com/WolframEdu">@WolframEdu</a></li> <li>Wolfram Careers: <a href= "https://twitter.com/WolframCareers">@WolframCareers</a></li> <li>Stephen Wolfram: <a href= "https://twitter.com/stephen_wolfram">@stephen_wolfram</a></li> <li>Conrad Wolfram: <a href= "https://twitter.com/conradwolfram">@conradwolfram</a></li> <li>Wolfram NKS: <a href= "https://twitter.com/WolframNKS">@WolframNKS</a></li> <li><a href="https://blog.wolfram.com">Wolfram Blog</a></li> <li><a href="http://blog.stephenwolfram.com/">Stephen Wolfram Blog</a></li> </ul> </li> <li>Wolfram Language / Mathematica <ul> <li>MathematicaTip: <a href= "https://twitter.com/MathematicaTip">@MathematicaTip</a></li> <li>Mathematica SE: <a href= "https://twitter.com/StackMma">@StackMma</a></li> <li>Tweet-a-Program: <a href= "https://twitter.com/wolframtap">@wolframtap</a>, <a href= "http://wolframtap.tumblr.com/archive">archive on Tumblr</a></li> <li>Mathematica Cookbook: <a href= "https://twitter.com/salmangano">@salmangano</a></li> <li>Wolfram Tip: <a href= "https://twitter.com/WolframTip">@WolframTip</a></li> <li>Sina Weibo: <ul> <li>面向教育的Mathematica: <a href= "http://www.weibo.com/u/5377153058">@面向教育的Mathematica</a></li> <li>Mathematica_李想: <a href= "http://www.weibo.com/u/1682600994">@Mathematica_李想</a></li> <li>Mathematica 中文使用者: <a href= "http://weibo.com/mmachineseusers">@Mathematica中文使用者</a></li> <li>Wolfram 语言编程珠玑: <a href= "http://www.weibo.com/wolframtip">@WolframTip</a></li> </ul> </li> <li><a href="http://mathematica.blogoverflow.com/">Mathematica StackExchange community blog</a></li> </ul> </li> <li>Wolfram|Alpha <ul> <li>Wolfram|Alpha: <a href= "https://twitter.com/Wolfram_Alpha">@Wolfram_Alpha</a></li> <li>Wolfram Fun Facts: <a href= "https://twitter.com/WolframFunFacts">@WolframFunFacts</a></li> <li>Wolfram|Alpha Can't: <a href= "https://twitter.com/wacnt">@wacnt</a></li> <li>WolframAlpha queries: <a href= "https://twitter.com/WA_queries">@WA_queries</a></li> <li>Wolfram_Alpha: <a href= "http://www.weibo.com/wolpha">@Wolfram_Alpha</a></li> <li><a href="http://wolframalpha.tumblr.com/">Wolfram|Alpha Tumblr</a></li> <li><a href="http://blog.wolframalpha.com/">Wolfram|Alpha blog</a></li> </ul> </li> </ul> /blog/wolfram-related_twitter_accounts_and_the_alike/#comments