<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace">Dear Dr. Kisil</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Thank you for your answer I'll carefully read.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Pr. C. Prud'homme has hacked our GiNaC fork to let people use this kind of expression.</div><div class="gmail_default" style><font face="courier new, monospace"><a href="https://github.com/feelpp/feelpp/commit/547c08b66e5b6019ab258477ab19a329cdf4138a">https://github.com/feelpp/feelpp/commit/547c08b66e5b6019ab258477ab19a329cdf4138a</a></font><br></div><div class="gmail_default" style><font face="courier new, monospace"><br></font></div><div class="gmail_default" style><font face="courier new, monospace">Now, the one that parse the string </font></div><div class="gmail_default" style><font face="courier new, monospace">"(x<0.5)*1000+(x>0.5)*10:x:y"</font></div><div class="gmail_default" style><font face="courier new, monospace">will find in the source file: </font></div><div class="gmail_default" style><font face="courier new, monospace">f[0] = 10.0*(a[0]>5.0000000000000000e-01)+1000.0*(a[0]<5.0000000000000000e-01);</font></div><div class="gmail_default" style><font face="courier new, monospace"><br></font></div><div class="gmail_default" style><font face="courier new, monospace">Thank again for your quick answer !</font></div><div class="gmail_default" style><font face="courier new, monospace"><br></font></div><div class="gmail_default" style><font face="courier new, monospace">All the best,</font></div><div class="gmail_default" style><font face="courier new, monospace"><br></font></div><div class="gmail_default" style><font face="courier new, monospace">VH</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-22 18:50 GMT+02:00 Vladimir V. Kisil <span dir="ltr"><<a href="mailto:kisilv@maths.leeds.ac.uk" target="_blank">kisilv@maths.leeds.ac.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Dear Vincent,<br>
<br>
You are right that GiNaC expression do not admit boolean<br>
terms directly. However with your example you can proceed as follow (I<br>
do understand that your actual target is much more complicated):<br>
<br>
1. Use the step function from GiNaC:<br>
<br>
f=2*x*step(x)+3*x*step(-x).<br>
<br>
[but for x=0 you need take care as step(0)=.5]<br>
<br>
Of course, if you have a hundred points where the function changes the<br>
expression, this becomes much more complicated<br>
<br>
2. Define your own function of three variables S(a,b,x) such that<br>
S(a,b,x)=1 for a<x<b and zero otherwise. GiNaC tutorial<br>
contains a demonstration how make a user-defined function. Then, any<br>
piece-wise function F will be a sum of terms f_i(x)*S(a_i,_b_i,x)<br>
where f_i is the expression for F on [a_i,b_i] (assuming disjoint<br>
partition.<br>
<br>
3. Finally, you may derive your own class from GiNaC::basic to hold<br>
your piece-wise function (again, GiNaC tutorial gives an example). As<br>
I see it shall have two lists: one with points of the partition,<br>
another with the respective expression. Then you add your custom<br>
methods to operate this class.<br>
<br>
<br>
The approaches are given in the order of increasing complexity, but<br>
the efficiently shall grow in the same direction.<br>
<br>
Best wishes,<br>
Vladimir<br>
--<br>
Vladimir V. Kisil <a href="http://www.maths.leeds.ac.uk/~kisilv/" target="_blank">http://www.maths.leeds.ac.uk/~kisilv/</a><br>
Book: Geometry of Mobius Transformations <a href="http://goo.gl/EaG2Vu" target="_blank">http://goo.gl/EaG2Vu</a><br>
Software: Geometry of cycles <a href="http://moebinv.sourceforge.net/" target="_blank">http://moebinv.sourceforge.net/</a><br>
>>>>> On Wed, 22 Apr 2015 16:47:13 +0200, Vincent Huber <<a href="mailto:vincent.huber@cemosis.fr">vincent.huber@cemosis.fr</a>> said:<br>
<br>
VH> Hello Dr. Kisil,<br>
<br>
VH> The question from C. Trophime is not about evaluating the<br>
VH> function but to define it. Feel++ <<a href="http://www.feelpp.org" target="_blank">http://www.feelpp.org</a>> is a<br>
VH> Finite Element library that main goal is to solve the<br>
VH> variational problem a(u,v)=f(v) that arises from a lot of<br>
VH> physical problems.<br>
<br>
VH> We use GiNaC to dynamically define the right hand side of our<br>
VH> problem, or our boundaries conditions and whatever can be<br>
VH> expressed with it.<br>
<br>
VH> The question - I guess - can be explained like that : I would<br>
VH> like to define<br>
<br>
VH> -<br>
<br>
VH> f(x) = 2*x if x>0 -<br>
<br>
VH> f(x) = 3*x if x<=0.<br>
<br>
VH> Thus, basically, I would like to write<br>
<br>
<br>
VH> ex MyEx = (x<=0)?3*x:2*x<br>
<br>
VH> To my best knowledge, boolean expression are not handled in<br>
VH> GiNaC, isn’t it ?<br>
<br>
VH> all the best,<br>
<br>
VH> Vincent H. -- Docteur Ingénieur de recherche CeMoSiS<br>
VH> <<a href="http://www.cemosis.fr" target="_blank">http://www.cemosis.fr</a>> - <a href="mailto:vincent.huber@cemosis.fr">vincent.huber@cemosis.fr</a> Tel: +33 (0)3<br>
VH> 68 8*5 02 06* IRMA - 7, rue René Descartes 67 000 Strasbourg<br>
<br>
VH> ----------------------------------------------------<br>
VH> Alternatives:<br>
<br>
VH> ----------------------------------------------------<br>
VH> _______________________________________________ GiNaC-list<br>
VH> mailing list <a href="mailto:GiNaC-list@ginac.de">GiNaC-list@ginac.de</a><br>
VH> <a href="https://www.cebix.net/mailman/listinfo/ginac-list" target="_blank">https://www.cebix.net/mailman/listinfo/ginac-list</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><font face="courier new, monospace">Docteur Ingénieur de recherche</font><div><font face="courier new, monospace"><a href="http://www.cemosis.fr" target="_blank">CeMoSiS</a> - <a href="mailto:vincent.huber@cemosis.fr" target="_blank">vincent.huber@cemosis.fr</a></font></div><div><font face="courier new, monospace">Tel: +33 (0)3 68 8<b>5 02 06</b></font></div><div><font face="courier new, monospace">IRMA - 7, rue René Descartes</font></div><div><font face="courier new, monospace">67 000 Strasbourg</font></div><div><br></div><div><img src="http://www.google.com/a/cpanel/cemosis.fr/images/logo.gif"></div></div></div>
</div>