Re: functional style compared to procedural style and comments on a Mathematica function I saw.



Jon Harrop wrote:

Jens Axel Søgaard wrote:

How will the above function look like if you replace And with &&?


Mathematica reformats that expression for you automatically:

It does. But not the way JH shows it

I got this  (note, I had to put Hold [] around it to keep it from "happening".
Also I changed == to == in the first clause, which in JH's rendering
is altered to {}.)  I

Hold[m === {} || And @@ (#1 === 0 & ) /@
     Rest[First[m]] && And @@ (#1 === 0 & ) /@
     First /@ Rest[m] && ssz[Map, Rest, Rest[m]]]



m == {} || And @@ (#1 === 0 &) /@ Rest[First[m]] && And @@ (#1 === 0 &) /@ First /@ Rest[m] && ssz[Map, Rest, Rest[m]]


Richard's objections sound almost reasonable when you can't see
Mathematica's front end typesetting code as you write it.

Note in particular that the Ands are not lined up. and the expression includes subsequences of === {} || And @@, && And @@ whose precedence would certainly puzzle some people.


If r = (#1===0&) then it also includes === {} || And @@ r /@ .....&& And @@ r /@

And of course one must wonder what the difference is between
  And  and && , both of which appear in the expression.

(By comparison, in Macsyma,  the two expressions
A and B

"and"(A,B)

are equivalent. )


The Fullform version looks like this

Hold[Or[SameQ[m,List[]], And[Apply[And,
     Map[Function[SameQ[Slot[1], 0]], Rest[First[m]]]],
    Apply[And, Map[Function[SameQ[Slot[1], 0]],
      Map[First,Rest[m]]]], ssz[Map, Rest, Rest[m]]]]]

In which the alignment is quite wrong, but the parsing
(i.e. which function has which arguments,) is obvious.

For example, you
can use conventional Mathematical notation of an inverted "V" in
Mathematica but if you post it to a newsgroup then people without
Mathematica might try to read it directly, i.e. without downloading
MathReader.

Oh, and finally, the expression mathematically speaking, is not the same and the expression programmatically speaking.

A or B   probably means, look at A, B .  If one of them is
true, the value is true.  If all of them are false, the value is false.

But in the PROGRAM above, we mean by
A or B

If A is true, the value is true  WITHOUT LOOKING AT B [which if we did look, would be an error].
If A is false, it is OK to look at B.

That is,  A or B   really means

if A then true else B.   Or in Mathematica,   If[A,true,B].

Did you really want to defend this as mathematical notation?

By the way, at least one programming language, the (late?) Pascal,
required that all operands of a boolean be evaluated.

RJF


.



Relevant Pages

  • Re: Symbolic inverse of a 12x12 matrix
    ... >> I am solving a problem using f95 that involves solving a 12x12 coupled ... As bourne out by your execution times. ... The long execution time seems to be related to the time Mathematica spends ... on rendering the result as Marcus pointed out. ...
    (sci.math.symbolic)
  • Re: functional style compared to procedural style and comments on a Mathematica function I saw.
    ... Mathematica reformats that expression for you automatically: ... Richard's objections sound almost reasonable when you can't see ... Mathematica's front end typesetting code as you write it. ... Mathematica but if you post it to a newsgroup then people without ...
    (sci.math.symbolic)