@Raul
Thanks - it has been very enlightening to see the
expression to grow 'more' tacit from line to line ...
I went through it (line by line) and stumbled upon this issue:
Until now I thought that
3 4 5 -: 3,4,5
1
giving identical results in subtraction
6 - 3 4 5
3 2 1
6 - 3,4,5
3 2 1
I then wrapped that into a function (still giving identical results)
6 (4 : 'x-y') 3 4 5
3 2 1
6 (4 : 'x-y') 3,4,5
3 2 1
but not with reverse order
3 4 5 (4 : 'y-x') 6
3 2 1
3,4,5 (4 : 'y-x') 6
3 4 1
This I do not understand ...
-M
At 2018-09-04 14:00, you wrote:
I was about to suggest something similar:
13 : '(%: x * */ x-y)'
[: %: [ * [: */ -
13 : '(%: y * */ y-x)'
[: %: ] * [: */ -~
13 :'y ([: %: ] * [: */ -~)-:+/y'
] ([: %: ] * [: */ -~) [: -: +/
taher=: ] ([: %: ] * [: */ -~) [: -: +/
taher 3 4 5
Variations are possible, of course. For example:
taher=: %:@(] * +/@:-~) +/@:-:
Thanks,
--
Raul
On Tue, Sep 4, 2018 at 9:46 AM 'Mike Day' via Programming
<programm...@jsoftware.com> wrote:
> Does this help?
> Each line is a small amendment to the preceding one...
> (-:@(+/))3 4 5 NB. Semiperimeter, s
> 6
> (-:@(+/)-0&,)3 4 5 NB. s - 0, a, b, c
> 6 3 2 1
> (-:@(+/)*/@:-0&,)3 4 5 NB. s * (s - a) * ...
> 36
> (-:@(+/)%:@(*/)@:-0&,)3 4 5 NB. Heronâs formula applied to 3 4 5
> 6
> (-:@(+/)%:@(*/)@:-0&,) NB. Let
interpreter remove unnecessary brackets...
> -:@(+/) %:@(*/)@:- 0&,
> So the semiperimeter is calculated just the
once. It relies on converting the triplet
a,b,c to the quadruplet 0, a, b, c, rather
than doing particularly smart bracketing.
> I donât often use [: but if you prefer
it, the following arises from a similar
building process using [: rather than @ and @:
> ([:-:(+/))3 4 5
> 6
> (([:-:(+/)) - 0&,)3 4 5
> 6 3 2 1
> (([:-:(+/))( [: */ - )0&,)3 4 5
> 36
> (([:-:(+/))( [: %: [: */ - )0&,)3 4 5
> 6
> (([:-:(+/))( [: %: [: */ - )0&,) NB. Get rid of extra brackets
> ([: -: +/) ([: %: [: */ -) 0&,
> Cheers,
> Mike
> Sent from my iPad
> > On 4 Sep 2018, at 12:50, Martin Kreuzer <i...@airkreuzer.com> wrote:
> >
> > Hi all -
> >
> > To calculate the area of a flat triangle, using Heron's formula,
> > A(a,b,c)= sqrt( s2*(s2-a)*(s2-b)*(s2-c) )
> > I wrote a simple function doing this:
> >
> > * get the three sides (as list input y)
> > * compute the half perimeter s2
> > * build the differences s2-y
> > * build product
> > * take square root
> >
> > My explicit solution looks like this
> >
> > taher=: 13 : '%: s2 * */ s2-y [ s2=. -: +/ y'
> >
> > and works
> >
> > taher 3 4 5
> > 6
> >
> > Suggested tacit version looks like this (and works too)
> >
> > tahert=: [: %: ([: -: +/) * [: */ ([: -: +/) - ]
> >
> > Q: Is there a way to reference the
intermediate result of ([: -: +/) the half perimeter s2
> > within the tacit expression, as has been done in the explicit..?
> > [Guess the interpreter takes care of this
anyway; my question aims at whether a shorter formulation could be reached.]
> >
> > Thanks
> > -M
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm