Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A simplier math formula
Message
De
17/12/2008 09:20:06
 
 
À
17/12/2008 08:52:30
Information générale
Forum:
Politics
Catégorie:
Autre
Divers
Thread ID:
01367448
Message ID:
01368099
Vues:
7
Thanks, small correction about associativity inline


>Hey, great post Gregory. Now even I understand it.
>
>
>>>>>>Was there ever a conclusion here as to what is correct?
>>>>>>
>>>>>>I would of done it like this:
>>>>>>(-2)^2 = 4
>>>>>>
>>>>>
>>>>>try:
>>>>>
>>>>>?5-2^2
>>>>>
>>>>>?-2^2
>>>>>
>>>>>obviously VFP and Excel has a bug.
>>>>
>>>>
>>>>Metin,
>>>>
>>>>This is not algebra
>>>>
>>>>The minus sign in the first expression is a binary operator.
>>>>In the second expression, it's a unary operator
>>>>
>>>>The unary minus has higher precedence than the exponent
>>>>The binary minus has lower precedence than the exponent
>>>>
>>>>No bug
>>>
>>>you say
>>>
>>>?5-2^2
>>>
>>>different than
>>>
>>>?-2^2+5
>>>
>>>that can't acceptable...
>>
>>Metin,
>>
>>I'll try to explain to a top 1% mathematician about computer languages - not algebra
>>I do not claim that this is complete - it's meant to help you understand
>>
>>If there are words you do not understand, try to find them here : http://www.thefreedictionary.com
>>
>>Operators
>>--------------
>>The arity (http://en.wikipedia.org/wiki/Arity) of an operator is the number of arguments it takes
>>eg multiplication takes two arguments, a * b could be written as *(a, b)
>>
>>A unary operator takes 1 argument and its arity is 1
>>a binary operator takes 2 arguments and its aritry is 2
>>a ternary operator takes 2 arguments and its arity is 3
>>a n-ary operator takes n arguments and its arity is n
>>
>>In essence, an operator with arity n is a function taking n arguments and returning exactly ONE result
>>
>>Prefix/postfix/infix
>>Notation and operators:
>>In a prefix notation, the operator is written before the argument, example from C#: ++i
>>In a postfix notation, the operator is written after the argument, example 3! (where ! is factorial, ie 3 * 2 * 1)
>>In an Infix notation, the operator is written between the arguments, eg : 1 + 2 or a * b
>>
>>
>>Precedence
>>The operators are assigned a precedence (sort of priority). Operators with higher precedence are evaluated before those with a lower precedence
>>This is by convention. Without them we would be forced to write fully parenthesized expressions
>>1 + 2 + 3 * 4 will be evaluated ((1+2) + (3*4))
>>
>>associativity
OUT >>If an operator is associative, eg (1+2)+3 = 1 + (2 + 3), it will be assigned a Left or a Right associativity

Each operator is assigned an associativity. It defines in which order an expresssion or part thereof will be evaluated for operators with equal precedence when there is a choice
eg: 1 + 2 + 3 could be (1+2) + 3 or (1 + (2+3)
An operator can be
- non associative, ie 1 + 2 + 3 is an illegal expression
- Left associative, ie evaluate from left to right. 1 + 2 + 3 becomes (1+2) + 3
- Right associative, ie evaluated from right to left. 1 + 2 + 3 becomes 1 + (2 + 3)

>>Why is Left/Right needed ? Addition - for example - is an binary operator (Arity = 2, takes 2 arguments)
>>
>>1 + 2 - 3
>>Since an operator is in essence a function that takes n arguments, would we write
>>Plus(1, Minus(2, 3)) or 1 + (2-3)
>>or
>>Minus(Plus(1,2),3) or (1+2) - 3
>>
>>So, the associativity comes into play with operators of equal precedence (+ and -, * and -)
>>
>>unary minus                    Right
>>exponent                          Right (vfp = Left)
>>multiplication, division  Left
>>addition, subtraction     Left 
>>
>>
>>
>>In the expressions below the minus sign is a unary operator, ie takes one argument
>>[ remember that unary minus has higher precedence ]
>>
>>-3
>>-2^2
>>
>>If we wrote it with functions
>>
>>Negate(3)
>>Exponent(Negate(2), 2)
>>
>>
>>
>>Here, it takes two arguments and is a binary operator
>>
>>0 - 3
>>0 - 2 ^2
>>
>>With functions
>>
>>Subtract(0, 3)
>>Subtract(0, Exponent(2,2))
>>
>>
>>How do we know that a minus is a unary operator ?
>>A unary minus comes at the beginning of an expression or immediately after a left parenthesis
>>
>>Ok, time to do some work now
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform