Referencedifferences

<differences>

Differences between successive child math or number values; one shorter than the input

<differences> is a Math Operator component that renders the differences between successive arguments: for inputs a1,a2,,ana_1, a_2, \ldots, a_n it gives a2a1,  a3a2,  ,  anan1a_2 - a_1,\; a_3 - a_2,\; \ldots,\; a_n - a_{n-1}.

The result is one shorter than the input, and is empty when the input has fewer than two values. <differences> undoes <cumulativeSum>, apart from the first value, which the running total has already absorbed.

Attributes and Properties

Attributes for <differences>

Highlighted (3)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

forceNumeric

boolean. Default value: false. Whether to force the operator to evaluate numerically rather than symbolically.

forceSymbolic

boolean. Default value: false. Whether to force the operator to evaluate symbolically rather than numerically.

Other (5)
avoidScientificNotation

Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

Number of decimal places to display when rendering this number.

displayDigits

Number of significant digits to display when rendering this number.

displaySmallAsZero

Threshold below which numbers are displayed as zero.

padZeros

Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <differences name="d">

Highlighted (2)
$d.forceNumeric

boolean. Whether to force the operator to evaluate numerically rather than symbolically.

$d.forceSymbolic

boolean. Whether to force the operator to evaluate symbolically rather than numerically.

Common to all components (4)
$d.doenetML

text. The DoenetML source code that produced this component.

$d.hide

boolean. Whether to hide this component from the rendered output.

$d.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$d.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: successive differences

Four inputs give three differences.


Example: first differences of a sequence

The first differences of the squares are the odd numbers, and their differences are constant — the signature of a quadratic.


Example: inverting a cumulative sum

Taking differences recovers the original values, except for the first one, which the cumulative sum folded into its starting entry.