查看“︁運算次序”︁的源代码
←
運算次序
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{NoteTA |G1=Math}} 在[[數學]]和[[計算機科學|-{A|zh:計算機科學;zh-cn:计算机科学;zh-tw:電腦科學;zh-hk:電腦科學;zh-sg:电脑科学;}-]]中,'''運算次序'''(也稱為'''運算順序'''、'''運算子優先順序''')是指決定在[[表示式]]中的哪一運算子首先被執行的規則。 比如,在[[四則運算]]中,一般有先乘除後加減的規定。就是說在{{波兰表示法|infix|2+3*4|tag=math}}這樣的式子中,按規定會先對3和4作[[乘法]],得出12,然後再把2和12加起來,最後就得出14。 自引入現代的代數標記法,乘法總是擁有比加法更高的優先次序。<ref name="Bronstein_1987"/><ref name="Math_2000">{{cite web |url=http://mathforum.org/library/drmath/view/52582.html |title=Ask Dr. Math |publisher=Math Forum |date=2000-11-22 |access-date=2012-03-05 |archive-date=2021-04-21 |archive-url=https://web.archive.org/web/20210421044228/http://mathforum.org/library/drmath/view/52582.html |dead-url=no }}</ref>而16和17世紀引入了指數(乘冪)以後,指數總是擁有比加法和乘法更高的優先次序。<ref name="Bronstein_1987">{{cite book |title=Taschenbuch der Mathematik |author-first1=Ilja Nikolaevič<!-- Nikolajewitsch --> |author-last1=Bronstein<!-- 1903–1976 --> |author-first2=Konstantin Adolfovič<!-- Adolfowitsch --> |author-last2=Semendjajew<!-- 1908–1988 --> |editor-first1=Günter |editor-last1=Grosche |editor-first2=Viktor |editor-last2=Ziegler<!-- 1922–1980--> |editor-first3=Dorothea |editor-last3=Ziegler |others=Weiß, Jürgen<!-- lector --> |translator-first=Viktor |translator-last=Ziegler |volume=1 |date=1987 |edition=23 |orig-year=1945 |publisher=[[Verlag Harri Deutsch]] (and [[B. G. Teubner Verlagsgesellschaft]], Leipzig) |publication-place=Thun, Switzerland / Frankfurt am Main, Germany |language=de |chapter=2.4.1.1. |pages=115–120 |isbn=3-87144-492-8 |title-link=Bronstein and Semendjajew}}</ref>這個規則的定立消除了混淆並允許了標記更加簡潔。當需要越過這規則,甚至簡單地強調一下,括號 ( ) 會用以標示另一次序或者是強調預定次序來避免混亂。例如 {{Math|(2 + 3) × 4 {{=}} 20}} 需要加優先於乘,而 {{Math|(3 + 5)<sup>2</sup> {{=}} 64}} 需要加優先於[[冪|乘冪]]。為了方便閱讀,有時括弧會換為方括弧,例如 {{Math|[2 × (3 + 4)] - 5 {{=}} 9}}。 ==基本規則== 一般用於算術和[[编程语言]]的運算次序如下:<ref name="Bronstein_1987"/> #[[冪|乘冪]]和[[方根]] <math> x^y </math> <math> \sqrt{} </math> #[[乘法|乘]][[除法|除]] <math> \times </math> <math> \div </math> #[[加法|加]][[減法|減]] <math> + </math> <math> - </math> 當算式中同時存在多層的運算子,最高層級的運算子就優先計算。 因為加法與乘法的[[交換律]]和[[結合律]],加法可以按任何左右次序計算,乘法亦然。但運算子混合起來時需要依從運算次序。 在某些場合,把除換成倒數相乘或者把減當成加的相反對於計算更佳。例如在[[計算機科學]]中,這允許用少一點[[二元運算]]並讓簡化了的[[表示式]]更容易利用交換律和結合律。轉換後,{{Math|3 ÷ 4 {{=}} 3 × {{sfrac|1|4}}}},即{{Math|3}}和{{Math|4}}的商等於{{Math|3}}和{{Math|{{sfrac|1|4}}}}的積;{{Math|3 − 4 {{=}} 3 + (−4)}},{{Math|3}}和{{Math|4}}的差等於{{Math|3}}與{{Math|−4}}的和。於是,{{Math|1 − 3 + 7}} 可以想像成 {{Math|1 + (−3) + 7}},三個項用任何次序相加都會得出答案是{{Math|5}}。 [[根號]]√傳統上是透過上面的橫線(線括號)框下被开方数(這避免了框下被开方数時需要括號)。其他函數用括號框著輸入來避免混淆。有時候,當輸入只是[[單項式]],括號可被省略。所以 {{Math|sin 3''x'' {{=}} sin(3''x'')}},而 {{Math|sin ''x'' + ''y'' {{=}} sin(''x'') + ''y''}},因為 {{Math|''x'' + ''y''}} 不是單項式。<ref name="Bronstein_1987"/>不少計算機和编程语言都要求函數加上括號。 組合符號可以凌駕這個一般的運算次序。<ref name="Bronstein_1987"/>組合符號可以視為單獨表示式。<ref name="Bronstein_1987"/>組合符號可以用結合律和分配律去除,而組合符號內的表示式簡單得不會在符號移除後造成混淆的時候,就應該移除。 ;例子 : <math>\sqrt{1 + 3} + 5 = \sqrt 4 + 5 = 2 + 5 = 7.</math> 分數線同樣是組合符號: : <math>\frac{1 + 2}{3 + 4} + 5 = \frac{3}{7} + 5.</math> 為了方便閱讀,其他組合符號例如大括弧 { } 或中括弧 [ ] 會與括弧 ( ) 並用。例如: : <math>[(1 + 2) - 3] - (4 - 5) = [3 - 3] - (-1) = 1.</math> ===負號(一元減號)=== 一元運算子 − (通常讀「負」)有不同的約定。在手寫和印刷數學,表達 {{Math|−3<sup>2</sup>}} 解讀為 {{Math|0 − (3<sup>2</sup>) {{=}} −9}}。<ref name="Bronstein_1987"/><ref name="Angel">{{cite book |author-first=Allen R. |author-last=Angel |title=Elementary Algebra for College Students |edition=8 |at=Chapter 1, Section 9, Objective 3}}</ref>但部分程式和编程语言,典型例子是[[Microsoft Excel]](和其他試算表程式)和[[Bc_(编程语言)|编程语言Bc]],一元運算子比二元運算子優先,換言之,負號優先於指數,所以在這些語言中 {{Math|−3<sup>2</sup>}} 會解讀為 {{Math|(−3)<sup>2</sup> {{=}} 9}}。<ref name="Microsoft_2015">{{cite web |url=https://support.microsoft.com/en-gb/kb/kbview/132686 |archive-url=https://web.archive.org/web/20150419091629/https://support.microsoft.com/en-gb/kb/kbview/132686 |archive-date=2015-04-19 |title=Formula Returns Unexpected Positive Value |publisher=[[Microsoft]] |date=2005-08-15 |access-date=2012-03-05}}</ref>這不適用於二元減號 − :例如在Microsoft Excel,<code>=-2^2</code>、<code>=-(2)^2</code>和<code>=0+-2^2</code>會得出4,不過<code>=0-2^2</code>和<code>=-(2^2)</code>會得出−4。 ===乘除混合=== 同樣,使用斜杠符號 / 在諸如 {{Math|1 / 2''x''}} 之類的表達式中可能會有歧義。<ref name="Ball_1978">{{cite book |title=Algorithms for RPN calculators |url=https://archive.org/details/algorithmsforrpn0000ball |author-first=John A. |author-last=Ball |date=1978 |edition=1 |publisher=[[Wiley-Interscience]], [[John Wiley & Sons, Inc.]] |location=Cambridge, Massachusetts, USA |isbn=0-471-03070-8 |page=[https://archive.org/details/algorithmsforrpn0000ball/page/31 31]}}</ref>如果改寫成{{Math|1 ÷ 2''x''}}並把除法解讀為倒數乘法,就變成: : {{math|1 ÷ 2 × ''x'' {{=}} 1 × {{sfrac|1|2}} × ''x'' {{=}} {{sfrac|1|2}} × ''x''}} 以此解讀 {{Math|1 ÷ 2''x''}} 就等於 {{Math|(1 ÷ 2)''x''}}。<ref name="Bronstein_1987"/><ref name="Rules">{{cite web |url=http://www.mathcentre.ac.uk/resources/uploaded/mc-ty-rules-2009-1.pdf |title=Rules of arithmetic |website=Mathcentre.ac.uk |access-date=2019-08-02 |archive-date=2021-02-24 |archive-url=https://web.archive.org/web/20210224142452/http://www.mathcentre.ac.uk/resources/uploaded/mc-ty-rules-2009-1.pdf |dead-url=no }}</ref>不過在部分學術文書中,省略了乘號的[[乘法]]被視為優先於除,{{math|1 ÷ 2''x''}} 等於 {{math|1 ÷ (2''x'')}} 而不是 {{math|(1 ÷ 2)''x''}}。舉一例子,學術期刊[[物理評論]]的交稿說明中講明乘優先於斜杠符號標示的除,<ref name="APS_2012">{{cite web |url=https://publish.aps.org/files/styleguide-pr.pdf |title=Physical Review Style and Notation Guide |publisher=[[American Physical Society]] |access-date=2012-08-05 |at=Section IV–E–2–e |archive-date=2013-04-20 |archive-url=https://web.archive.org/web/20130420125316/https://publish.aps.org/files/styleguide-pr.pdf |dead-url=no }}</ref>而其他著名物理課本也有此規定,包括[[列夫·朗道|朗道]]和[[葉夫根尼·利夫希茨|利夫希茨]]編纂的《[[理論物理學教程]]》以及《[[費曼物理學講義]]》。 ==記憶術== 基本上,各國都有不同的口訣讓學生記著運算次序。英文的口訣會以運算子的字首構成。 * 中文地區一般以「先乘除後加減」作為口訣,但是當中沒有涵蓋指數 * 美國普遍使用「PEMDAS」,代表「Parentheses(括號), Exponents(指數), Multiplication(乘)/Division(除), Addition(加)/Subtraction(減)」<ref name="Vanderbeek_2007">{{cite book |title=Order of Operations and RPN |author-first=Greg |author-last=Vanderbeek |date=June 2007 |type=Expository paper |series=Master of Arts in Teaching (MAT) Exam Expository Papers |id=Paper 46 |publisher=[[University of Nebraska]] |location=Lincoln, Nebraska, USA |url=https://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1045&context=mathmidexppap |access-date=2020-06-14 |archive-url=https://web.archive.org/web/20200614191608/https://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1045&context=mathmidexppap |archive-date=2020-06-14}}</ref> * 加拿大與紐西蘭使用「BEMDAS」,代表「Brackets(括號), Exponents(指數), Multiplication(乘)/Division(除), Addition(加)/Subtraction(減)」<ref name="Vanderbeek_2007"/> * 英國使用「BOMDAS」或「BIMDAS」,與前者相比,這兩個縮寫純粹改變了指數的詞彙(Orders/Indices)<ref name="Syllabus_2019">{{cite web |url=http://syllabus.bos.nsw.edu.au/assets/global/files/maths_s3_sampleu1.doc |format=DOC |title=Order of operations |website=Syllabus.bos.nsw.edu.au |access-date=2019-08-02 |archive-date=2021-02-24 |archive-url=https://web.archive.org/web/20210224172758/https://syllabus.bos.nsw.edu.au/assets/global/files/maths_s3_sampleu1.doc |dead-url=no }}</ref> * 其他英語地區普遍使用「BOMDAS」 這些口訣都有機會導致誤導,例如誤以為「先加後減」,就會錯誤地運算。<ref name="Ball_1978"/> : {{math|10 - 3 + 2}} 正確答案是 {{math|9}}(但如果先加後減就會變成 {{math|5}})。 ==特殊情況== ===連續乘冪=== 如果乘冪以堆疊上標的方式呈現,一般規則是從上到下:<ref name="Robinson_1958">{{cite journal |title=A report on primes of the form k · 2<sup>n</sup> + 1 and on factors of Fermat numbers |author-first=Raphael Mitchel |author-last=Robinson |author-link=Raphael Mitchel Robinson |journal=[[Proceedings of the American Mathematical Society]] |volume=9 |issue=5 |date=October 1958 |orig-year=1958-04-07 |location=[[University of California]], Berkeley, California, USA |doi=10.1090/s0002-9939-1958-0096614-7 |page=673–681 [677] |url=http://www.ams.org/journals/proc/1958-009-05/S0002-9939-1958-0096614-7/S0002-9939-1958-0096614-7.pdf |access-date=2020-06-28 |archive-url=https://web.archive.org/web/20200628100823/https://www.ams.org/journals/proc/1958-009-05/S0002-9939-1958-0096614-7/S0002-9939-1958-0096614-7.pdf |archive-date=2020-06-28}}</ref><ref name="Bronstein_1987"/><ref name="NIST_2010">{{cite book |title=NIST Handbook of Mathematical Functions |title-link=NIST Handbook of Mathematical Functions |editor-first=Frank W. J. |editor-last=Olver |editor2-first=Daniel W. |editor2-last=Lozier |editor3-first=Ronald F. |editor3-last=Boisvert |editor4-first=Charles W. |editor4-last=Clark |date=2010 |publisher=[[National Institute of Standards and Technology]] (NIST), [[U.S. Department of Commerce]], [[Cambridge University Press]] |isbn=978-0-521-19225-5 |mr=2723248}}[http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=9780521140638] {{Webarchive|url=https://archive.today/20130703230148/http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=9780521140638 |date=2013-07-03 }}</ref><ref name="Zeidler_2013">{{cite book |title=Springer-Handbuch der Mathematik I |title-link=Springer-Handbuch der Mathematik |volume=I |language=de |editor-first=Eberhard |editor-last=Zeidler |editor-link=:de:Eberhard Zeidler |author-last1=Zeidler |author-first1=Eberhard |author-link1=:de:Eberhard Zeidler |author-last2=Schwarz |author-first2=Hans Rudolf |author-last3=Hackbusch |author-first3=Wolfgang |author-link3=Wolfgang Hackbusch |author-last4=Luderer |author-first4=Bernd |author-link4=:de:Bernd Luderer |author-last5=Blath |author-first5=Jochen |author-last6=Schied |author-first6=Alexander |author-last7=Dempe |author-first7=Stephan |author-last8=Wanka |author-first8=Gert |author-link8=Gert Wanka |author-last9=Hromkovič |author-first9=Juraj |author-link9=Juraj Hromkovič |author-last10=Gottwald |author-first10=Siegfried |author-link10=Siegfried Gottwald |publisher=[[Springer Spektrum]], [[Springer Fachmedien Wiesbaden]] |publication-place=Berlin / Heidelberg, Germany |edition=1 |date=2013 |orig-year=2012 |isbn=978-3-658-00284-8 |id={{ISBN|3-658-00284-0}} |doi=10.1007/978-3-658-00285-5 |page=590 <!-- |url=https://www.springer.com/de/book/9783658002848 |access-date=2020-06-27 -->}} (xii+635 pages)</ref> : {{math|''a''<sup>''b''<sup>''c''</sup></sup> {{=}} ''a''<sup>(''b''<sup>''c''</sup>)</sup>}} 不是等同於 {{math|(''a''<sup>''b''</sup>)<sup>''c''</sup>}}。 但是,以[[脱字符|符號 ^ ]]或[[箭頭]] (↑) 作表其運算子的時候,並沒有普遍標準。<ref name="VanWinkle_2016">{{cite web |title=Exponentiation Associativity and Standard Math Notation |author-first=Lewis |author-last=Van Winkle |work=Codeplea - Random thoughts on programming |date=2016-08-23 |url=https://codeplea.com/exponentiation-associativity-options |access-date=2016-09-20 |archive-url=https://web.archive.org/web/20200628215506/https://codeplea.com/exponentiation-associativity-options |archive-date=2020-06-28}}</ref>例如,[[Microsoft Excel]]把<code>''a''^''b''^''c''</code>理解成 {{math|(''a''<sup>''b''</sup>)<sup>''c''</sup>}},而[[Google Search]]和[[Wolfram Alpha]]就理解成 {{math|''a''<sup>(''b''<sup>''c''</sup>)</sup>}}。所以<code>4^3^2</code>在前者會計成4096,在後者會計成262144。 ===連除=== 連除也存在同樣的含糊,例如 {{math|10 ÷ 5 ÷ 2}} 既可解讀為 : {{math|(10 ÷ 5) ÷ 2}} 又可解讀為 : {{math|10 ÷ (5 ÷ 2)}} 從左至右的計算原則使前者更加普遍。而且把除數變成分數的計算習慣也大大減少了含糊的產生。 ==參見== * [[运算]] * [[6÷2(1+2)]] ==資料來源== {{reflist}} [[Category:计算机科学]] [[Category:代数]]
该页面使用的模板:
Template:Cite book
(
查看源代码
)
Template:Cite journal
(
查看源代码
)
Template:Cite web
(
查看源代码
)
Template:Math
(
查看源代码
)
Template:NoteTA
(
查看源代码
)
Template:Reflist
(
查看源代码
)
Template:Webarchive
(
查看源代码
)
Template:波兰表示法
(
查看源代码
)
返回
運算次序
。
导航菜单
个人工具
登录
命名空间
页面
讨论
不转换
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息