Skip to Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
50
|
第二章
討論說明
不識此道的人可能會覺得
somePrimes
最前面的定義是最好理解的版本。首先,我必須說
沒有哪一種程式風格是「最好的」,所以不必特別屈就某種方式,精練的程式碼效率未
必佳。接下來我要為這種程式設計方式辯解,再一次強調我認為最恰當的版本。
首先,
@
算符的使用不該成為障礙,畢竟算符是很常見的,每個國小一年級的學生都須
學會 1 + 1 或是 $15 中算符的意義,算符並不神祕,只要你好好了解它。[Page-050]
然而,可讀性才是重點,此程式直接了當地表示出程式目的:「建立
{2^n-1, 2^n+1}
陣
列,其中
n
從
0
至
nmax
,接著將陣列展平為串列,消除重複值後,再將質數項挑出」【譯
註:原文為“select the primes of the union of the flattening of the table of pairs
{2^n-1,
2^n+1}
with
n
ranging from
0
to
nmax
",原文適當地表示出程式碼與問題描述之貼近程
度,譯文恐失原味】,如同前文所述,本程式最關鍵的動作是挑選質數,Mathematica 允
許你以不同表達方式強調表示式主要功能,這是相當方便的。
相反地,你也可以把函數置放於程式碼的結尾,降低其重要性,這也是後置式
//
的其
中一個特色,通常這會用於排版格式或運算計時等場合。舉例而言,下列程式碼的重點
在於取出
somePrimes[500]
的最後元素,順便輸出計算時間,計時指令置於結尾以便於
隨時刪除。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Mathematica Cookbook

Mathematica Cookbook

Sal Mangano
人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar

Publisher Resources

ISBN: 9789863470106