OŠ @ Jednoocí on 1/6/2016 Computer systems en.wikipedia.org/wiki/List_of_computer_algebra_systems

“symbolic math” | | symbolic computation | algebraic computation • Algebra: substitutions, simplification, special functions,39 … •NotesCalculus: on , groundwater , limits, dating series with expansions,Ar … •OndSolvingřej Šrámek, algebraic/differential Charles University in Prague, [email protected] December 23, 2015

Maple1WorkbyYokochi et al. (2012) www.maplesoft.com/products/maple/ MapleYokochi 2015 et al. Student(2012)proposeusing Edition … $12639Ar/40Ar⇤ as a chronometer of fluid migration and fluid–rock interac- Mapletion in 2015 the Earth’s Academic crust, … applicable $1560 to a much broader age range than simply using decay of the original atmospheric 39Ar. The picture in time: see Figure 1.Atfirstsight,Ifoundtheirmathabitunclear,esp.thetimedependenceof Maplethe various Example concentrations, so went through it in detail. One deals with a decay law for N with a production term P : dN = N + P, (1) dt whose from t =0to t = tf with initial condition N(0) = N0 and assuming constant P is

P t t N(t )= 1 e f + N e f . (2) f 0

39 40 ⇤ 39 Their model is a repeated application of (1–2), where N can be ArR or ArR (in the rock) or ArF or restart;40 ⇤ ArF (in the fluid) at various times tR (duration of Ar accumulation in rock) or tL (Ar loss from rock) or tF 39 39 40 40 ode(Ar gain:= bydiff(N(t),t) fluid), and P is P=( -lambda*N(t)Ar production in rock) + P; or KR40Y40 ( Ar⇤ production in rock). Their 3 dsolve({ode,concentrations and productionN(0)=0}); rates are per volume (cm )ofrockoroffluid. simplify(%); SymPy Python library for symbolic mathematics www.sympy.org live.sympy.org The lead developers are Ondřej Čertík and Aaron Maurer (wiki)

39 39 SymPyFigure 1: AnTutorial underground reservoir rock accumulates argon over a period tR.Both Ar ( K(n, p))and 40 40 docs.sympy.org/latest/tutorial/Ar⇤ (EC on K) are producedin the rock. Then the rock start to lose Ar and has done so for a period tL.ThefluidhasbeengainingthelostAroveraperiodtF.WhiletherocklosesArovertL,thefluidmay be migrating, therefore tF can be shorter than tL. symbols() () Eq() Matrix() ImmutableMatrix() () Rational() sympify() 39 39 .subs(,)Accumulation .evalf() of Arlambdify() in rock: .equals()ArR is produced with rate P while decays with decay rate 39. Inte- 39 simplify()grating in time expand() from 0 to factor()tR, with collect(,)ArR =0 initial coeff(,) condition cancel() (not necessarily apart() truetrigsimp() but irrelevant after few half-lives), one gets their eqn. 3 (hereafter eqn. Y3). Eqn. Y4 for 40Ar⇤ production rate holds at any time t, expand_trig() powsimp() expand_power_exp()40 expand_power_base() powdenest() expand_log()not just tR.Eqn.Y5givesthenumberof logcombine() (n)Ar ⇤ binomial(n,k)atoms produced gamma(z) over time period hyper(...)tR and depends .rewrite() on the final 40Kconcentration—butthisissubsequentlyassumedconstantoverthetimeperiodsinvolved. expand_func() hyperexpand() combsimp() list_to_frac([]) diff(,)Loss of .diff(,) Ar from () rock: Assumes .doit() that rockintegrate(,(,,)) loses Ar to fluid Integral() with a rate (,,) constant ↵ (and a corresponding Limit()“half-life”), .series(,,) i.e., the same .removeO() “decay law” as_finite_diff(,) as in radioactivity. finite_diff_weights(,,) Described by eqns. Y6–Y7. apply_finite_diff(,,,) The whole story of microstructure, connectivity is hidden in ↵. It is assumed that ↵ ,i.e.,theradiogeniclife-timeof39Ar solve(,) roots() dsolve(,) ⌧ 39 is much shorter than the Ar loss life-time. Eqn. Y6 integrates from t =0to t = tL with initial condition Matrix()39 39 ImmutableMatrix() .shape .row() .col() row_del() 40 col_del()⇤ 40 row_insert()⇤ ArR = ArR(tR) to eqn. Y10. Similarly eqn. Y7 with initial condition ArR = ArR(tR) integrates to col_insert()eqn. Y11. .T eye() zeros() ones() diag() .det() .rref() .nullspace() .eigenvals() .eigenvects() .diagonalize() .charpoly() Gain of Ar by fluid: It is assumed that the Ar lost from rock enters the fluid, which is expressed by besslj(,).rewrite()eqns. Y8–Y9. The full porosity factors (1 )/ are simplified as 1/ which is only valid for small . R R R R

1 OŠ @ Jednoocí on 1/6/2016 str() srepr() pprint() pretty() () print_mathml() dotprint()

SymPy Example… from sympy import init_session init_session() N = Function(’N’) t, P, lamda = symbols(’t P lamda’) ode = Eq(N(t).diff(t), P - lamda*N(t)) ode dsolve(ode, N(t), ics = {N(0):0})

Ha! SymPy cannot solve an ODE with ICs…??