factorial to OutputForm

5 views
Skip to first unread message

Ralf Hemmecke

unread,
May 18, 2024, 3:21:31 PM5/18/24
to fricas-devel
Hmmmm, am somehow unable to find where the transformation to the
SExpression below happens. Does that have to do with '%specialDisp?
But even then I could not find a special treatment for 'factorial.

Background of this question.
I actually wanted to tweak Format1D locally so that it prints
factorial(a) instead of a!. But obviously ´'factorial is not a known
operator for OutputForm, so it is basically impossible to output
factorial differently.

Ralf

%%% (511) -> fa := factorial a

(511) a!
Type: Expression(Integer)

%%% (517) -> kfa := kernels(fa).1

(517) a!
Type: Kernel(Expression(Integer))

%%% (519) -> (kfa::OutputForm) pretend SExpression

(519) (CONCAT a !)
Type: SExpression

Waldek Hebisch

unread,
May 18, 2024, 4:33:19 PM5/18/24
to fricas...@googlegroups.com
On Sat, May 18, 2024 at 09:21:27PM +0200, Ralf Hemmecke wrote:
> Hmmmm, am somehow unable to find where the transformation to the SExpression
> below happens. Does that have to do with '%specialDisp?
> But even then I could not find a special treatment for 'factorial.

This is regular '%display' property, set in BasicOperator.

> Background of this question.
> I actually wanted to tweak Format1D locally so that it prints
> factorial(a) instead of a!. But obviously ´'factorial is not a known
> operator for OutputForm, so it is basically impossible to output factorial
> differently.

'display' will set '%display' property to value that you give.
But this value will affect translation to OutputForm, so all
formatters.

--
Waldek Hebisch

Ralf Hemmecke

unread,
May 18, 2024, 5:32:48 PM5/18/24
to fricas...@googlegroups.com
> This is regular '%display' property, set in BasicOperator.

Ah. Cool.
And just for reference...

The property is defined in op.spad like this.

dfact x == postfix("!"::Symbol::O, (ATOM(x)$Lisp => x; paren x))

The following code will then print "factorial(n)" as factorial(n).


newdfact(x:OF):OF == prefix("factorial"::Symbol,[x])
fa := factorial(n)
k := kernels(fa).1
op := operator k -- this is the factorial BasicOperator
display(op, newdfact)

> 'display' will set '%display' property to value that you give. But
> this value will affect translation to OutputForm, so all formatters.

Yes. But if one wants to achieve something locally, other parts maybe
uninteresting.

Thank you for your help.

Ralf













Reply all
Reply to author
Forward
0 new messages