Find/write functions in a language agnostic way? -


edit (complete rewrite): consider function takes 2 inputs , adds sine of first cosine of second (and assumes arguments in radians). here in few languages

 $f = sub {sin($_[0])+cos($_[1])}; # perl  f = sin[#1]+cos[#2] &; # mathematica  def f(x,y) sin(x)+cos(y) end; # ruby  

(minor note: i've written pure function in perl , mathematica, wasn't sure how ruby).

my question: surely has written language/format/convention take:

x,y:sin(x)+cos(y)

and convert of 3 forms above on request.

ideally, conversion backwards well, that's lot more difficult.

so, language/format/convention?

to emphasize, i'm referring simple functions here, not complicated procedures, , assuming target languages define basic functions sin(), cos(), atan(), etc.

i've looked @ mathml, tex, , mathtype, none of them seem quite designed this.

my goal create library of astronomy functions can use without having port them hand. example:

$\tan ^{-1}\left(\frac{\sin (\text{dec}) \sin (\text{lat})-\cos (\text{dec}) \cos (\text{lat}) \sin (\text{d1}+\text{lon}-\text{ra})}{\sqrt{(\cos (\text{dec}) \sin (\text{lat}) \sin (\text{d1}+\text{lon}-\text{ra})+\sin (\text{dec}) \cos (\text{lat}))^2+\cos ^2(\text{dec}) \cos ^2(\text{d1}+\text{lon}-\text{ra})}}\right)$

there's nothing inherently difficult computing function, but, using search/replace, ugly convert 1 language another.

due difference in semantics , syntax between various languages you've listed (especially language "etc"), can't write useful functions in general way allows them used unchanged in more 1 target language.

your best chance @ pick 1 language define functions in. we'll call source language. write transpilers translate source language each target language. source language 1 of own invention; have limited semantics can represented in each of supported target languages.

for use case present (simple functions), don't think you'll find has done this. it's great deal of work not great benefit, when compared translating functions hand each target language.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -