2

For example like so.

x = 10;
xi = 11;
xv = 15;

Is there an automated way to spit these numbers out maybe 1-1000.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
William
  • 7,595
  • 2
  • 22
  • 70

2 Answers2

4

I advise against

The reasons I will say it is "poor advice to assign roman numerals as top variables", is that it forces you to name the variable through strings operations, you end up with meaningless variable names (hard to debug) and in a functional programming language like Mathematica, you should be avoiding variables anyhow.

String variables

In this answer Leonid Shifrin writes

Using strings and subsequently ToString - ToExpression just to generate variable names is pretty much unacceptable, or at the very least should be the last thing you try. I don't know of a single case where this couldn't be replaced with a better solution. [...] The general [reason] is that they lead us outside of the symbolic world, and involve parsing, which is bad both for performance reasons and also just because one should avoid parsing as much as possible (for example, it may be unsafe).

Meaningless variable names

The idea of using roman numerals for variables suggests there will be many variables following that pattern. If what you need is indexed variables, there are other better solutions. Otherwise, these will be just meaningless variable names, which only hinder you and other people trying to understand the code.

Lingering definitions

I think it would be better to exploit the functional style of Mathematica and avoid leaving lingering variable definitions. See this question about keeping the kernel clean.

rhermans
  • 36,518
  • 4
  • 57
  • 149
3

RomanNumeral will produce roman numeral representation for a given integer as a string. So, you could do something like Symbol[RomanNumeral[6]] or Symbol[ToLowerCase@RomanNumeral[6]]. Whether this is a good idea depends on context. My initial knee jerk reaction is that, no, it's not a good idea, but there may be a context in which it makes sense.

lericr
  • 27,668
  • 1
  • 18
  • 64