In [1]:
from math import *

from Goulib.notebook import *
from Goulib.table import Table
from friedman import seq

In [2]:
max=100
t=Table(range(max+1),titles=['n'])
def column(n, monadic='-s', dyadic='+-*/^_', permut=False):
    t.addcol(n)
    col = len(t.titles)-1
    for e in seq(n, monadic, dyadic, permut):
        n = int(e[0])
        # h(e[0],'=',e[1])
        if n <= max:
            e=e[1]
            old=t.get(n,col)
            if old is None or old.complexity()>e.complexity():
                t.set(n, col, e)

In [3]:
column(2018,permut=True) #yeargame


WARNING:root:19 has no solution

In [4]:
column(2019,permut=True) #yeargame


WARNING:root:13 has no solution

In [5]:
column(4444) # four-four


WARNING:root:17 has no solution

In [6]:
column(123456789)


WARNING:root:58 has no solution

In [7]:
column(999) # 999 clock


WARNING:root:5 has no solution

In [8]:
t


Out[8]:
n201820194444123456789999
0$${218 \cdot 0}$$$${219 \cdot 0}$$$${44-44}$$$${1+23+45+6-78+\sqrt{9}}$$$${\left(9-9\right)9}$$
1$${28 \cdot 0+1}$$$${20-19}$$$${\frac{4+4-4}{4}}$$$${-\frac{1+23+45+6-78}{\sqrt{9}}}$$$${\frac{\frac{9}{\sqrt{9}}}{\sqrt{9}}}$$
2$${20-18}$$$${2+19 \cdot 0}$$$${\left(4+4-4\right)-\sqrt{4}}$$$${1+23+4+56+7-89}$$$${\frac{9+9}{9}}$$
3$${-\left(\frac{10}{2}-8\right)}$$$${2+10-9}$$$${\frac{4+4+4}{4}}$$$${\left(1+23+4+56-78\right)-\sqrt{9}}$$$${\left(9+\sqrt{9}\right)-9}$$
4$${2+10-8}$$$${\frac{2+10}{\sqrt{9}}}$$$${\left(4+4-\sqrt{4}\right)-\sqrt{4}}$$$${-\frac{12+3+45+6-78}{\sqrt{9}}}$$$${\frac{9+\sqrt{9}}{\sqrt{9}}}$$
5$${\frac{10\sqrt{2}}{\sqrt{8}}}$$$${10-2-\sqrt{9}}$$$${\frac{4+4+\sqrt{4}}{\sqrt{4}}}$$$${\frac{1+2+34+56-78}{\sqrt{9}}}$$ 
6$${\left(0+\sqrt{18}\right)\sqrt{2}}$$$${2+0+1+\sqrt{9}}$$$${\frac{4+4+4}{\sqrt{4}}}$$$${\left(1+2+34+56-78\right)-9}$$$${\frac{9+9}{\sqrt{9}}}$$
7$${\left(0+\sqrt{81}\right)-2}$$$${\frac{20+1}{\sqrt{9}}}$$$${\frac{44}{4}-4}$$$${-\left(1+23+45+6+7-89\right)}$$ 
8$${21 \cdot 0+8}$$$${\frac{10}{2}+\sqrt{9}}$$$${4+4+4-4}$$$${\frac{12+34+56-78}{\sqrt{9}}}$$$${9+\frac{9}{-9}}$$
9$${0+\frac{18}{2}}$$$${2+10-\sqrt{9}}$$$${\frac{44}{4}-\sqrt{4}}$$$${1+23+4+56-78+\sqrt{9}}$$$${9+9-9}$$
10$${2+0+1 \cdot 8}$$$${20-1-9}$$$${\frac{44-4}{4}}$$$${\frac{1+23+45+6+7+8}{9}}$$$${9+\frac{9}{9}}$$
11$${20-1-8}$$$${20 \cdot 1-9}$$$${\frac{\frac{44}{\sqrt{4}}}{\sqrt{4}}}$$$${1+2+34+56+7-89}$$$${\frac{99}{9}}$$
12$${20 \cdot 1-8}$$$${20+1-9}$$$${\frac{4+44}{4}}$$$${\left(1+2+34+56-78\right)-\sqrt{9}}$$$${9+\frac{9}{\sqrt{9}}}$$
13$${20+1-8}$$ $${\frac{44}{4}+\sqrt{4}}$$$${\frac{12+34+56+7+8}{9}}$$ 
14$${10+\frac{8}{2}}$$$${\frac{10}{2}+9}$$$${4+4+4+\sqrt{4}}$$$${\frac{12+34+5+67+8}{9}}$$ 
15$${\frac{120}{8}}$$$${2+10+\sqrt{9}}$$$${4+\frac{44}{4}}$$$${\left(12+34+56-78\right)-9}$$$${9+9-\sqrt{9}}$$
16$${0+18-2}$$$${20-1-\sqrt{9}}$$$${4+4+4+4}$$$${\frac{1+23+45+67+8}{9}}$$ 
17$${0+2 \cdot 8+1}$$$${20 \cdot 1-\sqrt{9}}$$ $${\frac{1+23+45+6+78}{9}}$$ 
18$${28-10}$$$${20+1-\sqrt{9}}$$$${\frac{44}{\sqrt{4}}-4}$$$${\frac{1+23+4+56+78}{9}}$$$${\left(9-\sqrt{9}\right)\sqrt{9}}$$
19 $${29-10}$$ $${\frac{1+2+34+56+78}{9}}$$ 
20$${2+0+18}$$$${\left(0+1+9\right)2}$$$${\frac{44-4}{\sqrt{4}}}$$$${\frac{12+34+56+78}{9}}$$ 
21$${21+0 \cdot 8}$$$${2+0+19}$$$${\frac{44-\sqrt{4}}{\sqrt{4}}}$$$${\left(12+34+56-78\right)-\sqrt{9}}$$$${9+9+\sqrt{9}}$$
22 $${20-1+\sqrt{9}}$$$${\frac{44\sqrt{4}}{4}}$$$${\frac{123+4+56+7+8}{9}}$$ 
23 $${20+1\sqrt{9}}$$$${\frac{44+\sqrt{4}}{\sqrt{4}}}$$$${\frac{123+4+5+67+8}{9}}$$ 
24$${\left(2+0+1\right)8}$$$${20+1+\sqrt{9}}$$$${\frac{4+44}{\sqrt{4}}}$$$${\frac{123+4+5+6+78}{9}}$$$${9\sqrt{9}-\sqrt{9}}$$
25   $${-\left(12+34+5+6+7-89\right)}$$ 
26$${10+2 \cdot 8}$$$${\left(10+\sqrt{9}\right)2}$$$${4+\frac{44}{\sqrt{4}}}$$$${\left(12+3+4+5+6+7-8\right)-\sqrt{9}}$$ 
27$${20-1+8}$$$${\left(2+0+1\right)9}$$ $${\frac{123+45+67+8}{9}}$$$${9+9+9}$$
28$${20+1 \cdot 8}$$$${20-1+9}$$$${44+4\left(-4\right)}$$$${\frac{123+45+6+78}{9}}$$ 
29$${20+\sqrt{81}}$$$${20+1 \cdot 9}$$ $${\frac{123+4+56+78}{9}}$$ 
30 $${20+1+9}$$ $${\frac{1+23+45+6+7+8}{\sqrt{9}}}$$$${9\sqrt{9}+\sqrt{9}}$$
31   $${1+23+4+56+7\left(-8\right)+\sqrt{9}}$$ 
32 $${2+10\sqrt{9}}$$ $${\frac{123+45+6-78}{\sqrt{9}}}$$ 
33   $${12+34+56-78+9}$$$${\frac{99}{\sqrt{9}}}$$
34 $${\frac{102}{\sqrt{9}}}$$ $${\frac{1+234+56+7+8}{9}}$$ 
35   $${\frac{123+4+56-78}{\sqrt{9}}}$$ 
36$${0+18 \cdot 2}$$$${\left(2+10\right)\sqrt{9}}$$$${44-4-4}$$$${\frac{1+234+5+6+78}{9}}$$$${9+9\sqrt{9}}$$
37   $${12+34+56+7+8\left(-9\right)}$$ 
38$${20+18}$$$${0+19 \cdot 2}$$$${44-4-\sqrt{4}}$$$${12+3+45+67-89}$$ 
39$${\frac{80}{2}-1}$$$${20+19}$$ $${\frac{12+34+56+7+8}{\sqrt{9}}}$$ 
40$${\frac{10}{2}8}$$$${\frac{120}{\sqrt{9}}}$$$${44-\sqrt{4}-\sqrt{4}}$$$${1+2+34+56+7\left(-8\right)+\sqrt{9}}$$ 
41$${1+\frac{80}{2}}$$  $${\frac{1+234+56+78}{9}}$$ 
42  $${\left(44+\sqrt{4}\right)-4}$$$${\frac{12+34+5+67+8}{\sqrt{9}}}$$ 
43  $${44+\frac{4}{-4}}$$$${\left(12+34+56+7\left(-8\right)\right)-\sqrt{9}}$$ 
44 $${\frac{90}{2}-1}$$$${4+44-4}$$$${\left(1+2+34+5+6+7-8\right)-\sqrt{9}}$$ 
45 $${\frac{10}{2}9}$$$${44+\frac{4}{4}}$$$${\frac{12+3+45+67+8}{\sqrt{9}}}$$ 
46 $${1+\frac{90}{2}}$$$${4+44-\sqrt{4}}$$$${12+34+5+67+8\left(-9\right)}$$ 
47   $${1+23+45+67-89}$$ 
48  $${44+\sqrt{4}+\sqrt{4}}$$$${\frac{12+345+67+8}{9}}$$ 
49   $${\frac{12+345+6+78}{9}}$$ 
50  $${4+44+\sqrt{4}}$$$${1+2+34+5+6+7-8+\sqrt{9}}$$ 
51   $${\frac{1+23+45+6+78}{\sqrt{9}}}$$ 
52  $${4+4+44}$$$${-\left(12+3+4+5+6+7-89\right)}$$ 
53   $${\frac{1+2+3+456+7+8}{9}}$$ 
54$${\frac{108}{2}}$$  $${\frac{1+23+4+56+78}{\sqrt{9}}}$$$${\left(9+9\right)\sqrt{9}}$$
55   $${\frac{1+23+456+7+8}{9}}$$ 
56   $${123+4+5+6+7-89}$$ 
57 $${\left(20-1\right)\sqrt{9}}$$ $${\frac{1+2+34+56+78}{\sqrt{9}}}$$ 
58     
59$${80-21}$$$${20\sqrt{9}-1}$$ $${12+34+5+6+7-8+\sqrt{9}}$$ 
60 $${20 \cdot 1\sqrt{9}}$$$${44+4 \cdot 4}$$$${\frac{12+34+56+78}{\sqrt{9}}}$$ 
61$${81-20}$$$${20\sqrt{9}+1}$$ $${\frac{12+3+456+78}{9}}$$ 
62   $${\frac{1+23+456+78}{9}}$$ 
63 $${\left(20+1\right)\sqrt{9}}$$ $${\frac{123+45+6+7+8}{\sqrt{9}}}$$ 
64$${\left(10-2\right)8}$$  $${1+23+45+67+8\left(-9\right)}$$ 
65   $${1+23+4+5+6+\frac{78}{\sqrt{9}}}$$ 
66   $${\frac{123+456+7+8}{9}}$$ 
67 $${\frac{201}{\sqrt{9}}}$$ $${\frac{1+23+4+567+8}{9}}$$ 
68$${80-12}$$  $${\frac{1+2+34+567+8}{9}}$$ 
69 $${90-21}$$ $${\frac{12+34+567+8}{9}}$$ 
70 $${\frac{210}{\sqrt{9}}}$$ $${1+23+4+5+6+7+8\sqrt{9}}$$ 
71 $${91-20}$$ $${\frac{1+234+56-78}{\sqrt{9}}}$$ 
72$${82-10}$$$${\left(10-2\right)9}$$ $${\left(12+34+56-78\right)\sqrt{9}}$$$${9 \cdot 9-9}$$
73   $${\frac{123+456+78}{9}}$$ 
74   $${1+2+34+5+6+\frac{78}{\sqrt{9}}}$$ 
75   $${12+34+5+6+7+8+\sqrt{9}}$$ 
76     
77$${80-2-1}$$  $${\frac{1+2+3+4+5+678}{9}}$$ 
78$${10 \cdot 8-2}$$$${90-12}$$ $${\frac{123+4+567+8}{9}}$$$${9 \cdot 9-\sqrt{9}}$$
79$${0+81-2}$$  $${\frac{1+23+4+5+678}{9}}$$ 
80  $${\left(44-4\right)\sqrt{4}}$$$${\frac{1+2+34+5+678}{9}}$$ 
81$${2+80-1}$$  $${\frac{12+34+5+678}{9}}$$$${9\sqrt{9}\sqrt{9}}$$
82$${2+10 \cdot 8}$$$${92-10}$$ $${\frac{12+3+45+678}{9}}$$ 
83$${2+0+81}$$  $${\frac{1+23+45+678}{9}}$$ 
84  $${\left(44-\sqrt{4}\right)\sqrt{4}}$$$${\frac{123+45+6+78}{\sqrt{9}}}$$$${9 \cdot 9+\sqrt{9}}$$
85   $${123+4+5+6+7\left(-8\right)+\sqrt{9}}$$ 
86  $${44\sqrt{4}-\sqrt{4}}$$$${1+23+4+56+7-8+\sqrt{9}}$$ 
87 $${90-2-1}$$ $${\frac{123+4+56+78}{\sqrt{9}}}$$ 
88 $${10 \cdot 9-2}$$$${44+44}$$$${12+34+5+6+7+8\sqrt{9}}$$ 
89 $${0+91-2}$$ $${\left(1+2+34+56+7-8\right)-\sqrt{9}}$$ 
90$${\frac{180}{2}}$$ $${44\sqrt{4}+\sqrt{4}}$$$${\frac{1+234+567+8}{9}}$$$${99-9}$$
91 $${2+90-1}$$ $${123+4+5+6+7\left(-8\right)+9}$$ 
92$${12+80}$$$${2+10 \cdot 9}$$$${4+44\sqrt{4}}$$$${123+45+6+7-89}$$ 
93 $${102-9}$$ $${\left(123+45+6-78\right)-\sqrt{9}}$$ 
94$${102-8}$$  $${\frac{123+45+678}{9}}$$ 
95 $${\frac{190}{2}}$$ $${\frac{12+345+6-78}{\sqrt{9}}}$$ 
96$${\left(2+10\right)8}$$ $${\left(4+44\right)\sqrt{4}}$$$${\left(123+4+56-78\right)-9}$$$${99-\sqrt{9}}$$
97   $${12+3+45+6+7+8\sqrt{9}}$$ 
98   $${\left(12+34+56+7-8\right)-\sqrt{9}}$$ 
99 $${102-\sqrt{9}}$$ $${123+45+6-78+\sqrt{9}}$$ 
100   $${1+2+3+4+5+6+7+8 \cdot 9}$$ 

In [9]:
from friedman import Monadic, context
functions=context.functions

In [10]:
print(functions.keys()) #list allowed functions


SortedKeysView(SortedDict({'acos': (<built-in function acos>, 9999, None, None, '\\arccos'), 'acosh': (<built-in function acosh>, 9999, None, None, '\\cosh^{-1}'), 'asin': (<built-in function asin>, 9999, None, None, '\\arcsin'), 'asinh': (<built-in function asinh>, 9999, None, None, '\\sinh^{-1}'), 'atan': (<built-in function atan>, 9999, None, None, '\\arctan'), 'atan2': (<built-in function atan2>, 9999, None, None, None), 'atanh': (<built-in function atanh>, 9999, None, None, '\\tanh^{-1}'), 'copysign': (<built-in function copysign>, 9999, None, None, None), 'cos': (<built-in function cos>, 9999, None, None, None), 'cosh': (<built-in function cosh>, 9999, None, None, None), 'exp': (<built-in function exp>, 9999, None, None, 'e^{%s}'), 'factorial': (<built-in function factorial>, 9999, '%s!', 'fact', '%s!'), 'factorial2': (<function factorial2 at 0x0000018125328510>, 9999, '%s!', 'fact', '%s!!'), 'fmod': (<built-in function fmod>, 9999, None, None, None), 'gamma': (<built-in function gamma>, 9999, None, None, '\\Gamma'), 'gcd': (<built-in function gcd>, 9999, None, None, None), 'hypot': (<built-in function hypot>, 9999, None, None, None), 'isclose': (<built-in function isclose>, 9999, None, None, None), 'ldexp': (<built-in function ldexp>, 9999, None, None, None), 'log': (<built-in function log>, 9999, None, None, '\\ln'), 'log10': (<built-in function log10>, 9999, None, None, '\\log_{10}'), 'log2': (<built-in function log2>, 9999, None, None, '\\log_2'), 'modf': (<built-in function modf>, 9999, None, None, None), 'pow': (<built-in function pow>, 9999, None, None, None), 'remainder': (<built-in function remainder>, 9999, None, None, None), 'sin': (<built-in function sin>, 9999, None, None, None), 'sinh': (<built-in function sinh>, 9999, None, None, None), 'sqrt': (<function sqrt at 0x0000018125315598>, 9999, None, None, '\\sqrt{%s}'), 'tan': (<built-in function tan>, 9999, None, None, None), 'tanh': (<built-in function tanh>, 9999, None, None, None)}))

In [11]:
m=Monadic(0,functions)+Monadic(1,functions)+Monadic(2,functions)+Monadic(5,functions)+Monadic(7,functions)
for x in m.items():
    h(x[0],'=',x[1])


0 = ${\arccos\left(1\right)}$
0.28366218546322625 = ${\cos\left(5\right)}$
0.3010299956639812 = ${\log_{10}\left(2\right)}$
0.4161468365471424 = ${-\cos\left(2\right)}$
0.5403023058681398 = ${\cos\left(1\right)}$
0.6569865987187891 = ${\sin\left(7\right)}$
0.6931471805599453 = ${\ln\left(2\right)}$
0.6989700043360189 = ${\log_{10}\left(5\right)}$
0.7539022543433046 = ${\cos\left(7\right)}$
0.7615941559557649 = ${\tanh\left(1\right)}$
0.7853981633974483 = ${\arctan\left(1\right)}$
0.8414709848078965 = ${\sin\left(1\right)}$
0.8450980400142568 = ${\log_{10}\left(7\right)}$
0.8714479827243188 = ${\tan\left(7\right)}$
0.8813735870195429 = ${\sinh^{-1}\left(1\right)}$
0.9092974268256817 = ${\sin\left(2\right)}$
0.9589242746631385 = ${-\sin\left(5\right)}$
0.9640275800758169 = ${\tanh\left(2\right)}$
0.9999092042625951 = ${\tanh\left(5\right)}$
0.9999983369439447 = ${\tanh\left(7\right)}$
1 = ${\Gamma\left(2\right)}$
1.1071487177940904 = ${\arctan\left(2\right)}$
1.1752011936438014 = ${\sinh\left(1\right)}$
1.3169578969248166 = ${\cosh^{-1}\left(2\right)}$
1.373400766945016 = ${\arctan\left(5\right)}$
1.4142135623730951 = ${\sqrt{2}}$
1.4288992721907328 = ${\arctan\left(7\right)}$
1.4436354751788103 = ${\sinh^{-1}\left(2\right)}$
1.5430806348152437 = ${\cosh\left(1\right)}$
1.5574077246549023 = ${\tan\left(1\right)}$
1.5707963267948966 = ${\arcsin\left(1\right)}$
1.6094379124341003 = ${\ln\left(5\right)}$
1.9459101490553132 = ${\ln\left(7\right)}$
2 = ${2}$
2.185039863261519 = ${-\tan\left(2\right)}$
2.23606797749979 = ${\sqrt{5}}$
2.2924316695611777 = ${\cosh^{-1}\left(5\right)}$
2.3124383412727525 = ${\sinh^{-1}\left(5\right)}$
2.321928094887362 = ${\log_2\left(5\right)}$
2.6339157938496336 = ${\cosh^{-1}\left(7\right)}$
2.644120761058629 = ${\sinh^{-1}\left(7\right)}$
2.6457513110645907 = ${\sqrt{7}}$
2.718281828459045 = ${e^{1}}$
2.807354922057604 = ${\log_2\left(7\right)}$
3.380515006246586 = ${-\tan\left(5\right)}$
3.6268604078470186 = ${\sinh\left(2\right)}$
3.7621956910836314 = ${\cosh\left(2\right)}$
5 = ${5}$
7 = ${7}$
7.38905609893065 = ${e^{2}}$
24 = ${\Gamma\left(5\right)}$
74.20321057778875 = ${\sinh\left(5\right)}$
74.20994852478785 = ${\cosh\left(5\right)}$
120 = ${5!}$
148.4131591025766 = ${e^{5}}$
548.3161232732465 = ${\sinh\left(7\right)}$
548.3170351552121 = ${\cosh\left(7\right)}$
720 = ${\Gamma\left(7\right)}$
1096.6331584284585 = ${e^{7}}$
5040 = ${7!}$