On Monday, May 23, 2016 at 6:11:55 PM UTC-7, paulmasson wrote:
>
> With all due deference to the work that went into making piecewise 
> functions symbolic, it's too much overhead for purely numerical 
> applications, as for example WKB approximations. Here's some sample code 
> <http://sagecell.sagemath.org/?z=eJzFVW1vmzAQ_l6p_-GkfYhJnAKGduskpP2PKIkc4jBrBIhtknS_fmeHt6aoard14wvGfu65u-fOx1bsQBDgFArwvt7eAChhalUAAX1QhlTSZx74wFYk9LkHU8j4fs_txyy6HPUboT0nxSy0B96KAJtyn_CZ_bq9ub3ZorMDgTMd8cc3mpy9FYc5MGQRhNPCGeVcG0ggsOtvsjBC8dRcuNYYeEIYJQENA89zhJZyAANogNpwIxItcpGaUpEFmlBGIxrTe_pAP9Mv9HFJEcvr3CTWZ08HkOXlhudgty8bTVCOtAW5NBIUro3fnTohrHQt7BNUUqTiJLXA3A-1VEKDftpvylymsKuL1Miy0MA1yKKqTWtn81Aiw7MQsxH5jlohp9Mfp61upLTPkSsyqSde-41SYFBFvRdKpjxfW2kyxfOmvliPmvahOs65y8RbBMuWpKlRz8KrSpVnAmQeeitnjDk3DWOb4EDOHesKQX7cBdQ_2CuAPYRvG6ST6cEac6me1lyS62PmRxgieC8VYX9Tkfm1JE4P5P4zSRzxmQ7b4nd1mb9ZmOhDhUHSt7fK_5Yi_shb864O-df3pB0uIabUzhcy6XYnOIu5ynQSUhBHnu_WFpQ0s8Z7zsFGOdirHOyKIxrliF7liK444lGO-FWOuFOkqLeZQIa7IAhxIJsSi7UvjwKqMsdpzI0rqCwy3EBRdWt34kdr1g1wAgto67XA8t3dT10nuIkxd16wOTql8QcHSzowsLCZg9FgAGQW-AwZ0FHG6JpxQNgGM4DHDn5BL_v-qPLSaJsWvonLEWdelwv0q53MtPwpkkVM2ZJCWualSjC2u3saohtrv74IloQBfdnI3fO0l0WCLh4pLvk5wRV4w2BmbTTDC-Kzy-9pLLQ3-x7PIaQBVmBwZb6XJ9LEgpu_ACkxe4w=&lang=sage>
>  
> for a uniform approximation to a wavefunction in a power potential 
> constructing symbolic functions from numeric functions, and here's the 
> equivalent code 
> <http://sagecell.sagemath.org/?z=eJzFVF1v2jAUfUfiP1xpD7XhhsQGunVSpP0PBMgFN7MUEnCcju7X79pJCO3YRNeq80v8cc-559zreKsfQDNQCAXwr8MBgNWutgUwqA7Wsb2JJYcY5IqJWHEYQaZ2O-UX42lz1G8If86KsfAHfMVAjlTM1NivhoPhYEvJDgyOeCGfuq_Yka8URCCJRTOFRQDlqnKQQuLn30zhtFUb13CtSXjKJLIERcJ5IPSUZ2EAbWDllNNppXO9caVlC4KgxCnOcI63-Bm_4N0SKVbVuUt9zp4OIMvLe5WD3242WlGBtAsKNlIqXKc_nIZC-NJ1YV6P1ZkpC0GlaIvgx6Oy7Ka-4d2aTBBdUe-0NRuVr72pzKq87QxVssY-CfqyRkEDXyTLjuTUTRYJvgrBpK5trW_XgR1PLCsKimcnAf2grgJ1m75eVDB068HK2Ke1MuzlsYynJAkueJZv8xy9NB0co-d8jelAdMTzFv2r8-hq69N3tk79_nO7_7fZ2fve7b92-aNvc1FvM03yJ0ki4BO4kqTsykcN-zLXFSgX5Joiow2iqDpcuXdUmYqQW7Mhkw8mq8xPnS5mKJcImzIvbUpv2WSOgjzv89KtG4ZUJPi7j9N42pkijcTkDmmqjinNerWexuf0X9a9PPTjiMl81JQ1_ENRcIUwGnUy-Tl-_JxAtqhxi0quBU5D7OsTzhpQl68X_wx-keD8TsSyeSd7fD-7ut6X-yYwweTsllTfyx-s1UKbvwCI9enS&lang=sage>
>  
> without using piecewise and just plotting the numeric functions.
>
> The code without symbolic functions is expected to be faster, but it 
> really is a lot faster. Wouldn't it make sense to have an option to avoid 
> symbolic functions in some way? Maybe define a numerical_piecewise function 


If you want to do numerical work, you should probably stick to the 
scipy/numpy framework. "numerical functions" there are usually callables. 
There's no need to involve symbolic functions at all. If you're finding a 
"numerical_piecewise" is useful for you, go ahead, but since you can write 
if/then/else constructions in a python function anyway, I don't expect it 
will give you much advantages to abstract that away.

Sage does provide a framework to go from symbolic and polynomial 
expressions (which are represented in a way such that certain mathematical 
properties of the functions are recognizable to the system) to black-box 
functions that can be used for fast evaluation at points via 
"fast_callable". If you have a mathematical expression (possibly 
symbolically derived) that you subsequently want to use for numerical work, 
making a callable out of it via "fast_callable" might be a good idea. It 
basically converts the expression into a straight-line program for 
evaluation.

If you're finding yourself in a scenario where you're often getting 
symbolic piecewise functions that you want to use numerically, then you 
could benefit from making "fast_callable" aware of piecewise functions and 
have it produce efficient code to handle them numerically. That could be an 
interesting project.
 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to