タグ: wolfram alpha

Use wolfram from python.

Wolfram alpha is a computational knowledge engine developed by Wolfram Research. It is an online service that answers factual queries directly by computing the answer from externally sourced “curated data”.
You know, the service can be used from following URL.
https://www.wolframalpha.com/
By the way, if there is API to use wolfram alpha from another applications, it sounds nice doesn’t it.
Yah, wolfram python API was developed and uploaded pypi!
So, to use the API I installed wolframalpha by using pip command.

iwatobioen$ pip install walframalpha

Let’s use the library.
To use API, I created wolfram web site account and got API-Key. Then start jupyter notebook.

import wolframalpha
client = wolframalpha.Client( "yourAPIkey!!"  )
# get weather forecast
res = client.query( "weather in Newyork tomorrow" )
# print response
for pod in res.pods:
    for sub in pod.subpods:
        print( sub["plaintext"] )
>>>output
weather forecast | New York City, United States
  | tomorrow
between 6 °C and 8 °C
few clouds (very early morning  |  early morning onward)  |  partly cloudy (very early morning to early morning)
between 6 °C and 13 °C
few clouds (early morning  |  late morning to early afternoon)  |  clear (early morning to late morning  |  early afternoon onward)
between 3 °C and 10 °C
clear (late afternoon to night)  |  cloudy (late night onward)
None
| clear: 51.7% (3.8 days)   |  overcast: 0% (0 minutes)
| rain: 19.6% (1.4 days)
None
None
low: -11 °C
Feb 1993 | average high:  | 7 °C
average low:  | -2 °C | high: 19 °C
Feb 2011
(daily ranges, not corrected for changes in local weather station environment)
res = client.query("np complete problems")
for pod in res.pods:
    for sub in pod.subpods:
        print( sub["plaintext"] )
>>>output
NP complete problems
bin packing problem  |  chromatic number problem  |  clique problem  |  crossing number problem  |  directed Hamiltonian cycle problem  |  domatic number problem  |  dominating set problem  |  feedback arc set problem  |  feedback vertex set problem  |  Hamiltonian cycle problem  |  Hamiltonian path problem  |  hitting set problem  |  independent set problem  |  knapsack problem  |  max cut problem  |  minimum cover problem  |  partition problem  |  satisfiability problem  |  set packing problem  |  set splitting problem  |  ...   (total:  27)
Is there a partition of a finite set of items U into disjoint sets U_1, U_2, ..., U_k such that the sum of the sizes of the items in each U_i is B or less.
Given a graph G = (V, E) and a positive integer K<=|V|, is G K-colorable?
Given a graph G = (V, E) and a positive integer K<=|V|, does G contain a clique of size K or more?
Does a graph have a crossing number of K or less?
Does a graph contain a directed Hamiltonian cycle?
Given a graph G = (V, E) and a positive integer K<=|V|, is the domatic number of G at least K?
Given a graph G = (V, E) and a positive integer K<=|V|, is there a dominating set of size K or less for G?
Given a directed graph G = (V, A) and a positive integer K<=|A|, is there a subset A'(subset equal)A with |A'|<=K such that A' contains at least one arc from every directed cycle in G?
Given a directed graph G = (V, A) and a positive integer K<=|V|, is there a subset V'(subset equal)V with |V'|<=K such that V' contains at least one vertex from every directed cycle in G?
Does a graph contain a Hamiltonian cycle?
Does there exist a function f:V->{1, 2, ..., K} such that f(u)!=f(v) whenever {u, v} element E?
Does G contain a subset V'(subset equal)V with |V'|>=K such that every two vertices in V' are joined by an edge in E?
Can a graph be embedded in the plane with K or fewer pairs edges crossing one another.
Can V be partitioned into k>=K disjoint sets V_1, V_2, ..., V_k such that each V_i is a dominating set for G?
Is there a subset V'(subset equal)V with |V'|<=K such that for all u element V - V',  there is a v element V' for which {u, v} element E?
Does G contain a subset V'(subset equal)V such that |V'|>=K and such that no two vertices in V' are joined by an edge in E?
Does C contain a subset C'(subset equal)C with |C'| with |C'|<=K such that every element of S belongs to at least one member of C'?
Does G contain a subset V(subset equal)V_1 and a subset E(subset equal)E_1 such that |V| = |V_2|, |E| = |E_2|, and there exists a one-to-one function f:V_2->V satisfying {u, v} element E_2 iff {f(u), f(v)} element E?
Does M contain a subset M'(subset equal)M such that |M'| = q and no two elements of M' agree in any coordinate?
Is there a subset V'(subset equal)V with |V'|<=K such that for each edge {u, v} element E,  at least one of u and v belongs to V'?
| formulation date | formulators | status
bin packing problem |  |  | proved NP-complete
chromatic number problem |  |  | proved NP-complete
clique problem |  |  | proved NP-complete
crossing number problem |  |  | proved NP-complete
directed Hamiltonian cycle problem |  |  | proved NP-complete
domatic number problem | 1975  (42 years ago) | Ernest Cockayne  |  Stephen Hedetniemi | proved NP-complete
dominating set problem |  |  | proved NP-complete
feedback arc set problem |  |  | proved NP-complete
feedback vertex set problem |  |  | proved NP-complete
Hamiltonian cycle problem |  |  | proved NP-complete
Hamiltonian path problem |  |  | proved NP-complete
hitting set problem |  |  | proved NP-complete
independent set problem |  |  | proved NP-complete
knapsack problem |  |  | proved NP-complete
max cut problem |  |  | proved NP-complete
minimum cover problem |  |  | proved NP-complete
partition problem |  |  | proved NP-complete
satisfiability problem |  |  | proved NP-complete
set packing problem |  |  | proved NP-complete
set splitting problem |  |  | proved NP-complete
subgraph isomorphism problem |  |  | proved NP-complete
subset product problem |  |  | proved NP-complete
subset sum problem |  |  | proved NP-complete
three-dimensional matching problem |  |  | proved NP-complete
3-satisfiability problem |  |  | proved NP-complete
traveling salesman problem |  |  | proved NP-complete
vertex cover problem |  |  | proved NP-complete
 | proof date | provers
chromatic number problem | 1972 (45 years ago) | Richard Karp
clique problem | 1972 (45 years ago) | Richard Karp
crossing number problem | 1983 (34 years ago) | Michael Garey  |  David S. Johnson
directed Hamiltonian cycle problem | 1972 (45 years ago) | Richard Karp
domatic number problem | 1976 (1 year later)  (41 years ago) | Michael Garey  |  David S. Johnson  |  Robert Tarjan
feedback arc set problem | 1972 (45 years ago) | Richard Karp
feedback vertex set problem | 1972 (45 years ago) | Richard Karp
Hamiltonian cycle problem | 1972 (45 years ago) | Richard Karp
hitting set problem | 1972 (45 years ago) | Richard Karp
knapsack problem | 1972 (45 years ago) | Richard Karp
max cut problem | 1972 (45 years ago) | Richard Karp
minimum cover problem | 1972 (45 years ago) | Richard Karp
partition problem | 1972 (45 years ago) | Richard Karp
satisfiability problem | 1971 (46 years ago) | Stephen Cook
set packing problem | 1972 (45 years ago) | Richard Karp
set splitting problem | 1973 (44 years ago) | László Lovász
subgraph isomorphism problem | 1971 (46 years ago) | Stephen Cook
subset product problem | 1972 (45 years ago) | Richard Karp
subset sum problem | 1972 (45 years ago) | Richard Karp
three-dimensional matching problem | 1972 (45 years ago) | Richard Karp
3-satisfiability problem | 1971 (46 years ago) | Stephen Cook
vertex cover problem | 1972 (45 years ago) | Richard Karp
NP complete problems  |  NP problems  |  mathematical problems  |  solved mathematics problems

It worked. Wolfram alpha is high quality service so web site very useful. The site can use image file as query!!!
And the python library is cool too I think.