Received: from mx0.gmx.net (mx0.gmx.net [213.165.64.100]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with SMTP id q15G6VO7024176 for ; Sun, 5 Feb 2012 17:06:32 +0100 Received: (qmail 8661 invoked by alias); 5 Feb 2012 16:06:26 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 05 Feb 2012 16:06:25 -0000 Received: from relay2.uni-heidelberg.de (EHLO relay2.uni-heidelberg.de) [129.206.210.211] by mx0.gmx.net (mx038) with SMTP; 05 Feb 2012 17:06:25 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q15G41Um032377 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 5 Feb 2012 17:04:01 +0100 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id q159D6G5017104; Sun, 5 Feb 2012 17:04:01 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 1940158 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Sun, 5 Feb 2012 17:04:01 +0100 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id q15G41ul016442 for ; Sun, 5 Feb 2012 17:04:01 +0100 Received: from neptune.ucc.ie (neptune.ucc.ie [143.239.153.183]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q15G3cEm032286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 5 Feb 2012 17:03:42 +0100 Received: from csmvddesktop (csmvddesktop.ucc.ie [143.239.74.97]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dongen) by neptune.ucc.ie (Postfix) with ESMTPSA id C2EDC200B4 for ; Sun, 5 Feb 2012 16:03:58 +0000 (GMT) References: <4F2A68F9.1010508@morningstar2.co.uk> <20120202111808.GA15304@csmvddesktop> <20120202131844.GA16372@csmvddesktop> <20120202133153.GA16604@csmvddesktop> <20120203151218.GA30208@csmvddesktop> <4F2BFFA6.1020306@morningstar2.co.uk> <20120203155926.GA30436@csmvddesktop> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="NzB8fVQJ5HfG6fxh" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Message-ID: <20120205160826.GA6939@csmvddesktop> Date: Sun, 5 Feb 2012 16:08:26 +0000 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: dongen Subject: Re: Mapping Functions Versions for All and Some To: LATEX-L@listserv.uni-heidelberg.de In-Reply-To: Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-GMX-Antispam: 0 (eXpurgate); Detail=5D7Q89H36p6sJLDpZh614Kjz2nt6F3tHdUkWaJ871MCH8SloSw6nX/iX5R4Z5w8RlcCXv qfQLUWxwHlL11mR6rbB/HVsNPcOpkK+9p2HfnDIPt6eqi83R0xJNSj7zS4BYHcjYaMu5QaWpA6lO PzIVvwLVqigxFQnx/lckXhQ0pwfPWPbheBwFujBjkmXdrHkVpbDOlhrvhw=V1; X-Resent-By: Forwarder X-Resent-For: rainer.schoepf@gmx.net X-Resent-To: rainer@rainer-schoepf.de Status: R X-Status: X-Keywords: X-UID: 7020 --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Bruno Le Floch [2012-02-03 15:01:01 -0500]: : > : All LaTeX3 functions are either fully expandable or engine-protected. In : > : this case, we are talking about protected functions: these are not : > : expandable. (In the documentation, expandable functions are marked with : > : a star.) : : Joseph is right. Regular expression matching is already tough enough : to not try to do it expandably (besides, that would become : unreasonably slow, and would break in corner cases). What you seem to : be trying can be done as follows instead: Hi again, I've made some progress with the recurrence equations, but I have a error that I don't understand. I'd appreciate it if you could have a quick look. Given the standard (naive) definition of the Fibonacci numbers (f[0]=1, f[1]=1,f[i]=f[i-1],f[i-2]), my code generates the following artificial macros: \f macro:#1->\f:n {#1} \f:n macro:#1->\exp_args:Nx \recurrence_f_0:x {\int_eval:n {#1}} \recurrence_f_0:x macro:#1->\int_compare:nTF {#1=0}{1}{\recurrence_f_1:x {#1}} \recurrence_f_1:x macro:#1->\int_compare:nTF {#1=1}{1}{\recurrence_f_2:x {#1}} \recurrence_f_2:x macro:#1->\bool_if:nTF {\int_compare_p:n{1=1}}{\f:n{#1-1}+\f:n{#1-2}}{\recurrence_f_3:x {#1}} \recurrence_f_3:x \long macro:#1->\error {f[ #1 ] undefined.} The macros \f and \f:n are wrappers. The macros \recurrence_f_0, ..., \recurrence_f_2 deal with the three different conditions, and \recurrence_f_3 deals with errors, which cannot occur here, but in general cases may not be matched. Computing \f{0} and \f{1} works fine, but evaluating \f{2} doesn't. The current code I have is packaged as a .tex and a .sty file. If you have any comments on the problem, or indeed, the source files, then that'd be much appreciated. I've tried to keep the code simple. Optimising can be done later. I'm attaching the source files. Regards, Marc van Dongen --NzB8fVQJ5HfG6fxh Content-Type: text/x-tex; charset=us-ascii Content-Disposition: attachment; filename="recurrence.tex" \documentclass[12pt]{article} \usepackage[paper=a4paper,landscape]{geometry} \usepackage{recurrence} \begin{document} \section{Start} %\tracingmacros=1 \NewRecDef{f[0]=1, f[1]=1, f[i]=f[i-1]+f[i-2]} \begin{tt} \begin{tabular}{ll} f & \meaning\f \\ f:n & \expandafter\meaning\csname f:n\endcsname \\ recurrence\_f\_0:x & \expandafter\meaning\csname recurrence_f_0:x\endcsname \\ recurrence\_f\_1:x & \expandafter\meaning\csname recurrence_f_1:x\endcsname \\ recurrence\_f\_2:x & \expandafter\meaning\csname recurrence_f_2:x\endcsname \\ recurrence\_f\_3:x & \expandafter\meaning\csname recurrence_f_3:x\endcsname \end{tabular} \end{tt} % \f{2} \end{document} --NzB8fVQJ5HfG6fxh Content-Type: text/x-tex; charset=us-ascii Content-Disposition: attachment; filename="recurrence.sty" \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{recurrence}[2012/02/02 Recurrence Equation Support] %\usepackage{tikz} \usepackage{xparse} \usepackage{expl3} \usepackage{l3regex} \usepackage{l3int} \ExplSyntaxOn \def\testme#1{[[[#1]]]} \clist_new:N \recurrence_csv_list \tl_new:N \recurrence_tl_bin \tl_new:N \recurrence_tl_temp \tl_new:N \recurrence_tl_name \tl_new:N \recurrence_tl_index \tl_new:N \recurrence_tl_rhs \tl_new:N \recurrence_tl_guard \regex_const:Nn \recurrence_tl_integer_regex { ^[-+]*[0-9]+$ } \regex_const:Nn \recurrence_tl_true { true } \int_new:N \recurrence_case_count \cs_new_nopar:Npn \recurrence_prefix: { recurrence } \cs_new_nopar:Npn \recurrence_is_integer:xTF #1{ \regex_match:NnTF \recurrence_tl_integer_regex {#1} } \cs_new_nopar:Npn \recurrence_is_integer:NTF #1{ % I don't understand why I need the exp_args:Nx \exp_args:Nx \recurrence_is_integer:xTF {\tl_use:N #1} } \cs_new_nopar:Npn \recurrence_case_name:xx #1#2{ \recurrence_prefix: _ #1 _ #2:x } % #1 is integer token list \cs_new_nopar:Npn \recurrence_case_name:N #1{ \recurrence_case_name:xx \recurrence_tl_name {\int_use:N #1} } % #1 is integer \cs_new_nopar:Npn \recurrence_case_name:n #1{ \recurrence_case_name:xx \recurrence_tl_name {#1} } % #1 is index % #2 is rhs \cs_new_nopar:Npn \recurrence_define_constant:xx #1#2{% \edef\recurrence_current_case_count{\int_use:N \recurrence_case_count} \int_incr:N \recurrence_case_count \cs_new_nopar:cpx {\recurrence_case_name:n \recurrence_current_case_count} ##1{ \exp_not:N \int_compare:nTF {##1=#1} {#2} {\cs:w \recurrence_case_name:N \recurrence_case_count \cs_end:{##1}} } } % #1 is guard tl % #2 is rhs tl \cs_new_nopar:Npn \recurrence_case_definition:xx #1#2{ \edef\recurrence_current_case_count{\int_use:N \recurrence_case_count} \int_incr:N \recurrence_case_count \cs_new_nopar:cpx {\recurrence_case_name:n \recurrence_current_case_count} ##1{ \exp_not:N \bool_if:nTF {#1} {#2} {\cs:w \recurrence_case_name:N \recurrence_case_count \cs_end:{##1}} } } % #1 is name tl % #2 is index tl % #3 is rhs tl % #4 is guard tl \cs_new_nopar:Npn \recurrence_case_definition:NNNN #1#2#3#4{ \exp_args:Nx \recurrence_sanitise:nNN {{\tl_use:N #1} {\tl_use:N #2}} #3 #4 \regex_replace_all:NnN \recurrence_tl_true {\\int_compare_p:n \{ 1 = 1 \}} #4 \recurrence_case_definition:xx #4 #3 } \cs_new_nopar:Npn \recurrence_sanitise:nNN #1#2#3{ \recurrence_sanitise:nnNN #1 #2 #3 } % #1 is name % #2 is index % #3 is rhs tl % #4 is guard tl \cs_new_nopar:Npn \recurrence_sanitise:nnNN #1#2#3#4{ \recurrence_sanitise:nnN {#1} {#2} #3 \recurrence_sanitise:nnN {#1} {#2} #4 } % #1 is name % #2 is index % #3 is tl list \cs_new_nopar:Npn \recurrence_sanitise:nnN #1#2#3{ \regex_replace_all:nnN {#2} {\#1} #3 \regex_replace_all:nnN {\b#1\b\[([^\]]+)\]} {\\#1:n\{\1\}} #3 } \cs_new_nopar:Npn \recurrence_error_definition:{ \edef\recurrence_current_case_count{\int_use:N \recurrence_case_count} \cs_new:cpx {\recurrence_case_name:n \recurrence_current_case_count}##1{ \exp_not:N \error{\tl_use:N \recurrence_tl_name[~##1~]~undefined.} } } \cs_new_nopar:Npn \recurrence_wrapper_definitions:{ \edef\recurrence_temp{\tl_use:N \recurrence_tl_name} \cs_new_nopar:cpx {\recurrence_temp} ##1{% \exp_after:wN \exp_not:N \cs:w \recurrence_temp :n \cs_end: {##1} } \cs_new_nopar:cpx {\recurrence_temp :n} ##1{% \noexpand \exp_args:Nx \exp_after:wN \exp_not:N \cs:w \recurrence_case_name:n 0 \cs_end: {\exp_not:N \int_eval:n{##1}} } } \cs_new_nopar:Npn \NewRecDef:n #1{ \begingroup \clist_set:Nn \recurrence_csv_list {#1} \clist_map_inline:Nn \recurrence_csv_list { \regex_extract_once:nnNTF { ^(\w+)\[(\w+)\]\=(.+?)\|(.+)\|(.+) } {##1|true||} \recurrence_tl_temp { % at this stage, \recurrence_tl_temp has 6 items, % 0th: a[i]= expression | guard | guard option \seq_pop:NN \recurrence_tl_temp \recurrence_tl_bin \seq_pop:NN \recurrence_tl_temp \recurrence_tl_name \seq_pop:NN \recurrence_tl_temp \recurrence_tl_index \seq_pop:NN \recurrence_tl_temp \recurrence_tl_rhs \seq_pop:NN \recurrence_tl_temp \recurrence_tl_guard \recurrence_is_integer:NTF \recurrence_tl_index {\recurrence_define_constant:xx \recurrence_tl_index \recurrence_tl_rhs} {\recurrence_case_definition:NNNN \recurrence_tl_name \recurrence_tl_index \recurrence_tl_rhs \recurrence_tl_guard} } { \recurrence_error } } \recurrence_error_definition: \recurrence_wrapper_definitions: \endgroup } \DeclareDocumentCommand\NewRecDef{ m }{ \NewRecDef:n {#1} } \ExplSyntaxOff --NzB8fVQJ5HfG6fxh--