# Re: [ot-users] Simplified symbolic functions

 Hello, You can use intermediate variables using multiple expressions with the comma separator: >>> f=ot.SymbolicFunction(['x1', 'x2', 'x3'], ['x3=x1+x2,x3']) >>> f([2,3,0]) class=Point name=Unnamed dimension=1 values=[5] But this only works to return a single value as only the last _expression_ is returned, Otherwise there's an api call to return all values at the same time instead of a single value: muParserBase.h:107:     value_type  Eval() const; muParserBase.h:108:    value_type* Eval(int &nStackSize) const; j De : users-boun...@openturns.org de la part de BAUDIN Michael Envoyé : mercredi 14 février 2018 12:30:54 À : users@openturns.org Objet : [ot-users] Simplified symbolic functions   Hi,   I have a symbolic function that I would like to simplify and I do not see how.   Here is the test case. The function has 8 inputs and 2 outputs. In Python it is simple to define :   def functionCrue(X) :     Q, Ks, Zv, Zm, Hd, Zb, L, B = X     alpha = (Zm - Zv)/L     H = (Q/(Ks*B*sqrt(alpha)))**(3.0/5.0)     Zc = H + Zv     Zd = Zb + Hd     S = Zc - Zd     return [H,S] myFunction = PythonFunction(8, 2, functionCrue)   As you can see, the code is simplified by intermediate variables which are used by subsequent Python statements. For exemple, the slope of the river alpha is first computed, then the height H is computed depending on the slope. Then the variable S is computed based on Zc and Zd, where Zc is computed depending on the height H.   When I define the function as a symbolic function, the current definition is more involved.   inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B'] formulas = ['(Q/(Ks*B*sqrt((Zm - Zv)/L)))^(3.0/5.0)','(Q/(Ks*B*sqrt((Zm - Zv)/L)))^(3.0/5.0)+Zv-(Zb + Hd)'] myFunction = SymbolicFunction(inputs, formulas)   As you can see, I cannot reuse the value of the first output into the second output.   The following interface would be much easier to use. The formulas variable is a list of couples, where the first item is the name of the output variable and the second item is the string to evaluate it.   inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B'] output1 = [‘alpha’, '(Zm - Zv)/L'] output2 = [‘H’, '(Q/(Ks*B*sqrt(alpha)))^(3.0/5.0)'] output3 = [‘Zc’, 'H + Zv'] output4 = [‘Zd’, 'Zb + Hd'] output5 = [‘S’, 'Zc - Zd'] formulas = [output1,output2,output3,output4,output5] myFunction = SymbolicFunction(inputs, formulas)   Is there another way of doing this ? Do you agree that the suggestion is worth being developed ?   Best regards,   Michaël Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse. Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message. Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus. ____________________________________________________ This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval. If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message. E-mail communication cannot be guaranteed to be timely secure, error or virus-free.
```_______________________________________________
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users