Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give solution constants of ODEs unique names #16007

Closed
rwst opened this issue Mar 25, 2014 · 59 comments
Closed

give solution constants of ODEs unique names #16007

rwst opened this issue Mar 25, 2014 · 59 comments

Comments

@rwst
Copy link

rwst commented Mar 25, 2014

(this was reported as part of #6882)

... solving of ode y'=c*x is not correct, the free variable is messed up with a parameter, see sage-devel - thanks for Yuri Karadzhov

sage: from sage.calculus.calculus import symbolic_expression_from_maxima_string
sage: symbolic_expression_from_maxima_string('%c')
c
sage: c=var('c'); y=function('y',x); eq=diff(y,x)==c*x; eq
D[0](y)(x) == c*x
sage: desolve(eq,y,ivar=x)
1/2*c*x^2 + c

the answer should be something like 1/2cx2 + c1

The fix depends on closing #8734. The c variable that comes from Sage can then be easily recognized, and the constant c should then be renamed to c1 or _C1.

Depends on #8734

CC: @kcrisman

Component: calculus

Author: Ralf Stephan

Branch: a8df107

Reviewer: Nils Bruin, Karl-Dieter Crisman

Issue created by migration from https://trac.sagemath.org/ticket/16007

@rwst rwst added this to the sage-6.2 milestone Mar 25, 2014
@nbruin
Copy link
Contributor

nbruin commented Mar 26, 2014

comment:2

Actually, these variables are very easy to recognize any way:

sage: function('f',x)
f(x)
sage: var('c')
c
sage: W=diff(f(x),x,x)-f(x)+c
sage: V=diff(f(x),x)-f(x)+c
sage: maxima_calculus(V).ode2(f(x),x)
'f(x)=(c*%e^-x+%c)*%e^x
sage: maxima_calculus(W).ode2(f(x),x)
'f(x)=%k1*%e^x+%k2*%e^-x+c

As you can see, maxima creates these constants as %c, %k1, %k2, so there's no collision there. The collision only happens upon conversion back to sage. So we make the conversion more intelligent there wouldn't be an issue at all. Using sage.interfaces.maxima_lib.max_to_sr this would be fairly straightforward.

@rwst
Copy link
Author

rwst commented Mar 26, 2014

Branch: u/rws/ticket/16007

@rwst
Copy link
Author

rwst commented Mar 26, 2014

comment:4

Indeed, many thanks. With this easy patch the output is now

sage: sage: x=function('x',t)
sage: sage: var('c')
c
sage: sage: desolve(diff(x,t)+2*x==t^2-2*t+c,x,ivar=t).expand()
1/2*t^2 + _C*e^(-2*t) + 1/2*c - 3/2*t + 3/4

sage: desolve(diff(f(x),x,x)-f(x),f(x))
_K2*e^(-x) + _K1*e^x

Any more variables?


New commits:

ee630f5add %c,%k1,%k2 to recognized maxima objects

@rwst
Copy link
Author

rwst commented Mar 26, 2014

Commit: ee630f5

@rwst
Copy link
Author

rwst commented Mar 26, 2014

Changed dependencies from #8734 to none

@rwst
Copy link
Author

rwst commented Mar 26, 2014

Author: Ralf Stephan

@zimmermann6
Copy link

comment:5

seems to be a duplicate of #9421.

Paul

@rwst
Copy link
Author

rwst commented Mar 27, 2014

comment:6

Yes. So, are you okay with this solution applied to #9421, instead of the warning? If so, then I will make a reviewer's patch there and invalid this ticket.

@zimmermann6
Copy link

comment:7

yes I agree with this solution, but I won't have time quite soon to check the doctests still pass.

Paul

@kcrisman
Copy link
Member

comment:8

It might be worth doing a few things. First, you must have documentation testing this fix - especially since people will be confused by underscore variables without some documentation! Also, how many different things can show up? Just c, k1, k2, or also c1 et al, or k3, ... ? It would be worth asking on the Maxima email list about what outputs can possibly happen (assuming it's working - I was at some point subscribed to the "new" version but now am apparently not again).

But I agree it's very unlikely for anyone to have an underscore variable, so this could be a good compromise... there remains the issue of substituting in for non-Sageified variables.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@rwst
Copy link
Author

rwst commented Jun 5, 2014

comment:11

Deleted misplaced comment.

@rwst
Copy link
Author

rwst commented Jun 6, 2014

comment:12

Maxima-discuss list mail:

On 05-06-2014 16:36, Ralf Stephan wrote:
>Sage uses Maxima to solve ODEs. To do that bug free we would
>need to know which constant vars apart from %c, %k1, %k2 are
>returned by Maxima. Can you please help?
looking at the source code of the programs in share/diffequations,
it seems to me that those 3 are the only ones. I don't know if you
have other programs in mind, apart from those in share/diffequations.

Regards,
Jaime

I take it then the ticket is complete for review.

@kcrisman
Copy link
Member

kcrisman commented Jun 6, 2014

comment:13

Thanks for doing that due diligence. Yes, I believe these only arise from a contrib package in Maxima.

I take it then the ticket is complete for review.

Well... see in comment:8

First, you must have documentation testing this fix - especially since people will be confused by underscore variables without some documentation!

It's really unfortunate with the underscores. But I hate to think of checking whether C, C1, C2 etc. were defined and then using whatever the next one was. Anyway, unless Nils (who knows this stuff better than me) objects to your solution (quoting #9421 comment:9)

(with the righter solution being: making sage's "forget the %" more intelligent, so that collisions can be avoided)

then as I said, this is definitely much better than leaving it 'as is'.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2014

Changed commit from ee630f5 to 630ea92

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2014

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

1e9b54b8734: more doctests fixed
06b95288734: fix doctests
6fffc21Merge branch 'develop' into t/8734/ticket/8734-1
3d74cad8734: rename private function, doctest it
3180e7bMerge branch 'develop' into t/8734/ticket/8734-1
cec96818734: merge conflicts
f702088take back unrelated change
2d31fb18734: doc cosmetics
100c8ebMerge branch 't/8734/ticket/8734-1' into t/16007/ticket/16007
630ea9216007: fix doctests; add documentation

@rwst
Copy link
Author

rwst commented Jun 7, 2014

comment:15

Merged in #8734. Thanks for the doctest reminder.

@kcrisman
Copy link
Member

kcrisman commented Jun 8, 2014

comment:16

Merged in #8734. Thanks for the doctest reminder.

No problem. Do you think it's useful to add an example where there might have otherwise been a collision of names, or is that superfluous?

Also, why is the doctest

sefms('%k1*%x + %k2*%y + %c')

and not

sefms('%k1*x + %k2*y + %c')

I'm not sure what the % is doing on the variables, though I don't doubt Sage would strip those percents off, if I recall that part of the code correctly (it's been a while, though).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

92a3fa316007: make doctest test intended case

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2014

Changed commit from 630ea92 to 92a3fa3

@rwst
Copy link
Author

rwst commented Jun 19, 2014

comment:35

Well, now there is a code point where the behaviour can be changed. So, again, is there anything missing?

@kcrisman
Copy link
Member

comment:36

though I don't know how one would typeset the underscore in any case.

Turns out it currently just keeps the underscore.

This change could minutely slow down latex for variables that start with underscores, or if the symtable gets huge... but that is probably silly to worry about for now, neither are likely in the near future. Also may help with #6882. So I'm happy with this commit.

So, again, is there anything missing?

Doctest (presumably just in latex_variable_name) for the latexing. I realize this seems like a lot of rounds, but I've found the review process very helpful in the past, anyway. (And I'm sorry I haven't time to check out the last commit of #8734 yet.)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 25, 2014

Changed commit from fe2a0f0 to 28a08aa

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 25, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

7918e73Merge branch 'develop' into t/16007/ticket/16007
28a08aa16007: doctest latexification; move author info to top

@rwst
Copy link
Author

rwst commented Jun 25, 2014

comment:38

Replying to @kcrisman:

So, again, is there anything missing?

Doctest (presumably just in latex_variable_name) for the latexing. I realize this seems like a lot of rounds, but I've found the review process very helpful in the past, anyway. (And I'm sorry I haven't time to check out the last commit of #8734 yet.)

I appreciate your thoroughness, and thanks for the review!

@kcrisman
Copy link
Member

comment:39

Okay, if doctests pass (currently attempting to build the branch but it will take a while) then I'm happy with this. Thanks for working on so many symbolics/calculus things recently.

@vbraun
Copy link
Member

vbraun commented Jun 26, 2014

comment:41

Doctests don't pass (try make ptestlong)

sage -t --long src/doc/en/tutorial/tour_algebra.rst
**********************************************************************
File "src/doc/en/tutorial/tour_algebra.rst", line 156, in doc.en.tutorial.tour_algebra
Failed example:
    desolve(DE, [x,t])
Expected:
    (c + e^t)*e^(-t)
Got:
    (_C + e^t)*e^(-t)
**********************************************************************

@kcrisman
Copy link
Member

comment:42

Nuts!!! I could have sworn I checked everything... and now I see why long tests on #8734 are taking so long too, I did make testlong and not make ptestlong. Very sorry about this.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2014

Changed commit from 28a08aa to 4add98a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

2c680268734: adapt doctest to recent change of output
793bb058734: reraise in "other" cases with bare "raise"
b5857b7Merge branch 'u/rws/ticket/8734-1' of trac.sagemath.org:sage into t/16007/ticket/16007
4add98a16007: fix documentation examples

@rwst
Copy link
Author

rwst commented Jun 26, 2014

comment:44

Not all of #8734 was merged. Sorry for the inconvenience.

@vbraun
Copy link
Member

vbraun commented Jun 26, 2014

comment:45

So has the code from #8734 been reviewed? If not make it a dependency here so I don't accidentally merge it.

@rwst
Copy link
Author

rwst commented Jun 26, 2014

Dependencies: #8734

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 2, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

6bfa305Merge branch 'develop' into t/16007/ticket/16007
a1959858734: remove superfluous code
67426e1Merge branch 'u/rws/ticket/8734-1' of trac.sagemath.org:sage into t/16007/ticket/16007

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 2, 2014

Changed commit from 4add98a to 67426e1

@kcrisman
Copy link
Member

kcrisman commented Jul 2, 2014

comment:48

I am not going to check whether this passes tests, but at any rate the changes most recent seem fine, although I don't know why the non-doctest pieces had to have the constant C instead of c (but I don't really care about that). So if anyone checks it passes tests we are good here, since #8734 is positive review.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2014

Changed commit from 67426e1 to a8df107

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

65107d4Merge branch 'develop' into t/8734/ticket/8734-1
4e073836882: add rules for e, i, I
e5a53436882: do word search/replace for symtable keys
4c1b0eb6882: correction to previous commit
518de3e6882: add symable rules for e,i,I; fix maxima_var; add doctests
7a6696bMerge branch 'u/rws/bugs_in_conversion_of_variable_names_from_maxima_to_sage' of trac.sagemath.org:sage into t/8734/ticket/8734-1
a8df107Merge branch 't/8734/ticket/8734-1' into t/16007/ticket/16007

@rwst
Copy link
Author

rwst commented Jul 3, 2014

comment:50

Thanks. Pulled in changes from dependencies. I'll run a patchbot on this now.

@vbraun
Copy link
Member

vbraun commented Jul 8, 2014

Changed branch from u/rws/ticket/16007 to a8df107

@fchapoton
Copy link
Contributor

Changed commit from a8df107 to none

@fchapoton

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants