Skip to content

Implement more math commands (e.g. trig, ln)#7258

Merged
sholderbach merged 6 commits intonushell:mainfrom
sholderbach:math-trig
Dec 1, 2022
Merged

Implement more math commands (e.g. trig, ln)#7258
sholderbach merged 6 commits intonushell:mainfrom
sholderbach:math-trig

Conversation

@sholderbach
Copy link
Copy Markdown
Member

@sholderbach sholderbach commented Nov 27, 2022

Description

Work towards #7073

  • Add math pi and math e constants
  • Add basic trigonometric functions
    • math sin
    • math cos
    • math tan
  • Add basic hyperbolic functions
    • math sinh
    • math cosh
    • math tanh
  • Add inverse for trigonometric functions
    • math arcsin
    • math arccos
    • math arctan
  • Add inverse hyperbolic functions
    • math arcsinh
    • math arccosh
    • math arctanh
  • Add natural logarithm
    • math ln

Tests + Formatting

  • Examples for each new command
  • Expand example test harness with math pi, math e, and math round

@sholderbach sholderbach marked this pull request as ready for review November 27, 2022 20:19
@sholderbach sholderbach changed the title [WIP] Implement more math commands (e.g. trig) Implement more math commands (e.g. trig, ln) Nov 27, 2022
sholderbach added a commit to sholderbach/nushell that referenced this pull request Nov 29, 2022
- [ ] Requires sign off from the team

Reasoning:

Most missing math commands are implemented with nushell#7258.
The `meval` crate itself declares that it doesn't strive to stringent
standards (https://docs.rs/meval/latest/meval/#related-projects).
For example no particular special casing or transformations are
performed to ensure numerical stability. It uses the same rust `std`
library functions we use or have access to (and `f64`).
While the command call syntax in nushell may be a bit more verbose,
having a single source of truth and common commands is beneficial.
Furthermore the `math` commands can themselves implement broadcasting
over lists (or table columns).

Closes nushell#7073

Removed dependencies:
- `meval`
- `nom 1.2.4` (duplicate)
@sholderbach sholderbach mentioned this pull request Nov 29, 2022
2 tasks
sholderbach added a commit to sholderbach/nushell that referenced this pull request Nov 29, 2022
- [ ] Requires sign off from the team

Reasoning:

Most missing math commands are implemented with nushell#7258.
The `meval` crate itself declares that it doesn't strive to stringent
standards (https://docs.rs/meval/latest/meval/#related-projects).
For example no particular special casing or transformations are
performed to ensure numerical stability. It uses the same rust `std`
library functions we use or have access to (and `f64`).
While the command call syntax in nushell may be a bit more verbose,
having a single source of truth and common commands is beneficial.
Furthermore the `math` commands can themselves implement broadcasting
over lists (or table columns).

Closes nushell#7073

Removed dependencies:
- `meval`
- `nom 1.2.4` (duplicate)
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Dec 1, 2022

Lots of repetitive code here, as is the way when adding a bunch of commands. I skimmed through these, mainly looking for copy-n-paste errors and such, and none jumped out at me. I think we should move ahead with landing these and your other math pr too, and then take a look at combining all this stuff in a math plugin. I think it's the only way we'll be able to do any meaningful perf testing to determine if moving to a plugin is the right thing to do.

@sholderbach
Copy link
Copy Markdown
Member Author

Thanks for going through all the boilerplate @fdncred!

Should I rebase the blocks of commands into their own commits so that removing them is easier if we decide to move them to a plugin?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Dec 1, 2022

Should I rebase the blocks of commands into their own commits so that removing them is easier if we decide to move them to a plugin?

That sounds like a pain. I probably wouldn't.

Currently implemented as commands

Work towards nushell#7073

Add them to the example test harness together with `math round`
`math sin`
`math cos`
`math tan`

Support degrees with the flag `--degrees`/`-d`
`math sinh`
`math cosh`
`math tanh`
- `math arcsin`
- `math arccos`
- `math arctan`

Again include `--degrees` or `-d` for convenient output in degrees
- `math arcsinh`
- `math arccosh`
- `math arctanh`
@sholderbach
Copy link
Copy Markdown
Member Author

Should I rebase the blocks of commands into their own commits so that removing them is easier if we decide to move them to a plugin?

That sounds like a pain. I probably wouldn't.

I was a masochist in this case.

@sholderbach sholderbach merged commit 1f175d4 into nushell:main Dec 1, 2022
sholderbach added a commit that referenced this pull request Dec 1, 2022
Currently implemented as commands

Work towards #7073

Add them to the example test harness together with `math round`
sholderbach added a commit that referenced this pull request Dec 1, 2022
`math sin`
`math cos`
`math tan`

Support degrees with the flag `--degrees`/`-d`
sholderbach added a commit that referenced this pull request Dec 1, 2022
`math sinh`
`math cosh`
`math tanh`
sholderbach added a commit that referenced this pull request Dec 1, 2022
- `math arcsin`
- `math arccos`
- `math arctan`

Again include `--degrees` or `-d` for convenient output in degrees
sholderbach added a commit that referenced this pull request Dec 1, 2022
- `math arcsinh`
- `math arccosh`
- `math arctanh`
@sholderbach sholderbach deleted the math-trig branch December 1, 2022 14:59
sholderbach added a commit that referenced this pull request Jan 4, 2023
Reasoning: 

Most missing math commands are implemented with #7258.
The `meval` crate itself declares that it doesn't strive to stringent
standards (https://docs.rs/meval/latest/meval/#related-projects).
For example no particular special casing or transformations are
performed to ensure numerical stability. It uses the same rust `std`
library functions we use or have access to (and `f64`).
While the command call syntax in nushell may be a bit more verbose,
having a single source of truth and common commands is beneficial.
Furthermore the `math` commands can themselves implement broadcasting
over lists (or table columns).

Closes #7073

Removed dependencies:
- `meval`
- `nom 1.2.4` (duplicate)

User-Facing Changes:

Scripts using `math eval` will break. 
We remove a further `eval` like behavior to get results through runtime evaluation (albeit limited in scope)

Tests:

- Updated tests that internally used `math eval`.
- Removed one test that primarily used `math eval` to obtain a result from `str join`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants