read_exponential: Parses the integer coefficient in an exponential term.

View source: R/domain.R

read_exponentialR Documentation

Parses the integer coefficient in an exponential term.

Description

Parses the integer coefficient in an exponential term.

Usage

read_exponential(s, has_index)

Arguments

s

A string that starts with one of the following forms: exp(x), exp(-x), exp(2x), exp(-2x), exp(12*x), exp(-123*x), followed by other terms. If has_index == TRUE, the first term should be rewritten in x with an index (e.g. exp(x1), exp(-2*x2)).

has_index

A logical, indicates whether the term is written in a component (e.g. x1, x2) as opposed to a uniform term (i.e. x).

Details

Parses the coefficient in the first exponential term and returns the rest of the terms.

Value

A list containing the following elements:

power_numer

An integer, the integer coefficient inside the first exponential term.

idx

An integer, the index of the term matched (e.g. 3 for exp(2*x3)). NULL if has_index == FALSE.

s

A string, the rest of the unparsed string.

If parsing is unsuccessful, NULL is returned.

Examples

# Unsuccessful parsing, not starting with exponential, returns \code{NULL}.
read_exponential("x", FALSE)
# Unsuccessful parsing, not starting with exponential, returns \code{NULL}.
read_exponential("x1^2+exp(2x2)", TRUE)
read_exponential("exp(x)", FALSE)
read_exponential("exp(x1)", TRUE)
read_exponential("exp(-x)", FALSE)
read_exponential("exp(-x1)+x2^2", TRUE)
read_exponential("exp(2x)", FALSE)
read_exponential("exp(2x1)+x2^(-2/3)", TRUE)
read_exponential("exp(-2x)", FALSE)
read_exponential("exp(-2x1)+exp(x3)", TRUE)
read_exponential("exp(12x)", FALSE)
read_exponential("exp(12x2)+x3^(-3)+x4^2", TRUE)
read_exponential("exp(-12x)", FALSE)
read_exponential("exp(-12x3)+x1^(2/5)+log(x2)", TRUE)
read_exponential("exp(123*x)", FALSE)
read_exponential("exp(123*x1)+x2^4", TRUE)
read_exponential("exp(-123*x)", FALSE)
read_exponential("exp(-123*x4)+exp(2*x3)", TRUE)

genscore documentation built on May 29, 2024, 9 a.m.