Ask Your Question
4

How to magically define variables and use functional notation instead of methods

asked 2011-05-21 23:55:46 +0200

kcrisman gravatar image

I am always too lazy to look up again where it is that one can do these things. Not that I would ever use such dangerous things myself.

  • Magically define variables (so that you don't have to var('y'))
  • Magically define functions (so that one doesn't need boof.annoying_method(), but instead can do annoying_method(boof))

Once it's on here, people can find it more easily and put themselves in more danger.

edit retag flag offensive close merge delete

Comments

There is a rather old sage-devel discussion talking about implicit symbolic variable creation (http://groups.google.com/group/sage-devel/browse_thread/thread/f1286e92d4d2ce83/bfc0b357f3635435). But I don't think this exists in Sage, currently.

Kelvin Li gravatar imageKelvin Li ( 2011-05-22 02:18:27 +0200 )edit

Why would one do those things? Methods are certainly easier to find (tab completion) than functions, and they don't pollute the name space. And why should anything become a symbolic variable that isn't up a tree by the count of three?

Simon King gravatar imageSimon King ( 2011-05-22 14:45:26 +0200 )edit

@Simon King - you betray your programming prowess with that question :) I agree that in the long run, it is better to do this; however, for people who have never used any command-line interface, both of these things are serious stumbling blocks. Methods aren't always easy to find, either, and pollution of the name space is in the eye of the beholder. That said, notice I say "put themselves in more danger."

kcrisman gravatar imagekcrisman ( 2011-05-23 09:05:20 +0200 )edit

@Kelvin Li - This does definitely exist, I just have forgotten what it is. Also, the thread above speaks to Simon's question, since it points out that math-specific programming languages tend to have these pre-defined - not that we should necessarily, but that it's a non-obvious question. I sure hope someone remembers this answer!

kcrisman gravatar imagekcrisman ( 2011-05-23 09:07:43 +0200 )edit

I'm not sure I understand your question. Are you talking about pre-defining things you might want to use; for example, in your init.sage file? If you're not, I don't know what you mean, since Python will complain about any symbol it doesn't recognize, and I don't believe there is a way to change that. (I could be wrong, though.)

Jason Bandlow gravatar imageJason Bandlow ( 2011-05-23 10:46:47 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2011-05-23 17:31:32 +0200

It looks like it is only implemented in the notebook: execute automatic_names(True). (See #7482 for the relevant ticket.)

edit flag offensive delete link more

Comments

I knew I could count on you! See http://www.sagemath.org/doc/reference/sagenb/misc/support.html as well for doc. Thanks - in retrospect, should have been obvious, but I was hung up on the word 'magic'...

kcrisman gravatar imagekcrisman ( 2011-05-23 21:47:09 +0200 )edit
1

answered 2011-05-23 17:43:49 +0200

Shashank gravatar image

I have a related question. Would it be possible to have variables with bars on them Something like this

rhobar=var('\bar{rho}')

Each time I use bar I cannot copy paste the latex output in my paper/document.

edit flag offensive delete link more

Comments

Your question should not be listed as an "answer" to the question on this page. Anyway: "var('rhobar', latex_name='\\bar{\\rho}')" does what you want, as does "var('rhobar', latex_name=r'\bar{\rho}')"

John Palmieri gravatar imageJohn Palmieri ( 2011-05-23 18:41:58 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-05-21 23:55:46 +0200

Seen: 946 times

Last updated: May 23 '11