6
$\begingroup$

This question can not be typed easily, using mathematica stackexchange interface.

So here is a GIF file :

enter image description here

My question is : Can we construct a function f whose output is

f /@ {7/3, 7/3, 7/3} (* all symbols become slash symbols after copy and paste *)

{"Slash form", "MiddleBar form", "Divide form"}

?

enter image description here

For this (=the existence of such f) to be possible, there must be something stronger than built in Hold.

$\endgroup$
1
  • $\begingroup$ I think the question can be boiled down to "Why does Hold[7÷3] evaluate to Hold[7/3]? When does the conversion happen?" Interesting question. (+1) $\endgroup$
    – xzczd
    Mar 31, 2023 at 3:57

1 Answer 1

5
$\begingroup$

There is no f that could do this by itself because those forms are taken care of during parsing.

So by the time any evaluation rules associated with f take an effect there will be no trace of \[Divide] and only \ (or rather Times and Power).

Your input which is sent for evaluation is:

RowBox[{"{", 
  RowBox[{RowBox[{"7", "/", "3"}], ",", 
  FractionBox["7", "3"], ",", 
  RowBox[{"7", "\[Divide]", "3"}]}], 
"}"}]

but we can exercise on a simpler string:

FullForm @ MakeExpression["f[7\[Divide]3]", StandardForm ]

HoldComplete[f[Times[7, Power[3, -1]]]]

You can intercept parsing but that's a modification to an 'environment' rather than evaluation alone so you'd need to provide a specific use case in order to get a suited solution.

Here is one example of such enhancement:

{7/3, 7/3, 7/3} (* original cell with 2D typesetting *)
Internal`InheritedBlock[{MakeExpression}
, MakeExpression[RowBox[{n_, "/", d_}], fmt_] := HoldComplete["Slash form"]
; MakeExpression[RowBox[{n_, "\[Divide]", d_}], fmt_] := HoldComplete["Divide form"]
; MakeExpression[FractionBox[n_, d_], fmt_] := HoldComplete["MiddleBar form"]

; ToExpression @ NotebookRead[PreviousCell[]][[1, 1]]
]

{"Slash form", "MiddleBar form", "Divide form"}

$\endgroup$
1
  • $\begingroup$ I was preparing something to comment, but somehow I ran out of such things. Thank you for answering this difficult question! $\endgroup$
    – imida k
    Apr 1, 2023 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.