Skip to content

MathematicalSyntaxErrors

Frédéric Chapoton edited this page Mar 10, 2019 · 10 revisions

The Top Mathematical Syntax Errors in Sage

This page is for help with the mathematical syntax used in Sage generally, and in particular inside CoCalc. There is a highly related page for working with and editing CoCalc worksheets, including help with the user-interface.

The Good News: The 16--21 errors described here (depending on how you count) are easily responsible for over 95% of mistakes that I see students making in mid-level undergraduate math courses. (e.g. integral calculus, multi-variable calculus, differential equations, matrix algebra, discrete math, ...) In fact, the first five errors might be responsible for 80% just by themselves.

Remember: if you don't find what you need, or if you'd like to ask a question, then please email [email protected] at any time. We'd love to hear from you! Please include a link (the URL address in your browser) to any relevant project or document, as part of your email.

Context: A worksheet is a file ending in .sagews and is subdivided into cells. Each cell has an input region and an output region, which might be 0, 1, 2, or many lines long. The input can be mathematical, in the Sage syntax, or it could be in many other formats, including markdown, html, R, and so forth. This page deals with Sage, and not those other languages.

List of Categories:

Citation: By the way, much of this information has been taken from Sage for Undergraduates, a book written by Gregory V. Bard and published by The American Mathematical Society in 2015. (The pdf-file of that book is available for free, and the print version has an extremely low price.) This file is largely based on Appendix A: "What to do When Frustrated!" of that book.


1. Implicit multiplication

This particular case is best explained with an example:

solve( x^3 - 5x^2 + 6x == 0, x ) <--- Wrong!

is not correct. You must type instead

solve( x^3 - 5*x^2 + 6*x == 0, x )

In other words, Sage needs that asterisk or multiplication symbol between the coefficients 5 and 6, and the terms to which they are attached: namely $x^2$ and $x$. For some reason, trigonometric functions really cause this confusion for some users. Sage will reject

f(x) = 5cos( 6x ) <--- Wrong!

but will accept

f(x) = 5*cos( 6*x )

Another common manifestation is

f(x) = x(x+1) <--- Wrong!

but instead it should be

f(x) = x*(x+1)

In defense of Sage, it should be noted that Java, C, C++, Python, FORTRAN, Pascal, BASIC, and many other computer languages have this same rule. However, for those users who find this extremely frustrating, there is a way out of this requirement. If you place the following line

implicit_multiplication(True)

at the start of a CoCalc session, then you will be in "implicit multiplication mode."

Consider the following code:

implicit_multiplication(True)
g=(12+3x)/(-12+2x)
plot( g, 2, 8, ymin=-30, ymax=30 )

Note that the definition of $g$ above does not have an asterisk between the 3 and the first $x$ nor between the 2 and the second $x$. Because we are in "implicit multiplication mode," those two missing asterisks are forgiven.

Note about SageMathCell: At this particular moment (July 6th, 2016) the implicit_multiplication trick will work in CoCalc, but not in SageMathCell.

2. Did you forget to declare a variable?

The declaration of variables can be something confusing to those who have not done a lot of programming in the years prior to learning Sage. In languages such as C, C++, and Java, all the variables must be declared---no exceptions. In Sage, the variable $x$ is pre-declared. All other variables have to be declared, except variables that are declared in a way that you could call "implicit declaration." I'll explain implicit declaration in a moment.

Let's say that I want to graph a sphere, $ x^2 + y^2 + z^2 = r^2 $ for the value $r=5$. As you can see, I need $x$, $y$, and $z$ to write that equation, but I also have a constant $r=5$. Therefore, I must declare the $y$ and the $z$ with var("y z") very early in my code, perhaps at the first or second line.

The $r$ can be declared "implicitly." For example, if I give the command r=5 then Sage will understand that $r$ is a variable. Therefore, a var("r") is not needed.

The variable $x$ is always pre-declared, so there's absolutely no need to declare var("x") in my code.

var("y z")
r=5
implicit_plot3d( x^2 + y^2 + z^2 == r^2, (x,-r,r), (y,-r,r), (z,-r,r) )

For stylistic reasons, some users like to declare $x$ anyway. They would therefore type var("x y z") in place of var("y z") because there is no impact in Sage to the redundant declaration of $x$. Of course, visually there is a difference---it treats $x$ in a more egalitarian way among $x$, $y$, and $z$.

Finally, functions (e.g. $f(x)$ or $g(x)$) do not have to be declared---they are defined via a special Sage-specific syntax. Just to summarize, consider the following code:

var("t")
g = 9.82

f1(t) = 3 - 5*t
f2(t) = 4 + 5*t
f3(t) = 7 + 0.5*g*t^2

plot( [ f1(t), f2(t), f3(t) ], (t, 0, 2), gridlines="minor" )

We have to declare $t$, because it is a variable, and we're not putting a value into it. The $f_1(t)$, $f_2(t)$, and $f_3(t)$ need not be declared, because they are functions. Lastly, we do not have to declare $g$, because when we assign 9.82 to $g$, we are declaring it implicitly.

The reason for this is the preparser. The transformation for declaring a function to the underlying Python code looks like that:

sage: preparse("f1(t) = 3 - 5*t")

actually defines t as a variable, then creates the right hand side expression in t and finally calls the method .function(t) to declare this intermediate symbolic expression to be a function in t.

__tmp__=var("t")
f1 = symbolic_expression(Integer(3) - Integer(5)*t).function(t)

3. Huge error messages appear

In almost all cases, when something incorrect is inputted into Sage, an extremely long error message appears. This many-lined report can be extremely intimidating, and even moderately experienced Sage users might not know what to make of it.

This is actually called a "stack trace" and it is very useful to experienced programmers, who can use it to locate a bug very rapidly. However (for new users) it can be very intimidating. The key is to realize that the last line of the error message is usually the most useful.

Whenever you have a huge error message, start with the very last line. That's often all you need. Alternatively, some students find it easier to ignore the error message entirely, read their own code, and figure out what is wrong themselves.

4. Mismatched Parentheses

Matching parentheses can be tricky, and therefore some users can get frustrated by mismatched parentheses. Luckily, Sage has two great features to help you with this commonly performed task.

4$\frac{1}{3}$. Automatic syntax highlighting

This feature is better demonstrated by an example. With cut-and-paste, put the following code into a cell of a CoCalc worksheet.

f(x) = 1/(1 + 1/(3 + 1/(5 + 1/(7 + 1/(1 + 1/(3 + 1/(5 + 1/(7 + x))))))))

plot( f(x), -5, 5 )

Now click on f(x), and scroll with the arrow keys along that long expresion. What you'll see is that the parentheses will turn green as you pass over them. Now, if you look carefully at the right of the expression, whenever you pass over a "$($", the matching "$)$" will also turn green simultaneously. This helps you identify which parentheses match with which other parentheses.

While the previous example was a bit contrived, a real-world example is the following function, which represents the future value (after $t$ years) of a sequence of annual deposits of 1000 dollars, invested at 6% compounded monthly.

v(t) = 1000*((1+0.005)^(12*t)-1)/0.005

As you can see, there are six parentheses (three left and three right), and indeed, it can be tricky to get their placement exactly right.

4$\frac{2}{3}$. Showing a function

Sometimes, after entering a function, it can be a great help to use the show(f(x)) command to see if you've got it right or not. For example,

f(x) = 1/(1 + 1/(3 + 1/(5 + 1/(7 + 1/(1 + 1/(3 + 1/(5 + 1/(7 + x))))))))

show(f(x))

produces the lovely (and correct) image below:

5. Commas in the middle of large numbers

The comma is a very important symbol in most computer languages, including Python, on which Sage is based. That's why we do not use commas inside of large numbers when programming in almost any computer language.

As an example, the correct syntax for solving

$$\begin{array}{rcl} 59x + 79y & = & 572 \\ x + y & = & 8 \\ \end{array}$$

is to type

var("x y") 
solve( [59*x + 79*y == 572, x + y == 8] , [x,y] )

and press shift+enter.

However, the highly related problem $$\begin{array}{rcl} 59x + 79y & = & 28,233 \ x + y & = & 387 \ \end{array}$$

is not solved by typing

var("x y") 
solve( [59*x + 79*y == 28,233, x + y == 387 ] , [x,y] )

but instead, you should remove the comma from inside the 28,233. In other words, you should type instead

var("x y") 
solve( [59*x + 79*y == 28233, x + y == 387 ] , [x,y] )

This is even more important for very large numbers, like 7,255,881. We really want to have those two interior commas in a number that large, when we write text such as in an email or on MathExchange. However, while programming, we do not use the interior commas.

Instead, you should type

var("x y") 
solve( [15163*x + 20303*y == 7255881, 257*x + 257*y == 99459 ] , [x,y] )

which correctly computes the answer $x=117$ and $y=270$.

6. Capitalizing the built-in functions

When using Sage, we should be very careful not to capitalize the built-in functions. For example, the following code is correct:

print(sin(pi/4))
print(ln(e^3))
print(sqrt(60))
print(arctan(1))

While the following code is incorrect, because the initial letters of the built-in functions have been (illegally) capitlized.

print(Sin(pi/4))
print(Ln(e^3))
print(Sqrt(60))
print(Arctan(1))

By the way, if you look in most calculus textbooks, you will see that it is a long-standing tradition not to capitalize those initial letters.

6$\frac{1}{2}$. A note about "log" vs "ln":

While we're talking about the built-in functions, it might be nice to clarify an issue about log and ln. In higher mathematics, the useful logarithm is almost always the natural logarithm, not the common logarithm or the binary logarithm. For this reason, higher mathematics textbooks, such as those used in the university curriculum after the midpoint of a math degree, use log(x) to mean the natural logarithm of $x$.

Yet, high-school mathematics textbooks, and many textbooks used in freshman calculus or precalculus, use the following notation:

  • ln(x) is the natural logarithm of $x$. (In other words, base $e$.)
  • ld(x) is the binary logarithm of $x$. (In other words, base $2$.)
  • log(x) is the common logarithm of $x$. (In other words, base $10$.)
  • It should be noted that the last one is very popular in both chemistry and geology. For example, pH uses the common logarithm, as does the Richter scale for earthquakes.

In any case, to be compatible with higher mathematics textbooks, Sage uses log(x) internally to mean the natural logarithm of $x$, not the common logarithm.

Yet, if you type ln(x), Sage will understand and allow it. This leads to an odd situation. If you type ln(17) then Sage will respond log(17), and that can be rather confusing to a precalculus student.

7. Parameters in the wrong order

When programming, it is very easy to get the parameters in the wrong order. Consider the following example. Let's suppose that I'm asked to find the 4th-degree Taylor approximation to the function $f(x)=\sqrt{x}$ computed about the point $x=9$.

Therefore, I type taylor( sqrt(x), x, 4, 9 ) and I get back something very strange. The response is

715/8589934592*(x - 4)^9 - 429/1073741824*(x - 4)^8 + 33/16777216*(x - 4)^7 - 21/2097152*(x - 4)^6 + 7/131072*(x - 4)^5 - 5/16384*(x - 4)^4 + 1/512*(x - 4)^3 - 1/64*(x - 4)^2 + 1/4*x + 1

which is weird because I am expecting a 4th-degree polynomial, and I have a 9th-degree polynomial instead. Moreover, the repeated appearance of $(x-4)$ makes it seem as though the polynomial were constructed about $x=4$ and not about $x=9$.

I should have typed instead taylor( sqrt(x), x, 9, 4 ) to do that. I get the much more reasonable answer of

-5/279936*(x - 9)^4 + 1/3888*(x - 9)^3 - 1/216*(x - 9)^2 + 1/6*x + 3/2

which is a polynomial of the fourth degree. Because I see repeated uses of $(x-9)$, I know it is constructed about $x=9$.

This whole episode shows you that the order of parameters matters a lot. Moreover, if you do exchange two parameters, then you might be asking for something valid, but very different from your intension.

The best way to painlessly avoid this problem is to type taylor? which will bring up a help window about the taylor command. You can glue a question mark to the end of any command, and Sage will bring up the help window for you.

8. Your internet connection has silently gone down

Few things can be more frustrating than a computer program which has become unresponsive, especially if you're working on something important. Sometimes, if working in a coffee-shop or a hotel, your wifi access will expire. This cuts off your internet connection, and severs the link between your computer and CoCalc.

CoCalc has a very handy feature. If you look in the upper-right corner of your web-browser window, you'll see a wifi-symbol, followed by a number, the unit "milliseconds" (abbreviated as "ms") and then a pair of diagonal arrows point at each other. Here's an example:

That means I have a good connection, and the latency is 66 milliseconds. In other words, a packet leaving CoCalc will arrive at my computer about 0.066 sec after it was sent. Alternatively, if my internet connection were to go down suddenly, I'd see something that looks like this:

and that's how I know that my internet connection has gone down. So if a command that normally works stops working, be sure and glance up and see---perhaps you've lost your internet connection!

9. Misspelling a command

Let's say that I want to make a nice 3D plot of some algebraic surface which is defined implicitly. Yet, perhaps I have forgotten... is the command implicit_plot3D? implicitplot3D? implicitplot3d? implicit_plot3d? or implicitPlot3D?

What I should do, in a SageMathCell, is type imp and then hit the tab button. After a few moments, a handy pull-down list appears with the five commands that begin with the letters "imp."

Sometimes, a command is a method of some object. For example, look at the following code.

A = matrix( 3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
print(A)
A.rref()

The rref command "belongs" to A, because this command is only for matrices, and A is a matrix. (The way to say this in computer science is "rref is a method of the object A, which has class matrix.")

What if I forget that the command is rref? If you type the first two lines of the previous code block, and then type (on the third line) type only A.r followed by the tab button, then you get a rather long list of commands which would be suitable for that situation. Of course, rref is among them.

In the next remark, we'll explain what you should do if you've forgotten the name of a command.

9$\frac{3}{4}$. Getting help without remembering the name of a command

If you remember the name of a command, such as A.rref(), then you can use the question mark operator to get help for it, as we discussed in the previous question above. However, if you've forgotten the command to compute a null space (just to pick an example), then you have several options.

  • Search in Google for: null space "sage reference manual"
  • Search in Google for: null space site:sagemath.org
  • Download a copy of the book Sage for Undergraduates, by Gregory Bard, published by the American Mathematical Society in 2015. The electronic version is a 100% free pdf file.

Note: That middle option deserves some further information. The term site:sagemath.org, with no spaces on either side of the colon, will restrict Google to search on webpages whose URL ends in sagemath.org and therefore your search is far more focused. Of course, you can use this with any URL that you like. Sometimes it is useful to search with site:edu.

There used to be a command called search_doc, but in many cases it has been rendered inoperative, for technical reasons.

10. Scientific notation mistakes

The letter e in Sage usually refers to 2.718281828... just like in calculus and related courses. However, it sometimes indicates scientific notation.

For example, if you type 10^19.39 into Sage, then the reply will be 2.45470891568503e19.

Now, if you want to multiply this answer by 2, ...

  • You should type 2*2.45470891568503e19

  • You should not type 2*2.45470891568503*e19 because e19 looks like a variable name.

  • You should definitely not type 2*2.45470891568503*e^19 because $e$ is being interpreted as 2.718281828 when it appears alone. (Contrastingly, when e appears in the middle of a number, then it is interpreted as scientific notation.)

  • However, you can type instead 2*2.45470891568503*10^19 which is fine. This is probably preferred, because it is more human readable.

  • When looking at a number, the human reflex is to look at the left-most part, because those are the most significant figures. The right-most part, ordinarily, refers to precision that you don't usually need. For example, typing N(sqrt(2)) yields 1.41421356237310. Honestly, the 237310 at the end is a level of precision not really required by most applications.

  • In stark contrast to this, the numbers 6.02e23 and 6.02e-23 are very, very different numbers. It is important to understand that while 6.02 and 6 are "almost the same number" in a certain sense, 6.02e23 and 6.02 are not "almost the same number" at all. It is crucial to understand that 6.02e23 and 6.02e-23 are not "almost the same thing."

  • You might imagine that very few people might make the mistake which I describe in the previous bullet, but that's not true in practice. The next entry is a true story.

10$\frac{1}{2}$. The tale of the damaged identity matrix

Sometimes, when working with matrix algebra (linear algebra), we might want to perform a check on our computation. We might multiply back two inputs and expect to see an identity matrix.

If you don't know what "the identity matrix is," basically it is a square grid of numbers that has exactly the following pattern, but it can be of different sizes. (Here is a $3\times 3$ identity matrix, and a $4 \times 4$ identity matrix.) $$ I_3 = \left [ \begin{array}{ccc} 1 & 0 & 0 \ 0 & 1 & 0 \ 0 & 0 & 1 \end{array} \right ] \hspace{1in} I_4 = \left [ \begin{array}{cccc} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 1 & 0 \ 0 & 0 & 0 & 1 \end{array} \right ] $$

Once, in the third column of a $4\times 4$ identity matrix, we did not see the $0$s we were hoping for. We saw instead something analogous to 1.4572234780951267e-14. Did this mean our calculation was in error? I highlighted one of the values, and asked my class what it meant, when we didn't get the $0$s in the required spots.

Much to my horror, the class wasn't able to understand that $1.4572234780951267\times 10^{-14}$ is very near to zero. That's especially true because our original problem had numbers that were between 3 and 107. This "error" is $10^{-15}$ times as much as the original inputs. A good analogy is if you are trying to guess the salary of a computer programmer (roughly $10^5$ dollars), and your guess is off by ten billionths of a penny. Normally, you'd consider such a guess to be very correct.

11. Using currency signs inside of equations

While Sage is an excellent tool for financial mathematics, be certain that you put no dollar signs in front of the numbers. Likewise, you should not put the Euro symbol after any numbers. You should not use any other currency symbols either.

Like any programming language, Sage uses those symbols to perform various tasks.

For example, to find the monthly payment on a 30-year mortgage for a $ 450,000 house with 10% down, and 4% compounded monthly, you should type

find_root( 450000*0.9 == x*(1 - (1 + 0.04/12)^-(12*30))/(0.04/12), 0, 1000000) 

which correctly computes the answer: $ 1933.53... is the monthly payment.

You may not put a dollar sign in front of the 450000, nor in front of the 1000000.

Also, note that I did not include the comma inside of 450000 when indicating $ 450,000. (See also the entry "5: Commas in the middle of large numbers" of this list, above.)

For those who have not studied mathematical finance, note that the above code solves the equation $$ 450000(0.9) = x \frac{1 - \left (1+\frac{0.04}{12} \right)^{-(30)(12)}}{\frac{0.04}{12}} $$ for $x$ where $ 0 < x < 1,000,000 $. This is a general case of the formula for the present value of a decreasing annuity, $$ PV = c\frac{1 - (1+r/m)^{-mt}}{r/m} $$

12. Mistakes involving the percent sign

The percent sign has a special meaning in Python, and therefore in Sage. It cannot be used to indicate a numerical percentage. When you wish to use a number like 5% or 7%, you must type 0.05 or 0.07.

For example, if asked "How much should I invest today, at 7% compounded annually, to have $ 25,000 available to me, 10 years from now?", you must not type

find_root( 25000 == x*(1 + 7%)^10, 0, 1000000 )

because that use of the percent sign is illegal. You should type instead,

find_root( 25000 == x*(1 + 0.07)^10, 0, 1000000 )

which gives the correct answer of $ 12,708.73...

An extremely common error, seen frequently, is to use 7 in place of 0.07. The code

find_root( 25000 == x*(1 + 7)^10, 0, 1000000 )

gives the answer 2.3283064365386963e-05 dollars, which is less than 1/429th of a penny. This answer is completely absurd, but answers like this frequently appear on the quizzes and tests of business administration students.

If you're curious, the % sign in Python is used to look up entries in a data structure that Python calls "a dictionary," and for some advanced print statements that carefully control the output formatting.

13. Placing line-breaks where they aren't permitted

There are times when Python and Sage simply insist that certain spots not contain a line break.

If you are typing code from some printed page, given by an instructor, a collaborator, or from the book Sage for Undergraduates, you might run into another inconsistency. Namely, the width of this printed page, in characters, is vastly smaller than a SageMathCell cell or the screen of CoCalc. Therefore, there are times when one must break the line in print (to make the code fit on the page) but it might not always make sense to do so on the screen.

Here is an example. The following code

y = find_root( x^x == 7, 1, 4 )

print("After searching numerically, for a real number x inside the interval 1 < x < 4, Sage has determined that the solution to x^x=7 is given by ", y)

is legal if typed on two lines: a line beginning with y = find_root(, a blank line, and a line beginning with print("After. However, if you break up that large quote among two or more different lines, then Sage will respond with an error message. Nonetheless, on a printed page, it might be entirely necessary to break up that line, so that the code can fit on the line.

One compromise is to type instead

y = find_root( x^x == 7, 1, 4 )

print "After searching numerically, for",
print "a real number x inside the",
print "interval 1 < x < 4, Sage has",
print "determined that the solution",
print "to x^x=7 is given by ", y

which is equally readable both on screen and in print.

My only word of advice is to experiment, and to be patient as you try various possibilities.

14. Using indentation that Python does not understand

In many of the common programming languages, such as Java, C, C++, Pascal, and so forth, the indentation does not matter at all. While there are style guides, and some instructors enforce those, the compiler isn't interested in your indentation. However, in Python, the exact opposite is true. The indentation is very important, and it affects how the computer views your code. This can flummox experienced and semi-experienced programmers who come to Python, having learned other languages before.

Consider the following bit of python code, and note the careful indentation.

def newton_method(f, x_old, max_iterate = 10, verbose=False):

    """An implementation of Newton’s Method, to find a
    root of f(x) given an initial guess for x. A default of 10
    iterations will be carried out unless the optional
    parameter max_iterate is set to something else. Set
    verbose = True to see all the intermediate stages."""

    f_prime(x) = diff( f, x )
    for j in range(0, max_iterate):
        ratio = f(x_old) / f_prime(x_old)  
        x_new = x_old - ratio    
        if (verbose is True):    
                 print "iteration=", j
                 print "x_old=", x_old
                 print "f(x)=", f(x_old)
                 print "f’(x)=", f_prime(x_old)
                 print "ratio=", ratio
                 print "x_new=", x_new
                 print()
        x_old = N(x_new)
    return x_old

By the way, the above code was taken from Sage for Undergraduates, a book written by Gregory V. Bard and published by The American Mathematical Society in 2015. The pdf-file of that book is available for free, and the print version has an extremely low price. The code above was Figure 6 in Section 5.4.1 (page 250 of the print version).

Here's how the indentation of the code informs Python of the relationships between the commands.

  • The print statements are subordinate to the if statement, which is subordinate to the for statement, which is subordinate to the def statement. Therefore, they are indented three times.

  • The if statement, and the setting of the variables ratio, x_new, and x_old with the = sign, are subordinate to the for statement and the def statement, but not the if statement. The programmer must be careful with the indentation to avoid screwing up that relationship.

  • The "docstring" (i.e. the very large comment set off in quotes), the setting of the function f_prime(x) with the = sign, the for statement, and the return statement, are only subordinate to the def statement. Therefore, they are indented once.

  • All the commands above, except the def statement itself, are subordinate to the def statement but possibly to other statements too. That's why the def statement is the only command that is indented zero times.

  • In summary, the indentation shows which commands are subordinate to which other commands. The indentation is absolutely important. It is not a minor detail.

You might find reading all of "Ch 5: Programming in Sage and Python" of the book Sage for Undergraduates to be a useful introduction to Python. That book was written by Gregory V. Bard and published by The American Mathematical Society in 2015. (The pdf-file of that book is available for free, and the print version has an extremely low price.)

15. Missing a colon in Python commands that have subordinate commands

Look at the large block of code in the previous item. Do you see how the def command, the for command, and the if command each have a set of commands subordinate to them?

Whenever a command (such as def, for, or if, but also else) has commands subordinate to it, there must be a colon (:) at the end of that line. This colon isn't optional, and it helps Python understand the syntax. While the colon makes the code more human readable, I find that sometimes programmers often forget it.

16. Using braces and brackets as higher-order parentheses

A common question in a "college algebra" class might be to expand something like $$ -1 + 2x\left (5 - x\left (3 + x\left (2 - x\left (3 + x \right )\right )\right )\right ) $$ to get the answer $$ 2x^5 + 6x^4 - 4x^3 - 6x^2 + 10x - 1 $$

However, older textbooks will write $$ -1 + 2x\left (5 - x\left {3 + x\left [ 2 - x\left (3 + x \right )\right ]\right }\right ) $$ instead of the original, using brackets and braces as higher-order parentheses. It's been a long time since such usage was common, but often home-schooled students will learn from their parents' high school algebra textbooks.

In any case, brackets have a specific meaning in Python and therefore, Sage. Brackets indicate lists, and should never be used as higher-order parentheses. Likewise, braces should never be used as higher-ordered parentheses. (If you are curious, braces in Python are used to program a data structure that maps one value to another, which Python calls "a dictionary.")

The correct way to code $$ -1 + 2x\left (5 - x\left (3 + x\left (2 - x\left (3 + x \right )\right )\right )\right ) $$ is with

-1 + 2*x*(5 - x*(3 + x*(2 - x*(3 + x ))))

and for completeness, the correct way to code $$ 2x^5 + 6x^4 - 4x^3 - 6x^2 + 10x - 1 $$ is with

2*x^5 + 6*x^4 - 4*x^3 - 6*x^2 + 10*x - 1

Didn't find what you needed?

Remember: if you don't find what you need, or if you'd like to ask a question, then please email [email protected] at any time. We'd love to hear from you! Please include a link (the URL address in your browser) to any relevant project or document, as part of your email.

Analytics

Clone this wiki locally