uiua-lang / uiua

A stack-based array programming language
https://www.uiua.org
MIT License
1.51k stars 106 forks source link

Incorrect inverse with swapped power and log #486

Closed mlochbaum closed 4 months ago

mlochbaum commented 4 months ago

Example: expressions -:8 °(-:8) 3 and ÷:8 °(÷:8) 3 return 3 but ⁿ:8 °(ⁿ:8) 3 and ₙ:8 °(ₙ:8) 3 don't. It seems °(ⁿ:8) 3 is computed as °(ⁿ3) 8 and similarly for log, but the inverses should be ₙ8 for ⁿ:8 and ⁿ:8÷:1 for ₙ:8.

(Found while checking if Uiua would do better than BQN on an inverse I had to back out, that is, Tr 440 with Tr ← ×⊙(ⁿ:2÷12). Not at the moment it seems.)

kaikalii commented 4 months ago

They should invert correctly now. Not sure if this makes your case work though.

mlochbaum commented 4 months ago

The math looks right. For Tr it doesn't know how to work with dip and a constant. So it works if the arithmetic for Tr 440 is written out but not with Tr 440 itself. Code link if you want to take a look. What it would need to do is exchange ⊙(ⁿ:2÷12) and 440. I guess if it sees arithmetic followed by dip it could try this?