Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Richard Fateman <fateman@xxxxxxxxxxxxxxx>
- Date: Tue, 23 Aug 2005 18:02:04 GMT
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 {}.) IHold[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
.
- References:
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Jon McLoone
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Nasser Abbasi
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Richard J. Fateman
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Jon Harrop
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Richard J. Fateman
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Jon Harrop
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Jens Axel Søgaard
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- From: Jon Harrop
- Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- Prev by Date: Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- Next by Date: Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- Previous by thread: Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- Next by thread: Re: functional style compared to procedural style and comments on a Mathematica function I saw.
- Index(es):
Relevant Pages
|