Nell’iperspazio con Rocket: il Framework Web di Rust!
Main
1. All-In-One Scientific Research With SageTEX
Hsin-Yu Ko
National Taiwan University
June 9, 2012
1/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
1/7
2. Concept of WEB
1
WEB is Not WWW
• Coding And Documenting
Simultaneously
• CWEB, CWEAVE,
FortranWEB. . .
• Generate foo.o and foo.dvi. . .
• Text/TeX + C/Fortran. . .
1
Knuth, Donald E. (1992). Literate Programming. 2/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
2/7
3. Why Do We Need WEB?
Famous proverb goes,
“Read The Friendly Manual!!”
– Anonymous Hacker
It is much easier to have manual in hand before jumping into
source codes, and so does SCIENCE. Here’s an example
Listing 1: bad_example.py
d e f I n t e r f e r e n c e ( w1 , w2 ) :
i m p o r t numpy a s np ;
x=np . a r a n g e ( 0 , 2 ∗ np . p i , 0 . 1 ) ;
p s i=np . e x p (−x ) ;
p s i ∗=(np . s i n ( w1∗ x)+np . s i n ( w2∗ x ) ) ;
return psi ;
print ( Interference (1.2 ,3.0))
3/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
3/7
4. Better Example
• Commenting, a fairly good solution to simple cases
Listing 2: good_example.py
d e f I n t e r f e r e n c e ( w1 , w2 ) :
"""
This code i s w r i t e n to i n v e s t i g a t e
t h e i n t e r f e r e n c e o f s i n e waves w i t h
a n g u l a r f r e q u e n c y w1 and w2 .
Attanuating with unit length
"""
i m p o r t numpy a s np ;
# A look at the region [0 ,2∗ pi ]
x=np . a r a n g e ( 0 , 2 ∗ np . p i , 0 . 1 ) ;
# Wave a t t a n u a t i o n
p s i=np . e x p (−x ) ;
# Wave s u p e r p o s i t i o n p r i n c e p l e
p s i ∗=(np . s i n ( w1∗ x)+np . s i n ( w2∗ x ) ) ;
return psi ;
# An e x a m p l e on s i n ( 1 . 2 x ) and s i n ( 3 x )
print ( Interference (1.2 ,3.0))
4/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
4/7
5. Scientist Want Further Type-Setting
A
What About Using Type Setting of LTEX?
A
Listing 3: LTEX_example.py
documentclass { a r t i c l e }
usepackage { sagetex }
b e g i n { document }
We u s e $ e ^ x $ a s a t t a n u a t i o n o f waves .
begin { sageblock }
i m p o r t numpy a s np
y=np . a r a n g e ( 0 , 2 ∗ p i , 0 . 2 )
f ( x)= e x p (−x ) ∗ ( s i n ( 1 . 2 ∗ x)+ s i n ( 3 ∗ x ) )
end { s a g e b l o c k }
I n t e r f e r e n c e mapping i s [ s a g e { f } . ]
And R e c e i v i n g
[ f ( y )= s a g e { [ r o u n d ( f ( i ) , 2 ) f o r i i n y ] } ]
D i r e c t p l o t i n g t h e r e s u l t
sageplot { plot ( f ,(0 ,2∗ pi ))}
end { document }
Switch to see result at here
5/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
5/7
6. What Is/Why Sage??
• Python-Based/Compatible
• Integrated Math and Scientific Interface
• Free and Powerful
◦ Numpy and Scipy
◦ Maxima
◦ R
◦ Jmol
◦ GAP
◦ Singular
◦ Axiom
◦ GP
• LTEXCompatible
A
• Demos
6/
Hsin-Yu Ko kosinyj@gmail.com PyCon Taiwan 2012 7
6/7