bradhowes/swift-math-parser
Math expression parser built with Point•Free's swift-parsing package
Symbol Splitting
When implied multiplication mode is active and the name of a variable or a 1-parameter (unary) function is not found in their corresponding map, the token evaluation routine will attempt to resolve them by splitting the names into two or more pieces that all resolve to known variables and/or functions. For example, using the default variable map and unary function map from MathParser:
pie=>pi * eesin(2π)=>e sin(2 pi)eeesgn(-1)=>e e e * -1
As you can see, this could lead to erroneous resolution of variable names and functions, but this behavior is only used when the initial lookup of the name fails, and it is never performed when the symbol names are separated by a space. However, if you make a mistake and forget to provide the definition of a custom variable or function, it could provide a value instead of an error. For instance, consider evaluating tabs(-3) where t is a custom variable set to 1.2 and tabs is a custom function but it is not provided for in the custom unary function map:
tabs(-3)=>1.2 * abs(-3)=>3.6
If implied multiplication had not been active, the evaluator would have correctly reported an issue -- either returning NaN or a Result.failure describing the missing function.
[^1]: Redundant since there is already the ^ operator. [^2]: Exact up to 20! -- larger numbers are approximations
[ci]: https://github.com/bradhowes/swift-math-parser/actions/workflows/CI.yml [status]: https://github.com/bradhowes/swift-math-parser/actions/workflows/CI.yml/badge.svg [cov]: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/bradhowes/ad941184ed256708952a2057fc5d7bb4/raw/swift-math-parser-coverage.json [spiv]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbradhowes%2Fswift-math-parser%2Fbadge%3Ftype%3Dswift-versions [spi]: https://swiftpackageindex.com/bradhowes/swift-math-parser [spip]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbradhowes%2Fswift-math-parser%2Fbadge%3Ftype%3Dplatforms [mit]: https://img.shields.io/badge/License-MIT-A31F34.svg [license]: https://opensource.org/licenses/MIT
Package Metadata
Repository: bradhowes/swift-math-parser
Homepage: https://swiftpackageindex.com/bradhowes/swift-math-parser/main/documentation/mathparser
Stars: 71
Forks: 7
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: math, parser, parser-combinators, pointfree, swift, wolfram-alpha
README: README.md