([: %&4 [: %: *:@:(+/@:^)&2 - +:@:(+/@:^)&4) 3 4 5 6
As the square of the area of a triangle is a symmetric polynomial of the squares of the sides, the above tacit code also works. Den tirsdag den 4. september 2018 13.51.07 CEST skrev Martin Kreuzer <[email protected]>: 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
