From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id B37A93858D1E for ; Wed, 29 Nov 2023 09:03:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B37A93858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B37A93858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701248591; cv=none; b=a0bzmkvm4MHf91qytMCmX0JuzLDQY+ygWOMdaWogppk3Uo1W+1GBqATj8EQrf1YmckJKZK0GfB2QeLZzT+LlRB0E7nRyNDqqUQ4fO27eYS7QxZ4GACsX5IA+gURkVGSGFAn/spNAOw+u9MB36vzh/v5nUJ6kb2MSSh2DfWfl5C4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701248591; c=relaxed/simple; bh=fXwKdYrI1WyHis++LGs5M7zSYT/GdiKRpi0CGjrQs+A=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=kClTmwLpecTH3CVpBc98vh6hTQ4z7jj+33lutRbQ7SdnRSznc0/mJW8OuEWgEXiRzW/do/SjNC7ToWgyBkWT8gKj7y6Be9my8OLx6a3DJzYcHlG6upEu4wYbl9ub9PJZ5ykjtb+pKTR42b6sH7dghS1RNMTc20zPLa1F3fpYcgI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50bbb78efb5so2256353e87.3 for ; Wed, 29 Nov 2023 01:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701248586; x=1701853386; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=gsyCdYticQiKy32O7f/neaTiPlpMF4/Qj3QnECpCcbU=; b=GRcK1ybQeMPX5Sw0Eu+8Gn+kfFNjy2Pbld3TlxKX7Z4hlLyJ1VO2ySUiRGvaiLwg50 +ijNHeqApkJeJOZ37FfC59J6gpdZdbtVOknJaRmLxT1yyjH2dccilZdEGFgsibTksrc2 yj7IYpwAhbJP1/ARvFp9RfMMNkiy3oywP9WCPdx+Q6PNNk9q8nrNlNzghSg+Tkaxy94R lERRkb3E8v001VXfFJhIewd5/kQ67HwjpzVClK3KqRuzubPSK8GeN8CdzGCt/gnd43sM 7iPwS4C7QIILj88Xa0VH4m3BnH5Y6IwZwyP37lII2dBdeO26Z82ukEZo4If07S+riPdX dVNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701248586; x=1701853386; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gsyCdYticQiKy32O7f/neaTiPlpMF4/Qj3QnECpCcbU=; b=o78ykSfbPJQZ3Le7eMDStMHZ0NPNDd5bgnDM4Cl80j6mi5O839xBgxZ9zn8I4Lptop SFBsJOMt6fqcbzy7PWrJNjupxKI7au9Al0bxpmVH+zIx5KWIbG8RZ2j52fQHY7dWCklb ChcYtSD7QLtJJFUYmqFzlc8TEM42/QDD15DlCSjk5rcFNgdf7pDvZgMOz05ZasHuroD0 mRjT60XecYh4eQkehnumUB8vwUbyXK+d1BGlzOgwou+hfNn55N/t+MG+dkg+r2uLjgHw h0CYdsDZD/VvlSdUuAROj3McgJKIrNoiQZhqOQs8eaxbUeeICWjcERVpA6RzN64Nsc2T nJHw== X-Gm-Message-State: AOJu0Yw1eegHsoC9H6/HOe9aXPSgHILYzpRotcGOlOFvFrlXC5uIehmo ZSiWa24L/+vP1XD3ijin9ym+ZdZIpuKA3pObEoKLKXi9457zLA== X-Google-Smtp-Source: AGHT+IGs5ldpC4Xa4ntLoBvXYhXJhGBUI4RroERATlPcPcdfFp8JSdcqEVMzRVDlKN3sAytmO5g3DITcUCi8Akp++OY= X-Received: by 2002:ac2:4e10:0:b0:50a:a5f7:47fb with SMTP id e16-20020ac24e10000000b0050aa5f747fbmr14395193lfr.49.1701248586066; Wed, 29 Nov 2023 01:03:06 -0800 (PST) MIME-Version: 1.0 From: Damien Mattei Date: Wed, 29 Nov 2023 10:02:54 +0100 Message-ID: Subject: infix precedence optimizer for Scheme+ for Kawa To: kawa mailing list Content-Type: multipart/alternative; boundary="000000000000a5b07b060b46cdc8" X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000a5b07b060b46cdc8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable hello, i have added optimisation features for infix precedence ( https://github.com/damien-mattei/Scheme-PLUS-for-Kawa/blob/main/optimize-in= fix.scm) for the kawa parser version of Scheme+ ( https://github.com/damien-mattei/Scheme-PLUS-for-Kawa/blob/main/curly-infix= 2prefix4kawa.scm ) for example for a given code in Scheme+ like this: ; modify coefficients layer(define (modification_des_poids M_i_o =CE=B7 z_input z_output z=CC=83_output =E1=90=81_i_o =E1=83=9Bz=E2=B3=86=E1=83=9Bz= =CC=83) ; derivative of activation function of the layer ; the length of output and input layer with coeff. used for bias update {(len_layer_output len_layer_input_plus1forBias) <+ (dim-matrix M_i_o)} ; use values and define-values to create bindings {len_layer_input <+ {len_layer_input_plus1forBias - 1}} (for-each-in (j (in-range len_layer_output)) ; line (for-each-in (i (in-range len_layer_input)) ; column , parcours les colonnes de la ligne sauf le bias {M_i_o[j {i + 1}] <- M_i_o[j {i + 1}] - (- =CE=B7) * z_input[i] * =E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83(z_output[j] z=CC=83_output= [j]) * =E1=90=81_i_o[j]}) ; and update the bias {M_i_o[j 0] <- M_i_o[j 0] - (- =CE=B7) * 1.0 * =E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83(z_output[j] z=CC=83_output[j]) = * =E1=90=81_i_o[j]})) without optimization it is transformed after parsing in: (define (modification_des_poids M_i_o =CE=B7 z_input z_output z=CC=83_output =E1=90=81_i_o =E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83) (<+ (len_layer_output l= en_layer_input_plus1forBias) (dim-matrix M_i_o)) (<+ len_layer_input (- len_layer_input_plus1forBias 1)) (for-each-in (j (in-range len_layer_output)) (for-each-in (i (in-range len_layer_input)) ($nfx$ (bracket-apply M_i_o j (+ i 1)) <- (bracket-apply M_i_o j (+ i 1)) - (- =CE=B7) * (bracket-apply z_input i) * (=E1=83=9Bz=E2=B3=86= =E1=83=9Bz=CC=83 (bracket-apply z_output j) (bracket-apply z=CC=83_output j)) * (bracket-apply =E1=90=81= _i_o j))) ($nfx$ (bracket-apply M_i_o j 0) <- (bracket-apply M_i_o j 0) - (- =CE=B7) * 1.0 * (=E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83 (bracket-apply z_= output j) (bracket-apply z=CC=83_output j)) * (bracket-apply =E1=90=81_i_o j)))) this cause the $nfx$ algorithm to be executed at runtime. for example in the above code {M_i_o[j {i + 1}] <- M_i_o[j {i + 1}] - (- =CE=B7) * z_input[i] * =E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83(z_output[j] z=CC=83_output[j]) * =E1=90= =81_i_o[j]} at each iteration of loop $nfx$ is called with its arguments: ($nfx$ (bracket-apply M_i_o j (+ i 1)) <- (bracket-apply M_i_o j (+ i 1)) - (- =CE=B7) * (bracket-apply z_input i) * (=E1=83=9Bz=E2=B3=86= =E1=83=9Bz=CC=83 (bracket-apply z_output j) (bracket-apply z=CC=83_output j)) * (bracket-apply =E1=90=81_i_o j)) Now the infix parser, before compilation produce a code like this, where $nfx$ calls are replaced by the symbolic expression according to the operator precedence rules: (define (modification_des_poids M_i_o =CE=B7 z_input z_output z=CC=83_output =E1=90=81_i_o =E1=83=9Bz=E2=B3=86=E1=83=9Bz=CC=83) (<+ (len_layer_output l= en_layer_input_plus1forBias) (dim-matrix M_i_o)) (<+ len_layer_input (- len_layer_input_plus1forBias 1)) (for-each-in (j (in-range len_layer_output)) (for-each-in (i (in-range len_layer_input)) (<- (bracket-apply M_i_o j (+ i 1)) (- (bracket-apply M_i_o j (+ i 1)) (* (- =CE=B7) (* (bracket-apply z_input i) (* (=E1=83=9Bz=E2= =B3=86=E1=83=9Bz=CC=83 (bracket-apply z_output j) (bracket-apply z=CC=83_output j)) (bracket-apply =E1=90=81_i_o j))))))) (<- (bracket-apply M_i_o j 0) (- (bracket-apply M_i_o j 0) (* (- =CE=B7) (* 1.0 (* (=E1=83=9Bz= =E2=B3=86=E1=83=9Bz=CC=83 (bracket-apply z_output j) (bracket-apply z=CC=83_output j)) (bracket-apply =E1=90=81_i_o j)))))))) so for the above expressions the simplest scheme code is evaluated at runti= me: (<- (bracket-apply M_i_o j (+ i 1)) (- (bracket-apply M_i_o j (+ i 1)) (* (- =CE=B7) (* (bracket-apply z_input i) (* (=E1=83= =9Bz=E2=B3=86=E1=83=9Bz=CC=83 (bracket-apply z_output j) (bracket-apply z=CC=83_output j)) (bracket-apply =E1=90=81_i_o j)))))) the performance at runtime in mathematic computation algorithms are now _twice_ faster just with this optimization. Next optimization will concern bracket-apply but this is a big work, inference type need to be performed on many expressions of all files of code.. Damien --000000000000a5b07b060b46cdc8--