getify / Functional-Light-JS

Pragmatic, balanced FP in JavaScript. @FLJSBook on twitter.
http://FLJSBook.com
Other
16.6k stars 1.95k forks source link

Chapter 2 equation - f(x) = 2x^2 + 3 #26

Closed yodiyo closed 7 years ago

yodiyo commented 7 years ago

Yes, I promise I've read the Contributions Guidelines.

I found this equation confusing, so I wonder if it needs an explanation. I'm actually not familiar with the symbol ^ - I've looked it up and it seems to be exponent, which I take as "to the power of". Yet, when I try it in the console (so based on JavaScript), it seems to act like a plus. So for 8^2 , I'd expect 64, but in the console, the answer is 10.

Anyway, the point is you've used an equation early on that's already flummoxed me and stopped me continuing, which is ironical given what the book is trying to do.

NB I don't have a strong programming background, but I did have a fairly strong mathematical education - although that was over 20 years ago and largely forgotten!

parro-it commented 7 years ago

@yodiyo, I don't think it intend f(x) = 2x^2 + 3 to be interpreted as a javascript expression, but as a mathematical equation. ^ in javascript is the Bitwise XOR operator, it's not the exponent operator (there will be a ** operator for that in future js releases)

getify commented 7 years ago

The equation in question is pretty explicitly talked about in the surrounding text as a mathematical equation, not a JS function. Moreover, this isn't even valid JS to say f(x) =, nor is 2x. Both those are broken syntax from a JS perspective, before you even get to the ^2 part.

I could use an image to show it more like handwritten math notation, but I thought it was pretty well known that x^2 is the text form of the x-squared. Sorry for the confusion. Not really sure how to practically fix it though.

agebhar1 commented 7 years ago

@getify ... maybe write f(x) = 2*x*x + 3?

getify commented 7 years ago

@agebhar1 I understand that fixes the 2x and x^2 parts to be something that would work in JS, but the f(x) = .. part is still entirely invalid.

agebhar1 commented 7 years ago

You've lost me there.

getify commented 7 years ago

This question is about the reader assuming that f(x) = 2x^2 + 3 is supposed to be valid JS, and then being frustrated that it's in fact not valid JS. If you change it to f(x) = 2*x*x + 3, you still have invalid JS. There is absolutely no way to define a function in JS with f(x) = ... So I don't see how any of the proposed changes here would actually address the OP concern.

yodiyo commented 7 years ago

I wasn't actually expecting JS, just using the console to calculate the equation (obviously wrongly).

I just thought you might want to know that I wasn't familiar with x^2

I actually searched for "math notation ^" and this led me to http://www.rapidtables.com/math/symbols/Basic_Math_Symbols.htm

And it has a^b caret exponent 2 ^ 3 = 8

As I said, I have little programming experience, so it was a little lost on me, but maybe I'm not your intended audience.

bmacdonald-editor commented 7 years ago

From a typesetting perspective, using superscript tags would probably work best. So the following: f(x) = 2<sup>3</sup> Appears as: f(x) = 23 You'll need to style it as plain text, not code, which I think is for the best, since the code font seems to convey the idea that it's runnable JS.

agebhar1 commented 7 years ago

@getify I have got it! Typesetting formulas would great by LaTeX but after quick search did not find a service which renders URL encoded LaTeX to image :disappointed:

agebhar1 commented 7 years ago

... find one

yurrriq commented 7 years ago

I'm not sure how exactly it'd be of use here, but MathJax is great. On macOS, LaTeXiT is handy too.

agebhar1 commented 7 years ago

MathJax is awesome, but is there a way to get it work with restricted (Github flavored) Markdown?

yurrriq commented 7 years ago

I don't think so. :disappointed:

nick-walt commented 7 years ago

I would recommend typesetting it like an example in a math textbook, similar to what Andreas (@agebhar1) posted above. Everyone has, at some point, seen math equations in a text book and will on some level recognise it.

Also, given the context of this book I honestly can't see experienced programmers getting math equations confused with JS for much longer than a nanosecond. Am I on the right track in my thinking?

agebhar1 commented 7 years ago

Unfortunately GF Mardown is very restricted in typesetting math. I found this issue "Rendering math equations?" so MathJax isn't a option.

I tried SVG with GF Markdown which does also not worked due to security reasons. Then I found a "hack" which incorporates GitHub pages ... was too lazy to give it a try.

The last option I had i mind was using PNG. The result looks ugly IMHO. GitHub flavored Markdown strip the style attribute from <img> ... with a style style="position: relative; top: 6px;" it will look better but it's also not scalable. A screenshot with applied CSS

TL;DR I come along with @nick-walt

Also, given the context of this book I honestly can't see experienced programmers getting math equations confused with JS for much longer than a nanosecond.

@getify How would the (final) PDF be rendered?

yurrriq commented 7 years ago

You can set the DPI higher when calling latex to generate a better-looking PNG. I've had success in the past with generating giant PNGs and then scaling them down with GraphicsMagick.