From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/108101 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: Re: Code lua in a table Date: Mon, 20 Jul 2020 14:56:58 +0900 Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Content-Type: multipart/mixed; boundary="===============2487510843551384771==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18611"; mail-complaints-to="usenet@ciao.gmane.io" To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl" Original-X-From: ntg-context-bounces@ntg.nl Mon Jul 20 08:05:30 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxOva-0004ky-6X for gctc-ntg-context-518@m.gmane-mx.org; Mon, 20 Jul 2020 08:05:30 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id C28BD185CD6; Mon, 20 Jul 2020 08:05:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TF6ZuUXObigY; Mon, 20 Jul 2020 08:05:04 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id ED7F2185CDF; Mon, 20 Jul 2020 08:05:04 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 1E6C6185C96 for ; Mon, 20 Jul 2020 08:05:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bUfKzKmhaEHi for ; Mon, 20 Jul 2020 08:05:03 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.6.55; helo=pv50p00im-ztdg10021901.me.com; envelope-from=haksan@me.com; receiver= X-Greylist: delayed 479 seconds by postgrey-1.36 at zapf.ntg.nl; Mon, 20 Jul 2020 08:05:03 CEST Original-Received: from pv50p00im-ztdg10021901.me.com (pv50p00im-ztdg10021901.me.com [17.58.6.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 3F42B185A2F for ; Mon, 20 Jul 2020 08:05:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1595224622; bh=rv2Oti/iEA9EEMaERbCk+MqU0g0uWSlEKo4NiZjUfTc=; h=From:Content-Type:Subject:Date:To:Message-Id; b=CiGuNNAJKZSsyJA8frqr1eCXal5yun+LxEd9uwXNzLKOl9WHLkgT01OZrVQI/71dz we98XdxpbKQi6acGo9QGLOU1mcA1zv0GwCjZHl4Zryjr63OJj4aH1yopHff9NPAKXg AE7BA0r6N9u+l6rJdtl7C2vNa2KbzSDJLtO5ibWtzA7gno0iULS9x7wBbiQDr8JK0l /A9AmCHYBne+ZbXhvW4D6eZJlIOUmapxmW3r5961w+RFS5GDdo5u6PVZBil79zN5Ga eml/GgXG07u6A6SGtKeCV9E31QTUw6Yl+6QQrbLvmnSL93/B2ymWGAHmsYgQ+b/fZL vsHlvKDhXvViw== Original-Received: from apple.ssu.ac.kr (apple.soongsil.ac.kr [203.253.9.6]) by pv50p00im-ztdg10021901.me.com (Postfix) with ESMTPSA id B0B828803C5 for ; Mon, 20 Jul 2020 05:57:01 +0000 (UTC) In-Reply-To: X-Mailer: Apple Mail (2.3608.80.23.2.2) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-20_01:2020-07-17, 2020-07-20 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=610 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2004280000 definitions=main-2007200044 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:108101 Archived-At: --===============2487510843551384771== Content-Type: multipart/alternative; boundary="Apple-Mail=_E179E8A8-D613-46BA-871F-7CE37FF49C1B" --Apple-Mail=_E179E8A8-D613-46BA-871F-7CE37FF49C1B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Dear Fabrice, You may split Binom(n,k) function into two functions as following: ***** \startluacode P=3D{} combi =3D P function P.fact (n) if n <=3D 0 then return 1 else return n * P.fact(n-1) end end function P.ncr(n,r) return P.fact(n)/(P.fact(r)*P.fact(n-r)) end combi =3D { fact =3D fact, ncr =3D ncr, } \stopluacode ****** Your table is actually Pascal=E2=80=99d triangle.=20 Using the above function, I was able to draw Pascal=E2=80=99s triangles. Hans helped me to complete it. I couldn=E2=80=99t wikify it at that time because I don=E2=80=99t know = how to. I=E2=80=99ll do it soon. Here is the whole code for Pascal=E2=80=99s triangle in two different = ways using Lua, Metafun and ConTeXt. You may enhance the code. \startbuffer[pt1] numeric n,r,s,u,dx,dy,tt; u :=3D 1.8cm; path p, q; pair A,B,start,now; A :=3D dir(210)*u; B :=3D dir(-30)*u; dy :=3D sind(30)*u; dx :=3D 2*cosd(30)*u; for n=3D0 upto 4: start :=3D n*dir(210)*u; for r=3D0 upto n: s :=3D n-r; tt :=3D lua("mp.print(P.ncr(" & decimal n & "," & decimal r & " = ))"); now :=3D start+r*right*dx; dotlabel.top(textext("$\displaystyle {" & decimal n & "\choose" = & decimal r & "} =3D "& decimal tt & "$"),now); draw (now+A) -- now -- (now+B); endfor; endfor; \stopbuffer \startbuffer[pt2] numeric n,r,s,u,dx,dy,tt; u :=3D 1cm; path p, q; pair A,B,start,now; A :=3D dir(210)*u; B :=3D dir(-30)*u; dy :=3D sind(30)*u; dx :=3D 2*cosd(30)*u; for n=3D0 upto 8: start :=3D n*dir(210)*u; for r=3D0 upto n: s :=3D n-r; tt :=3D lua("mp.print(P.ncr(" & decimal n & "," & decimal r & " = ))"); =20 now :=3D start+r*right*dx; label(textext("$" & decimal tt & "$"),now); endfor; endfor; \stopbuffer \startluacode P=3D{} combi =3D P function P.fact (n) if n <=3D 0 then return 1 else return n * P.fact(n-1) end end function P.ncr(n,r) return P.fact(n)/(P.fact(r)*P.fact(n-r)) end combi =3D { fact =3D fact, ncr =3D ncr, } \stopluacode \starttext \processMPbuffer[pt1] \blank[big] \processMPbuffer[pt2] \stoptext I hope that it helps. Best regards, Dalyoung --Apple-Mail=_E179E8A8-D613-46BA-871F-7CE37FF49C1B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Dear = Fabrice,

You may = split Binom(n,k) function into two functions as following:

*****
\startluacode
P=3D{}
combi =3D P

function P.fact (n)
= if n = <=3D 0 then
return 1
else
return n * P.fact(n-1)
end
end

function P.ncr(n,r)
= return P.fact(n)/(P.fact(r)*P.fact(n-r))
end
combi =3D {
fact =3D = fact,
ncr =3D ncr,
}
\stopluacode
******

Your table = is actually Pascal=E2=80=99d triangle. 
Using the above = function, I was able to draw Pascal=E2=80=99s triangles.
Hans = helped me to complete it.
I couldn=E2=80=99t wikify = it at that time because I don=E2=80=99t know how to. =  I=E2=80=99ll do it soon.

Here = is the whole code for Pascal=E2=80=99s triangle in two different ways = using Lua, Metafun and ConTeXt.
You may enhance the = code.

\startbuffer[pt1]
numeric = n,r,s,u,dx,dy,tt; u :=3D 1.8cm;
path p, = q;
pair A,B,start,now;
A :=3D = dir(210)*u;
B :=3D dir(-30)*u;
dy :=3D sind(30)*u;
dx :=3D 2*cosd(30)*u;
for n=3D0 upto 4:
start :=3D n*dir(210)*u;
= for r=3D0 upto n:
s :=3D n-r;
tt :=3D lua("mp.print(P.ncr(" & decimal n & = "," & decimal r & " ))");
now :=3D = start+r*right*dx;
dotlabel.top(textext("$\displaystyle= {" & = decimal n & "\choose" = & decimal r & "} =3D = "& decimal tt & "$"),now);
= draw (now+A) -- now -- (now+B);
= endfor;
endfor;
\stopbuffer
\startbuffer[pt2]
numeric = n,r,s,u,dx,dy,tt; u :=3D 1cm;
path p, q;
pair A,B,start,now;
A :=3D dir(210)*u;
B :=3D dir(-30)*u;
dy :=3D sind(30)*u;
dx :=3D 2*cosd(30)*u;
for n=3D0 upto 8:
start :=3D n*dir(210)*u;
= for r=3D0 upto n:
s :=3D n-r;
tt :=3D lua("mp.print(P.ncr(" & decimal n & = "," & decimal r & " ))");
now :=3D = start+r*right*dx;
label(textext("$" & decimal tt & = "$"),now);
endfor;
endfor;
\stopbuffer
\startluacode
P=3D{}
combi =3D P

function P.fact (n)
= if n = <=3D 0 then
return 1
else
return n * P.fact(n-1)
end
end

function P.ncr(n,r)
= return= P.fact(n)/(P.fact(r)*P.fact(n-r))
end
combi =3D {
= fact =3D fact,
ncr =3D = ncr,
}
\stopluacode
\starttext

\processMPbuffer[pt1]
\blank[big]
\processMPbuffer[pt2]

\stoptext

I hope that it helps.

Best regards,

Dalyoung

= --Apple-Mail=_E179E8A8-D613-46BA-871F-7CE37FF49C1B-- --===============2487510843551384771== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============2487510843551384771==--