Loren on the Art of MATLAB

April 1st, 2008

MATLAB Language Translator

Google recently made a splash about its e-api-tools-for.html latest language tools. Translating one computer language to another is useful but passé. But suppose you could translate a computer language to a human language: MATLAB -> English and English -> MATLAB. Type in your word problem and get the code instantly. It could help you with your MATLAB accent, or, if English is not your first natural language, you might learn some vernacular from MATLAB's interpretation.

Contents

Some Translations

In particular, such a translator might be good at recognizing and translating common phrases. Here are but a few of the phrases the translator (under development) gets right.

  • eye(newt), from Shakespeare's hags
  • ceil(approval), from Good Housekeeping
  • wait(theWorld)
  • angle(repose), an excellent book by Wallace Stegner
  • balance(power), axis(power), etc., assuming you've pre-empted the function with your own variable or function, of course
  • gallery(art)
  • length(day) (day has the same caveat as power above)
  • residue(ashes)
  • sign(theTimes)
  • sound(music), thanks to Julie Andrews, among others
  • theTotal = sum(theParts)

Notice how the parentheses are pronounced in English : "of".

Command Duality

The MATLAB translator understands command-function duality and the nuances of English. It would not do to write the last example as

  • wait theWorld

Nor would

  • polar bear

be okay because polar doesn't take a character array for its first argument.

However, it would be okay to say

  • global warming
  • median strip

What Are Your Translation Needs?

Sure, we will translate between MATLAB and other languages once we have the English version ready to go. And, I should warn you that Steve Eddins from the Steve on Image Processing blog has been working for years on mindread.m as well. Beyond these two obvious needs, what other translation needs do you have? Or other thoughts on this post? What about MATLAB poetry (Tim?)? Let me know here.


Get the MATLAB code

Published with MATLAB® 7.6

19 Responses to “MATLAB Language Translator”

  1. anon replied on :

    My favorite feature of this code translation is the

    analyze(data);
    groundBreakingMonograph.tex = write(paper);
    submit;

    Of course, after today passes, there is always http://pdos.csail.mit.edu/scigen/

  2. Dan K replied on :

    Very nice… But I keep waiting for matlab to do away with the pesky need to know the question. We need a lower level of effort. We need a function which can take the random fluctuations of the universe and give us the answer we want (kind of like a neural net… and possibly with equal accuracy! Sorry to any NN enthusiasts out there). Some might question the need for such a function, but I would say “why” not?
    Dan

  3. Urs (us) Schwarz replied on :

    april 1, 2008

  4. Mark H. replied on :

    How about Matlab to Fortran IV? For all your retrocomputing needs…

    I, for my part, eagerly await the plugins for mindread.m that generate the graphs I want: automunge.m and psychicplot.m. That and 4-D bar plots. (”I just visualize it in n dimensions and generalize to n=4.”)

    ;-P

  5. Cris Luengo replied on :

    That’s great! MATLAB could be the intermediate language for translation tools. You would translate your typical political speech in Russian to MATLAB code, then translate it to English.

  6. Dan K replied on :

    Now the really important question is whether this functionality will be vectorized. If so maybe sign(theTimes) could be the new Nostradamus! It is also clear to me that in this day and age, weight(theWorld) had better be able to handle complex inputs!
    Dan

  7. Loren replied on :

    Dan-

    Looks like your into

    theSwing(things)

    Of course being vectorized and handling complex inputs are part of the requirements.

    –Loren

  8. naor replied on :

    Maybe you can use my recent Mie scattering routine. It’s vectorized, so the option for one wavelength is:
    fullMie(’once’)

  9. Tim Davis replied on :

    Thanks, schur(L|n), along with your fellow MathWorkers, listed below:

    R = qr (6.02214179e+23)
    load penny ; and (find (r == etree (P)))
    P*A'+Q*U*L(:,n)
    save perrier psi(weekday(3))
    edge (convhull, 'canny')
    swapbytes (j:k)
    

    for adding such great tools to MATLAB. These tools are particularly effective when terminated with the semironical statement terminator, namely,

    ;-)
    

    Thanks,

    ( )'*eye(m)\( )
    
  10. Tim Davis replied on :

    MATLAB is far better than those silly ads you see on web pages. It can do the following, all by itself:

    find (triu (lu (ver)), 'first') ;
    
  11. Tim Davis replied on :

    MATLAB poetry? You realize it’s very dangerous thing to ask me for poetry …. :-) Here’s a recent MATLAB Haiku, although it says more about C than MATLAB:

    Land-lubbers set sail,
    C coding in mexFunction :
    MATLUBbers at C.

    You can find more of the same at
    http://www.cise.ufl.edu/~davis/Horror_matrices.html

    In one recent one, for Gene Golub, I “translated” Kubla Khan into “Golub,Gene” in which

    A damsel with a dulcimer
    In a vision once I saw:
    It was an Abyssinian maid,
    And on her dulcimer she played,
    Singing of Mount Abora.

    becomes

    A damsel with a dual chip core
    In a vision once I saw:
    It was by math’matician made,
    And on her dual chip core she played,
    Singing of MATLAB aura.

  12. Bob M. replied on :

    Related to the reference to mindread.m: Interlisp had the DWIM function which could be applied when the debugger identified a problem. The function name was an acronym for “Do What I Mean.” It would make repairs based on a database of common errors in Lisp. The interrupted computation would then proceed.

  13. Tim Davis replied on :

    The URL name, above, comes from UK postal regulations. I’m not making this up: it is illegal to mail “horror comics and matrices” to the UK. So what is a “horror matrix”? A very ill-conditioned one, perhaps? Here’s my definition, aka the Jabberwok, with lots of MATLAB puns:

    Twas fill-in, and the slow transpose
    Did dir'ect factor in archive
    All tipsy were the banded 'ones
    And memory paths outgave.
    
    "Beware the 'OrrorMat, my son!
    The cols that peak, the try's that catch!
    Beware the Netlib blurb, and shun
    the fractal banded mats!"
    
    He took his direct slash in hand:
    Long time the max cond foe he sought ---
    So rested he by the elim' tree
    And stood while(1) in thought.
    
    And as in out-core work he stood,
    The 'OrrorMat, with speyes of NaN,
    Came loading through the world-wide web
    And core dumped as it ran!
    
    For one! to n! and 'til the end
    The direct slash went snicker-snack!
    He left it tril, and with diag
    He went condesting back.
    
    "And hast thou slain the 'OrrorMat?
    Gzip to tars, my direct code!
    O factorize day! tril(U)! tril(A)!"
    He posted in his ode.
    
    `Twas fill-in, and the slow transpose
    Did dir'ect factor in archive
    All tipsy were the banded 'ones
    And memory paths outgave.
    
  14. Tim Davis replied on :

    I’m not making this up:

    Matlab is a word in Urdu that means “Aim, Desire, Meaning, Motive, Object, Wish”. A similar word “matloobah,” means “requisite”. When you lack MATLAB, you have Matli, or “Malaise, Queasiness, Qualm”, and your efforts and skills are Matrookah (that is, “obsolete”).

    http://www.geocities.com/urdudict/m/mat.htm

    … but I *am* making this up, just this morning:

    Ah, MATLAB, matloobah matlab!
    Your codes in M I gotta have.
    I code in C sometimes for speed,
    but mostly all it's M I need.
    Lacking MATLAB, matrookah matli:
    there's naught to do but code in C.
    

    How’s that for a quadlingual poem (MATLAB, English, Urdu, and C)? ;-)

  15. Tim Davis replied on :
    function post = Loren (blog)
    % LOREN(blog) : a Schur e-composition at blogs.mathworks.com/loren
    %
    % The Schur e-composition is followed by a depth-first
    % post-ordering of the sparse elimination tree of the
    % Companion form of the blog.  For very complex topics,
    % the blog is then post-processed with CSF2RSF to convert
    % the blog to real form, for easier reader digestion and
    % rank-extraction.  Information transferral, from source
    % to reader, is accomplished via the companion matrix of
    % the sum of two matrices, compan(U+L|n).
    %
    % Can be followed by Schur_update (blog, line, string) :
    % a low-rank update/downdate, which modifies one or more
    % rows of a Schur e-composition.  This is useful for
    % post error elimination and spurious comments.
    %
    % See also cholupdate, rsf2csf, csf2rsf, schur, etree, schur_update, compan
    
    [U,L] = schur (blog) ;
    n = length (blog) ;
    [parent, post] = etree (compan (U + L|n)) ;
    if (n > 1000)
       post = csf2rsf (blog (post)) ;
    end
    
  16. Loren replied on :

    Tim-

    You have outdone yourself! These are some real gems (and maybe complex too?).

    –Loren

  17. Scott Cinnamond replied on :

    Loren; I’m interested in translating natural language (system) requirements into some formal language. If the MATLAB translator could “convert” requirements into MATLAB, are there other tools conversion/code-generation tools available to move portions of that output to, say UML?

  18. Loren replied on :

    Scott-

    This post, from April 1, was mostly in jest. MATLAB doesn’t have translation tools for natural languages. We do have ways to convert your MATLAB code into stand-alone executables, and Simulink has some tools for generating code suitable for embedded systems and real-time systems that you might check out. You also might check the file exchange to see if there are any UML tools.

    –Loren

  19. Tom Clark replied on :

    Funnily enough, I actually have a script,

    do_phd()
    

    which regenerates my entire PhD work so far…

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Loren Shure works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics.

  • Jun: I totally can not believe it, Loren. You are really helpful. Thank you so much, MATLAB master!
  • Loren: Wow folks- Always lots of interest when there’s a quickie to try out! I will only make 2 general...
  • Loren: Jun- ismember is your friend here: >> [aa,ind] = ismember(Array2,Arra y1) aa = 1 1 1 1 1 1 1 ind = 1 2 1 4 4 3...
  • Dan: I like the first way better than the second way. Combining the arrays into one and running any is nice, although...
  • James Myatt: How about I = (a == 0 | b == 0); a(I) = []; b(I) = [];
  • Tunc: Hello Loren, love your blog because of such inspiring and challenging comments to such ’small’...
  • Pekka Kumpulainen: Here is my tradeoff. I usually want to keep the original variables as they are most probably...
  • Iain: Followup: Of course, to allow NaNs (counting them as non-zero): mask = (a~=0) & (b~=0); The mask says “a...
  • Matt Fig: I would usually go with something like this: y = a&b; x = a(y); y = b(y); But I was surprised to find...
  • kk: c=all([a;b]) a(c) a(b)

These postings are the author's and don't necessarily represent the opinions of The MathWorks.