# How to define a named constant with evaluation rules similar to GoldenRatio?

I want to define a named constant standing for a more complicated symbolic expression, for example, PlasticConstant for the plastic constant:

((9 - √69)^(1/3) + (9 + √69)^(1/3))/(2^(1/3) 3^(2/3))


and I want it to have evaluation rules similar to GoldenRatio:

• it remains in its named form during normal evaluation (so, simple Set does not solve my problem);
• it can be numerically evaluated to an arbitrary precision using N;
• it can be converted to the underlying expression in radicals by FunctionExpand, can be converted to a Root object by RootReduce;
• FullSimplify is able to replace it with its underlying expression when it helps reducing overall complexity of a containing expression, but leaves it in its named form otherwise;

Equality and inequality operators between the named constant and its underlying expression should automatically evaluate to Boolean values:

PlasticConstant == ((9 - √69)^(1/3) + (9 + √69)^(1/3))/(2^(1/3) 3^(2/3))
(* True *)


similar to how it happens here:

GoldenRatio == (1 + √5)/2
(* True *)


How can we do it?

• Related (128444). It doesn't cover FunctionExpand, RootReduce or FullSimplify. Commented Jun 4, 2018 at 23:37
• I'd try it with upvalues, but I'm not sure which cases will suffice. Commented Jun 4, 2018 at 23:47

I think the OP's goals are going to be hard to achieve. GoldenRatio is embedded in the system in ways I don't know. Here is some examples of the embedding that come from an internal Trace of FunctionExpand@GoldenRation:
GoldenRatio /. SimplifyDumpPositiveRules
SimplifyDump$FSTab /@ % (* {901} {GoldenRatio :> 1/2 (1 + Sqrt[5])} *)  Some of the OP's goals can be handled programmatically. For instance: ClearAll[OneThird]; SetAttributes[OneThird, {Constant}]; N[OneThird, p_: MachinePrecision] := N[1/3, p]; OneThird // N[#, 22] & (* 0.3333333333333333333333 *)  However, automatic conversion to its numerical value does not happen for OneThird as it does for GoldenRatio: 3. OneThird 3. GoldenRatio (* 3. OneThird 4.8541 *)  Maybe someone else will know how to do it. An internal trace reveals nothing. • You need NumericQ[OneThird] = True as in @Szabolcs' answer to the related question. Commented Jun 4, 2018 at 23:49 • @CarlWoll Thanks. Commented Jun 4, 2018 at 23:51 • Also, I usually do N[OneThird, _] = 1/3 instead, but I don't think it makes a difference. Commented Jun 4, 2018 at 23:51 • I think rules for FunctionExpand and FullSimplify can be added somehow via SimplifyDumpPositiveRules and SimplifyDump$FSTab. What do numeric indexes in the latter mean? What index do I use to add my own entry? Commented Jun 5, 2018 at 17:34
• @VladimirReshetnikov Yes, I think you're right. The numbers are indices for $FSTab. You can look at them with ?SimplifyDump$FSTab. Obviously you would use an index that is not present in Cases[DownValues[SimplifyDump$FSTab], HoldPattern@SimplifyDump$FSTab[n_Integer] :> n, Infinity]`. (I don't know for sure that any missing one is safe.) Commented Jun 5, 2018 at 17:41