Regnearternes hierarki: Forskelle mellem versioner

Content deleted Content added
m Typo fixing, typos fixed: istedet → i stedet ved brug af AWB
Linje 35:
===Blandet division og multiplikation===
:''i dette afsnit anvendes det engelske divisionssymbol "÷"''
Der kan være flertydighed i anvendelsen af [[Skråstreg#I_matematikI matematik|skråstreg symbolet]] / i udtryk såsom 1/2''x''.<ref name="Ball_1978">{{cite book |title=Algorithms for RPN calculators |url=https://archive.org/details/algorithmsforrpn0000ball |url-access=registration |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> Hvis man omskriver dette udtryk som {{nowrap|1 ÷ 2''x''}} og så fortolker divisionssymbolet som visende den [[multiplikative inverse]], fås:
: {{nowrap|1 ÷ 2 × ''x'' {{=}} 1 × {{sfrac|1|2}} × ''x'' {{=}} {{sfrac|1|2}} × ''x''}}.
 
Med denne fortolkning {{nowrap|1 ÷ 2''x''}} er det lig med {{nowrap|(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}}</ref> Men i en del akademisk litteratur, anvendes [[underforstået multiplikation]], som bliver fortolket som havende højere præcedens end division, sådan at {{nowrap|1 ÷ 2''x''}} er lig {{nowrap|1 ÷ (2''x'')}}, ikke {{nowrap|(1 ÷ 2)''x''}}.
 
Fx er manuskript indsendelsesinstruktionerne for tidsskriftet ''[[Physical Review]]'' at (kun underforstået?) multiplikation har højere præcedens end division med en skråstreg,<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&ndash;E&ndash;2&ndash;e}}</ref> og dette er også konventionen observeret i prominente fysikbøger såsom ''[[Course of Theoretical Physics]]'' af [[Lev Landau|Landau]] og [[Evgeny Lifshitz|Lifshitz]] - og ''[[Feynman Lectures on Physics]]''.<ref name="NB1">For example, the third edition of ''Mechanics'' by [[Landau and Lifshitz (book)|Landau and Lifshitz]] contains expressions such as ''hP''<sub>''z''</sub>/2{{pi}} (p. 22), and the first volume of the ''[[Feynman Lectures]]'' contains expressions such as 1/2{{sqrt|''N''}} [http://www.feynmanlectures.caltech.edu/I_06.html (p. 6–7)]. In both books, these expressions are written with the convention that the [[Slash (punctuation)|solidus]] is evaluated last. This also implies that an expression like 8/2(4) has solution 1 as the omission of the [[Multiplication_signMultiplication sign| multiplication sign (x * or .)]] implies that the solidus is evaluated last even if positioned more to the left.</ref>
<ref name="NB2">"Of" is equivalent to division or multiplication, and commonly used especially at primary school level, as in "Half ''of'' fifty".</ref>
 
Linje 50:
Nogle [[programmeringssprog]] anvender regnearternes hierarki, som er kompatibel med hvad der anvendes i matematik,<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 |url-status=live |archive-url=https://web.archive.org/web/20200628215506/https://codeplea.com/exponentiation-associativity-options |archive-date=2020-06-28}}</ref> selvom andre, såsom [[APL]], [[Smalltalk (programmeringssprog)|Smalltalk]], [[Occam]] and [[Mary (programmeringssprog)|Mary]], ikke har operator præcedens regler (i APL er evaluering striks fra højre til venstre; i Smalltalk osv. er det striks venstre til højre).
 
Yderligere, fordi mange operatorer ikke er associative, er præcedensen indenfor ethvert enkelt niveau sædvanligvis defineret ved at gruppere venstre til højre så at <code>16/4/4</code> fortolkes som {{nowrap|(16/4)/4 {{=}} 1}} istedeti stedet for {{nowrap|16/(4/4) {{=}} 16}}; sådanne operatorer bliver måske fejlagtigt kaldet for "venstre associativ". Undtagelser eksisterer; fx, sprog med operatorer som korresponderer til [[cons]] operation på lister grupperer dem typisk fra højre til venstre ("højre associativ"), fx i [[Haskell (programmeringssprog)|Haskell]], <code>1:2:3:4:[] == 1:(2:(3:(4:[]))) == [1,2,3,4]</code>.
 
[[Dennis_RitchieDennis Ritchie|Skaberen]] af [[C (programmeringssprog)|programmeringssproget C]] har sagt at præcedens i C (programmeringssprog som låner disse regler fra C, er fx: [[C++]], [[Perl]] og [[PHP]]), ville være mere formålstjenligt hvis [[Bitwise_operationBitwise operation|bitwise operatorer]] flyttes op over [[Relationel_operatorRelationel operator|sammenligningsoperatorer]].<ref name="Ritchie_1996">{{cite book |author-first=Dennis M. |author-last=Ritchie |author-link=Dennis M. Ritchie |url=https://www.bell-labs.com/usr/dmr/www/chist.html |chapter=The Development of the C Language |title=History of Programming Languages |edition=2 |publisher=[[ACM Press]] |date=1996}}</ref> Men mange programmører er blevet tilvænt til denne præcedens. Det relative præcedens niveau af [[Operator (programmering)|operatorer]], der findes i mange C-lignende sprog, er som følger:
 
{| class="wikitable"