Konrad-Franz Posted October 26, 2021 Share Posted October 26, 2021 (edited) Calculations of the form -x^y take place in AutoIt contrary to the mathematical standard (https://en.wikipedia.org/wiki/Order_of_operations#Unary_minus_sign). According to this standard, the power calculation is first, followed by the negation. This is what happens in the computer algebra system Maxima, as well as in Javascript. AutoIt handles this the other way round, first the negation, then the power calculation. The list 'operator precedence' ('From highest precedence to lowest') reflects this misleadingly by placing the '^' sign above the '-' sign, thus suggesting a precedence of power calculation over negation. It is not acceptable to have to convert expressions of the form -x^y in mathematically correct formulas to -(x^y) just because AutoIt does not adhere to the mathematical standard. Edited October 27, 2021 by Konrad-Franz Link to comment Share on other sites More sharing options...
Nine Posted October 26, 2021 Share Posted October 26, 2021 Based on your own link : Unary minus sign There are differing conventions concerning the unary operator − (usually read "minus"). In written or printed mathematics, the expression −32 is interpreted to mean −(32) = − 9.[1][19] In some applications and programming languages, notably Microsoft Excel, PlanMaker (and other spreadsheet applications) and the programming language bc, unary operators have a higher priority than binary operators, that is, the unary minus has higher precedence than exponentiation, so in those languages −32 will be interpreted as (−3)2 = 9.[20] This does not apply to the binary minus operator −; for example in Microsoft Excel while the formulas =−2^2, =-(2)^2 and =0+−2^2 return 4, the formula =0−2^2 and =−(2^2) return −4. There are different conventions. If we change it to your preference, someone else will complain that it does not follow Excel and other languages. It is a "dam if you do, dam if you don't" dilemma. Earthshine 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 26, 2021 Moderators Share Posted October 26, 2021 (edited) Konrad-Franz, Welcome to the AutoIt forum. As a programmer of some 50+ years experience I would never rely on operator precedence in any mathematical expression and would always use parentheses to make the order explicit. While this may make the original formulation of the expression slightly more onerous, the advantages of not having to rely on the arbitrary operator precedence (amply shown in the post above) of the various programming languages that might be used to evaluate it far outweigh this minor inconvenience. M23 Edited October 26, 2021 by Melba23 Older than I thought! Skysnake, Earthshine and Musashi 3 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted October 26, 2021 Share Posted October 26, 2021 (edited) @Konrad-Franz there are indeed differing conventions among applications and programming languages. For instance Wolfram Mathematica also handles -2^3 as (-2)^3 = -8 Would you go as far as say that Mathematica isn't mathematically sound and call Stephen Wolfram an impostor? Edited October 26, 2021 by jchd Thinkos! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Konrad-Franz Posted October 26, 2021 Author Share Posted October 26, 2021 Hello Nine. If you calculate like AutoIt -3^2 = 9 and 3^2 = 9 then the minus sign is obviously meaningless. Do you consider this logical? If 'spreadsheet applications' and 'other languages' (which? relevant?) ignore the mathematical (and logical!) standard, they should change their behaviour and not AutoIt also take this erroneous path. Melba23, hello to you too. If you would get from a mathematical programme like Maxima endless formulas which you have to transfer to AutoIt, you would not consider to add hundreds of (mostly unnecessary) parantheses. No, you would long for a consistent standard to which AutoIt adheres too. Link to comment Share on other sites More sharing options...
Konrad-Franz Posted October 26, 2021 Author Share Posted October 26, 2021 Hello jchd. WolframAlpha is calculating -3^2 = -9. This is the mathematical standard! Any further questions? Link to comment Share on other sites More sharing options...
jchd Posted October 26, 2021 Share Posted October 26, 2021 (edited) I said "Wolfram Mathematica", not "Wolfram Alpha". Edited October 26, 2021 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 26, 2021 Moderators Share Posted October 26, 2021 Konrad-Franz, I would argue that the author of Maxima is at fault for not offering the ability to produce precedence-explicit expressions given the known differences between the various platforms on which they might be used. But then I would say that, wouldn't I! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted October 26, 2021 Share Posted October 26, 2021 The question made me wonder and look twice since the discrepancy was blatant: if fact I'm by default using an overloaded version of Minus I need for special purposes. Living my specific environment, indeed: FullForm[-a^b] Times[-1,Power[a,b]] Sorry for noise. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Konrad-Franz Posted October 26, 2021 Author Share Posted October 26, 2021 (edited) OK jchd. And what is 'Wolfram Mathematica" saying to -3^2? The same same like AutoIt (9) or the mathematical solution (-9). By the way: Your example -2^3 is not helpful, because in case of an exponentiation with a negative base and an odd exponent the result will be negative regardless of whether you write the expression (-2)^3 = -8 or -(2^3) = -8. However, it becomes problematic with even exponents. Edited October 27, 2021 by Konrad-Franz Link to comment Share on other sites More sharing options...
jchd Posted October 26, 2021 Share Posted October 26, 2021 (edited) Yes I answered a bit hastily! Yet I prefer typing defensively with potentially ambiguous constructs. At least in Mma, we have the possibility to decide precedence, associativity, distributivity, ... of every user function. Edited October 26, 2021 by jchd JockoDundee 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JockoDundee Posted October 27, 2021 Share Posted October 27, 2021 Proof that Google stole Microsoft source code: Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Popular Post JockoDundee Posted October 27, 2021 Popular Post Share Posted October 27, 2021 (edited) 22 hours ago, Konrad-Franz said: It is not acceptable to have to convert expressions of the form -x^y in mathematically correct formulas to -(x^y) just because AutoIt does not adhere to the mathematical standard. Totally unacceptable… I can’t even imagine the horror of having to convert expressions just because you decided to use a language written by some guy who negated before he expontiated. It’s an outrage and you should ask for a full refund. Edited October 27, 2021 by JockoDundee CoffeeJoe, SkysLastChance, jchd and 2 others 1 4 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
mikell Posted October 27, 2021 Share Posted October 27, 2021 ... or at least a tiny update of the corresponding page in the helpfile, to mention as said Melba "don't rely on operator precedence" - btw in this case such a thread would never have existed Link to comment Share on other sites More sharing options...
CoffeeJoe Posted October 27, 2021 Share Posted October 27, 2021 6 minutes ago, mikell said: in this case such a thread would never have existed Where's the fun in that? Link to comment Share on other sites More sharing options...
mikell Posted October 27, 2021 Share Posted October 27, 2021 No fun, just an ascertainment - please read post #1 again CoffeeJoe 1 Link to comment Share on other sites More sharing options...
Exit Posted October 27, 2021 Share Posted October 27, 2021 How to encrypt the digit 1 ? Spoiler ConsoleWrite(-3^-3^-0& @CRLF) App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
mikell Posted October 27, 2021 Share Posted October 27, 2021 ConsoleWrite("Exit is crazy"^0 & @CRLF) Jfish, Exit and Werty 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now