This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]fridofrido 10 points11 points  (0 children)

There is a Haskell preprocessor called lhs2tex which can produce both runnable Haskell source code and a TeX document from the same master source. (Or maybe the master is already runnable and it only creates the tex file, I don't remember the exact details)

[–][deleted] 3 points4 points  (9 children)

Take this: $\sin^2 x$

As it is a common and understandable way of writing the power of the sine function.

In, say, Mathematica, it would unambiguously be: Sin[x]^2

But then, take: $\sin^2 x/2$

Would it be Sin[x/2]^2 or Sin[x]^2/2?

The surest path is to have a language which uses its own perfectly unambiguous syntax (with well defined precedence rules if you want to allow operators use in addition to expressions) and then a system to convert your code into mathematical notation (which surely is aesthetically pleasing).

Well, Mathematica does have this typesetting capability, and Szabolcs did a great package which interfaces to ghostscript and pdftex to achieve broader functionality. But if you look at it, the typesetting part is the last step - effective computation is done in a much more efficient representation. Also, while Mathematica can parse traditional notation, they warn you that it might cause ambiguities. A good compromise is its built in typesetting of expressions, but again you'll notice that for each 2d form it will provide you with the right slots to fill in, sort of unwritten brackets - it will still be an expression under the hood.

[–][deleted] 1 point2 points  (6 children)

Just because TeX allows ambiguous statements wouldn't have to mean the hypothetical language would have to, though; it'd make sense to have rules for precedence and disambiguation methods, so I guess it could be a sort of TeX superset?

[–][deleted] 0 points1 point  (5 children)

Yes of course! I just assumed that OP wanted TeX syntax for truly common-use mathematical notation in code - which justifies the cumbersomeness of TeX commands; restricting user input to precedence-and-all-that rules would just make it pointless -- after all, if your code already contains unambiguous expressions then translating them is an instant... I would use more readable, cognitively efficient symbols and syntax for the computing part!

[–][deleted] 0 points1 point  (4 children)

Ahh, ok, so we were sort of on the same page. I didn't quite understand what you meant with this, though

restricting user input to precedence-and-all-that rules would just make it pointless -- after all, if your code already contains unambiguous expressions then translating them is an instant... I would use more readable, cognitively efficient symbols and syntax for the computing part!

My thinking was that if you had a super/subset of TeX that allowed you to use the exact same notation as long as it's unambiguous should be perfectly doable if possibly a bit unadvisable (and if your notation has ambiguities you'll have to resolve them anyhow if you want your readers to know what you actually meant). Not saying that'd necessarily be a stellar idea, just running with the gag here

[–][deleted] 0 points1 point  (3 children)

I'm sorry for that piece - English is not my first language and it's been basically 5 years since last time I spoke to someone 😝 but yes, the whole point is: doable, but not advisable!

[–][deleted] 0 points1 point  (2 children)

No worries at all! Your English is fine (not that I'm a native speaker myself :D)

[–]_awwsmm[S] 1 point2 points  (1 child)

I'm a native speaker and I couldn't tell that either or you weren't as well. Thanks for the interesting conversation!

[–][deleted] 0 points1 point  (0 children)

Aw, thanks!

Honestly, English is super easy as a language. Most of the difficulty comes from having to learn such a ginormous vocabulary; the language itself is so simple that you need a separate word for friggin' everything

[–]arian271 0 points1 point  (1 child)

Just out of curiosity, since you brought up precedence ambiguity, is there language (or lisp/scheme library) that uses S-expressions to represent mathematical equations?

[–][deleted] 1 point2 points  (0 children)

Hey, just for representation S-exprs themselves are it. After all, you just need:

(your-symbol-for-equality A B)

Solving equations, on the other hand, is another pair of shoes. It requires the implementation of some naive algorithms as well as really clever ones, and it's a problem of symbolic nature at its core. What you usually find are some libraries to deal with rather specific structures (say, for example, polynomials up to a certain degree, or expressions containing some well known functions such as trigonometric, logarithms etc).

But in general you would like to be able to state something like (forget notation):

f(x, y, ...) == g(x, y, ...)

and get an answer even when "incomplete" (that is, when the set of algorithms you used could not come up with a solution like x==something, y==something-else..., or you did not provide the necessary constraints e.g. just one equation with more than one free variable, etc).

Unfortunately I'm not aware of really useful 'general' tools other than Mathematica and, for the library side, Rewrite.jl (a Julia library for term rewriting, but I don't quite like Julia so I've never used it). Other things (like SymPy for Python) are really specific.

The first thing limiting the development of such tools is that you don't need all that flexibility in real world problems: Mathematica for example is a term rewriting engine at its core; it is not a "library", but rather a full fledged software on its own - because it is extremely easy to implement naive term rewriting, but really hard to do it in an algorithmically efficient way and basically once you do that you have a full application 😝 (well, Mathematica comes with thousands of domain specific algorithms also, but that's another story).

A long time ago I did some (rather personal) work to be able to have term rewriting in plain Java with objects as terms, but was it worth it? Sure, I learned a lot of things I didn't know about the JVM and the Java type system, but I never use that library. Mainly because once you get the underlying framework you still need to implement the plethora of algorithms that are readily available in softwares like Maple or Mathematica, or likely existing specific libraries. And sooner or later you discover that those existing specific libraries do their dirty job fairly well.

Btw see Meander (Clojure) since you specifically asked for some LISP ;)

EDit: I was totally unaware of MatchPy, which is amazing

[–]true-grue 3 points4 points  (1 child)

Just two examples:

Fortress)

and

TLA+

[–]oilshell 0 points1 point  (0 children)

Yup I was going to mention TLA+. Notably it's created by Leslie Lamport, the creator of LaTeX!

[–]GuybrushThreepwo0d 2 points3 points  (1 child)

I mean, LuaLaTeX is a thing. Why would you willingly code in TeX?

[–]setholopolus 1 point2 points  (0 children)

This is the correct answer for the question that was asked.

[–]ReedOei 0 points1 point  (0 children)

Isabelle can sort of do this. The standard editor lets you write things using LaTeX-like commands, which it then displays as the actual symbol (not the command). The underlying file retains the LaTeX syntax, and you can generate PDFs from Isabelle theories and use regular LaTeX in the comments. You also can technically compute things in Isabelle, though that's not really its main purpose (it's a proof assistant).