Skip to content

Commit

Permalink
More doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhowes committed Jul 15, 2023
1 parent 8bfdf68 commit 6b7040f
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 168 deletions.
10 changes: 8 additions & 2 deletions Sources/MathParser/Documentation.docc/CustomSymbols.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Custom Symbols

The ``MathParser`` package tries to offer a great out-of-the-box experience without any configuration. It also offers
a way to integrate your own functionality by way of providing custom variables and functions which the parser and
evaluator can then use to successfully resolve and evaluate your math expressions.

By default, ``MathParser`` provides two constants (`π` and `e`) and a large number of common functions by default for
all math expression parsing and evaluation:
all math expression parsing and evaluation.

The functions provided are those that are often used in math and programming:

- 1-argument functions: `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `log10`, `ln` (`loge`), `log2`, `exp`, `ceil`,
`floor`, `round`, `sqrt` (``), `cbrt` (cube root), `abs`, `sgn`
- 2-argument functions: `atan`, `hypot`, `pow` [^1]
- 2-argument functions: `atan`, `hypot`, `pow`

You can also provide additional definitions or redefine the defaults by providing your own mapping function for any or
all of the three collections (variables, 1-arg (unary) functions, and 2-arg (binary) functions).
Expand Down
11 changes: 7 additions & 4 deletions Sources/MathParser/Documentation.docc/ImpliedMultiplication.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Implied Multiplication

Math expression are often written without explicitly indicating when multiplication takes place, and instead rely on
convention. For instance, instead of writing `2 * (3 + 4)` one usually writes `2(3 + 4)`. Likewise, it is not uncommon
to see numeric values before a function or a common constant such as `π`, so instead of `3 * sin(0.5 * π)` we might
write `3sin(0.5π)` or perhaps `3 sin(0.5 π)` to make it a little easier to read.
convention.

Often instead of writing `2 * (3 + 4)` one usually writes `2(3 + 4)` with the understanding that `2` is being
multiplied to the value of `3 + 4`. Likewise, it is not uncommon to see numeric values before a function or a constant
such as `π`, so instead of `3 * sin(0.5 * π)` we might see `3sin(0.5π)` or perhaps `3 sin(0.5 π)` to make it a little
easier to read.

``MathParser`` supports parsing of math expressions where a multiplication symbol might not be present between two
terms. It is disabled by default, but the
``MathParser/init(variables:variableDict:unaryFunctions:unaryFunctionDict:binaryFunctions:binaryFunctionDict:enableImpliedMultiplication:)``
initializer allows it to be enabled via the `enableImpliedMultiplication` parameter.

## Notes
## Space Oddities

Be aware that with implied multiplication enabled, you could encounter strange parsing if you do not use spaces between
the "-" operator:
Expand Down
84 changes: 6 additions & 78 deletions docs/data/documentation/mathparser.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"doc://MathParser/documentation/MathParser/CustomSymbols": {
"abstract" : [
{
"text" : "By default, ",
"text" : "The ",
"type" : "text"
},
{
Expand All @@ -98,31 +98,23 @@
"type" : "reference"
},
{
"text" : " provides two constants (",
"text" : " package tries to offer a great out-of-the-box experience without any configuration. It also offers",
"type" : "text"
},
{
"code" : "π",
"type" : "codeVoice"
},
{
"text" : " and ",
"text" : " ",
"type" : "text"
},
{
"code" : "e",
"type" : "codeVoice"
},
{
"text" : ") and a large number of common functions by default for",
"text" : "a way to integrate your own functionality by way of providing custom variables and functions which the parser and",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "all math expression parsing and evaluation:",
"text" : "evaluator can then use to successfully resolve and evaluate your math expressions.",
"type" : "text"
}
],
Expand Down Expand Up @@ -192,71 +184,7 @@
"type" : "text"
},
{
"text" : "convention. For instance, instead of writing ",
"type" : "text"
},
{
"code" : "2 * (3 + 4)",
"type" : "codeVoice"
},
{
"text" : " one usually writes ",
"type" : "text"
},
{
"code" : "2(3 + 4)",
"type" : "codeVoice"
},
{
"text" : ". Likewise, it is not uncommon",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "to see numeric values before a function or a common constant such as ",
"type" : "text"
},
{
"code" : "π",
"type" : "codeVoice"
},
{
"text" : ", so instead of ",
"type" : "text"
},
{
"code" : "3 * sin(0.5 * π)",
"type" : "codeVoice"
},
{
"text" : " we might",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "write ",
"type" : "text"
},
{
"code" : "3sin(0.5π)",
"type" : "codeVoice"
},
{
"text" : " or perhaps ",
"type" : "text"
},
{
"code" : "3 sin(0.5 π)",
"type" : "codeVoice"
},
{
"text" : " to make it a little easier to read.",
"text" : "convention.",
"type" : "text"
}
],
Expand Down
73 changes: 56 additions & 17 deletions docs/data/documentation/mathparser/customsymbols.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"abstract" : [
{
"text" : "By default, ",
"text" : "The ",
"type" : "text"
},
{
Expand All @@ -10,31 +10,23 @@
"type" : "reference"
},
{
"text" : " provides two constants (",
"text" : " package tries to offer a great out-of-the-box experience without any configuration. It also offers",
"type" : "text"
},
{
"code" : "π",
"type" : "codeVoice"
},
{
"text" : " and ",
"text" : " ",
"type" : "text"
},
{
"code" : "e",
"type" : "codeVoice"
},
{
"text" : ") and a large number of common functions by default for",
"text" : "a way to integrate your own functionality by way of providing custom variables and functions which the parser and",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "all math expression parsing and evaluation:",
"text" : "evaluator can then use to successfully resolve and evaluate your math expressions.",
"type" : "text"
}
],
Expand Down Expand Up @@ -69,6 +61,57 @@
"text" : "Overview",
"type" : "heading"
},
{
"inlineContent" : [
{
"text" : "By default, ",
"type" : "text"
},
{
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser",
"isActive" : true,
"type" : "reference"
},
{
"text" : " provides two constants (",
"type" : "text"
},
{
"code" : "π",
"type" : "codeVoice"
},
{
"text" : " and ",
"type" : "text"
},
{
"code" : "e",
"type" : "codeVoice"
},
{
"text" : ") and a large number of common functions by default for",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "all math expression parsing and evaluation.",
"type" : "text"
}
],
"type" : "paragraph"
},
{
"inlineContent" : [
{
"text" : "The functions provided are those that are often used in math and programming:",
"type" : "text"
}
],
"type" : "paragraph"
},
{
"items" : [
{
Expand Down Expand Up @@ -263,10 +306,6 @@
{
"code" : "pow",
"type" : "codeVoice"
},
{
"text" : " [^1]",
"type" : "text"
}
],
"type" : "paragraph"
Expand Down
Loading

0 comments on commit 6b7040f

Please sign in to comment.