Variable names start with a letter or underscore and can contain letters, digits, underscores, and apostrophes.
x
_list
point_3
quadratic_equation
f''
An assignment sets a variable's value. It consists of a variable name, the := operator, and then the value. For example: h := 0.
Using just an equal sign will also work (like h = 0), but it's not preferred, since it can be confusing.
For example:
42
-72.40
Strings are little bits of text between double quotes. For example:
"Hello, world!"
"Adding a positive number moves you to the right on the number line."
To include a double quote in a string, use two double quotes:
"She said ""Hi!"" to Bob"
She said "Hi!" to Bob
The simplest way to create a list is to use square brackets: [1, 2, 3].
Lists can contain any expression, including other lists: [1, "two", sin(3), [4, 5]].
Derivita lists keep track of their opening and closing delimiters, so that you can use them to represent different mathematical ideas, such as points, sets, and vectors.
A list made with just brackets will have no delimiters, so [1, 2, 3] is equivalent to a student entering 1, 2, 3 and will be displayed as: 1, 2, 3
To create a list with delimiters you use the list keyword, along with any of the supported delimiters:
list<1, 2>
list{1, 2}
list[1, 2]
list(1, 2)
list(1, 2]
list[1, 2)
To create a matrix, use a list of lists, where all inner lists have the same length and each has the same delimiters as the outer list:
matrix_without_delimiters := [
[1, 2, 3],
[4, 5, 6]
]
matrix_in_square_brackets := list[
list[x, x^2],
list[y, y^2],
list[z, z^2]
]
You can build up expressions by using functions and operators on values, variables, and other expressions.
Some are mathematical:
2 + 3
sin(pi/2)
And others are just for the code:
item_count(my_list)
is_equivalent(correct_answer, student_input)
You can use these operators:
Unary operators: + - (positive and negative)
Arithmetic operators: + - * / ^
Comparison operators:
There are also some operators that are for display only. They don't perform any calculations, but make it easier to display certain math expressions.
Plus or minus: +/-, renders as ±
Approximately equal: ~=, renders as ≈
Implicit multiplication is always supported: 2a is equivalent to 2*a and a b is equivalent to a*b
There are 5 precedence levels for the operators. The exponent operator acts first, followed by unary operators, multiplication, addition, and comparison:
Comments enable you to leave a note in the code about what you're doing. Comments start with # and end at the end of the line:
# A single line comment
x := 3 # an inline comment
You can also create a multi-line comment by wrapping the comment in quotation marks:
"
This is a
multi-line comment.
"
If statements determine which of two branches to execute by testing whether the expression given after if is true or false. If the expression is truthy, the "if" branch is executed, otherwise, the "else" branch is executed (if present).
# If x is too big, put it back into the desired range. Otherwise, don't
# make any changes
if x > maximum {
x := maximum
}
You can test multiple conditions with else if:
if degree = 1 {
type = "linear"
} else if degree = 2 {
type = "quadratic"
} else {
type = "neither linear nor quadratic"
}
Use the special function math_funcs to declare names which should be treated as function names instead of variable names. This applies to any code after the math_funcs() statement, and also to any student input.
See the Custom Math Functions page for more information.
Start the code with the line import "geometry" to import several functions that aren't otherwise available. Other modules may be available to import in the future.
See the Geometry Notation page for more information.
At the top of each question's code, include a multiline comment that includes info about the course, assignment, and question author. When you change a question, leave a note about what you changed, along with your name and the date.
Derivita - Calculus I
Section 3.4 - The Chain Rule
Question 3
Coded by Devlin Daley on January 10, 2018
Changed by Andrew Baker on September 6, 2020:
-Started accepting answers found with intermediate rounding
-Added more detail to the solution for part b
Choose a date format that unambiguous, like 2019-07-04, or July 4, 2019, rather than 7/4/19 or 4/7/19.
Follow along with our video tutorials, if you haven't yet.
Browse the function reference to see more things you can do, or use the menu on the left to view advanced topics.