0
\$\begingroup\$

I proposed this code golf on sandbox:

Integer Logarithm

Take \$a \in ℤ_{>1}\$ and \$b \in ℤ_+\$ as inputs. Write a function \$f\$ that:

$$ f(a,b) = \left\{ \begin{array}{ll} \text{Just} \space \log_ab & \quad \text{if} \space \log_ab \in ℚ \\ \text{Nothing} & \quad \text{otherwise} \end{array} \right. $$

Rules

  • Types and formats of the inputs doesn't matter, but they must be able to represent at least 2 bits. For example, in C++, int, unsigned, std::vector<bool>, or even std::string containing ASCII digits are acceptable.

  • Type and format of the output doesn't matter either, but the fraction must be irreducible. In C++, std::optional<std::pair<int,unsigned>> is an example.

  • You must not use floating-point numbers because of their errors.

  • if \$a\$ and \$b\$ aren't in the sets as specified above, the challenge falls in don't care situation.

  • \$f\$ may be curried or uncurried.

  • As this is a code-golf, the shortest code in bytes wins.

But to think about it, I doubt that golfing languages natively support rational number arithmetic. Unlike this challenge, it actively requires arithmetics on rational numbers, in sake of, for example, Newton's method.

Do major golfing languages such as 05AB1E, Jelly, APL, and Charcoal natively support rational number arithmetic?

\$\endgroup\$
4
  • \$\begingroup\$ Can't this be done using just integer types? \$\endgroup\$
    – xnor
    Commented Feb 13, 2020 at 6:24
  • \$\begingroup\$ @xnor Do you mean you want \$\log_a{b} \in \mathbb{Z}\$? \$\endgroup\$ Commented Feb 13, 2020 at 6:25
  • 1
    \$\begingroup\$ No, I mean the solver can work with just integers by finding p,q so that a^q = b^p, and outputting p/q. Actually, even the ratio of their respective counts of prime factors in their factorizations should suffice. \$\endgroup\$
    – xnor
    Commented Feb 13, 2020 at 6:26
  • \$\begingroup\$ @xnor Aha! So it is possible with just integer types. Thanks. I will post it in few hours if there is no objections. \$\endgroup\$ Commented Feb 13, 2020 at 6:29

1 Answer 1

1
\$\begingroup\$

APL

… is not a golfing language.

That said, some APL implementations, like NARS2000, feature rational arithmetic. Others, like Dyalog APL, have a library that provides this functionality. Additionally, some APL derivatives, like J, do too.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .