Search code examples
numbersfractionsapl

NARS APL: Rational representation and numerator


In NARS, fractions are represented using r example 23r45 will be the fraction 23⁄45. The problem is, if I have a variable that contains a rational number, how do I access the numerator? Does a "numerator" function exist such that numerator 23r45 returns 23?


Solution

  • There is no built-in "numerator" function, but you can easily construct one:

          num←(⊣÷∨)∘1
          num 23r45
    23 
    

    For reference, the denominator can be found with:

          den←(⊢÷∨)∘1
          den 23r45
    45
    

    And so you can "split" a rational with:

          n_d←(,÷∨)∘1
          n_d 23r45
    23 45