STACK DocumentationDocumentation home | Category index | Parent | Site map
Numbers in STACK
Numerical answer tests are documented in a page dedicated to numerical answer tests.
In Maxima the special constants are defined to be
%i, %e, %pi
etc. STACK also uses single letters, e.g.
e: %e pi: %pi
Optionally, depending on the question settings, you have
i: %i j: %i
Sometimes you need to use
kill() command, but for security reasons users of STACK are not permitted to use this function. Instead use
stack_reset_vars(true) in the question variables. This resets all the special constants defined by STACK so the symbols can be redefined in an individual STACK question.
Internal representation of numbers
Maxima has two data types to represent numbers: integers and floats. Rational numbers are expressed as a division of two integers not with a dedicated data type, and surds with fractional powers or the
The option Surd for Square Root enables the question author to alter the way surds are displayed in STACK.
Similarly, complex numbers are not represented as a single object, but as a sum of real and imaginary parts, or via the exponential function. The input and display of complex numbers is difficult, since differences exist between mathematics, physics and engineering about which symbols to use. The option sqrt(-1) is set in each question to sort out meaning and display.
Floating point numbers
- To convert to a float use Maxima's
- To convert a float to an exact representation use
rat(x)to rationalise the decimal.
e:exp(1). This now potentially conflicts with scientific notation
2e3 which means
If you expect students to use scientific notation for numbers, e.g.
3e4 (which means ), then you may want to use the option for strict syntax.
Maxima and floats with trailing zeros
For its internal representation, Maxima always truncates trailing zeros from a floating point number. For example, the Maxima expression
0.01000 will be converted internally to
0.01. Actually this is a byproduct of the process of converting a decimal input to an internal binary float, and back again. Similarly, when a number is a "float" datatype, Maxima always prints at least one decimal digit to indicate the number is a float. For example, the floating point representation of the number ten is . This does not indicate significant figures, rather it indicates data type. In situations where the number of significant figures is crucial this is problematic.
Display of numbers in STACK is controlled with LaTeX, and the underlying LISP provides flexible ways to represent numbers.
Note, that apart from the units input, all other input types truncate the display of unnecessary trailing zeros in floating point numbers, loosing information about significant figures. So, when the student's answer is a floating point number, trailing zeros will not be displayed. If you want to specifically test for significant figures, use the units input type, with the teacher's answer having no units. The units input type should display the same number of significant figures as typed in by the student.
Display of numbers with LaTeX
The display of numbers is controlled by Maxima's
texnumformat command, which STACK modifies.
Stack provides two variables to control the display of integers and floats respectively. The default values are
These two variables control the output format of integers (identified by the predicate
integerp) and floats (identified by the predicate
floatnump) respectively. These variables persist, so you need to define their values each time you expect them to change.
These variables must be assigned a string following Maxima's
These variables can be defined in the question variables, for global effect. They can also be defined inside a Maxima block to control the display on the fly, and for individual expressions. For example, consider the following CASText.
The decimal number @n:73@ is written in base \(2\) as @(stackintfmt:"~2r",n)@, in base \(7\) as @(stackintfmt:"~7r",n)@, in scientific notation as @(stackintfmt:"~e",n)@ and in rhetoric as @(stackintfmt:"~r",n)@.
The result should be "The decimal numberis written in base as , in base as , in scientific notation as and in rhetoric as ."
To force all floating point numbers to scientific notation use
To force all floating point numbers to decimal floating point numbers use
You can also force all integers to be displayed as floating point decimals or in scientific notation using
stackintfmt and the appropriate template. This function calls the LISP
format function, which is complex and more example are available online elsewhere.
||Output four decimal places: floating point.|
||Note the rounding.|
||Output five decimal places: scientific notation.|
||Separate decimal groups of three digits with commas.|
||Old style Roman numerals.|
There are many other options within the LISP format command. Please note with the rhetoric and Roman numerals that the numbers will be in LaTeX mathematics environments.
Maxima has a separate system for controlling the number of decimal digits used in calculations and when printing the value of computed results. Trailing zeros will not be printed with the value. This is controlled by Maxima's
fpprintprec variables. The default for STACK is
fpprec:20, /* Work with 20 digits. */ fpprintprec:12, /* Print only 12 digits. */
Notes about numerical rounding
There are two ways to round numbers ending in a digit.
- Always round up, so that , , etc.
- Another common system is to use ``Bankers' Rounding". Bankers Rounding is an algorithm for rounding quantities to integers, in which numbers which are equidistant from the two nearest integers are rounded to the nearest even integer. , , etc. The supposed advantage to bankers rounding is that in the limit it is unbiased, and so produces better results with some statistical processes that involve rounding.
round(ex) command rounds multiples of 1/2 to the nearest even integer, i.e. Maxima implements Bankers' Rounding.
STACK has defined the function
significantfigures(x,n) to conform to convention of rounding up.
STACK numerical functions and predicates
The following commands which are relevant to manipulation of numbers are defined by STACK.
||Truncateto significant figures (does perform rounding).|
||Truncateto decimal places (does perform rounding).|
||Returns the hcf of a list of numbers.|
||Create a list with all parts for which
||This function takes an expressionand returns a list of coefficients of .|
||This function takes an expressionand returns a list of nonzero coefficients of .|
||Iswithin of ? I.e.|
||Iswithin of ? I.e. .|
The following commands generate displayed forms of numbers. These will not be manipulated further automatically, so you will need to use these at the last moment, e.g. only when generating the teacher's answer etc.
||Truncateto decimal places and display with trailing digits. Note, this always prints as a float (or integer), and not in scientific notation.|
||Truncateto significant figures and display with trailing digits. Note, this always prints as a float, and not in scientific notation.|
in the form . Only works with |
||An intert internal function to record thatshould be displayed to decimal places with trailing digits. This function does no rounding.|
||Determines ifis a real number. This includes surds and symbolic numbers such as .|
||Is the rational expression in its lowest terms?|
||Decides if any floats are in the expression.|
Documentation home | Category index | Parent | Site map