compute-engine icon indicating copy to clipboard operation
compute-engine copied to clipboard

Implement logarithms with bases other than E [FEATURE]

Open andrew-murdza opened this issue 1 year ago • 2 comments

\log_c should be interpreted as a log with base c

Relevant simplification rules

Undefined

  • {match:\log_c(a),replace:NaN,condition:c==1}
  • {match:\log_c(a),replace:NaN,condition:c\le 0}
  • \log_c(0)->NaN

Simple

  • \log_c(1)->0
  • \log_c(c)->1,
  • \log_c(c^a)->a

Log Properties

  • \log_c(ab)->\log_c(a)+\log_c(b)
  • \log_c(\frac{a}{b})->\log_c(a)-\log_c(b)
  • \log_c(\frac{1}{b})=-\log_c(b)
  • \log_c(c^ab)->a+\log_c(b)
  • \log_c(\frac{c^a}{b})->a-\log_c(b)
  • \log_c(\frac{b}{c^a})->\log_c(b)-a
  • \log_c(b^a)->a\log_c(b)

Change of Base

  • \log_c(b)\ln(c)->\ln(b)
  • \frac{\log_c(b)}{\log_d(b)}->\frac{\ln(d)}{\ln(c)}
  • \log_{1/c}(b)->-\log_c(b)

Base of C

  • c^{\log_c(a)}->a
  • c^{b\log_c(a)}->a^b
  • c^{\log_c(a)+b}->a\cdot c^b
  • c^{\log_c(a)-b}->\frac{a}{c^b}
  • c^{d\log_c(a)+b}->a^d\cdot c^b
  • c^{\log_c(a)-b}->\frac{a^d}{c^b}
  • c^{-\log_c(a)-b}->\frac{1}{a^dc^b}
  • c^{-\log_c(a)+b}->\frac{b^c}{a^d}

Infinity

  • {match:\log_c(\infty),replace:\infty,condition:c>1}
  • {match:\log_c(\infty),replace:-\infty,condition:0<c<1}

andrew-murdza avatar Jul 05 '24 22:07 andrew-murdza

log of arbitrary base should already be handled through canonicalization.

Do those represent cases that don’t work even though they should or is it just a placeholder list of possible simplifications? Could you check which ones are actually necessary?

You could also submit a PR with corresponding test cases. The relevant file should be test/compute-engine/simplify.test.ts

arnog avatar Jul 07 '24 01:07 arnog

I just checked and the are actually recognized by MathJSON. I had assumed that log_2 was not implemented because none of the log simplification rules worked for it. I will work on that. I will make the PR once the custom simplification rules can be implemented (it is a different bug)

andrew-murdza avatar Jul 07 '24 08:07 andrew-murdza