Ask Your Question
1

Print (input/)output numbers

asked 2020-05-24 18:06:12 +0100

jbirnick gravatar image

updated 2020-05-24 18:17:45 +0100

Hey,

when I use the sage it looks like this:

sage: factor(100)
2^2 * 5^2

sage: kronecker_symbol(3,5)
-1

sage: %hist
factor(100)
kronecker_symbol(3,5)
%hist

How can I get sage to look like this: (?)

sage: factor(100)
_1 = 2^2 * 5^2

sage: kronecker_symbol(3,5)
_2 = -1

sage: %hist
1: factor(100)
2: kronecker_symbol(3,5)
3: %hist

And can i edit the prompt to view the input number? I.e. to look like

sage[2]: kronecker_symbol(3,5)

If somebody has an idea please let me know.

Thanks a lot!

edit retag flag offensive close merge delete

Comments

Does the following post answers your question ? https://ask.sagemath.org/question/510...

tmonteil gravatar imagetmonteil ( 2020-05-24 18:23:03 +0100 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2020-05-24 18:47:08 +0100

vdelecroix gravatar image

updated 2020-05-24 18:47:31 +0100

These are really two distinct questions. The IPython history can be printed with line numbers. This is the option -n

sage: %hist -n
1: %hist -n

To see all available option, do in the sage console %history?.

Secondly, to customize the prompt you should write your own Promptsclass. This is documented at https://ipython.readthedocs.io/en/sta... (I also found the code of IPython useful https://github.com/ipython/ipython/bl...)

sage: ip = get_ipython()
sage: from IPython.terminal.prompts import Prompts, Token
sage: import os
sage: class MyPrompts(Prompts):
....:      def in_prompt_tokens(self):
....:            return [(Token.InPrompt, 'sage['),
....:                    (Token.PromptNum, str(self.shell.execution_count)),
....:                    (Token.InPrompt, ']: ')]
....:      def continuation_prompt_tokens(self, width=None):
....:          if width is None:
....:              width = self._width()
....:          return [(Token.Prompt, '.' * (width-2) + ': ')]
....:      def out_prompt_tokens(self):
....:           return [(Token.OutPrompt, '_'),
....:                   (Token.OutPromptNum, str(self.shell.execution_count)),
....:                   (Token.OutPrompt, ' = ')]
sage: ip.prompts = MyPrompts(ip)
sage[6]: 1+3
_6 = 4
sage[7]: 5+5
_7 = 10
edit flag offensive delete link more

Comments

Thank you! Too bad that there is no easier solution.

jbirnick gravatar imagejbirnick ( 2020-05-24 23:33:45 +0100 )edit

You can put that non easy solution inside the file ~/.sage/init.sage located in the dot sage folder usually located in your home directory to get it automatically setup when you start sage.

Sébastien gravatar imageSébastien ( 2020-05-25 12:34:19 +0100 )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

1 follower

Stats

Asked: 2020-05-24 18:06:12 +0100

Seen: 591 times

Last updated: May 24 '20