Opened 15 years ago

Closed 12 years ago

# [with patch, positive review] implement at for symbolics

Reported by: Owned by: was gfurnish major sage-4.2.1 calculus jason, burcin, was, mhansen sage-4.2.1.alpha0 Karl-Dieter Crisman David Joyner

### Description

```On 6/7/07, Randy LeVeque <rjl@amath.washington.edu> wrote:
> By the way, I'm just trying to figure out how sage does Taylor series.
> Maybe you can pass this on to whoever the best person is to chat with about
> this...
>
> In maple I can do things like
>
> > mtaylor(u(x+h,t+k),[h,k],3);
>                                                                      2
> u(x, t) + D[1](u)(x, t) h + D[2](u)(x, t) k + 1/2 D[1, 1](u)(x, t) h
>
>                                                      2
>       + h D[1, 2](u)(x, t) k + 1/2 D[2, 2](u)(x, t) k
>
>
> which is very convenient for numerical analysis when computing truncation
> errors of finite difference methods (h and k are mesh widths in space and
> time).  In sage a general expansion of this sort doesn't seem possible even
> in a single variable, e.g.,
>
> sage: taylor(u(x+h),h,0,4)
> x + h
>
> Apparently an undefined function like u(x) is taken to be the identity map?

To define a formal function, do u = function('u').  Then

sage: u = function('u')
sage: u(x + h)
u(x + h)
sage: diff(u(x+h), x)
diff(u(x + h), x, 1)

To get the Taylor expansion you would do this:

sage: taylor(u(x+h),h,0,4)

-- however -- this currently doesn't work in SAGE since we hadn't considered
doing this yet.   What happens is Maxima does the computation and outputs
the following expression:

'u(x)+(?%at('diff('u(x+h),h,1),h=0))*h+(?%at('diff('u(x+h),h,2),h=0))*h^2/2+(?%at('diff('u(x+h),h,3),h=0))*h^3/6+(?%at('diff('u(x+h),h,4),h=0))*h^4/24

SAGE doesn't know yet how to parse the "at" function, so you get
an error -- it will have to be added.   [Note that I don't necessarily consider
maxima the ultimate underlying engine for SAGE's symbolic computation
capabilities -- but it does provide a very quick way for SAGE to have
a powerful symbolic system for which a lot of subtle bugs have
already been fixed (over the last 40 years of Maxima development). ]

Definitely point out lots of things like this in your talk at SD4!

-- William
```

### comment:1 Changed 14 years ago by mabshoff

• Milestone set to sage-2.9.1

### comment:2 Changed 14 years ago by gfurnish

• Owner changed from was to gfurnish
• Status changed from new to assigned

### comment:3 Changed 13 years ago by AlexGhitza

• Type changed from defect to enhancement

### comment:4 Changed 12 years ago by kcrisman

This would also resolve #3914.

### comment:5 Changed 12 years ago by kcrisman

• Authors set to Karl-Dieter Crisman
• Cc jason burcin was mhansen added
• Status changed from new to needs_review
• Summary changed from implement at for symbolics to [with patch, needs review] implement at for symbolics

Try this patch. It should do the trick. Notice that I do not make it a normal symbolic function like in functions/other.py or something, because it's only for use here for now. If necessary, I could do that, though - it's a nice second way to do things instead of .subs(), so I could also import it globally if appropriate. I put in doctests for this, #3914, and a direct call.

### Changed 12 years ago by kcrisman

Based on 4.1.2.alpha4

### comment:7 in reply to: ↑ 6 Changed 12 years ago by kcrisman

It must have gotten lost somewhere during the latest Trac outage. This should work now.

### comment:8 Changed 12 years ago by wdj

• Status changed from needs_review to positive_review
• Summary changed from [with patch, needs review] implement at for symbolics to [with patch, positive review] implement at for symbolics

Passes sage -testall and does what it claims. Adds some very very useful functionality.

### comment:9 Changed 12 years ago by mhansen

• Merged in set to sage-4.2.1.alpha0
• Resolution set to fixed
• Reviewers set to David Joyner
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.