Remove mention of exponentiation from instructions...

…since tests/example does not include an exponentiation function or tests for it.

I can instead PR a branch that adds the function signature, tests, and example implementation but I was a little scared off by:

  • the note about re-running all recent submissions when the test file changes, and
  • having trouble understanding how running the tests in the repo for those changes is supposed to work.

When I run ‘./test.clj’ per the README, it modifies all the exercises///src/*.clj files to contain the example solutions. That seems… surprising? How do I get back to clean working directory w/out running git reset --hard after each test run?

Sorry, it’s unclear what you’re trying to do (or proposing to do?). Are you looking at the Clojure track repo or the Clojure test-runner repo? Are you suggesting an edit to an existing concept or practice exercise? Something else?

Sorry, the forum post was made via the link from the auto-responder that closed this PR: Remove mention of exponentiation from instructions... by esnyder · Pull Request #680 · exercism/clojure · GitHub, and then my post was put in moderation, so I couldn’t add the link the the PR :)

Right, so I’m not a Clojure maintainer so moving forward would be up to them, and you can work with them on any further changes.

That said, the docs aren’t necessarily exhaustive, given the test suite is the authoritative guide on what’s expected for a passing solution As long as the docs don’t directly contradict the test suite, we’re probably fine and don’t need to update the docs.

However, if we do want to update what the docs are saying, updating .docs/instructions.md directly for a practice exercise like Complex Numbers isn’t ideal. That file comes from the upstream problem-specifications repo that 75+ Exercism tracks can pull canonical docs and tests for practice exercises. As a result, any track-specific alterations to instructions.md or introduction.md might be lost when a maintainer syncs the latest docs edits from that repo.

However, we can provide additional track-specific notes by adding an instructions.append.md file or the corresponding introduction.append.md. The content of those append files will be added to the end of the corresponding docs and shown to the student on the platform. Those append files won’t be affected by a maintainer syncing the upstream docs so that’d likely be the preferred solution if you and the maintainers go forward with editing docs.

1 Like

Ah, thanks, that wasn’t clear to me.

FWIW, right now, the test suite doesn’t test for everything the docs say should be implemented for the exercise. I’ll wait and see if a clojure maintainer weighs in on whether I should PR adding the test + example for the exponentiation fn I guess :slight_smile:

Thank you for the guidance.

I’m pretty sure the canonical tests include exponentiation tests. A better path forward might be to implement any tests from the canonical data that are missing, assuming they aren’t intentionally omitted for some reason.

1 Like

Right, I forgot to mention that those particular tests were recently marked as not included in the tests.toml. That does imply the tests were intentionally omitted as you suggested.

@esnyder The problem specs state that exponentiation is optional. Since the original authors decided not to include it for the Clojure track, our best option is to keep it as is.

However, we will add a clarification about it, most likely in an append file in the near future. I’ll create an issue on GitHub to help track similar issues across exercises.

Thanks for bringing this to our attention.

3 Likes

I feel like Prob Specs should potentially be changed to not have that in the description, and that tracks that do expect the exponentiation should include it in an append.

Do we have any sense of how many tracks do/don’t have this?

The expected implementation should look the same across most tracks. The formula is already provided in the description:

“Raising e to a complex exponent can be expressed as e^(a + i * b) = e^a * e^(i * b) , the last term of which is given by Euler’s formula e^(i * b) = cos(b) + i * sin(b) .”

So if the language provides sin, cos, and exp functions, their track will certainly ask for it.

Solve Rational Numbers on Exercism lists 23 tracks having implemented this exercise. I checked the test files for the other 22 tracks and they all expect exponentiation. Therefore, Clojure is the exception.

2 Likes

Is there a reason this is hard in clojure, or should we just standardise?

The problem specs state that exponentiation is optional

If only one track has made it optional, I sense we should just make it compulsary.

1 Like

It’s pretty straightforward in Clojure too:

(defn exp [e [a b]]
  (let [e-to-a (Math/exp e a)]
    [(* e-to-a (Math/cos b))
     (* e-to-a (Math/sin b))]))

It’s easy in Clojure, either using Java interop or the new functions that have been added over the past few years. But 7 years ago, things might have been different, and the original authors might have had a good reason to exclude it.

What about the tracks that haven’t implemented the exercise yet? Not all of them have sin, cos, or exp functions. According to the specs, using those functions is the recommended implementation. If a language doesn’t have them, the problem becomes much more difficult—people will have to start looking into more advanced math to solve it, and even then they might not be able to.

That’s why this concept is marked as optional—because, in general, it’s much more difficult than the other tasks the exercise asks to implement. It makes much more sense to completely remove it from the instructions than to make it compulsory.

Here’s the full text from the specs:

" Defining the exponential function can be optional. ",
" If the language used does not have sine and cosine ",
" functions in the standard library, this will be ",
" significantly more difficult than the rest of the exer- ",
" cise and should probably not be part of the problem. ",
" The recommended implementation uses Euler’s formula ",
" exp(ix) = cos(x) + i * sin(x). This is not an ideal sol- ",
" ution but works for the purpose of teaching complex ",
" numbers.

What does e stand for in the function arguments?

Hint: The function should have only one parameter.

Well I have egg on my face :) I misread thoughtlessly; should be

(defn exp "Calculates e^(a + ib)" [[a b]]
  [(* (Math/exp a) (Math/cos b))
   (* (Math/exp a) (Math/sin b))])