├── main_problems
├── kepler_with_missing_axioms[3.7]
│ ├── data_kepler_n_points.dat
│ └── data_kepler_d.dat
└── grav_waves[3.4].ipynb
├── figures
├── FIGURES.gif
└── system_high_level.png
├── CITATION.cff
├── LICENSE
├── data_generation
├── data_gen_kepler.py
└── data_gen_mix.py
├── README.md
└── suppl_material_problems
├── I_43_16.ipynb
├── I_27_6.ipynb
├── II_34_2.ipynb
├── I_10_9.ipynb
├── I_15_10.ipynb
├── inelastic.ipynb
├── decay.ipynb
├── escape.ipynb
├── compton.ipynb
├── I_34_8.ipynb
├── light.ipynb
└── hall.ipynb
/main_problems/kepler_with_missing_axioms[3.7]/data_kepler_n_points.dat:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/figures/FIGURES.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/AI-Hilbert/main/figures/FIGURES.gif
--------------------------------------------------------------------------------
/figures/system_high_level.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/AI-Hilbert/main/figures/system_high_level.png
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | message: "If you use this software, please cite it as below."
3 | authors:
4 | - given-names: "Ryan"
5 | family-names: "Cory-Wright"
6 | - given-names: "Cristina"
7 | family-names: "Cornelio"
8 | - given-names: "Sanjeeb"
9 | family-names: "Dash"
10 | - given-names: "Bachir"
11 | family-names: "El Khadir"
12 | - given-names: "Lior"
13 | family-names: "Horesh"
14 | title: "[AI-Hilbert GitHub Repository], Evolving Scientific Discovery by Unifying Data and Background Knowledge with AI Hilbert"
15 | version: 1.0.1
16 | doi: 10.5281/zenodo.11453179
17 | date-released: 2024-6-3
18 | url: "https://github.com/IBM/AI-Hilbert"
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 International Business Machines
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/data_generation/data_gen_kepler.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import numpy as np
4 | import regex as re
5 | from scipy.optimize import minimize
6 |
7 | def generate_data_kepler(num, noise_all = False, noise_target = True):
8 | # amount of noise in the data = 1%
9 | noise_amount = 0.01
10 | data = []
11 | for i in range(num):
12 | m1 = np.random.uniform(low=0.5, high=3.0)
13 | m2 = np.random.uniform(low=0.5, high=3.0)
14 | d = np.random.uniform(low=30.0, high=150.0)
15 |
16 | # std from binary stars dataset
17 | # p m1 m2 d
18 | # 1089 0.54 0.5 107.27
19 | # 143.1 1.33 1.41 38.235
20 | # 930 0.88 0.82 113.769
21 | # 675.5 3.06 1.97 131.352
22 |
23 | if noise_all:
24 | m_std = 0.8048592656483493
25 | d_std = 35.42009818238792
26 | noise_m1 = np.random.normal(0, m_std, 1)[0] * noise_amount # μ = 0, σ = 2, size = 1
27 | noise_m2 = np.random.normal(0, m_std, 1)[0] * noise_amount # μ = 0, σ = 2, size = 1
28 | noise_d = np.random.normal(0, d_std, 1)[0] * noise_amount # μ = 0, σ = 2, size = 1
29 | m1 = m1 + noise_m1
30 | m2 = m2 + noise_m2
31 | d = d + noise_d
32 |
33 | p = np.sqrt(d**3 / (m1 + m2))
34 |
35 | if noise_target:
36 | p_std = 358.68001756440236
37 | noise_p = np.random.normal(0, p_std, 1)[0] * noise_amount # μ = 0, σ = 2, size = 1
38 | p = p + noise_p
39 |
40 | data.append([p, m1, m2, d])
41 |
42 |
43 |
44 | with open('data_kepler.dat', 'w') as f:
45 | for d in data:
46 | d_list = d[:-1]
47 | for d_i in d_list:
48 | # f.write(f'{d_i:.2f} ')
49 | f.write(f'{d_i} ')
50 | f.write('0.0 0.0') # for d1 and d2
51 | f.write('\n')
52 |
53 | with open('data_kepler_d.dat', 'w') as f:
54 | for d in data:
55 | #f.write(f'{d[-1]:.2f} ')
56 | f.write(f'{d[-1]} ')
57 |
58 | with open('data_kepler_n_points.dat', 'w') as f:
59 | f.write(f'{num}\n')
60 |
61 |
62 | #------------------------------------------------------------------------------------------------------------------------
63 |
64 | # DATA GENERATION
65 |
66 | seed_p = np.random.randint(0, 2**32)
67 | print('------> SEED: ', seed_p)
68 | #seed_p = 1432406613
69 | np.random.seed(seed_p)
70 |
71 | generate_data_kepler(20000, noise_all = False, noise_target = True)
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://GitHub.com/IBM/AI-Hilbert/tags/)
2 | [](https://zenodo.org/badge/latestdoi/791611893)
3 | [](https://opensource.org/licenses/MIT)
4 |
5 | # AI-Hilbert
6 | This repository contains the code and the data used for the experiments in the paper [Evolving Scientific Discovery by Unifying Data and
7 | Background Knowledge with AI Hilbert](https://nature.com/articles/s41467-024-50074-w) published in Nature Communications.
8 |
9 |
10 | AI Hilbert is an algebraic geometric based discovery system (based on Putinar's Positivstellensatz), that enables the discovery of fundamental laws of nature (or non-physical systems) based on knowledge (articulated in formal logic terms) and experimental data.
11 |
12 | **Visit our website** for a general overview, references, and some introductory videos: → [AI-Hilbert website](https://ai-hilbert.github.io) ←
13 |
14 |
15 |
16 |
17 | ## Code
18 |
19 | The code is organized in 3 folders. One containing the problems studied in the main paper, one containing the problems studied in the paper appendix and one for data generation.
20 |
21 | The folder `main_problems` contains:
22 | * A notebook for the **Hagen-Poissuille Equation**, **Einstein’s Relativistic Time Dilation Law** and **Kepler’s Third Law of Planetary Motion**: [hagen_einstein_kepler[3.3][3.5][3.6].ipynb](main_problems/hagen_einstein_kepler[3.3][3.5][3.6].ipynb)
23 | * A folder for the **revisited** problem of deriving **Kepler’s third law of planetary motion** from an incomplete background theory [kepler_with_missing_axioms[3.7]](main_problems/kepler_with_missing_axioms[3.7]) containing:
24 | * the corresponding notebook [kepler_with_missing_axioms[3.7].ipynb](main_problems/kepler_with_missing_axioms[3.7]/kepler_with_missing_axioms[3.7].ipynb)
25 | * the data used [data_kepler.dat](main_problems/kepler_with_missing_axioms[3.7]/data_kepler.dat), [data_kepler_d.dat](main_problems/kepler_with_missing_axioms[3.7]/data_kepler_d.dat), and [data_kepler_n_points.dat](main_problems/kepler_with_missing_axioms[3.7]/data_kepler_n_points.dat).
26 | * A notebook for the **Radiated Gravitational Wave Power Equation**: [grav_waves[3.4].ipynb](main_problems/grav_waves[3.4].ipynb)
27 | * A notebook for the **Bell Inequalities**: [bell_inequalities[3.8].ipynb](main_problems/bell_inequalities[3.8].ipynb)
28 |
29 | The folder `suppl_material_problems` contains a notebook for each of the following problems:
30 | * 6 problems from FSRD ([Feynman Symbolic Regression Database](https://space.mit.edu/home/tegmark/aifeynman.html) based on ["The Feynman Lectures on Physics"](https://www.feynmanlectures.caltech.edu)):
31 | * **I.15.10 FSRD**: [I_15_10.ipynb](suppl_material_problems/I_15_10.ipynb)
32 | * **I.27.6 FSRD**: [I_27_6.ipynb](suppl_material_problems/I_15_10.ipynb)
33 | * **I.34.8 FSRD**: [I_34_8.ipynb](suppl_material_problems/I_15_10.ipynb)
34 | * **I.43.16 FSRD**: [I_43_16.ipynb](suppl_material_problems/I_15_10.ipynb)
35 | * **II.10.9 FSRD**: [II_10_9.ipynb](suppl_material_problems/I_15_10.ipynb)
36 | * **II.34.2 FSRD**: [II_34_2.ipynb](suppl_material_problems/I_15_10.ipynb)
37 | * 6 additional problems:
38 | * **Inelastic Relativistic Collision**: [inelastic.ipynb](suppl_material_problems/inelastic.ipynb)
39 | * **Decay of Pion into Muon and Neutrino**: [decay.ipynb](suppl_material_problems/decay.ipynb)
40 | * **Radiation Damping and Light Scattering**: [light.ipynb](suppl_material_problems/light.ipynb)
41 | * **Escape Velocity**: [escape.ipynb](suppl_material_problems/escape.ipynb)
42 | * **Hall Effect**: [hall.ipynb](suppl_material_problems/hall.ipynb)
43 | * **Compton Scattering**: [compton.ipynb](suppl_material_problems/compton.ipynb)
44 |
45 | The folder `data_generation` contains:
46 | * A python file for generating the data for the Kepler problem [data_gen_kepler.py](data_generation/data_gen_kepler.py)
47 | * A python file [data_gen_mix.py](data_generation/data_gen_mix.py) for generating the data for the following problems:
48 | * Inelastic Relativistic Collision
49 | * Decay of Pion into Muon and Neutrino
50 | * Radiation Damping and Light Scattering
51 | * Escape Velocity
52 | * Hall Effect
53 | * Compton Scattering
54 | * Radiation Gravitational Wave Power
55 | * Hagen Poiseuille equation
56 |
57 | ## How to cite
58 |
59 | ```
60 | @article{AI_Hilbert,
61 | title={Evolving scientific discovery by unifying data and background knowledge with AI Hilbert},
62 | author={Ryan Cory-Wright and Cristina Cornelio and Sanjeeb Dash and Bachir El Khadir and Lior Horesh},
63 | volume = {15},
64 | url = {https://doi.org/10.1038/s41467-024-50074-w},
65 | doi = {10.1038/s41467-024-50074-w},
66 | journal = {Nature Communications},
67 | month = jul,
68 | year = {2024},
69 | pages = {5922},
70 | }
71 | ```
72 |
--------------------------------------------------------------------------------
/main_problems/grav_waves[3.4].ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "13702a10",
6 | "metadata": {},
7 | "source": [
8 | "# This notebook contains the code for section 3.4\n"
9 | ]
10 | },
11 | {
12 | "cell_type": "code",
13 | "execution_count": 2,
14 | "id": "77600d9b",
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# using Pkg;\n",
19 | "# Pkg.add(\"DynamicPolynomials\")\n",
20 | "# Pkg.add(\"MosekTools\")\n",
21 | "# Pkg.add(\"Symbolics\")\n",
22 | "\n",
23 | "using DynamicPolynomials\n",
24 | "using JuMP\n",
25 | "using MosekTools\n",
26 | "using LinearAlgebra\n",
27 | "using CSV\n",
28 | "using DataFrames\n",
29 | "import JSON\n",
30 | "using Dates\n",
31 | "using Gurobi\n",
32 | "using Symbolics"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "id": "cc16342b",
38 | "metadata": {},
39 | "source": [
40 | "# Radiated Gravitational Wave Power Equation"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "id": "edee531b",
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "@show 1+1\n",
51 | "\n",
52 | "@polyvar P x y Ω r G m₁ m₂ M a b d e f c Q₁₁ Q₁₂ Q₂₂ \n",
53 | "\n",
54 | "vars =[P x y Ω G r c m₁ m₂ Q₁₁ Q₁₂ Q₂₂]\n",
55 | "\n",
56 | "function differentiateTrig2(p) # p is a bivariate degree-2 trigonometric polynomials in x,y with variable coefficients\n",
57 | " \n",
58 | " q=2*Ω*y*div(sum(monomials(p).*coefficients(p).*(DynamicPolynomials.degree.(monomials(p), x).==2)), x)\n",
59 | " q+=-2*Ω*x*div(sum(monomials(p).*coefficients(p).*(DynamicPolynomials.degree.(monomials(p), y).==2)), y)\n",
60 | " q+=Ω*(-x^2+y^2)*div(sum(monomials(p).*coefficients(p).*(DynamicPolynomials.degree.(monomials(p), x).==1).*(DynamicPolynomials.degree.(monomials(p), y).==1)), x*y)\n",
61 | " q+=Ω*y*div(sum(monomials(p).*coefficients(p).*(DynamicPolynomials.degree.(monomials(p), x).==1).*(DynamicPolynomials.degree.(monomials(p), y).==0)), x)\n",
62 | " q+=Ω*x*div(sum(monomials(p).*coefficients(p).*(DynamicPolynomials.degree.(monomials(p), x).==0).*(DynamicPolynomials.degree.(monomials(p), y).==1)), y)\n",
63 | "\n",
64 | " return q\n",
65 | "end\n",
66 | "\n",
67 | "function tripDiffTrig2(p)\n",
68 | " return differentiateTrig2(differentiateTrig2(differentiateTrig2(p)))\n",
69 | "end\n",
70 | "\n",
71 | "\n",
72 | "#Q=m₁*m₂*r^2*[[y^2-1/3 x*y 0]; [x*y x^2-1/3 0]; [0 0 -1/3]]\n",
73 | "# Q=m₁*m₂*r^2*[[y^2-1/3 x*y 0]; [x*y x^2-1/3 0]; [0 0 -1/3]]\n",
74 | "\n",
75 | "# Let us now define our axioms\n",
76 | "axioms=[\n",
77 | " x^2+y^2-1, # Definition of sine and cosine\n",
78 | " Ω^2*r^3-G*(m₁+m₂), #Kepler's third law w/out G\n",
79 | " (m₁+m₂)*Q₁₁-m₁*m₂*r^2*tripDiffTrig2(y^2-1/3),\n",
80 | " (m₁+m₂)*Q₁₂-m₁*m₂*r^2*tripDiffTrig2(x*y),\n",
81 | " (m₁+m₂)*Q₂₂-m₁*m₂*r^2*tripDiffTrig2(x^2-1/3),\n",
82 | " 5*c^5*P+G*tr([Q₁₁ Q₁₂; Q₁₂ Q₂₂]^2)\n",
83 | " ]\n",
84 | "\n",
85 | "\n",
86 | " function all_monomials_up_to_max_deg_overall(x, deg, deg_overall, deg_elem)\n",
87 | " if size(x,1) == 0\n",
88 | " [1]\n",
89 | " else\n",
90 | " [ x[1]^k * m for k=0:min(deg, deg_overall, deg_elem[1]) \n",
91 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k, deg_elem[2:end])\n",
92 | " ]\n",
93 | " end\n",
94 | " end\n",
95 | " \n",
96 | " function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, deg_elem, u)\n",
97 | " [m\n",
98 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall, deg_elem)\n",
99 | " #if all(unit(m) .== u)\n",
100 | " ]\n",
101 | " end\n",
102 | " \n",
103 | " function degree_poly(p)\n",
104 | " maximum(DynamicPolynomials.degree.(monomials(p)))\n",
105 | " end\n",
106 | "\n",
107 | " deg = 6\n",
108 | " deg_overall=20\n",
109 | " deg_overall_q=18\n",
110 | " \n",
111 | " deg_elementwise=[1, 4, 4, 4, 3, 6, 1, 5, 5, 2, 2, 2] #vars =[P x y Ω G r c m₁ m₂ Q_11 Q_12 Q_22\n",
112 | " deg_elementwise_q=[1, 4, 5, 5, 5, 5] #vars =[P G r c m₁ m₂] #deg(r)=5, deg(c)=5, deg(G)=4\n",
113 | " \n",
114 | " candidate_mons = [\n",
115 | " mons_of_max_degree_and_unit_overall(vars, deg, deg_overall, deg_elementwise, [])\n",
116 | " for ai=axioms\n",
117 | " ]\n",
118 | " @show size.(candidate_mons)\n",
119 | " \n",
120 | " model = Model(Mosek.Optimizer)\n",
121 | " mons_q = mons_of_max_degree_and_unit_overall([P, G, r, c, m₁, m₂] , deg, deg_overall_q, deg_elementwise_q, []) # c, \n",
122 | " coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
123 | " \n",
124 | " q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
125 | " coeff_αs = [\n",
126 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
127 | " for (i,X)=enumerate(candidate_mons)\n",
128 | " ]\n",
129 | " @show size.(coeff_αs)\n",
130 | " αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
131 | " \n",
132 | " residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
133 | " eqs = coefficients(residual)\n",
134 | " \n",
135 | " # Ensure that the sum of the coefficients on the terms involving P isn't zero, in order that P is part of the final expression\n",
136 | " @constraint model sum(coeff_q[DynamicPolynomials.degree.(mons_q, P).>0]) == 1.0\n",
137 | " \n",
138 | " @constraint model eqs .== 0\n",
139 | " @objective model Max 0\n",
140 | "\n",
141 | " optimize!(model)\n",
142 | " @show termination_status(model)\n",
143 | "\n",
144 | " value_poly = p -> sum(value.(coefficients(p)).* monomials(p))\n",
145 | "\n",
146 | " value_q = value_poly(q)\n",
147 | " @show value_q\n",
148 | "\n",
149 | " @show value_αs = value_poly.(αs)"
150 | ]
151 | },
152 | {
153 | "cell_type": "markdown",
154 | "id": "b667dd18",
155 | "metadata": {},
156 | "source": [
157 | "### Output from the MIT SuperCloud environment\n",
158 | "```\n",
159 | " Resolving package versions...\n",
160 | " No Changes to `~/.julia/environments/v1.7/Project.toml`\n",
161 | " No Changes to `~/.julia/environments/v1.7/Manifest.toml`\n",
162 | " Resolving package versions...\n",
163 | " No Changes to `~/.julia/environments/v1.7/Project.toml`\n",
164 | " No Changes to `~/.julia/environments/v1.7/Manifest.toml`\n",
165 | " Resolving package versions...\n",
166 | " No Changes to `~/.julia/environments/v1.7/Project.toml`\n",
167 | " No Changes to `~/.julia/environments/v1.7/Manifest.toml`\n",
168 | "1 + 1 = 2\n",
169 | "tr(tripDiffTrig2.(Q) ^ 2) = 32.0x⁴Ω⁶r⁴m₁²m₂² + 64.0x²y²Ω⁶r⁴m₁²m₂² + 32.0y⁴Ω⁶r⁴m₁²m₂²\n",
170 | "size.(candidate_mons) = [(416392,), (416392,), (416392,)]\n",
171 | "size.(coeff_αs) = [(416392,), (416392,), (416392,)]\n",
172 | "Problem\n",
173 | " Name : \n",
174 | " Objective sense : max \n",
175 | " Type : LO (linear optimization problem)\n",
176 | " Constraints : 2847899 \n",
177 | " Cones : 0 \n",
178 | " Scalar variables : 1261433 \n",
179 | " Matrix variables : 0 \n",
180 | " Integer variables : 0 \n",
181 | "\n",
182 | "Optimizer started.\n",
183 | "Presolve started.\n",
184 | "Linear dependency checker started.\n",
185 | "Linear dependency checker terminated.\n",
186 | "Eliminator started.\n",
187 | "Freed constraints in eliminator : 0\n",
188 | "Eliminator terminated.\n",
189 | "Eliminator - tries : 1 time : 0.00 \n",
190 | "Lin. dep. - tries : 1 time : 0.97 \n",
191 | "Lin. dep. - number : 52533 \n",
192 | "Presolve terminated. Time: 2.60 \n",
193 | "Optimizer terminated. Time: 3.98 \n",
194 | "\n",
195 | "termination_status(model) = MathOptInterface.OPTIMAL\n",
196 | "value_q = 0.25Pr⁵m₁²c⁵ + 0.5Pr⁵m₁m₂c⁵ + 0.25Pr⁵m₂²c⁵ + 1.6G⁴m₁⁵m₂² + 4.800000000000001G⁴m₁⁴m₂³ + 4.800000000000001G⁴m₁³m₂⁴ + 1.6G⁴m₁²m₂⁵\n",
197 | "value_αs = value_poly.(αs) = Polynomial{true, Float64}[-1.6x²Ω⁴r⁶G²m₁³m₂² - 1.6x²Ω⁴r⁶G²m₁²m₂³ - 1.6y²Ω⁴r⁶G²m₁³m₂² - 1.6y²Ω⁴r⁶G²m₁²m₂³ - 1.6Ω⁴r⁶G²m₁³m₂² - 1.6Ω⁴r⁶G²m₁²m₂³, -1.6x⁴Ω⁴r⁶Gm₁²m₂² - 3.2x²y²Ω⁴r⁶Gm₁²m₂² - 1.6y⁴Ω⁴r⁶Gm₁²m₂² - 1.6Ω²r³G²m₁³m₂² - 1.6Ω²r³G²m₁²m₂³ - 1.6G³m₁⁴m₂² - 3.2G³m₁³m₂³ - 1.6G³m₁²m₂⁴, 0.05r⁵]\n",
198 | "```"
199 | ]
200 | }
201 | ],
202 | "metadata": {
203 | "kernelspec": {
204 | "display_name": "Julia 1.10.2",
205 | "language": "julia",
206 | "name": "julia-1.10"
207 | },
208 | "language_info": {
209 | "file_extension": ".jl",
210 | "mimetype": "application/julia",
211 | "name": "julia",
212 | "version": "1.9.1"
213 | }
214 | },
215 | "nbformat": 4,
216 | "nbformat_minor": 5
217 | }
218 |
--------------------------------------------------------------------------------
/suppl_material_problems/I_43_16.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "I-43-16 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/I_43.html\n",
10 | "\n"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 1,
16 | "metadata": {},
17 | "outputs": [
18 | {
19 | "name": "stderr",
20 | "output_type": "stream",
21 | "text": [
22 | "WARNING: both JuMP and DynamicPolynomials export \"map_coefficients\"; uses of it in module Main must be qualified\n",
23 | "WARNING: both SymbolicUtils and DynamicPolynomials export \"term\"; uses of it in module Main must be qualified\n"
24 | ]
25 | }
26 | ],
27 | "source": [
28 | "using DynamicPolynomials\n",
29 | "using JuMP\n",
30 | "using MosekTools\n",
31 | "using LinearAlgebra\n",
32 | "using CSV\n",
33 | "using DataFrames\n",
34 | "import JSON\n",
35 | "using Dates\n",
36 | "using Gurobi\n",
37 | "using SymbolicUtils # for symbolic simplification"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {},
43 | "source": [
44 | "functions for generating monomials"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 2,
50 | "metadata": {},
51 | "outputs": [
52 | {
53 | "data": {
54 | "text/plain": [
55 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
56 | ]
57 | },
58 | "execution_count": 2,
59 | "metadata": {},
60 | "output_type": "execute_result"
61 | }
62 | ],
63 | "source": [
64 | "function all_monomials_up_to_max_deg(x, deg)\n",
65 | " if size(x,1) == 0\n",
66 | " [1]\n",
67 | " else\n",
68 | " [ x[1]^k * m for k=0:deg \n",
69 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
70 | " ]\n",
71 | " end\n",
72 | "end\n",
73 | "\n",
74 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
75 | " [m\n",
76 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
77 | " #if all(unit(m) .== u)\n",
78 | " ]\n",
79 | "end\n",
80 | " \n",
81 | "function degree_poly(p)\n",
82 | " maximum(degree.(monomials(p)))\n",
83 | "end\n",
84 | "\n",
85 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
86 | " if size(x,1) == 0\n",
87 | " [1]\n",
88 | " else\n",
89 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
90 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
91 | " ]\n",
92 | " end\n",
93 | "end\n",
94 | "\n",
95 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
96 | " [m\n",
97 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
98 | " #if all(unit(m) .== u)\n",
99 | " ]\n",
100 | "end\n",
101 | "\n",
102 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
103 | " if size(x,1) == 0\n",
104 | " [1]\n",
105 | " else\n",
106 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
107 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
108 | " ]\n",
109 | " end\n",
110 | "end"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 3,
116 | "metadata": {},
117 | "outputs": [
118 | {
119 | "data": {
120 | "text/plain": [
121 | "1×10 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
122 | " v m F tau mu tau q E d Volt"
123 | ]
124 | },
125 | "execution_count": 3,
126 | "metadata": {},
127 | "output_type": "execute_result"
128 | }
129 | ],
130 | "source": [
131 | "@polyvar v m F tau mu tau qc E d Volt # \n",
132 | "\n",
133 | "x = [v m F tau mu tau qc E d Volt ] #"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": 4,
139 | "metadata": {},
140 | "outputs": [
141 | {
142 | "data": {
143 | "text/plain": [
144 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
145 | " -Ftau + vm\n",
146 | " -tau + mmu\n",
147 | " F - qE\n",
148 | " -Volt + Ed"
149 | ]
150 | },
151 | "execution_count": 4,
152 | "metadata": {},
153 | "output_type": "execute_result"
154 | }
155 | ],
156 | "source": [
157 | "axioms= \n",
158 | "[\n",
159 | " v * m - F * tau, \n",
160 | " mu * m - tau, \n",
161 | " F - qc * E, \n",
162 | " E * d - Volt, \n",
163 | "]\n"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": 6,
169 | "metadata": {},
170 | "outputs": [],
171 | "source": [
172 | "deg = 3\n",
173 | "deg_overall = 12\n",
174 | "theDegrees = [ 2 2 2 2 2 2 2 2 2 2] \n",
175 | " # v m F tau mu tau q E d Volt ] # \n",
176 | "\n",
177 | "candidate_mons = [\n",
178 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
179 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
180 | " for ai=axioms\n",
181 | "]\n",
182 | "\n",
183 | "@show size.(candidate_mons)\n",
184 | "\n",
185 | "#model = Model(Mosek.Optimizer)\n",
186 | "model = Model(Gurobi.Optimizer)\n",
187 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
188 | "\n",
189 | "mons_q = mons_of_max_degree_and_unit_overall([v mu qc d Volt ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
190 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
191 | "\n",
192 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
193 | "coeff_αs = [\n",
194 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
195 | " for (i,X)=enumerate(candidate_mons)\n",
196 | " ]\n",
197 | "@show size.(coeff_αs)\n",
198 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
199 | "\n",
200 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
201 | "eqs = coefficients(residual)\n",
202 | "\n",
203 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
204 | "@constraint model sum(coeff_q[degree.(mons_q, [v]).>0]) == 1.0\n",
205 | "\n",
206 | "@constraint model eqs .== 0\n",
207 | "@objective model Max 0\n",
208 | "\n",
209 | "optimize!(model)\n",
210 | "@show termination_status(model)"
211 | ]
212 | },
213 | {
214 | "cell_type": "code",
215 | "execution_count": 7,
216 | "metadata": {},
217 | "outputs": [
218 | {
219 | "data": {
220 | "text/plain": [
221 | "#43 (generic function with 1 method)"
222 | ]
223 | },
224 | "execution_count": 7,
225 | "metadata": {},
226 | "output_type": "execute_result"
227 | }
228 | ],
229 | "source": [
230 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": 8,
236 | "metadata": {},
237 | "outputs": [
238 | {
239 | "data": {
240 | "text/latex": [
241 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
242 | ],
243 | "text/plain": [
244 | "-p³c² + p³v² + m_0pv²c²"
245 | ]
246 | },
247 | "execution_count": 8,
248 | "metadata": {},
249 | "output_type": "execute_result"
250 | }
251 | ],
252 | "source": [
253 | "value_q = value_poly(q)\n",
254 | "value_q"
255 | ]
256 | },
257 | {
258 | "cell_type": "code",
259 | "execution_count": 9,
260 | "metadata": {},
261 | "outputs": [
262 | {
263 | "data": {
264 | "text/latex": [
265 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
266 | ],
267 | "text/plain": [
268 | "-p³c² + p³v² + m_0pv²c²"
269 | ]
270 | },
271 | "execution_count": 9,
272 | "metadata": {},
273 | "output_type": "execute_result"
274 | }
275 | ],
276 | "source": [
277 | "q_sim = simplify(value_q)"
278 | ]
279 | },
280 | {
281 | "cell_type": "markdown",
282 | "metadata": {},
283 | "source": [
284 | "which can be reorganized to arrive at the known relation p = m_0 * v /sqrt(1 - v*v/c*c)"
285 | ]
286 | },
287 | {
288 | "cell_type": "code",
289 | "execution_count": 10,
290 | "metadata": {},
291 | "outputs": [
292 | {
293 | "name": "stdout",
294 | "output_type": "stream",
295 | "text": [
296 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-p²c² + p²v² - mpvc² + mpv³, -pv²]\n"
297 | ]
298 | },
299 | {
300 | "data": {
301 | "text/plain": [
302 | "2-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
303 | " -p²c² + p²v² - mpvc² + mpv³\n",
304 | " -pv²"
305 | ]
306 | },
307 | "execution_count": 10,
308 | "metadata": {},
309 | "output_type": "execute_result"
310 | }
311 | ],
312 | "source": [
313 | "@show value_αs = value_poly.(αs)"
314 | ]
315 | },
316 | {
317 | "cell_type": "markdown",
318 | "metadata": {},
319 | "source": []
320 | }
321 | ],
322 | "metadata": {
323 | "kernelspec": {
324 | "display_name": "Julia 1.10.2",
325 | "language": "julia",
326 | "name": "julia-1.10"
327 | },
328 | "language_info": {
329 | "file_extension": ".jl",
330 | "mimetype": "application/julia",
331 | "name": "julia",
332 | "version": "1.9.4"
333 | }
334 | },
335 | "nbformat": 4,
336 | "nbformat_minor": 2
337 | }
338 |
--------------------------------------------------------------------------------
/suppl_material_problems/I_27_6.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "I-27-6 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/I_27.html\n",
10 | "\n",
11 | "Optical geometry - derivation of focal length based on distances (d1,d2) from lens and refraction index n \n",
12 | "\n",
13 | "foc = 1/(1/d1+n/d2) ==> foc/d1 + foc*n/d2 = 1 ==> foc*d2 + foc * n * d1 - d1 * d2=0\n"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 23,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "using DynamicPolynomials\n",
23 | "using JuMP\n",
24 | "using MosekTools\n",
25 | "using LinearAlgebra\n",
26 | "using CSV\n",
27 | "using DataFrames\n",
28 | "import JSON\n",
29 | "using Dates\n",
30 | "using Gurobi\n",
31 | "using SymbolicUtils # for symbolic simplification"
32 | ]
33 | },
34 | {
35 | "cell_type": "markdown",
36 | "metadata": {},
37 | "source": [
38 | "functions for generating monomials"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 24,
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "data": {
48 | "text/plain": [
49 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
50 | ]
51 | },
52 | "execution_count": 24,
53 | "metadata": {},
54 | "output_type": "execute_result"
55 | }
56 | ],
57 | "source": [
58 | "function all_monomials_up_to_max_deg(x, deg)\n",
59 | " if size(x,1) == 0\n",
60 | " [1]\n",
61 | " else\n",
62 | " [ x[1]^k * m for k=0:deg \n",
63 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
64 | " ]\n",
65 | " end\n",
66 | "end\n",
67 | "\n",
68 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
69 | " [m\n",
70 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
71 | " #if all(unit(m) .== u)\n",
72 | " ]\n",
73 | "end\n",
74 | " \n",
75 | "function degree_poly(p)\n",
76 | " maximum(degree.(monomials(p)))\n",
77 | "end\n",
78 | "\n",
79 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
80 | " if size(x,1) == 0\n",
81 | " [1]\n",
82 | " else\n",
83 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
84 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
85 | " ]\n",
86 | " end\n",
87 | "end\n",
88 | "\n",
89 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
90 | " [m\n",
91 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
92 | " #if all(unit(m) .== u)\n",
93 | " ]\n",
94 | "end\n",
95 | "\n",
96 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
97 | " if size(x,1) == 0\n",
98 | " [1]\n",
99 | " else\n",
100 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
101 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
102 | " ]\n",
103 | " end\n",
104 | "end"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 5,
110 | "metadata": {},
111 | "outputs": [
112 | {
113 | "data": {
114 | "text/plain": [
115 | "1×10 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
116 | " tvq n VQ top1 top2 h d1 d2 r foc"
117 | ]
118 | },
119 | "execution_count": 5,
120 | "metadata": {},
121 | "output_type": "execute_result"
122 | }
123 | ],
124 | "source": [
125 | "@polyvar tvq n VQ top1 top2 h d1 d2 r foc # \n",
126 | "\n",
127 | "x = [ tvq n VQ top1 top2 h d1 d2 r foc ] #"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": 17,
133 | "metadata": {},
134 | "outputs": [
135 | {
136 | "data": {
137 | "text/plain": [
138 | "6-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
139 | " VQ + tvq - nVQ\n",
140 | " -h² + 2top1d1\n",
141 | " 2top2d2 - nh²\n",
142 | " -h² + 2VQr\n",
143 | " top2 + top1 - tvq\n",
144 | " -foc - r + nfoc"
145 | ]
146 | },
147 | "execution_count": 17,
148 | "metadata": {},
149 | "output_type": "execute_result"
150 | }
151 | ],
152 | "source": [
153 | "axioms= \n",
154 | "[\n",
155 | " tvq - (n-1) * VQ,\n",
156 | " top1 * (2 * d1) - h^2 , # top1 - h^2 / (2 * d1),\n",
157 | " top2 * (2 * d2) - (n * h^2), # top2 - (n * h^2) / (2 * d2),\n",
158 | " VQ * (2 * r) - h^2, # VQ - h^2 / (2 * r),\n",
159 | " top1 + top2 - tvq,\n",
160 | " foc*(n-1) - r, # foc - r/(n-1)\n",
161 | " #d1>0,\n",
162 | " #d2>0,\n",
163 | " #h>0,\n",
164 | " #VQ>0,\n",
165 | " #r>0,\n",
166 | " #top1>0,\n",
167 | " #n>1,\n",
168 | " #tvq>0,\n",
169 | " #top2>0,\n",
170 | "]\n",
171 | " "
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": 34,
177 | "metadata": {},
178 | "outputs": [
179 | {
180 | "name": "stdout",
181 | "output_type": "stream",
182 | "text": [
183 | "size.(candidate_mons) = [(93784,), (93784,), (93784,), (93784,), (93784,), (93784,)]\n"
184 | ]
185 | }
186 | ],
187 | "source": [
188 | "deg = 3\n",
189 | "deg_overall = 14\n",
190 | "theDegrees = [ 2 2 2 2 2 2 3 3 2 2 ] \n",
191 | " # tvq n VQ top1 top2 h d1 d2 r foc \n",
192 | "\n",
193 | "candidate_mons = [\n",
194 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
195 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
196 | " for ai=axioms\n",
197 | "]\n",
198 | "\n",
199 | "@show size.(candidate_mons)\n",
200 | "\n",
201 | "#model = Model(Mosek.Optimizer)\n",
202 | "model = Model(Gurobi.Optimizer)\n",
203 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
204 | "\n",
205 | "mons_q = mons_of_max_degree_and_unit_overall([d1 d2 n foc], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
206 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
207 | "\n",
208 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
209 | "coeff_αs = [\n",
210 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
211 | " for (i,X)=enumerate(candidate_mons)\n",
212 | " ]\n",
213 | "@show size.(coeff_αs)\n",
214 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
215 | "\n",
216 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
217 | "eqs = coefficients(residual)\n",
218 | "\n",
219 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
220 | "@constraint model sum(coeff_q[degree.(mons_q, [foc]).>0]) == 1.0\n",
221 | "\n",
222 | "@constraint model eqs .== 0\n",
223 | "@objective model Max 0\n",
224 | "\n",
225 | "optimize!(model)\n",
226 | "@show termination_status(model)"
227 | ]
228 | },
229 | {
230 | "cell_type": "code",
231 | "execution_count": 29,
232 | "metadata": {},
233 | "outputs": [
234 | {
235 | "data": {
236 | "text/plain": [
237 | "#143 (generic function with 1 method)"
238 | ]
239 | },
240 | "execution_count": 29,
241 | "metadata": {},
242 | "output_type": "execute_result"
243 | }
244 | ],
245 | "source": [
246 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
247 | ]
248 | },
249 | {
250 | "cell_type": "code",
251 | "execution_count": 30,
252 | "metadata": {},
253 | "outputs": [
254 | {
255 | "data": {
256 | "text/latex": [
257 | "$$ foc^{2} + rfoc - nfoc^{2} $$"
258 | ],
259 | "text/plain": [
260 | "foc² + rfoc - nfoc²"
261 | ]
262 | },
263 | "execution_count": 30,
264 | "metadata": {},
265 | "output_type": "execute_result"
266 | }
267 | ],
268 | "source": [
269 | "value_q = value_poly(q)\n",
270 | "value_q"
271 | ]
272 | },
273 | {
274 | "cell_type": "code",
275 | "execution_count": 31,
276 | "metadata": {},
277 | "outputs": [
278 | {
279 | "data": {
280 | "text/latex": [
281 | "$$ foc^{2} + rfoc - nfoc^{2} $$"
282 | ],
283 | "text/plain": [
284 | "foc² + rfoc - nfoc²"
285 | ]
286 | },
287 | "execution_count": 31,
288 | "metadata": {},
289 | "output_type": "execute_result"
290 | }
291 | ],
292 | "source": [
293 | "q_sim = simplify(value_q)"
294 | ]
295 | },
296 | {
297 | "cell_type": "markdown",
298 | "metadata": {},
299 | "source": [
300 | "which can be simplified to (foc^2*h^2*r*(d1*d2 + d2*r - d1*d2*n + d1*n*r))/2\n",
301 | "\n"
302 | ]
303 | },
304 | {
305 | "cell_type": "code",
306 | "execution_count": 27,
307 | "metadata": {},
308 | "outputs": [
309 | {
310 | "name": "stdout",
311 | "output_type": "stream",
312 | "text": [
313 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[d1d2r²foc², -0.5d2r²foc², -0.5d1r²foc², -0.5d1d2rfoc² + 0.5nd1d2rfoc², d1d2r²foc², 0.0]\n"
314 | ]
315 | },
316 | {
317 | "data": {
318 | "text/plain": [
319 | "6-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
320 | " d1d2r²foc²\n",
321 | " -0.5d2r²foc²\n",
322 | " -0.5d1r²foc²\n",
323 | " -0.5d1d2rfoc² + 0.5nd1d2rfoc²\n",
324 | " d1d2r²foc²\n",
325 | " 0.0"
326 | ]
327 | },
328 | "execution_count": 27,
329 | "metadata": {},
330 | "output_type": "execute_result"
331 | }
332 | ],
333 | "source": [
334 | "@show value_αs = value_poly.(αs)"
335 | ]
336 | },
337 | {
338 | "cell_type": "markdown",
339 | "metadata": {},
340 | "source": []
341 | }
342 | ],
343 | "metadata": {
344 | "kernelspec": {
345 | "display_name": "Julia 1.10.2",
346 | "language": "julia",
347 | "name": "julia-1.10"
348 | },
349 | "language_info": {
350 | "file_extension": ".jl",
351 | "mimetype": "application/julia",
352 | "name": "julia",
353 | "version": "1.9.4"
354 | }
355 | },
356 | "nbformat": 4,
357 | "nbformat_minor": 2
358 | }
359 |
--------------------------------------------------------------------------------
/suppl_material_problems/II_34_2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "II-34-2 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/II_34.html\n",
10 | "\n",
11 | " mu = q*v*r/2\n"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 1,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "using DynamicPolynomials\n",
21 | "using JuMP\n",
22 | "using MosekTools\n",
23 | "using LinearAlgebra\n",
24 | "using CSV\n",
25 | "using DataFrames\n",
26 | "import JSON\n",
27 | "using Dates\n",
28 | "using Gurobi\n",
29 | "using SymbolicUtils # for symbolic simplification"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "functions for generating monomials"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 5,
42 | "metadata": {},
43 | "outputs": [
44 | {
45 | "data": {
46 | "text/plain": [
47 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
48 | ]
49 | },
50 | "execution_count": 5,
51 | "metadata": {},
52 | "output_type": "execute_result"
53 | }
54 | ],
55 | "source": [
56 | "function all_monomials_up_to_max_deg(x, deg)\n",
57 | " if size(x,1) == 0\n",
58 | " [1]\n",
59 | " else\n",
60 | " [ x[1]^k * m for k=0:deg \n",
61 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
62 | " ]\n",
63 | " end\n",
64 | "end\n",
65 | "\n",
66 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
67 | " [m\n",
68 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
69 | " #if all(unit(m) .== u)\n",
70 | " ]\n",
71 | "end\n",
72 | " \n",
73 | "function degree_poly(p)\n",
74 | " maximum(degree.(monomials(p)))\n",
75 | "end\n",
76 | "\n",
77 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
78 | " if size(x,1) == 0\n",
79 | " [1]\n",
80 | " else\n",
81 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
82 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
83 | " ]\n",
84 | " end\n",
85 | "end\n",
86 | "\n",
87 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
88 | " [m\n",
89 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
90 | " #if all(unit(m) .== u)\n",
91 | " ]\n",
92 | "end\n",
93 | "\n",
94 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
95 | " if size(x,1) == 0\n",
96 | " [1]\n",
97 | " else\n",
98 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
99 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
100 | " ]\n",
101 | " end\n",
102 | "end"
103 | ]
104 | },
105 | {
106 | "cell_type": "code",
107 | "execution_count": 2,
108 | "metadata": {},
109 | "outputs": [
110 | {
111 | "data": {
112 | "text/plain": [
113 | "1×8 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
114 | " A pi r mu I qc freq v"
115 | ]
116 | },
117 | "execution_count": 2,
118 | "metadata": {},
119 | "output_type": "execute_result"
120 | }
121 | ],
122 | "source": [
123 | "@polyvar A pi r mu I qc freq v # \n",
124 | "\n",
125 | "x = [ A pi r mu I qc freq v ] #"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": 3,
131 | "metadata": {},
132 | "outputs": [
133 | {
134 | "data": {
135 | "text/plain": [
136 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
137 | " A - pir²\n",
138 | " mu - AI\n",
139 | " I - qcfreq\n",
140 | " -v + 2pirfreq"
141 | ]
142 | },
143 | "execution_count": 3,
144 | "metadata": {},
145 | "output_type": "execute_result"
146 | }
147 | ],
148 | "source": [
149 | "axioms= \n",
150 | "[\n",
151 | " A - pi * r^2, # A = pi * r^2\n",
152 | " mu - I * A, # mu = I * A\n",
153 | " I - qc * freq, # I = q * freq\n",
154 | " freq * (2 * pi * r) - v, # freq = v/(2 * pi * r)\n",
155 | "]\n"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 6,
161 | "metadata": {},
162 | "outputs": [
163 | {
164 | "name": "stdout",
165 | "output_type": "stream",
166 | "text": [
167 | "size.(candidate_mons) = [(6924,), (6924,), (6924,), (6924,)]\n",
168 | "Set parameter Username\n",
169 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
170 | "Set parameter TimeLimit to value 600\n",
171 | "size.(coeff_αs) = [(6924,), (6924,), (6924,), (6924,)]\n",
172 | "Set parameter TimeLimit to value 600\n",
173 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
174 | "\n",
175 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
176 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
177 | "\n",
178 | "Optimize a model with 26839 rows, 27947 columns and 55830 nonzeros\n",
179 | "Model fingerprint: 0x8d978fcb\n",
180 | "Coefficient statistics:\n",
181 | " Matrix range [1e+00, 2e+00]\n",
182 | " Objective range [0e+00, 0e+00]\n",
183 | " Bounds range [0e+00, 0e+00]\n",
184 | " RHS range [1e+00, 1e+00]\n",
185 | "Presolve removed 26839 rows and 27947 columns\n",
186 | "Presolve time: 0.03s\n",
187 | "Presolve: All rows and columns removed\n",
188 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
189 | " 0 -0.0000000e+00 0.000000e+00 4.557000e-03 0s\n",
190 | "\n",
191 | "Solved in 0 iterations and 0.04 seconds (0.02 work units)\n",
192 | "Optimal objective -0.000000000e+00\n",
193 | "\n",
194 | "User-callback calls 60, time in user-callback 0.00 sec\n",
195 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
196 | ]
197 | },
198 | {
199 | "data": {
200 | "text/plain": [
201 | "OPTIMAL::TerminationStatusCode = 1"
202 | ]
203 | },
204 | "execution_count": 6,
205 | "metadata": {},
206 | "output_type": "execute_result"
207 | }
208 | ],
209 | "source": [
210 | "deg = 3\n",
211 | "deg_overall = 10\n",
212 | "theDegrees = [ 2 2 3 2 2 2 2 2 ] \n",
213 | " # A pi r mu I qc freq v \n",
214 | "\n",
215 | "candidate_mons = [\n",
216 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
217 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
218 | " for ai=axioms\n",
219 | "]\n",
220 | "\n",
221 | "@show size.(candidate_mons)\n",
222 | "\n",
223 | "#model = Model(Mosek.Optimizer)\n",
224 | "model = Model(Gurobi.Optimizer)\n",
225 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
226 | "\n",
227 | "mons_q = mons_of_max_degree_and_unit_overall([ mu qc v r ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
228 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
229 | "\n",
230 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
231 | "coeff_αs = [\n",
232 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
233 | " for (i,X)=enumerate(candidate_mons)\n",
234 | " ]\n",
235 | "@show size.(coeff_αs)\n",
236 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
237 | "\n",
238 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
239 | "eqs = coefficients(residual)\n",
240 | "\n",
241 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
242 | "@constraint model sum(coeff_q[degree.(mons_q, [mu]).>0]) == 1.0\n",
243 | "\n",
244 | "@constraint model eqs .== 0\n",
245 | "@objective model Max 0\n",
246 | "\n",
247 | "optimize!(model)\n",
248 | "@show termination_status(model)"
249 | ]
250 | },
251 | {
252 | "cell_type": "code",
253 | "execution_count": 7,
254 | "metadata": {},
255 | "outputs": [
256 | {
257 | "data": {
258 | "text/plain": [
259 | "#31 (generic function with 1 method)"
260 | ]
261 | },
262 | "execution_count": 7,
263 | "metadata": {},
264 | "output_type": "execute_result"
265 | }
266 | ],
267 | "source": [
268 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
269 | ]
270 | },
271 | {
272 | "cell_type": "code",
273 | "execution_count": 8,
274 | "metadata": {},
275 | "outputs": [
276 | {
277 | "data": {
278 | "text/latex": [
279 | "$$ mu - 0.5rqcv $$"
280 | ],
281 | "text/plain": [
282 | "mu - 0.5rqcv"
283 | ]
284 | },
285 | "execution_count": 8,
286 | "metadata": {},
287 | "output_type": "execute_result"
288 | }
289 | ],
290 | "source": [
291 | "value_q = value_poly(q)\n",
292 | "value_q"
293 | ]
294 | },
295 | {
296 | "cell_type": "code",
297 | "execution_count": 9,
298 | "metadata": {},
299 | "outputs": [
300 | {
301 | "data": {
302 | "text/latex": [
303 | "$$ mu - 0.5rqcv $$"
304 | ],
305 | "text/plain": [
306 | "mu - 0.5rqcv"
307 | ]
308 | },
309 | "execution_count": 9,
310 | "metadata": {},
311 | "output_type": "execute_result"
312 | }
313 | ],
314 | "source": [
315 | "q_sim = simplify(value_q)"
316 | ]
317 | },
318 | {
319 | "cell_type": "markdown",
320 | "metadata": {},
321 | "source": [
322 | "which is indeed the knwon relation mu = q r v / 2"
323 | ]
324 | },
325 | {
326 | "cell_type": "code",
327 | "execution_count": 10,
328 | "metadata": {},
329 | "outputs": [
330 | {
331 | "name": "stdout",
332 | "output_type": "stream",
333 | "text": [
334 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[qcfreq, 1.0, A, 0.5rqc]\n"
335 | ]
336 | },
337 | {
338 | "data": {
339 | "text/plain": [
340 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
341 | " qcfreq\n",
342 | " 1.0\n",
343 | " A\n",
344 | " 0.5rqc"
345 | ]
346 | },
347 | "execution_count": 10,
348 | "metadata": {},
349 | "output_type": "execute_result"
350 | }
351 | ],
352 | "source": [
353 | "@show value_αs = value_poly.(αs)"
354 | ]
355 | },
356 | {
357 | "cell_type": "markdown",
358 | "metadata": {},
359 | "source": []
360 | }
361 | ],
362 | "metadata": {
363 | "kernelspec": {
364 | "display_name": "Julia 1.10.2",
365 | "language": "julia",
366 | "name": "julia-1.10"
367 | },
368 | "language_info": {
369 | "file_extension": ".jl",
370 | "mimetype": "application/julia",
371 | "name": "julia",
372 | "version": "1.9.4"
373 | }
374 | },
375 | "nbformat": 4,
376 | "nbformat_minor": 2
377 | }
378 |
--------------------------------------------------------------------------------
/data_generation/data_gen_mix.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import numpy as np
4 | import regex as re
5 | from scipy.optimize import minimize
6 |
7 | np.random.seed(42)
8 |
9 |
10 | # Inelastic Relativistic Collision # inelastic relativistic collision law
11 | def generate_data_inelastic(num, noise_all = False, noise_target = False):
12 | # amount of noise in the data = 1%
13 | noise_amount = 0.01
14 | data = []
15 | for i in range(num):
16 | m = np.random.uniform(low=0.5, high=2.0)
17 | v_c = np.random.uniform(low=0.5, high=1.0)
18 | c = 1
19 | m_c = ( (4 * m) / (np.sqrt(3)) )
20 | p_c = (4 * m_c * v_c * c) / (np.sqrt(3 * (c**2 - v_c**2)))
21 |
22 | std = 0.833
23 | p_c_std = 22.098849327020748
24 |
25 | noise_m = np.random.normal(0, std, 1)[0] * noise_amount
26 | noise_v_c = np.random.normal(0, std, 1)[0] * noise_amount
27 | noise_p_c = np.random.normal(0, p_c_std, 1)[0] * noise_amount
28 |
29 | if noise_all:
30 | m = m + noise_m
31 | v_c = v_c + noise_v_c
32 | p_c = p_c + noise_p_c
33 | if noise_target:
34 | p_c = p_c + noise_p_c
35 |
36 | data.append([p_c, m, v_c, c])
37 | with open('data_inelastic.dat', 'w') as f:
38 | for d in data:
39 | for d_i in d:
40 | f.write(f'{d_i} ')
41 | f.write('\n')
42 |
43 |
44 | # Decay of Pion into Muon and Neutrino # kinetic energy, and momentum when a pion at rest decays into a muon and a neutrino,
45 | def generate_data_decay(num, noise_all = False, noise_target = False):
46 | # amount of noise in the data = 1%
47 | noise_amount = 0.01
48 | data = []
49 |
50 | for i in range(num):
51 | m_pi = np.random.uniform(low=0.5, high=2.0)
52 | m_u = np.random.uniform(low=0.5, high=2.0)
53 | p_v = (m_pi**2 - m_u**2) / (2 * m_pi)
54 |
55 | std = 0.833
56 | p_v_std = 0.7711755220155624
57 |
58 | noise_m_pi = np.random.normal(0, std, 1)[0] * noise_amount
59 | noise_m_u = np.random.normal(0, std, 1)[0] * noise_amount
60 | noise_m_p = np.random.normal(0, std, 1)[0] * noise_amount
61 | noise_p_v = np.random.normal(0, p_v_std, 1)[0] * noise_amount
62 |
63 | if noise_all:
64 | m_pi = m_pi + noise_m_pi
65 | m_u = m_u + noise_m_u
66 | p_v = p_v + noise_p_v
67 | if noise_target:
68 | p_v = p_v + noise_p_v
69 |
70 | data.append([p_v, m_pi, m_u])
71 |
72 | with open('data_decay.dat', 'w') as f:
73 | for d in data:
74 | for d_i in d:
75 | f.write(f'{d_i} ')
76 | f.write('\n')
77 |
78 |
79 | # Radiation Damping and Light Scattering # the light scattering law,
80 | def generate_data_light(num, noise_all = False, noise_target = False):
81 | # amount of noise in the data = 1%
82 | noise_amount = 0.01
83 | data = []
84 |
85 | for i in range(num):
86 | q_c = np.random.uniform(low=0.5, high=2.0)
87 | x_0 = np.random.uniform(low=0.5, high=2.0)
88 | w = np.random.uniform(low=0.5, high=2.0)
89 | pi = np.pi
90 | p = 4/3 * pi * q_c**2 * x_0**2 * w**4
91 |
92 | std = 0.833
93 | p_std = 94.05754932859698
94 |
95 | noise_q_c = np.random.normal(0, std, 1)[0] * noise_amount
96 | noise_x_0 = np.random.normal(0, std, 1)[0] * noise_amount
97 | noise_w = np.random.normal(0, std, 1)[0] * noise_amount
98 | noise_p = np.random.normal(0, p_std, 1)[0] * noise_amount
99 |
100 | if noise_all:
101 | q_c = q_c + noise_q_c
102 | x_0 = x_0 + noise_x_0
103 | w = w + noise_w
104 | p = p + noise_p
105 | if noise_target:
106 | p = p + noise_p
107 |
108 | data.append([p, q_c, x_0, w])
109 |
110 | with open('data_light.dat', 'w') as f:
111 | for d in data:
112 | for d_i in d:
113 | f.write(f'{d_i} ')
114 | f.write('\n')
115 |
116 |
117 | # Escape Velocity # the minimal velocity that enables an object to overcome the gravitational pull of a plane,
118 | def generate_data_escape(num, noise_all = False, noise_target = False):
119 | # amount of noise in the data = 1%
120 | noise_amount = 0.01
121 | data = []
122 | for i in range(num):
123 | G = 1
124 | m = np.random.uniform(low=0.5, high=2.0)
125 | r = np.random.uniform(low=0.5, high=2.0)
126 | v_e = np.sqrt((2*G*m)/r)
127 |
128 | std = 0.833
129 | v_e_std = 0.4030474579043394
130 |
131 | noise_m = np.random.normal(0, std, 1)[0] * noise_amount
132 | noise_r = np.random.normal(0, std, 1)[0] * noise_amount
133 | noise_v_e = np.random.normal(0, v_e_std, 1)[0] * noise_amount
134 |
135 | if noise_all:
136 | m = m + noise_m
137 | r = r + noise_r
138 | v_e = v_e + noise_v_e
139 | if noise_target:
140 | v_e = v_e + noise_v_e
141 |
142 | data.append([v_e, G, m, r])
143 |
144 | with open('data_escape.dat', 'w') as f:
145 | for d in data:
146 | for d_i in d:
147 | f.write(f'{d_i} ')
148 | f.write('\n')
149 |
150 |
151 |
152 | # Hall Effect #the Hall potential of an electrical conductor.
153 | def generate_data_hall(num, noise_all = False, noise_target = False):
154 | # amount of noise in the data = 1%
155 | noise_amount = 0.01
156 | data = []
157 |
158 | for i in range(num):
159 | h = np.random.uniform(low=0.5, high=2.0)
160 | l = np.random.uniform(low=0.5, high=2.0)
161 | I = np.random.uniform(low=0.5, high=2.0)
162 | b = np.random.uniform(low=0.5, high=2.0)
163 | N = np.random.uniform(low=0.5, high=2.0)
164 | q_e = np.random.uniform(low=0.5, high=2.0)
165 | u_h = (h * l * I * b) / (N * q_e)
166 |
167 | std = 0.833
168 | u_h_std = 2.2342097847869353
169 |
170 | noise_h = np.random.normal(0, std, 1)[0] * noise_amount
171 | noise_l = np.random.normal(0, std, 1)[0] * noise_amount
172 | noise_I = np.random.normal(0, std, 1)[0] * noise_amount
173 | noise_b = np.random.normal(0, std, 1)[0] * noise_amount
174 | noise_N = np.random.normal(0, std, 1)[0] * noise_amount
175 | noise_q_e = np.random.normal(0, std, 1)[0] * noise_amount
176 | noise_u_h = np.random.normal(0, u_h_std, 1)[0] * noise_amount
177 |
178 | if noise_all:
179 | h = h + noise_h
180 | l = l + noise_l
181 | I = I + noise_I
182 | b = b + noise_b
183 | N = N + noise_N
184 | q_e = q_e + noise_q_e
185 | u_h = u_h + noise_u_h
186 | if noise_target:
187 | u_h = u_h + noise_u_h
188 |
189 | data.append([u_h, h, l, I, b, N, q_e])
190 |
191 | with open('data_hall.dat', 'w') as f:
192 | for d in data:
193 | for d_i in d:
194 | f.write(f'{d_i} ')
195 | f.write('\n')
196 |
197 |
198 |
199 | # Compton Scattering
200 | def generate_data_compton(num, noise_all=False, noise_target=False):
201 | # amount of noise in the data = 1%
202 | noise_amount = 0.01
203 | data = []
204 | for i in range(num):
205 | h = 1
206 | c = 1
207 | l_1 = np.random.uniform(low=0.5, high=2.0)
208 | m_e = 1
209 | cos_t = np.random.uniform(low=0.05, high=1.0)
210 | l_2 = l_1 + ((h * (1 - cos_t)) / (m_e * c ))
211 |
212 | std = 0.833
213 | l_2_std = 0.6148374283827321
214 |
215 | noise_l_1 = np.random.normal(0, std, 1)[0] * noise_amount
216 | noise_cos_t = np.random.normal(0, std, 1)[0] * noise_amount
217 | noise_l_2 = np.random.normal(0, l_2_std, 1)[0] * noise_amount
218 |
219 | if noise_all:
220 | l_1 = l_1 + noise_l_1
221 | cos_t = cos_t + noise_cos_t
222 | l_2 = l_2 + noise_l_2
223 | if noise_target:
224 | l_2 = l_2 + noise_l_2
225 |
226 | data.append([l_2, l_1, cos_t, h, c, m_e])
227 |
228 | with open('data_compton.dat', 'w') as f:
229 | for d in data:
230 | for d_i in d:
231 | f.write(f'{d_i} ')
232 | f.write('\n')
233 |
234 |
235 | # Radiation Gravitational Wave Power
236 | def generate_data_radiationGravitationalWavePower(num, noise_all=False, noise_target=False):
237 | # amount of noise in the data = 1%
238 | noise_amount = 0.01
239 | data = []
240 | for i in range(num):
241 | m1 = np.random.uniform(low=0.5, high=2.0)
242 | m2 = np.random.uniform(low=0.5, high=2.0)
243 | r = np.random.uniform(low=0.5, high=2.0)
244 | G = 1
245 | c = 1
246 | p = - (32 * G**4 * m1**2 * m2**2 * (m1 + m2))/(5 * c**5 * r**5)
247 |
248 | std = 0.833
249 | p_std = 533.2198022034981
250 |
251 | noise_m1 = np.random.normal(0, std, 1)[0] * noise_amount
252 | noise_m2 = np.random.normal(0, std, 1)[0] * noise_amount
253 | noise_r = np.random.normal(0, std, 1)[0] * noise_amount
254 | noise_p = np.random.normal(0, p_std, 1)[0] * noise_amount
255 |
256 | if noise_all:
257 | m1 = m1 + noise_m1
258 | m2 = m2 + noise_m2
259 | r = r + noise_r
260 | p = p + noise_p
261 | if noise_target:
262 | p = p + noise_p
263 | data.append([p, m1, m2, r])
264 | with open('data_WavePower.dat', 'w') as f:
265 | for d in data:
266 | for d_i in d:
267 | f.write(f'{d_i} ')
268 | f.write('\n')
269 |
270 |
271 | # Hagen Poiseuille equation
272 | def generate_data_HagenPoiseuille(num, noise_all=False, noise_target=False):
273 | # amount of noise in the data = 1%
274 | noise_amount = 0.01
275 | data = []
276 | for i in range(num):
277 | p = np.random.uniform(low=0.5, high=2.0)
278 | l = np.random.uniform(low=0.5, high=2.0)
279 | mu = np.random.uniform(low=0.5, high=2.0)
280 | rad = np.random.uniform(low=0.5, high=5.0)
281 | r = np.random.uniform(low=0, high=rad)
282 | u = - (p * (r**2 - rad**2)) / ( 4 * l * mu)
283 |
284 | std = 0.833
285 | u_std = 2.300493890164562
286 |
287 | noise_p = np.random.normal(0, std, 1)[0] * noise_amount
288 | noise_l = np.random.normal(0, std, 1)[0] * noise_amount
289 | noise_mu = np.random.normal(0, std, 1)[0] * noise_amount
290 | noise_r = np.random.normal(0, std, 1)[0] * noise_amount
291 | noise_rad = np.random.normal(0, std, 1)[0] * noise_amount
292 | noise_u = np.random.normal(0, u_std, 1)[0] * noise_amount
293 |
294 | if noise_all:
295 | p = p + noise_p
296 | l = l + noise_l
297 | r = r + noise_r
298 | mu = mu + noise_mu
299 | rad = rad + noise_rad
300 | # while not (rad > r):
301 | # rad = np.random.uniform(low=r, high=5.0)
302 | # rad = rad + noise_rad
303 | u = u + noise_u
304 | if noise_target:
305 | u = u + noise_u
306 |
307 | data.append([u, p, l, mu, r, rad])
308 |
309 | with open('data_HagenPoiseuille.dat', 'w') as f:
310 | for d in data:
311 | for d_i in d:
312 | f.write(f'{d_i} ')
313 | f.write('\n')
314 |
315 |
316 |
317 | generate_data_inelastic(10, noise_all = False, noise_target = True)
318 | generate_data_decay(10, noise_all = False, noise_target = True)
319 | generate_data_light(10, noise_all = False, noise_target = True)
320 | generate_data_escape(10, noise_all = False, noise_target = True)
321 | generate_data_hall(10, noise_all = False, noise_target = True)
322 | generate_data_compton(10, noise_all = False, noise_target = True)
323 | generate_data_radiationGravitationalWavePower(10, noise_all = False, noise_target = True)
324 | generate_data_HagenPoiseuille(10, noise_all = False, noise_target = True)
325 |
326 |
327 |
328 |
329 |
--------------------------------------------------------------------------------
/suppl_material_problems/I_10_9.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "II-10-9 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/II_10.html\n",
10 | "\n",
11 | "E = sigmaF/(eps * (1+ chi))"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 1,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "using DynamicPolynomials\n",
21 | "using JuMP\n",
22 | "using MosekTools\n",
23 | "using LinearAlgebra\n",
24 | "using CSV\n",
25 | "using DataFrames\n",
26 | "import JSON\n",
27 | "using Dates\n",
28 | "using Gurobi\n",
29 | "using SymbolicUtils # for symbolic simplification"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "functions for generating monomials"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 12,
42 | "metadata": {},
43 | "outputs": [
44 | {
45 | "data": {
46 | "text/plain": [
47 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
48 | ]
49 | },
50 | "execution_count": 12,
51 | "metadata": {},
52 | "output_type": "execute_result"
53 | }
54 | ],
55 | "source": [
56 | "function all_monomials_up_to_max_deg(x, deg)\n",
57 | " if size(x,1) == 0\n",
58 | " [1]\n",
59 | " else\n",
60 | " [ x[1]^k * m for k=0:deg \n",
61 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
62 | " ]\n",
63 | " end\n",
64 | "end\n",
65 | "\n",
66 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
67 | " [m\n",
68 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
69 | " #if all(unit(m) .== u)\n",
70 | " ]\n",
71 | "end\n",
72 | " \n",
73 | "function degree_poly(p)\n",
74 | " maximum(degree.(monomials(p)))\n",
75 | "end\n",
76 | "\n",
77 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
78 | " if size(x,1) == 0\n",
79 | " [1]\n",
80 | " else\n",
81 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
82 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
83 | " ]\n",
84 | " end\n",
85 | "end\n",
86 | "\n",
87 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
88 | " [m\n",
89 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
90 | " #if all(unit(m) .== u)\n",
91 | " ]\n",
92 | "end\n",
93 | "\n",
94 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
95 | " if size(x,1) == 0\n",
96 | " [1]\n",
97 | " else\n",
98 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
99 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
100 | " ]\n",
101 | " end\n",
102 | "end"
103 | ]
104 | },
105 | {
106 | "cell_type": "code",
107 | "execution_count": 13,
108 | "metadata": {},
109 | "outputs": [
110 | {
111 | "data": {
112 | "text/plain": [
113 | "1×9 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
114 | " E eps_0 sigmaF sigmaP N qc delta P chi"
115 | ]
116 | },
117 | "execution_count": 13,
118 | "metadata": {},
119 | "output_type": "execute_result"
120 | }
121 | ],
122 | "source": [
123 | "@polyvar E eps_0 sigmaF sigmaP N qc delta P chi # \n",
124 | "\n",
125 | "x = [E eps_0 sigmaF sigmaP N qc delta P chi ] #"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": 20,
131 | "metadata": {},
132 | "outputs": [
133 | {
134 | "data": {
135 | "text/plain": [
136 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
137 | " sigmaP - sigmaF + Eeps_0\n",
138 | " sigmaP - Nqcdelta\n",
139 | " P - Eeps_0chi\n",
140 | " P - Nqcdelta"
141 | ]
142 | },
143 | "execution_count": 20,
144 | "metadata": {},
145 | "output_type": "execute_result"
146 | }
147 | ],
148 | "source": [
149 | "axioms= \n",
150 | "[\n",
151 | " E * eps_0 - (sigmaF - sigmaP), # E = (sigmaF - sigmaP)/eps\n",
152 | " sigmaP - N * qc * delta, # sigmaP = N * q * delta\n",
153 | " P - chi * eps_0 * E, # P = chi * eps * E\n",
154 | " P - N * qc * delta, # P = N * q * delta\n",
155 | "]\n",
156 | "\n"
157 | ]
158 | },
159 | {
160 | "cell_type": "code",
161 | "execution_count": 26,
162 | "metadata": {},
163 | "outputs": [
164 | {
165 | "name": "stdout",
166 | "output_type": "stream",
167 | "text": [
168 | "size.(candidate_mons) = [(7547,), (7547,), (7547,), (7547,)]\n",
169 | "Set parameter Username\n",
170 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
171 | "Set parameter TimeLimit to value 600\n",
172 | "size.(coeff_αs) = [(7547,), (7547,), (7547,), (7547,)]\n",
173 | "Set parameter TimeLimit to value 600\n",
174 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
175 | "\n",
176 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
177 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
178 | "\n",
179 | "Optimize a model with 29489 rows, 31091 columns and 69478 nonzeros\n",
180 | "Model fingerprint: 0x645fd877\n",
181 | "Coefficient statistics:\n",
182 | " Matrix range [1e+00, 1e+00]\n",
183 | " Objective range [0e+00, 0e+00]\n",
184 | " Bounds range [0e+00, 0e+00]\n",
185 | " RHS range [2e+00, 2e+00]\n",
186 | "Presolve removed 29489 rows and 31091 columns\n",
187 | "Presolve time: 0.03s\n",
188 | "Presolve: All rows and columns removed\n",
189 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
190 | " 0 -0.0000000e+00 0.000000e+00 4.261000e-03 0s\n",
191 | "\n",
192 | "Solved in 0 iterations and 0.04 seconds (0.03 work units)\n",
193 | "Optimal objective -0.000000000e+00\n",
194 | "\n",
195 | "User-callback calls 55, time in user-callback 0.00 sec\n",
196 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
197 | ]
198 | },
199 | {
200 | "data": {
201 | "text/plain": [
202 | "OPTIMAL::TerminationStatusCode = 1"
203 | ]
204 | },
205 | "execution_count": 26,
206 | "metadata": {},
207 | "output_type": "execute_result"
208 | }
209 | ],
210 | "source": [
211 | "deg = 3\n",
212 | "deg_overall = 10\n",
213 | "theDegrees = [ 1 2 2 2 2 2 2 2 1] \n",
214 | " # E eps_0 sigmaF sigmaP N qc delta P chi \n",
215 | "\n",
216 | "candidate_mons = [\n",
217 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
218 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
219 | " for ai=axioms\n",
220 | "]\n",
221 | "\n",
222 | "@show size.(candidate_mons)\n",
223 | "\n",
224 | "#model = Model(Mosek.Optimizer)\n",
225 | "model = Model(Gurobi.Optimizer)\n",
226 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
227 | "\n",
228 | "mons_q = mons_of_max_degree_and_unit_overall([ E sigmaF eps_0 chi qc ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
229 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
230 | "\n",
231 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
232 | "coeff_αs = [\n",
233 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
234 | " for (i,X)=enumerate(candidate_mons)\n",
235 | " ]\n",
236 | "@show size.(coeff_αs)\n",
237 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
238 | "\n",
239 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
240 | "eqs = coefficients(residual)\n",
241 | "\n",
242 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
243 | "@constraint model sum(coeff_q[degree.(mons_q, [E]).>0]) == 2.0\n",
244 | "\n",
245 | "@constraint model eqs .== 0\n",
246 | "@objective model Max 0\n",
247 | "\n",
248 | "optimize!(model)\n",
249 | "@show termination_status(model)"
250 | ]
251 | },
252 | {
253 | "cell_type": "code",
254 | "execution_count": 27,
255 | "metadata": {},
256 | "outputs": [
257 | {
258 | "data": {
259 | "text/plain": [
260 | "#91 (generic function with 1 method)"
261 | ]
262 | },
263 | "execution_count": 27,
264 | "metadata": {},
265 | "output_type": "execute_result"
266 | }
267 | ],
268 | "source": [
269 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
270 | ]
271 | },
272 | {
273 | "cell_type": "code",
274 | "execution_count": 28,
275 | "metadata": {},
276 | "outputs": [
277 | {
278 | "data": {
279 | "text/latex": [
280 | "$$ -sigmaF + Eeps_0 + Eeps_0chi $$"
281 | ],
282 | "text/plain": [
283 | "-sigmaF + Eeps_0 + Eeps_0chi"
284 | ]
285 | },
286 | "execution_count": 28,
287 | "metadata": {},
288 | "output_type": "execute_result"
289 | }
290 | ],
291 | "source": [
292 | "value_q = value_poly(q)\n",
293 | "value_q"
294 | ]
295 | },
296 | {
297 | "cell_type": "code",
298 | "execution_count": 29,
299 | "metadata": {},
300 | "outputs": [
301 | {
302 | "data": {
303 | "text/latex": [
304 | "$$ -sigmaF + Eeps_0 + Eeps_0chi $$"
305 | ],
306 | "text/plain": [
307 | "-sigmaF + Eeps_0 + Eeps_0chi"
308 | ]
309 | },
310 | "execution_count": 29,
311 | "metadata": {},
312 | "output_type": "execute_result"
313 | }
314 | ],
315 | "source": [
316 | "q_sim = simplify(value_q)"
317 | ]
318 | },
319 | {
320 | "cell_type": "markdown",
321 | "metadata": {},
322 | "source": [
323 | "which can be reorganized to arrive at the known relation E = sigmaF/(eps * (1+ chi))\n"
324 | ]
325 | },
326 | {
327 | "cell_type": "code",
328 | "execution_count": 30,
329 | "metadata": {},
330 | "outputs": [
331 | {
332 | "name": "stdout",
333 | "output_type": "stream",
334 | "text": [
335 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[1.0, -1.0, -1.0, 1.0]\n"
336 | ]
337 | },
338 | {
339 | "data": {
340 | "text/plain": [
341 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
342 | " 1.0\n",
343 | " -1.0\n",
344 | " -1.0\n",
345 | " 1.0"
346 | ]
347 | },
348 | "execution_count": 30,
349 | "metadata": {},
350 | "output_type": "execute_result"
351 | }
352 | ],
353 | "source": [
354 | "@show value_αs = value_poly.(αs)"
355 | ]
356 | }
357 | ],
358 | "metadata": {
359 | "kernelspec": {
360 | "display_name": "Julia 1.10.2",
361 | "language": "julia",
362 | "name": "julia-1.10"
363 | },
364 | "language_info": {
365 | "file_extension": ".jl",
366 | "mimetype": "application/julia",
367 | "name": "julia",
368 | "version": "1.9.4"
369 | }
370 | },
371 | "nbformat": 4,
372 | "nbformat_minor": 2
373 | }
374 |
--------------------------------------------------------------------------------
/suppl_material_problems/I_15_10.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "I-15-10 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/I_15.html\n",
10 | "\n",
11 | "given the resting mass, m0, the velocity v find the momentum:\n",
12 | "p = m_0 * v /sqrt(1 - v*v/c*c)\n"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": 1,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "using DynamicPolynomials\n",
22 | "using JuMP\n",
23 | "using MosekTools\n",
24 | "using LinearAlgebra\n",
25 | "using CSV\n",
26 | "using DataFrames\n",
27 | "import JSON\n",
28 | "using Dates\n",
29 | "using Gurobi\n",
30 | "using SymbolicUtils # for symbolic simplification"
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "metadata": {},
36 | "source": [
37 | "functions for generating monomials"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": 2,
43 | "metadata": {},
44 | "outputs": [
45 | {
46 | "data": {
47 | "text/plain": [
48 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
49 | ]
50 | },
51 | "execution_count": 2,
52 | "metadata": {},
53 | "output_type": "execute_result"
54 | }
55 | ],
56 | "source": [
57 | "function all_monomials_up_to_max_deg(x, deg)\n",
58 | " if size(x,1) == 0\n",
59 | " [1]\n",
60 | " else\n",
61 | " [ x[1]^k * m for k=0:deg \n",
62 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
63 | " ]\n",
64 | " end\n",
65 | "end\n",
66 | "\n",
67 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
68 | " [m\n",
69 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
70 | " #if all(unit(m) .== u)\n",
71 | " ]\n",
72 | "end\n",
73 | " \n",
74 | "function degree_poly(p)\n",
75 | " maximum(degree.(monomials(p)))\n",
76 | "end\n",
77 | "\n",
78 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
79 | " if size(x,1) == 0\n",
80 | " [1]\n",
81 | " else\n",
82 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
83 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
84 | " ]\n",
85 | " end\n",
86 | "end\n",
87 | "\n",
88 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
89 | " [m\n",
90 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
91 | " #if all(unit(m) .== u)\n",
92 | " ]\n",
93 | "end\n",
94 | "\n",
95 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
96 | " if size(x,1) == 0\n",
97 | " [1]\n",
98 | " else\n",
99 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
100 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
101 | " ]\n",
102 | " end\n",
103 | "end"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": 3,
109 | "metadata": {},
110 | "outputs": [
111 | {
112 | "data": {
113 | "text/plain": [
114 | "1×5 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
115 | " m m_0 p v c"
116 | ]
117 | },
118 | "execution_count": 3,
119 | "metadata": {},
120 | "output_type": "execute_result"
121 | }
122 | ],
123 | "source": [
124 | "@polyvar m m_0 p v c # \n",
125 | "\n",
126 | "x = [ m m_0 p v c ] #"
127 | ]
128 | },
129 | {
130 | "cell_type": "code",
131 | "execution_count": 4,
132 | "metadata": {},
133 | "outputs": [
134 | {
135 | "data": {
136 | "text/plain": [
137 | "2-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
138 | " p - mv\n",
139 | " -m_0c² + m²c² - m²v²"
140 | ]
141 | },
142 | "execution_count": 4,
143 | "metadata": {},
144 | "output_type": "execute_result"
145 | },
146 | {
147 | "name": "stderr",
148 | "output_type": "stream",
149 | "text": [
150 | "WARNING: both JuMP and DynamicPolynomials export \"map_coefficients\"; uses of it in module Main must be qualified\n",
151 | "WARNING: both JuMP and DynamicPolynomials export \"coefficient\"; uses of it in module Main must be qualified\n",
152 | "WARNING: both DataFrames and DynamicPolynomials export \"combine\"; uses of it in module Main must be qualified\n"
153 | ]
154 | }
155 | ],
156 | "source": [
157 | "axioms= \n",
158 | "[\n",
159 | " p - m * v, # momentum definition \n",
160 | " m^2 * (c^2 - v^2) - m_0 * c^2, # resting mass to enertic mass relation m = m_0/ sqrt(1 - v*v/c*c)\n",
161 | " \n",
162 | "]\n"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": 6,
168 | "metadata": {},
169 | "outputs": [
170 | {
171 | "name": "stdout",
172 | "output_type": "stream",
173 | "text": [
174 | "size.(candidate_mons) = [(1003,), (1003,)]\n",
175 | "Set parameter Username\n",
176 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
177 | "Set parameter TimeLimit to value 600\n",
178 | "size.(coeff_αs) = [(1003,), (1003,)]\n",
179 | "Set parameter TimeLimit to value 600\n",
180 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
181 | "\n",
182 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
183 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
184 | "\n",
185 | "Optimize a model with 3136 rows, 2262 columns and 5463 nonzeros\n",
186 | "Model fingerprint: 0xf2178e7c\n",
187 | "Coefficient statistics:\n",
188 | " Matrix range [1e+00, 1e+00]\n",
189 | " Objective range [0e+00, 0e+00]\n",
190 | " Bounds range [0e+00, 0e+00]\n",
191 | " RHS range [1e+00, 1e+00]\n",
192 | "Presolve removed 3136 rows and 2262 columns\n",
193 | "Presolve time: 0.00s\n",
194 | "Presolve: All rows and columns removed\n",
195 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
196 | " 0 -0.0000000e+00 0.000000e+00 8.400000e-05 0s\n",
197 | "\n",
198 | "Solved in 0 iterations and 0.01 seconds (0.00 work units)\n",
199 | "Optimal objective -0.000000000e+00\n",
200 | "\n",
201 | "User-callback calls 53, time in user-callback 0.00 sec\n",
202 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
203 | ]
204 | },
205 | {
206 | "data": {
207 | "text/plain": [
208 | "OPTIMAL::TerminationStatusCode = 1"
209 | ]
210 | },
211 | "execution_count": 6,
212 | "metadata": {},
213 | "output_type": "execute_result"
214 | }
215 | ],
216 | "source": [
217 | "deg = 3\n",
218 | "deg_overall = 12\n",
219 | "theDegrees = [ 3 3 3 3 3 ] \n",
220 | " # m m_0 p v c \n",
221 | "\n",
222 | "candidate_mons = [\n",
223 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
224 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
225 | " for ai=axioms\n",
226 | "]\n",
227 | "\n",
228 | "@show size.(candidate_mons)\n",
229 | "\n",
230 | "#model = Model(Mosek.Optimizer)\n",
231 | "model = Model(Gurobi.Optimizer)\n",
232 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
233 | "\n",
234 | "mons_q = mons_of_max_degree_and_unit_overall([m_0 p v c ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
235 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
236 | "\n",
237 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
238 | "coeff_αs = [\n",
239 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
240 | " for (i,X)=enumerate(candidate_mons)\n",
241 | " ]\n",
242 | "@show size.(coeff_αs)\n",
243 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
244 | "\n",
245 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
246 | "eqs = coefficients(residual)\n",
247 | "\n",
248 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
249 | "@constraint model sum(coeff_q[degree.(mons_q, [p]).>0]) == 1.0\n",
250 | "\n",
251 | "@constraint model eqs .== 0\n",
252 | "@objective model Max 0\n",
253 | "\n",
254 | "optimize!(model)\n",
255 | "@show termination_status(model)"
256 | ]
257 | },
258 | {
259 | "cell_type": "code",
260 | "execution_count": 7,
261 | "metadata": {},
262 | "outputs": [
263 | {
264 | "data": {
265 | "text/plain": [
266 | "#43 (generic function with 1 method)"
267 | ]
268 | },
269 | "execution_count": 7,
270 | "metadata": {},
271 | "output_type": "execute_result"
272 | }
273 | ],
274 | "source": [
275 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
276 | ]
277 | },
278 | {
279 | "cell_type": "code",
280 | "execution_count": 8,
281 | "metadata": {},
282 | "outputs": [
283 | {
284 | "data": {
285 | "text/latex": [
286 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
287 | ],
288 | "text/plain": [
289 | "-p³c² + p³v² + m_0pv²c²"
290 | ]
291 | },
292 | "execution_count": 8,
293 | "metadata": {},
294 | "output_type": "execute_result"
295 | }
296 | ],
297 | "source": [
298 | "value_q = value_poly(q)\n",
299 | "value_q"
300 | ]
301 | },
302 | {
303 | "cell_type": "code",
304 | "execution_count": 9,
305 | "metadata": {},
306 | "outputs": [
307 | {
308 | "data": {
309 | "text/latex": [
310 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
311 | ],
312 | "text/plain": [
313 | "-p³c² + p³v² + m_0pv²c²"
314 | ]
315 | },
316 | "execution_count": 9,
317 | "metadata": {},
318 | "output_type": "execute_result"
319 | }
320 | ],
321 | "source": [
322 | "q_sim = simplify(value_q)"
323 | ]
324 | },
325 | {
326 | "cell_type": "markdown",
327 | "metadata": {},
328 | "source": [
329 | "which can be reorganized to arrive at the known relation p = m_0 * v /sqrt(1 - v*v/c*c)"
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": 10,
335 | "metadata": {},
336 | "outputs": [
337 | {
338 | "name": "stdout",
339 | "output_type": "stream",
340 | "text": [
341 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-p²c² + p²v² - mpvc² + mpv³, -pv²]\n"
342 | ]
343 | },
344 | {
345 | "data": {
346 | "text/plain": [
347 | "2-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
348 | " -p²c² + p²v² - mpvc² + mpv³\n",
349 | " -pv²"
350 | ]
351 | },
352 | "execution_count": 10,
353 | "metadata": {},
354 | "output_type": "execute_result"
355 | }
356 | ],
357 | "source": [
358 | "@show value_αs = value_poly.(αs)"
359 | ]
360 | },
361 | {
362 | "cell_type": "markdown",
363 | "metadata": {},
364 | "source": []
365 | }
366 | ],
367 | "metadata": {
368 | "kernelspec": {
369 | "display_name": "Julia 1.10.2",
370 | "language": "julia",
371 | "name": "julia-1.10"
372 | },
373 | "language_info": {
374 | "file_extension": ".jl",
375 | "mimetype": "application/julia",
376 | "name": "julia",
377 | "version": "1.9.4"
378 | }
379 | },
380 | "nbformat": 4,
381 | "nbformat_minor": 2
382 | }
383 |
--------------------------------------------------------------------------------
/suppl_material_problems/inelastic.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Inelastic Relativistic Collision\n",
8 | "https://www.feynmanlectures.caltech.edu/info/exercises/inelastic_relativistic_collision.html\n",
9 | "\n",
10 | "\n",
11 | "A particle of mass m, moving at speed v = 4c/5, collides inelastically with a similar particle at rest.\n",
12 | "\n",
13 | "(a) What is the speed vc of the composite particle?\n",
14 | "\n",
15 | "(b) What is its mass mc?"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 3,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "using DynamicPolynomials\n",
25 | "using JuMP\n",
26 | "using MosekTools\n",
27 | "using LinearAlgebra\n",
28 | "using CSV\n",
29 | "using DataFrames\n",
30 | "import JSON\n",
31 | "using Dates\n",
32 | "using Gurobi\n",
33 | "using FileIO\n",
34 | "using JLD2"
35 | ]
36 | },
37 | {
38 | "cell_type": "markdown",
39 | "metadata": {},
40 | "source": [
41 | "functions for generating monomials"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": 13,
47 | "metadata": {},
48 | "outputs": [
49 | {
50 | "data": {
51 | "text/plain": [
52 | "mons_of_max_degree_and_unit_overall (generic function with 1 method)"
53 | ]
54 | },
55 | "execution_count": 13,
56 | "metadata": {},
57 | "output_type": "execute_result"
58 | }
59 | ],
60 | "source": [
61 | "function all_monomials_up_to_max_deg(x, deg)\n",
62 | " if size(x,1) == 0\n",
63 | " [1]\n",
64 | " else\n",
65 | " [ x[1]^k * m for k=0:deg \n",
66 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
67 | " ]\n",
68 | " end\n",
69 | "end\n",
70 | "\n",
71 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
72 | " [m\n",
73 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
74 | " #if all(unit(m) .== u)\n",
75 | " ]\n",
76 | "end\n",
77 | " \n",
78 | "function degree_poly(p)\n",
79 | " maximum(degree.(monomials(p)))\n",
80 | "end\n",
81 | "\n",
82 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
83 | " if size(x,1) == 0\n",
84 | " [1]\n",
85 | " else\n",
86 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
87 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
88 | " ]\n",
89 | " end\n",
90 | "end\n",
91 | "\n",
92 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
93 | " if size(x,1) == 0\n",
94 | " [1]\n",
95 | " else\n",
96 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
97 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
98 | " ]\n",
99 | " end\n",
100 | "end\n",
101 | "\n",
102 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
103 | " [m\n",
104 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
105 | " #if all(unit(m) .== u)\n",
106 | " ]\n",
107 | "end\n"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": 5,
113 | "metadata": {},
114 | "outputs": [
115 | {
116 | "data": {
117 | "text/plain": [
118 | "1×11 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
119 | " m_m m_c m_r v_m v_c c p_m p_c E_m E_r E_c"
120 | ]
121 | },
122 | "execution_count": 5,
123 | "metadata": {},
124 | "output_type": "execute_result"
125 | }
126 | ],
127 | "source": [
128 | "@polyvar m_m m_c m_r v_m v_c c p_m p_c E_m E_r E_c # the order matters per evaluation(?)\n",
129 | "\n",
130 | "x =[m_m m_c m_r v_m v_c c p_m p_c E_m E_r E_c ] "
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": 18,
136 | "metadata": {},
137 | "outputs": [
138 | {
139 | "data": {
140 | "text/latex": [
141 | "$$ E_r^{2} + 2E_mE_r + E_m^{2} $$"
142 | ],
143 | "text/plain": [
144 | "E_r² + 2E_mE_r + E_m²"
145 | ]
146 | },
147 | "execution_count": 18,
148 | "metadata": {},
149 | "output_type": "execute_result"
150 | }
151 | ],
152 | "source": [
153 | "E_c = E_m + E_r # conservation of energy\n",
154 | "cEs =E_c^2 # conservation of energy squared "
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": 42,
160 | "metadata": {},
161 | "outputs": [
162 | {
163 | "data": {
164 | "text/plain": [
165 | "9-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
166 | " c²p_m² - v_m²p_m² - m_m²v_m²c²\n",
167 | " E_m² - c²p_m² - m_m²c⁴\n",
168 | " E_r - m_rc²\n",
169 | " E_r² + 2.0E_mE_r + E_m² - c²p_c² - m_c²c²\n",
170 | " 0.0\n",
171 | " p_c - p_m\n",
172 | " -0.8c + v_m\n",
173 | " m_r - m_m\n",
174 | " c²p_c² - v_c²p_c² - m_c²v_c²c²"
175 | ]
176 | },
177 | "execution_count": 42,
178 | "metadata": {},
179 | "output_type": "execute_result"
180 | }
181 | ],
182 | "source": [
183 | "axioms= \n",
184 | "[\n",
185 | " #p_m^2*(c^2 - v_m^2)-m_m^2*v_m^2*c^2,\n",
186 | " p_m^2*(c^2-v_m^2) - m_m^2*v_m^2*c^2, # momentum of moving particle p_m = m*v / (sqrt(1-v^2/c^2))\n",
187 | " E_m^2 - (m_m*c^2)^2 - (p_m*c)^2, # square energy of moving particle\n",
188 | " E_r - m_r*c^2, # energey of particple at rest\n",
189 | " E_c^2 - (m_c *c)^2 - (p_c*c)^2, # energy of composite particle\n",
190 | " #E_m + E_r - E_c, # conservation of energy\n",
191 | " 2*E_m*E_r - E_c^2 + E_m^2 + E_r^2, # conservation of energy squared \n",
192 | " #cEs, #2*E_m*E_r - E_c^2 + E_m^2 + E_r^2, # conservation of energy squared \n",
193 | " #\n",
194 | " p_c - p_m, # conservation of momentum \n",
195 | " v_m - 4/5*c, # moving velocity of the mass is 4/5c \n",
196 | " m_r - m_m, # resting mass of particle at rest and particle at motion is equal \n",
197 | " #m_c - m_m - m_r, # mass of composite particle\n",
198 | " p_c^2*(c^2-v_c^2) - m_c^2*v_c^2*c^2, # momentum of the composite particle p_c = m_c*v_c / (sqrt(1-v^2/c^2))\n",
199 | "]"
200 | ]
201 | },
202 | {
203 | "cell_type": "code",
204 | "execution_count": null,
205 | "metadata": {},
206 | "outputs": [],
207 | "source": [
208 | "deg = 4\n",
209 | "deg_overall = 8\n",
210 | "theDegrees = [2 2 2 4 4 4 2 2 2 2 2] # m_m m_c m_r v_m v_c c p_m p_c E_m E_r E_c \n",
211 | "\n",
212 | "candidate_mons = [\n",
213 | " #mons_of_max_degree_and_unit_overall(x, deg, deg_overall, [])\n",
214 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
215 | " for ai=axioms\n",
216 | "]\n",
217 | "@show size.(candidate_mons)\n",
218 | "\n",
219 | "# model = Model(Mosek.Optimizer)\n",
220 | "model = Model(Gurobi.Optimizer)\n",
221 | "mons_q = mons_of_max_degree_and_unit_overall([ m_c m_m p_m c ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
222 | "\n",
223 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
224 | "\n",
225 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
226 | "coeff_αs = [\n",
227 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
228 | " for (i,X)=enumerate(candidate_mons)\n",
229 | " ]\n",
230 | "@show size.(coeff_αs)\n",
231 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
232 | "\n",
233 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
234 | "eqs = coefficients(residual)\n",
235 | "\n",
236 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
237 | "@constraint model sum(coeff_q[degree.(mons_q, [m_c ]).>0]) == 4.0 # insist that some variables will appear\n",
238 | "#@constraint model sum(coeff_q[degree.(mons_q,[v_m]).>0]) == 0.0 # insist that some variables will not appear\n",
239 | "@constraint model eqs .== 0\n",
240 | "@objective model Max 0\n",
241 | "\n",
242 | "optimize!(model)\n",
243 | "@show termination_status(model)"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": 53,
249 | "metadata": {},
250 | "outputs": [
251 | {
252 | "data": {
253 | "text/plain": [
254 | "#239 (generic function with 1 method)"
255 | ]
256 | },
257 | "execution_count": 53,
258 | "metadata": {},
259 | "output_type": "execute_result"
260 | }
261 | ],
262 | "source": [
263 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": 54,
269 | "metadata": {},
270 | "outputs": [
271 | {
272 | "data": {
273 | "text/latex": [
274 | "$$ -1.3333333333333333m_c^{4}cs^{2} + 5.333333333333332m_m^{2}m_c^{2}cs^{3} + 9.48148148148148m_m^{4}cs^{4} $$"
275 | ],
276 | "text/plain": [
277 | "-1.3333333333333333m_c⁴cs² + 5.333333333333332m_m²m_c²cs³ + 9.48148148148148m_m⁴cs⁴"
278 | ]
279 | },
280 | "execution_count": 54,
281 | "metadata": {},
282 | "output_type": "execute_result"
283 | }
284 | ],
285 | "source": [
286 | "value_q = value_poly(q)\n",
287 | "value_q"
288 | ]
289 | },
290 | {
291 | "cell_type": "code",
292 | "execution_count": 27,
293 | "metadata": {},
294 | "outputs": [
295 | {
296 | "name": "stdout",
297 | "output_type": "stream",
298 | "text": [
299 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[11.111111111111114, 8.888888888888893cp_m² + 11.111111111111114v_mp_m² + 8.888888888888891m_m²c³ + 11.111111111111114m_m²v_mc²]\n"
300 | ]
301 | },
302 | {
303 | "data": {
304 | "text/plain": [
305 | "2-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
306 | " 11.111111111111114\n",
307 | " 8.888888888888893cp_m² + 11.111111111111114v_mp_m² + 8.888888888888891m_m²c³ + 11.111111111111114m_m²v_mc²"
308 | ]
309 | },
310 | "execution_count": 27,
311 | "metadata": {},
312 | "output_type": "execute_result"
313 | }
314 | ],
315 | "source": [
316 | "@show value_αs = value_poly.(αs)"
317 | ]
318 | },
319 | {
320 | "cell_type": "markdown",
321 | "metadata": {},
322 | "source": [
323 | "Solving the above for m_c^2 : 4/3 c^4 m_c^4 + 16/3 m_m^2 c^6 m_c^2 + 9.48 m_m^4 c^8\n"
324 | ]
325 | },
326 | {
327 | "cell_type": "code",
328 | "execution_count": 115,
329 | "metadata": {},
330 | "outputs": [
331 | {
332 | "data": {
333 | "text/latex": [
334 | "$$ c^{2}p_c^{2} - v_c^{2}p_c^{2} - 2m_c^{2}v_cc^{2} $$"
335 | ],
336 | "text/plain": [
337 | "c²p_c² - v_c²p_c² - 2m_c²v_cc²"
338 | ]
339 | },
340 | "execution_count": 115,
341 | "metadata": {},
342 | "output_type": "execute_result"
343 | }
344 | ],
345 | "source": [
346 | "#p_c^2 * (c^2 - v_c^2) - m_c^2 * v_c*2 * c^2 # momentum of composite particle\n",
347 | "Solving the above for m_c^2 : 4/3 c^4 m_c^4 + 16/3 m_m^2 c^6 m_c^2 + 9.48 m_m^4 c^8\n"
348 | ]
349 | },
350 | {
351 | "cell_type": "markdown",
352 | "metadata": {},
353 | "source": [
354 | "After reordering we get the correct composite mass expression:\n"
355 | ]
356 | }
357 | ],
358 | "metadata": {
359 | "kernelspec": {
360 | "display_name": "Julia 1.10.2",
361 | "language": "julia",
362 | "name": "julia-1.10"
363 | },
364 | "language_info": {
365 | "file_extension": ".jl",
366 | "mimetype": "application/julia",
367 | "name": "julia",
368 | "version": "1.9.4"
369 | }
370 | },
371 | "nbformat": 4,
372 | "nbformat_minor": 2
373 | }
374 |
--------------------------------------------------------------------------------
/suppl_material_problems/decay.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "pion, muon, neutrino \n",
8 | "https://www.feynmanlectures.caltech.edu/info/solutions/pion_muon_neutrino_sol_1.pdf\n",
9 | "\n",
10 | "A pion (mπ = 273 me) at rest decays into a muon (mμ = 207 me) and a neutrino (mν = 0). \n",
11 | "Find the kinetic energy and momentum of the muon and the neutrino in MeV. "
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 1,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "using DynamicPolynomials\n",
21 | "using JuMP\n",
22 | "using MosekTools\n",
23 | "using LinearAlgebra\n",
24 | "using CSV\n",
25 | "using DataFrames\n",
26 | "import JSON\n",
27 | "using Dates\n",
28 | "using Gurobi"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "functions for generating monomials"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": 2,
41 | "metadata": {},
42 | "outputs": [
43 | {
44 | "data": {
45 | "text/plain": [
46 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
47 | ]
48 | },
49 | "execution_count": 2,
50 | "metadata": {},
51 | "output_type": "execute_result"
52 | }
53 | ],
54 | "source": [
55 | "function all_monomials_up_to_max_deg(x, deg)\n",
56 | " if size(x,1) == 0\n",
57 | " [1]\n",
58 | " else\n",
59 | " [ x[1]^k * m for k=0:deg \n",
60 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
61 | " ]\n",
62 | " end\n",
63 | "end\n",
64 | "\n",
65 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
66 | " [m\n",
67 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
68 | " #if all(unit(m) .== u)\n",
69 | " ]\n",
70 | "end\n",
71 | " \n",
72 | "function degree_poly(p)\n",
73 | " maximum(degree.(monomials(p)))\n",
74 | "end\n",
75 | "\n",
76 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
77 | " if size(x,1) == 0\n",
78 | " [1]\n",
79 | " else\n",
80 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
81 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
82 | " ]\n",
83 | " end\n",
84 | "end\n",
85 | "\n",
86 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
87 | " [m\n",
88 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
89 | " #if all(unit(m) .== u)\n",
90 | " ]\n",
91 | "end\n",
92 | "\n",
93 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
94 | " if size(x,1) == 0\n",
95 | " [1]\n",
96 | " else\n",
97 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
98 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
99 | " ]\n",
100 | " end\n",
101 | "end"
102 | ]
103 | },
104 | {
105 | "cell_type": "markdown",
106 | "metadata": {},
107 | "source": [
108 | "define symbolic variables"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": 4,
114 | "metadata": {},
115 | "outputs": [
116 | {
117 | "data": {
118 | "text/plain": [
119 | "1×8 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
120 | " p_v p_mu p_p m_mu m_p E_v E_mu E_p"
121 | ]
122 | },
123 | "execution_count": 4,
124 | "metadata": {},
125 | "output_type": "execute_result"
126 | }
127 | ],
128 | "source": [
129 | "@polyvar p_v p_mu p_p m_mu m_p E_v E_mu E_p \n",
130 | "\n",
131 | "x =[p_v p_mu p_p m_mu m_p E_v E_mu E_p] "
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 5,
137 | "metadata": {},
138 | "outputs": [
139 | {
140 | "data": {
141 | "text/plain": [
142 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
143 | " -p_mu + p_v\n",
144 | " E_p - m_p\n",
145 | " E_v - p_v\n",
146 | " E_p - E_mu - E_v\n",
147 | " E_mu² - m_mu² - p_mu²"
148 | ]
149 | },
150 | "execution_count": 5,
151 | "metadata": {},
152 | "output_type": "execute_result"
153 | }
154 | ],
155 | "source": [
156 | "axioms= # c^2 is 1, maybe add c^2 or cs(=c^2) later on ...\n",
157 | "[\n",
158 | " p_v - p_mu, # consevation of momentum (pion at rest) \n",
159 | " E_p - m_p, # relativity mass energy relation (pion is at rest, energy is equal mass) \n",
160 | " E_v - p_v, # neutrino is massless its energy equals its momentum, E p ν = ν \n",
161 | " #E_mu - m_p + p_v, # conservation of energy \n",
162 | " E_p - E_mu - E_v, # conservation of energy\n",
163 | " E_mu^2 - p_mu^2 - m_mu^2 # fundamental kinematic equation for the muon \n",
164 | "]"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": 6,
170 | "metadata": {},
171 | "outputs": [
172 | {
173 | "name": "stdout",
174 | "output_type": "stream",
175 | "text": [
176 | "size.(candidate_mons) = [(2643,), (2643,), (2643,), (2643,), (2643,)]\n",
177 | "Set parameter Username\n",
178 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
179 | "size.(coeff_αs) = [(2643,), (2643,), (2643,), (2643,), (2643,)]\n",
180 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
181 | "\n",
182 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
183 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
184 | "\n",
185 | "Optimize a model with 9616 rows, 13269 columns and 31808 nonzeros\n",
186 | "Model fingerprint: 0xb68270fc\n",
187 | "Coefficient statistics:\n",
188 | " Matrix range [1e+00, 1e+00]\n",
189 | " Objective range [0e+00, 0e+00]\n",
190 | " Bounds range [0e+00, 0e+00]\n",
191 | " RHS range [4e+00, 4e+00]\n",
192 | "Presolve removed 9474 rows and 13123 columns\n",
193 | "Presolve time: 0.01s\n",
194 | "Presolved: 142 rows, 146 columns, 464 nonzeros\n",
195 | "\n",
196 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
197 | " 0 -0.0000000e+00 0.000000e+00 2.400000e-05 0s\n",
198 | "\n",
199 | "Use crossover to convert LP symmetric solution to basic solution...\n",
200 | "Crossover log...\n",
201 | "\n",
202 | " 36 DPushes remaining with DInf 0.0000000e+00 0s\n",
203 | "\n",
204 | " 40 PPushes remaining with PInf 0.0000000e+00 0s\n",
205 | " 0 PPushes remaining with PInf 0.0000000e+00 0s\n",
206 | "\n",
207 | " Push phase complete: Pinf 0.0000000e+00, Dinf 0.0000000e+00 0s\n",
208 | "\n",
209 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
210 | " 43 -0.0000000e+00 0.000000e+00 0.000000e+00 0s\n",
211 | " 43 -0.0000000e+00 0.000000e+00 0.000000e+00 0s\n",
212 | "\n",
213 | "Solved in 43 iterations and 0.02 seconds (0.02 work units)\n",
214 | "Optimal objective -0.000000000e+00\n",
215 | "\n",
216 | "User-callback calls 164, time in user-callback 0.00 sec\n",
217 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
218 | ]
219 | },
220 | {
221 | "data": {
222 | "text/plain": [
223 | "OPTIMAL::TerminationStatusCode = 1"
224 | ]
225 | },
226 | "execution_count": 6,
227 | "metadata": {},
228 | "output_type": "execute_result"
229 | }
230 | ],
231 | "source": [
232 | "deg = 3\n",
233 | "deg_overall = 6\n",
234 | "\n",
235 | "theDegrees = [2 2 2 3 3 3 3 3 ] # p_v p_mu p_p m_mu m_p E_v E_mu E_p \n",
236 | "\n",
237 | "candidate_mons = [\n",
238 | " mons_of_max_degree_and_unit_overall(x, deg, deg_overall, [])\n",
239 | " #all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
240 | " for ai=axioms\n",
241 | "]\n",
242 | "\n",
243 | "@show size.(candidate_mons)\n",
244 | "\n",
245 | "# model = Model(Mosek.Optimizer)\n",
246 | "model = Model(Gurobi.Optimizer)\n",
247 | "mons_q = mons_of_max_degree_and_unit_overall([p_v m_p m_mu ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
248 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
249 | "\n",
250 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
251 | "coeff_αs = [\n",
252 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
253 | " for (i,X)=enumerate(candidate_mons)\n",
254 | " ]\n",
255 | "@show size.(coeff_αs)\n",
256 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
257 | "\n",
258 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
259 | "eqs = coefficients(residual)\n",
260 | "\n",
261 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
262 | "@constraint model sum(coeff_q[degree.(mons_q, [p_v]).>0]) == 4.0\n",
263 | "\n",
264 | "@constraint model eqs .== 0\n",
265 | "@objective model Max 0\n",
266 | "\n",
267 | "optimize!(model)\n",
268 | "@show termination_status(model)"
269 | ]
270 | },
271 | {
272 | "cell_type": "code",
273 | "execution_count": 7,
274 | "metadata": {},
275 | "outputs": [
276 | {
277 | "data": {
278 | "text/plain": [
279 | "#31 (generic function with 1 method)"
280 | ]
281 | },
282 | "execution_count": 7,
283 | "metadata": {},
284 | "output_type": "execute_result"
285 | }
286 | ],
287 | "source": [
288 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
289 | ]
290 | },
291 | {
292 | "cell_type": "code",
293 | "execution_count": 8,
294 | "metadata": {},
295 | "outputs": [
296 | {
297 | "data": {
298 | "text/latex": [
299 | "$$ -2.0m_p^{2} + 2.0m_mu^{2} + 4.0p_vm_p $$"
300 | ],
301 | "text/plain": [
302 | "-2.0m_p² + 2.0m_mu² + 4.0p_vm_p"
303 | ]
304 | },
305 | "execution_count": 8,
306 | "metadata": {},
307 | "output_type": "execute_result"
308 | }
309 | ],
310 | "source": [
311 | "value_q = value_poly(q)\n",
312 | "value_q"
313 | ]
314 | },
315 | {
316 | "cell_type": "code",
317 | "execution_count": 32,
318 | "metadata": {},
319 | "outputs": [
320 | {
321 | "name": "stdout",
322 | "output_type": "stream",
323 | "text": [
324 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-4.0E_p + 2.0E_v + 4.0m_p + 2.0p_mu, 2.0E_p + 2.0m_p - 4.0p_mu, -4.0E_p + 2.0E_v + 2.0p_mu, -2.0E_p - 2.0E_mu + 2.0E_v, -2.0]\n"
325 | ]
326 | },
327 | {
328 | "data": {
329 | "text/plain": [
330 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
331 | " -4.0E_p + 2.0E_v + 4.0m_p + 2.0p_mu\n",
332 | " 2.0E_p + 2.0m_p - 4.0p_mu\n",
333 | " -4.0E_p + 2.0E_v + 2.0p_mu\n",
334 | " -2.0E_p - 2.0E_mu + 2.0E_v\n",
335 | " -2.0"
336 | ]
337 | },
338 | "execution_count": 32,
339 | "metadata": {},
340 | "output_type": "execute_result"
341 | }
342 | ],
343 | "source": [
344 | "@show value_αs = value_poly.(αs)"
345 | ]
346 | },
347 | {
348 | "cell_type": "markdown",
349 | "metadata": {},
350 | "source": [
351 | "the solution for p_v (neutrino momentum) above can be rewritten as p_v = (m_p^2 - m_u^2)/2 m_p as expected \n"
352 | ]
353 | }
354 | ],
355 | "metadata": {
356 | "kernelspec": {
357 | "display_name": "Julia 1.10.2",
358 | "language": "julia",
359 | "name": "julia-1.10"
360 | },
361 | "language_info": {
362 | "file_extension": ".jl",
363 | "mimetype": "application/julia",
364 | "name": "julia",
365 | "version": "1.9.4"
366 | }
367 | },
368 | "nbformat": 4,
369 | "nbformat_minor": 2
370 | }
371 |
--------------------------------------------------------------------------------
/suppl_material_problems/escape.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Escape velocity\n",
8 | "https://byjus.com/physics/derivation-of-escape-velocity/\n",
9 | "\n",
10 | " With the help of the escape velocity formula, it is possible to calculate the minimum velocity that an object requires to overcome a particular planet’s or object’s gravitational pull\n",
11 | " \n",
12 | " v_e = sqrt(2 G M /r) \n",
13 | "\n",
14 | "Assume a perfect sphere-shaped planet of radius R and mass M. Now, if a body of mass m is projected from a point A on the surface of the planet. "
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": 1,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "using DynamicPolynomials\n",
24 | "using JuMP\n",
25 | "using MosekTools\n",
26 | "using LinearAlgebra\n",
27 | "using CSV\n",
28 | "using DataFrames\n",
29 | "import JSON\n",
30 | "using Dates\n",
31 | "using Gurobi"
32 | ]
33 | },
34 | {
35 | "cell_type": "markdown",
36 | "metadata": {},
37 | "source": [
38 | "functions for generating monomials"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 2,
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "data": {
48 | "text/plain": [
49 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
50 | ]
51 | },
52 | "execution_count": 2,
53 | "metadata": {},
54 | "output_type": "execute_result"
55 | }
56 | ],
57 | "source": [
58 | "function all_monomials_up_to_max_deg(x, deg)\n",
59 | " if size(x,1) == 0\n",
60 | " [1]\n",
61 | " else\n",
62 | " [ x[1]^k * m for k=0:deg \n",
63 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
64 | " ]\n",
65 | " end\n",
66 | "end\n",
67 | "\n",
68 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
69 | " [m\n",
70 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
71 | " #if all(unit(m) .== u)\n",
72 | " ]\n",
73 | "end\n",
74 | " \n",
75 | "function degree_poly(p)\n",
76 | " maximum(degree.(monomials(p)))\n",
77 | "end\n",
78 | "\n",
79 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
80 | " if size(x,1) == 0\n",
81 | " [1]\n",
82 | " else\n",
83 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
84 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
85 | " ]\n",
86 | " end\n",
87 | "end\n",
88 | "\n",
89 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
90 | " [m\n",
91 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
92 | " #if all(unit(m) .== u)\n",
93 | " ]\n",
94 | "end\n",
95 | "\n",
96 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
97 | " if size(x,1) == 0\n",
98 | " [1]\n",
99 | " else\n",
100 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
101 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
102 | " ]\n",
103 | " end\n",
104 | "end"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 3,
110 | "metadata": {},
111 | "outputs": [
112 | {
113 | "data": {
114 | "text/plain": [
115 | "1×9 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
116 | " m v_e r E_k_i E_k_f U_g_i U_g_f G M"
117 | ]
118 | },
119 | "execution_count": 3,
120 | "metadata": {},
121 | "output_type": "execute_result"
122 | }
123 | ],
124 | "source": [
125 | "@polyvar m v_e r E_k_i E_k_f U_g_i U_g_f G M # the order matters per evaluation(?) # a_y a_x dv_x dv_y\n",
126 | "\n",
127 | "x = [m v_e r E_k_i E_k_f U_g_i U_g_f G M ] #dv_x dv_y a_y a_x"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": 8,
133 | "metadata": {},
134 | "outputs": [
135 | {
136 | "data": {
137 | "text/plain": [
138 | "0"
139 | ]
140 | },
141 | "execution_count": 8,
142 | "metadata": {},
143 | "output_type": "execute_result"
144 | }
145 | ],
146 | "source": [
147 | "\n",
148 | "#dx2dt2=differentiate(differentiate(dx,dt),dt)\n",
149 | "#dy2dt2=differentiate(differentiate(dy,dt),dt)"
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": 4,
155 | "metadata": {},
156 | "outputs": [
157 | {
158 | "data": {
159 | "text/plain": [
160 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
161 | " E_k_i - 0.5mv_e²\n",
162 | " E_k_f\n",
163 | " rU_g_i + mGM\n",
164 | " U_g_f\n",
165 | " -U_g_f + U_g_i - E_k_f + E_k_i"
166 | ]
167 | },
168 | "execution_count": 4,
169 | "metadata": {},
170 | "output_type": "execute_result"
171 | }
172 | ],
173 | "source": [
174 | "axioms= \n",
175 | "[\n",
176 | " E_k_i - 1/2 * m * v_e^2, # initial kinetic energy \n",
177 | " E_k_f - 0, # final kinetic energy is 0\n",
178 | " U_g_i *r + G *M * m, # initial garvitational potential\n",
179 | " U_g_f - 0, # final energy \n",
180 | " E_k_i + U_g_i - E_k_f - U_g_f, # conservation of energy\n",
181 | " #F * dx^2 - G * M *m, # the gravitational force\n",
182 | " #dW - F * dx, # work needed to displace a body by dx distance against the gravitational force pull\n",
183 | " #work done against the gravitational attraction to take the body from the planet’s surface to infinity can be easily calculated by integrating the equation for work done within the limits x = R to x = ∞\n",
184 | " #m*dx2dt2*r^3-G*M*m*dx, # force in the x direction\n",
185 | " #m*dy2dt2*r^3-G*M*m*dy, # force in the y direction\n",
186 | " #m*a_x*r^3-G*M*m*dx, # force in the x direction\n",
187 | " #m*a_y*r^3-G*M*m*dy, # force in the y direction\n",
188 | " # r^2 - dx^2 - dy^2, # polar coordinates transformation\n",
189 | " #dx2dt2 * r^2 + G*M *r, # gravitational field intensity of point mass\n",
190 | " #E_g_x * m - m * dx2dt2,\n",
191 | " #E_g_y * m - M * dy2dt2,\n",
192 | "]\n",
193 | " #a_x* dt - dv_x, # a_x = dv_x / dt\n",
194 | " #a_y* dt - dv_y, # a_y = dv_y / dt\n",
195 | " "
196 | ]
197 | },
198 | {
199 | "cell_type": "code",
200 | "execution_count": 5,
201 | "metadata": {},
202 | "outputs": [
203 | {
204 | "name": "stdout",
205 | "output_type": "stream",
206 | "text": [
207 | "size.(candidate_mons) = [(5832,), (5832,), (5832,), (5832,), (5832,)]\n",
208 | "Set parameter Username\n",
209 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
210 | "Set parameter TimeLimit to value 600\n",
211 | "size.(coeff_αs) = [(5832,), (5832,), (5832,), (5832,), (5832,)]\n",
212 | "Set parameter TimeLimit to value 600\n",
213 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
214 | "\n",
215 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
216 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
217 | "\n",
218 | "Optimize a model with 24717 rows, 29827 columns and 59433 nonzeros\n",
219 | "Model fingerprint: 0xfe2d1c27\n",
220 | "Coefficient statistics:\n",
221 | " Matrix range [5e-01, 1e+00]\n",
222 | " Objective range [0e+00, 0e+00]\n",
223 | " Bounds range [0e+00, 0e+00]\n",
224 | " RHS range [1e+00, 1e+00]\n",
225 | "Presolve removed 24717 rows and 29827 columns\n",
226 | "Presolve time: 0.01s\n",
227 | "Presolve: All rows and columns removed\n",
228 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
229 | " 0 -0.0000000e+00 0.000000e+00 7.228000e-03 0s\n",
230 | "\n",
231 | "Solved in 0 iterations and 0.03 seconds (0.02 work units)\n",
232 | "Optimal objective -0.000000000e+00\n",
233 | "\n",
234 | "User-callback calls 53, time in user-callback 0.01 sec\n",
235 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
236 | ]
237 | },
238 | {
239 | "data": {
240 | "text/plain": [
241 | "OPTIMAL::TerminationStatusCode = 1"
242 | ]
243 | },
244 | "execution_count": 5,
245 | "metadata": {},
246 | "output_type": "execute_result"
247 | }
248 | ],
249 | "source": [
250 | "deg = 3\n",
251 | "deg_overall = 8\n",
252 | "theDegrees = [1 2 3 2 2 2 2 2 1 1] \n",
253 | " # m v_e r E_k_i E_k_f U_g_i U_g_f G M\n",
254 | "\n",
255 | "candidate_mons = [\n",
256 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
257 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
258 | " for ai=axioms\n",
259 | "]\n",
260 | "\n",
261 | "@show size.(candidate_mons)\n",
262 | "\n",
263 | "# model = Model(Mosek.Optimizer)\n",
264 | "model = Model(Gurobi.Optimizer)\n",
265 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
266 | "\n",
267 | "mons_q = mons_of_max_degree_and_unit_overall([G M m v_e r], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
268 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
269 | "\n",
270 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
271 | "coeff_αs = [\n",
272 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
273 | " for (i,X)=enumerate(candidate_mons)\n",
274 | " ]\n",
275 | "@show size.(coeff_αs)\n",
276 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
277 | "\n",
278 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
279 | "eqs = coefficients(residual)\n",
280 | "\n",
281 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
282 | "@constraint model sum(coeff_q[degree.(mons_q, [v_e ]).>0]) == 1.0\n",
283 | "\n",
284 | "@constraint model eqs .== 0\n",
285 | "@objective model Max 0\n",
286 | "\n",
287 | "optimize!(model)\n",
288 | "@show termination_status(model)"
289 | ]
290 | },
291 | {
292 | "cell_type": "code",
293 | "execution_count": 6,
294 | "metadata": {},
295 | "outputs": [
296 | {
297 | "data": {
298 | "text/plain": [
299 | "#29 (generic function with 1 method)"
300 | ]
301 | },
302 | "execution_count": 6,
303 | "metadata": {},
304 | "output_type": "execute_result"
305 | }
306 | ],
307 | "source": [
308 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
309 | ]
310 | },
311 | {
312 | "cell_type": "code",
313 | "execution_count": 7,
314 | "metadata": {},
315 | "outputs": [
316 | {
317 | "data": {
318 | "text/latex": [
319 | "$$ -2.0mGM + mv_e^{2}r $$"
320 | ],
321 | "text/plain": [
322 | "-2.0mGM + mv_e²r"
323 | ]
324 | },
325 | "execution_count": 7,
326 | "metadata": {},
327 | "output_type": "execute_result"
328 | }
329 | ],
330 | "source": [
331 | "value_q = value_poly(q)\n",
332 | "value_q"
333 | ]
334 | },
335 | {
336 | "cell_type": "markdown",
337 | "metadata": {},
338 | "source": [
339 | "Rearanging, we get the expected expression for the escape velocity : v_e^2 = 2G M / r\n",
340 | "that is v_e = \\sqrt(2G M / r)"
341 | ]
342 | },
343 | {
344 | "cell_type": "code",
345 | "execution_count": 8,
346 | "metadata": {},
347 | "outputs": [
348 | {
349 | "name": "stdout",
350 | "output_type": "stream",
351 | "text": [
352 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-2.0r, 2.0r, -2.0, 2.0r, 2.0r]\n"
353 | ]
354 | },
355 | {
356 | "data": {
357 | "text/plain": [
358 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
359 | " -2.0r\n",
360 | " 2.0r\n",
361 | " -2.0\n",
362 | " 2.0r\n",
363 | " 2.0r"
364 | ]
365 | },
366 | "execution_count": 8,
367 | "metadata": {},
368 | "output_type": "execute_result"
369 | }
370 | ],
371 | "source": [
372 | "@show value_αs = value_poly.(αs)"
373 | ]
374 | }
375 | ],
376 | "metadata": {
377 | "kernelspec": {
378 | "display_name": "Julia 1.10.2",
379 | "language": "julia",
380 | "name": "julia-1.10"
381 | },
382 | "language_info": {
383 | "file_extension": ".jl",
384 | "mimetype": "application/julia",
385 | "name": "julia",
386 | "version": "1.9.4"
387 | }
388 | },
389 | "nbformat": 4,
390 | "nbformat_minor": 2
391 | }
392 |
--------------------------------------------------------------------------------
/suppl_material_problems/compton.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# This notebook contains background theory for the Compton Scattering Problem, and a solution using AI Hilbert.\n",
8 | "\n",
9 | "You will need to have installed Julia, CPLEX (or Gurobi) to reproduce the code run here.\n",
10 | "\n",
11 | "We ran everything using Julia version 1.7.3, and CPLEX\n",
12 | "\n",
13 | "If you wish to use Gurobi, comment out the \"using CPLEX\" line and uncomment the \"using Gurobi\" line"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 1,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "using DynamicPolynomials\n",
23 | "using JuMP\n",
24 | "using LinearAlgebra\n",
25 | "using CSV\n",
26 | "using DataFrames\n",
27 | "import JSON\n",
28 | "using Dates\n",
29 | "using CPLEX\n",
30 | "#using Gurobi"
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "metadata": {},
36 | "source": [
37 | "### Functions for generating monomials"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {},
43 | "source": [
44 | "We have two versions of these functions: one which only controls the overall degree, and one which also controls each variable's degree, in order to have finer grained control"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 2,
50 | "metadata": {},
51 | "outputs": [
52 | {
53 | "data": {
54 | "text/plain": [
55 | "mons_of_max_degree_and_unit_overall (generic function with 1 method)"
56 | ]
57 | },
58 | "execution_count": 2,
59 | "metadata": {},
60 | "output_type": "execute_result"
61 | }
62 | ],
63 | "source": [
64 | "function all_monomials_up_to_max_deg(x, deg)\n",
65 | " if size(x,1) == 0\n",
66 | " [1]\n",
67 | " else\n",
68 | " [ x[1]^k * m for k=0:deg \n",
69 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
70 | " ]\n",
71 | " end\n",
72 | "end\n",
73 | "\n",
74 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
75 | " [m\n",
76 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
77 | " #if all(unit(m) .== u)\n",
78 | " ]\n",
79 | "end\n",
80 | " \n",
81 | "function degree_poly(p)\n",
82 | " maximum(degree.(monomials(p)))\n",
83 | "end\n",
84 | "\n",
85 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
86 | " if size(x,1) == 0\n",
87 | " [1]\n",
88 | " else\n",
89 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
90 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
91 | " ]\n",
92 | " end\n",
93 | "end\n",
94 | "\n",
95 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
96 | " if size(x,1) == 0\n",
97 | " [1]\n",
98 | " else\n",
99 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
100 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
101 | " ]\n",
102 | " end\n",
103 | "end\n",
104 | "\n",
105 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
106 | " [m\n",
107 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
108 | " #if all(unit(m) .== u)\n",
109 | " ]\n",
110 | "end"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 3,
116 | "metadata": {},
117 | "outputs": [
118 | {
119 | "data": {
120 | "text/plain": [
121 | "1×15 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
122 | " f1 lambda1 f2 lambda2 h me c cos E1 E2 Ee1 Ee2 p1 p2 pe2"
123 | ]
124 | },
125 | "execution_count": 3,
126 | "metadata": {},
127 | "output_type": "execute_result"
128 | }
129 | ],
130 | "source": [
131 | "@polyvar f1 lambda1 f2 lambda2 h me c cos E1 E2 Ee1 Ee2 p1 p2 pe2\n",
132 | "u =[f1 lambda1 f2 lambda2 h me c cos E1 E2 Ee1 Ee2 p1 p2 pe2]"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": 4,
138 | "metadata": {},
139 | "outputs": [
140 | {
141 | "data": {
142 | "text/plain": [
143 | "10-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
144 | " -Ee2 + Ee1 - E2 + E1\n",
145 | " E1 - f1h\n",
146 | " E2 - f2h\n",
147 | " cp1 - f1h\n",
148 | " cp2 - f2h\n",
149 | " -c + f1lambda1\n",
150 | " -c + f2lambda2\n",
151 | " Ee1 - mec²\n",
152 | " Ee2² - c²pe2² - me²c⁴\n",
153 | " pe2² - p2² - p1² + 2cosp1p2"
154 | ]
155 | },
156 | "execution_count": 4,
157 | "metadata": {},
158 | "output_type": "execute_result"
159 | }
160 | ],
161 | "source": [
162 | "# Including some axioms here\n",
163 | "axioms2 =[\n",
164 | " E1+Ee1-E2-Ee2, # conservation of energy, E1 is initial photon energy, E2 final energy, Ee1/Ee2 is initial/final electron energy\n",
165 | " E1-h*f1, # photon energy in terms of frequency (f1 is initial frequency, f2 is final frequency)\n",
166 | " E2-h*f2,\n",
167 | " p1*c - h*f1, # photon momemntum in terms of frequency (p1 is initial photon momentum, p2 is final momentum)\n",
168 | " p2*c - h*f2,\n",
169 | " lambda1*f1-c, # relationship between frequency and wavelength\n",
170 | " lambda2*f2-c,\n",
171 | " Ee1-me*c^2, # energy of essentially stationary (relative to speed of light) electron\n",
172 | " Ee2^2-pe2^2*c^2-me^2*c^4, #relativistic energy-momentum relation applied to the electron after collision (after squaring); pe2 is final momentum\n",
173 | " pe2^2-p1^2-p2^2+2*p1*p2*cos, # conservation of momentum, after taking inner product of vector representation of conservation law\n",
174 | " ]"
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "execution_count": 5,
180 | "metadata": {},
181 | "outputs": [
182 | {
183 | "name": "stdout",
184 | "output_type": "stream",
185 | "text": [
186 | "size.(candidate_mons) = [(54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,)]\n",
187 | "size.(coeff_αs) = [(54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,), (54264,)]\n",
188 | "CPLEX Error 3003: Not a mixed-integer problem.\n",
189 | "Version identifier: 22.1.1.0 | 2022-11-27 | 9160aff4d\n",
190 | "Parallel mode: deterministic, using up to 8 threads for concurrent optimization:\n",
191 | " * Starting dual Simplex on 1 thread...\n",
192 | " * Starting Barrier on 6 threads...\n",
193 | " * Starting primal Simplex on 1 thread...\n",
194 | "Tried aggregator 1 time.\n",
195 | "LP Presolve eliminated 420157 rows and 370276 columns.\n",
196 | "Aggregator did 175781 substitutions.\n",
197 | "Reduced LP has 1977 rows, 2589 columns, and 7208 nonzeros.\n",
198 | "Presolve time = 1.17 sec. (349.78 ticks)\n",
199 | "Initializing dual steep norms . . .\n",
200 | "\n",
201 | "Iteration log . . .\n",
202 | "Iteration: 1 Dual infeasibility = 47.000000\n",
203 | "Iteration: 171 Dual infeasibility = 33.999990\n",
204 | "Iteration: 347 Dual infeasibility = 15.999990\n",
205 | "Iteration: 483 Dual objective = 1.000000\n",
206 | "\n",
207 | "Dual simplex solved model.\n",
208 | "\n",
209 | "termination_status(model) = MathOptInterface.OPTIMAL\n",
210 | "value_poly2(q) = 0.5h²c² - 0.5h²c²cos² - 0.5lambda2hmec³ + 0.5lambda1hmec³ - 0.5lambda2hmec³cos + 0.5lambda1hmec³cos\n",
211 | "value_αs = value_poly2.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-0.25lambda2hc + 0.25lambda1hc - 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 - 0.25lambda2hccos - 0.25lambda1lambda2cosEe2 - 0.25lambda1lambda2cosEe1 + 0.25f1lambda1²lambda2cosp2, 0.25lambda2hc - 0.25lambda1hc + 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 + 0.5lambda1²Ee1 + 0.25lambda2hccos + 0.25lambda1lambda2cosEe2 + 0.25lambda1lambda2cosE2 + 0.5lambda1lambda2mec² - 0.5lambda1²mec² + 0.25lambda1lambda2mec²cos - 0.5f1lambda1²lambda2cosp2, -0.25lambda2hc - 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 - 0.25lambda1lambda2cosEe2 - 0.25lambda1lambda2cosE1 + 0.5lambda2hccos² + 0.25lambda1f2lambda2²p2 - 0.5lambda1lambda2ccos²p1 - 0.25lambda1lambda2mec²cos + 0.25lambda1f2lambda2²cosp2, -0.25lambda2hc - 0.25lambda2hccos + 0.5lambda1lambda2cos²E2 - 0.25f1lambda1²lambda2p1 + 0.5f1lambda1²lambda2cosp2 - 0.25f1lambda1²lambda2cosp1, -0.25lambda1lambda2E2 + 0.25lambda1lambda2cosEe2 + 0.25lambda1lambda2cosE1 - 0.25lambda1f2lambda2²p2 + 0.5lambda1lambda2ccos²p1 - 0.25lambda1lambda2mec²cos - 0.25lambda1f2lambda2²cosp2, -0.25h²c + 0.25lambda2hEe2 - 0.25lambda2hEe1 + 0.5lambda1hEe1 + 0.25lambda2hcosEe2 + 0.25lambda2hcosE2 - 0.25lambda2hcp1 + 0.5lambda2hcos²E2 - 0.25lambda2hccosp1 + 0.5lambda2hmec² - 0.5lambda1hmec² + 0.25lambda1lambda2cosEe2p2 - 0.25lambda1lambda2cosEe1p2 + 0.25lambda1lambda2cosE2p2 + 0.25lambda1lambda2cosE1p2 - 0.25f1lambda1lambda2hp1 + 0.25lambda2hmec²cos + 0.25lambda1lambda2ccosp1² + 0.25lambda1f2lambda2²pe2² - 0.25lambda1f2lambda2²p2² - 0.25f1lambda1lambda2hcosp1, -0.25h²c - 0.25lambda1hEe2 - 0.25lambda1hEe1 - 0.25lambda1hE2 - 0.25lambda1lambda2E2p2 + 0.5h²ccos² - 0.25lambda1lambda2cosE2p2 + 0.25lambda1lambda2cpe2² - 0.5lambda1hmec²cos + 0.25lambda1lambda2ccosp2² - 0.25f1lambda1²lambda2pe2² + 0.25f1lambda1²lambda2p2², 0.25lambda1lambda2Ee1 + 0.5lambda1lambda2E1 - 0.5lambda1²E1 + 0.25lambda2hccos + 0.25lambda1lambda2cosEe1 - 0.25lambda1lambda2cosE2 + 0.25lambda1lambda2cosE1 - 0.25lambda1lambda2ccosp2 + 0.25lambda1lambda2mec² + 0.25lambda1lambda2mec²cos, -0.25lambda1lambda2 - 0.25lambda1lambda2cos, -0.25lambda1lambda2c²cos - 0.25f1lambda1²lambda2c]\n"
212 | ]
213 | },
214 | {
215 | "data": {
216 | "text/plain": [
217 | "10-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
218 | " -0.25lambda2hc + 0.25lambda1hc - 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 - 0.25lambda2hccos - 0.25lambda1lambda2cosEe2 - 0.25lambda1lambda2cosEe1 + 0.25f1lambda1²lambda2cosp2\n",
219 | " 0.25lambda2hc - 0.25lambda1hc + 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 + 0.5lambda1²Ee1 + 0.25lambda2hccos + 0.25lambda1lambda2cosEe2 + 0.25lambda1lambda2cosE2 + 0.5lambda1lambda2mec² - 0.5lambda1²mec² + 0.25lambda1lambda2mec²cos - 0.5f1lambda1²lambda2cosp2\n",
220 | " -0.25lambda2hc - 0.25lambda1lambda2Ee2 - 0.25lambda1lambda2Ee1 - 0.25lambda1lambda2cosEe2 - 0.25lambda1lambda2cosE1 + 0.5lambda2hccos² + 0.25lambda1f2lambda2²p2 - 0.5lambda1lambda2ccos²p1 - 0.25lambda1lambda2mec²cos + 0.25lambda1f2lambda2²cosp2\n",
221 | " -0.25lambda2hc - 0.25lambda2hccos + 0.5lambda1lambda2cos²E2 - 0.25f1lambda1²lambda2p1 + 0.5f1lambda1²lambda2cosp2 - 0.25f1lambda1²lambda2cosp1\n",
222 | " -0.25lambda1lambda2E2 + 0.25lambda1lambda2cosEe2 + 0.25lambda1lambda2cosE1 - 0.25lambda1f2lambda2²p2 + 0.5lambda1lambda2ccos²p1 - 0.25lambda1lambda2mec²cos - 0.25lambda1f2lambda2²cosp2\n",
223 | " -0.25h²c + 0.25lambda2hEe2 - 0.25lambda2hEe1 + 0.5lambda1hEe1 + 0.25lambda2hcosEe2 + 0.25lambda2hcosE2 - 0.25lambda2hcp1 + 0.5lambda2hcos²E2 - 0.25lambda2hccosp1 + 0.5lambda2hmec² - 0.5lambda1hmec² + 0.25lambda1lambda2cosEe2p2 - 0.25lambda1lambda2cosEe1p2 + 0.25lambda1lambda2cosE2p2 + 0.25lambda1lambda2cosE1p2 - 0.25f1lambda1lambda2hp1 + 0.25lambda2hmec²cos + 0.25lambda1lambda2ccosp1² + 0.25lambda1f2lambda2²pe2² - 0.25lambda1f2lambda2²p2² - 0.25f1lambda1lambda2hcosp1\n",
224 | " -0.25h²c - 0.25lambda1hEe2 - 0.25lambda1hEe1 - 0.25lambda1hE2 - 0.25lambda1lambda2E2p2 + 0.5h²ccos² - 0.25lambda1lambda2cosE2p2 + 0.25lambda1lambda2cpe2² - 0.5lambda1hmec²cos + 0.25lambda1lambda2ccosp2² - 0.25f1lambda1²lambda2pe2² + 0.25f1lambda1²lambda2p2²\n",
225 | " 0.25lambda1lambda2Ee1 + 0.5lambda1lambda2E1 - 0.5lambda1²E1 + 0.25lambda2hccos + 0.25lambda1lambda2cosEe1 - 0.25lambda1lambda2cosE2 + 0.25lambda1lambda2cosE1 - 0.25lambda1lambda2ccosp2 + 0.25lambda1lambda2mec² + 0.25lambda1lambda2mec²cos\n",
226 | " -0.25lambda1lambda2 - 0.25lambda1lambda2cos\n",
227 | " -0.25lambda1lambda2c²cos - 0.25f1lambda1²lambda2c"
228 | ]
229 | },
230 | "execution_count": 5,
231 | "metadata": {},
232 | "output_type": "execute_result"
233 | }
234 | ],
235 | "source": [
236 | "### deg = 2\n",
237 | "deg_overall=6\n",
238 | "deg_overall_q=8 # degree of final polynomial law\n",
239 | "\n",
240 | "deg_elementwise=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] \n",
241 | "deg_elementwise_q=[2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2]\n",
242 | "\n",
243 | "deg = 8\n",
244 | "#maxD = 1\n",
245 | "\n",
246 | "candidate_mons = [\n",
247 | " mons_of_max_degree_and_unit_overall(u, deg, deg_overall, deg_elementwise)\n",
248 | " for ai=axioms2\n",
249 | "]\n",
250 | "@show size.(candidate_mons)\n",
251 | "#@show candidate_mons\n",
252 | "\n",
253 | "# If you want to use Gurobi instead of CPLEX, you need to comment out the next line, and uncomment out the subsequent line\n",
254 | "model = Model(CPLEX.Optimizer)\n",
255 | "# model = Model(Gurobi.Optimizer)\n",
256 | "# set_optimizer_attribute(model, \"Presolve\", 0)\n",
257 | "# set_optimizer_attribute(model, \"OptimalityTol\", 1e-9)\n",
258 | "# set_optimizer_attribute(model, \"FeasibilityTol\", 1e-9)\n",
259 | "# set_optimizer_attribute(model, \"IntFeasTol\", 1e-9)\n",
260 | "# set_optimizer_attribute(model, \"MIPGap\", 1e-9)\n",
261 | "# set_optimizer_attribute(model, \"Quad\", 1)\n",
262 | "\n",
263 | "# we are assuming only the initial and final wavelengths of light, the cosine of the angle of scatering are measurable.\n",
264 | "# Also, we assume h, me, c (Planck's constant, rest mass of electron, speed of light) are known and thus can appear in final expression\n",
265 | "mons_q = mons_of_max_degree_and_unit_overall([lambda1 lambda2 cos h me c] , deg, deg_overall_q, deg_elementwise_q)\n",
266 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
267 | "abs_coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"abq\")\n",
268 | "\n",
269 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
270 | "#@show q\n",
271 | "\n",
272 | "coeff_αs = [\n",
273 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
274 | " for (i,X)=enumerate(candidate_mons)\n",
275 | " ]\n",
276 | "@show size.(coeff_αs)\n",
277 | "\n",
278 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
279 | "#@show αs\n",
280 | "\n",
281 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms2));\n",
282 | "eqs = coefficients(residual)\n",
283 | "#@show residual\n",
284 | "#@show eqs\n",
285 | "\n",
286 | "\n",
287 | "# Ensure that the sum of the coefficients on the terms involving p isn't zero, in order that p is part of expression\n",
288 | "@constraint model sum(coeff_q[degree.(mons_q, lambda1).>0]) == 1.0\n",
289 | "\n",
290 | "@constraint model eqs .== 0\n",
291 | "@constraint model abs_coeff_q.>=coeff_q\n",
292 | "@constraint model abs_coeff_q.>=-coeff_q\n",
293 | "#@variable(model, t[i=1:maxD]>=0.0)\n",
294 | "#@constraint(model, imposeabs1[i=1:maxD], t[i]>=q(data_var[i,:]))\n",
295 | "#@constraint(model, imposeabs2[i=1:maxD], t[i]>=-q(data_var[i,:]))\n",
296 | "#@constraint(model, q(data_var[10,:]) == 0)\n",
297 | "@objective model Min sum(abs_coeff_q) # Reduce number of non-zero coefficients via Lasso trick\n",
298 | "#@objective model Min 100*sum(t) # Reduce number of non-zero coefficients via Lasso trick\n",
299 | "\n",
300 | "optimize!(model)\n",
301 | "@show termination_status(model)\n",
302 | "#@show q\n",
303 | "#@show value.(coeff_q)\n",
304 | "#@show value.(abs_coeff_q)\n",
305 | "\n",
306 | "\n",
307 | "value_poly2 = p -> sum(value.(coefficients(p)).* monomials(p))\n",
308 | "@show value_poly2(q)\n",
309 | "@show value_αs=value_poly2.(αs)"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": null,
315 | "metadata": {},
316 | "outputs": [],
317 | "source": []
318 | }
319 | ],
320 | "metadata": {
321 | "kernelspec": {
322 | "display_name": "Julia 1.9.4",
323 | "language": "julia",
324 | "name": "julia-1.9"
325 | },
326 | "language_info": {
327 | "file_extension": ".jl",
328 | "mimetype": "application/julia",
329 | "name": "julia",
330 | "version": "1.9.4"
331 | }
332 | },
333 | "nbformat": 4,
334 | "nbformat_minor": 4
335 | }
336 |
--------------------------------------------------------------------------------
/main_problems/kepler_with_missing_axioms[3.7]/data_kepler_d.dat:
--------------------------------------------------------------------------------
1 | 35.55153623338219 64.97677908944013 118.13910508374887 78.21279129409628 94.62842579434701 106.40471434978993 96.85692365802231 45.435348385568915 61.13719311894855 149.1991919147041 85.12232386339778 143.2243675236357 144.44000721624246 80.95742777369495 126.20378150335685 86.80693844400773 142.2733078176543 109.43810825055552 102.90470282766249 81.28249304033159 85.65524958806756 106.00170639410275 98.03006678463717 86.42562975416598 143.17737591666395 39.1575226215444 30.38805880990629 61.07312324499105 98.72309289038688 50.05182426563914 145.6387156135214 86.88591896215311 114.29072112542838 121.6929276289099 110.26850175840686 72.4891120974083 109.52761284367224 77.41949298339108 112.52068638114172 41.06969468583145 107.98752292911641 39.334198811058535 122.29840468983558 63.9994138881348 55.02105837173718 41.94009152175988 140.62902652897094 123.33756910791895 50.354904415544986 147.85278664609126 93.63930625624694 66.32539744249885 84.91103847096895 38.644601922061526 60.14354042876529 143.84971377198963 132.9131483692633 30.15855396711876 114.44322553613391 136.9984550561427 55.336367514617066 145.33335318102752 146.6105670313261 37.57810344719119 30.365326743559816 100.59729985445921 108.22415988068187 54.131789158746166 136.25372436521647 148.6577839181275 80.73230527769702 120.25123860521926 42.293882668390594 48.71600206440824 56.83988169495668 62.69470685225094 107.7665502630956 82.2836079303681 104.90425382185141 111.7956800095704 103.75938692916361 98.12803078248469 95.83241694246334 94.90534081448097 81.94697949556843 114.1675149502192 106.76045141590093 89.95501271695233 119.99821119070225 87.6622270614239 54.9479172051467 40.868044920103415 143.71256139902158 57.25050886620245 62.92290484236534 67.76587616333089 36.049282553968375 31.165659060336957 80.6451155253132 112.40639978177568 126.60312029907274 81.45680880795965 91.53747582866272 74.20835087318147 34.53332459812516 70.80948568602972 37.10575003430984 90.1706129790018 134.1364175990962 112.4999807787398 141.67264449383876 131.2262053348515 144.8609398810973 45.62927913047383 97.58958154567128 111.48047933835805 140.01851360711632 124.37165146014942 87.23034996726827 120.89475106894983 62.26355703543256 35.031790360777734 59.04787301632838 51.40369453252937 84.53580098384323 37.07419614655483 74.03871203193783 73.25967765500008 51.002172800322334 139.54283245675447 84.43070017573211 36.978251631396766 121.19027856459459 96.21517017661695 127.0403424690557 137.46181338268508 60.3446800015589 64.11949684223558 74.58189917452836 131.60442023296127 36.874357390938364 45.56044190820944 85.02003120161798 50.41949322727103 69.04733421114028 38.69041497176786 64.75290530572484 139.7249091295252 128.44332852307426 41.08291878792706 128.83796905704924 132.6626253287947 87.81322551577912 67.12062378682295 132.10325625211271 93.13607810676702 128.20635315954885 35.44532043134708 80.40212143470707 91.1262218896234 50.4251977447113 65.02780683210999 146.24467718292098 89.83313127032059 36.26048563469265 144.6906993919997 86.7438654048886 135.65436085393236 66.56429233754496 67.83030258010646 70.14127508924847 122.3160672123402 136.82711337055707 88.58575813139512 65.26560358843324 124.92992267265126 136.65250409070663 136.77140996341288 102.2332888384401 62.101612404898304 138.542546736798 122.55093665367876 96.45550233197262 66.66971126894023 98.73308450447402 86.40956455103972 82.06912723256642 69.8195011820237 124.29771782695231 83.61074053265234 133.48998446243866 123.56514349924764 138.47167503938374 44.98050680305632 41.63849131952172 110.85247389157263 83.4981505792214 128.89148479197377 110.25198474301817 147.24887717235868 113.66306340653209 80.92673401021008 55.573934272621386 147.26061128313842 121.21630836575511 70.37227973656329 71.92659107877509 125.88602848933324 140.07071562603738 102.46598797332676 148.50693378929117 138.2372342171708 67.3965773249131 125.7025220548299 100.95899500256803 147.15164981839033 51.96829682705814 79.65914016812172 81.34124213962201 73.75212405776995 137.78749757609702 139.46905486423833 48.111821144611895 62.00748447458285 103.43159877124653 75.6333889140468 125.38890998386317 110.34086022457703 108.65856807832378 42.60290344409236 131.2878023790262 138.83268007276635 48.9151746380914 79.12061901433175 89.92892959512068 46.81872409188884 62.55148835787725 75.89280985347631 78.92299143159877 144.73132290467683 94.8523243732702 132.1589477651811 85.3865374236149 66.71539369961899 148.4293637604371 46.552335960399795 77.22134570331761 82.27555047263166 33.237840975740056 54.56374024519788 117.6547049629241 55.8335023806326 149.79763978482157 70.22283511397289 65.45206090112015 91.11478707684482 45.394761909018165 47.5466322403459 141.61794184573318 110.7014324082957 111.36692806527294 113.27237104977573 131.79758657873208 39.3776461295503 46.58644500383249 90.22814525946507 75.9689154187411 49.87578449314293 127.39894296486449 85.9197469285975 48.60026588290451 88.58488535324355 82.70116315167303 58.67291622850031 85.67557390864246 149.01278641630427 84.04716787133785 85.48560976385161 78.99422984037867 79.24008499653958 135.4724516696333 53.0934821244895 52.867912435039905 131.7827105519142 86.59603768186051 138.400112703635 141.07273873500424 81.22017766137627 117.36201371503833 118.4428033642823 121.8432226722105 116.89370260840505 45.06956179663898 74.52826137487038 71.64976440338856 80.15248176590657 68.61026703853793 41.08069040939445 98.26459352470069 65.46859780970227 119.94383505567443 35.877833596461926 86.79694721867368 146.70829235664115 37.92758722455777 130.64493381836502 85.15260059890333 128.01990970596063 101.70018842409554 82.2179467237682 145.45946424857783 103.295955708362 80.54580293403538 56.19962261557246 133.70459515625953 50.913094793238386 90.93926046815497 116.67605107823321 71.50341068596978 85.35136156114432 81.69795963288695 135.00003095116165 115.79183788859723 58.74875508492844 39.70069741090319 142.70772857487924 73.937295873057 111.59398272924577 105.83638714824338 81.75483063302678 134.6362608366175 56.908738159079505 39.32857814464242 102.01607415676261 143.5635910583116 78.5558891521751 149.46263956853306 130.79517606923582 86.88726773701636 127.59905753919149 78.13767187590136 136.3229355919207 45.735293877908546 115.38514227068556 57.24848589891557 41.49622386029998 95.35823851223196 112.73201300823386 134.79120808931577 64.91416099865427 79.75082341919259 65.26463859460218 147.11386943678806 88.278402985251 105.19596815242635 136.20778281174518 32.40871062704856 39.020734776758445 145.06785675853064 66.70106990734476 148.61539524887903 36.654026242424884 122.89274396271392 103.2329311801796 108.35461253907665 113.27742895743363 42.494397637002415 62.49379871487409 53.41367916161605 82.40265151771887 105.3565307248866 115.22652927502617 30.08544460691672 93.12564044781014 141.53217735842082 60.031699165288934 144.4273951280906 135.20454859250273 143.55400124166903 127.9786158278508 77.43480540344852 119.77354630675919 118.5358263127565 47.476652971495895 75.23625906975809 122.7880555779818 115.04248686459404 81.09495310171002 52.789309960438715 45.41367006028041 73.64995429128734 81.90274202655787 38.3315190527097 130.26285453281827 50.320841556918396 83.3823454799764 140.15799782431904 59.009766232170456 50.5042897332216 55.71219641660685 144.7918332873108 81.6293409584803 92.88121601203773 71.65240368187779 43.117191375214745 77.62533002511887 125.87201320485617 115.8270443377637 55.55513834336537 72.28834849512418 53.714174827865385 112.23497307440235 146.2925787987234 137.48469174166047 36.62873790168293 62.25681115540469 50.924286951953654 121.42932783617378 138.06366803280872 105.51645330941572 118.61751933381196 56.480384039034206 78.1127836831241 68.59860160195348 47.54781667263608 96.27424039775495 85.52477112166181 107.26390692811074 146.49552322922125 79.68189450865893 31.962351930683578 134.5950905142061 113.9444776299482 56.35843486121777 74.4387759232814 143.95873935857273 140.10284073735113 52.58248658586796 35.72746555163897 47.45910918322574 135.99140974468315 35.93120283723363 52.77119774027468 125.00804704055437 90.53481711751425 32.793650082064985 79.75765303471634 44.44162314376443 54.31752732144879 74.0414431079368 119.07608551647225 87.99953890987675 67.70947501972344 96.79817946970739 40.09528495062944 47.8601292806502 147.7881640236325 65.36291704310472 49.850997235678676 63.66859511078005 94.10956568494043 43.658818020439384 119.40097812916008 138.05886919537602 75.90400484851503 118.08046044078252 111.03985129886318 36.424948416887666 147.5552637176619 120.80365989193002 35.214949185559135 135.5336514590799 68.34210885754689 30.83616041272753 86.47959651662316 37.04934838114284 71.95305114683009 82.1554594260167 132.26278445698995 102.45628252672056 125.75087631557679 77.30923112283087 144.88153951278858 129.27599953947868 110.37039325549983 129.91647535225013 133.66345454262623 75.62795608455734 138.90951144259475 80.181083325665 59.81374095409832 98.3816591127824 30.19632375969178 37.960268727471636 32.769369934286864 71.1510012707868 136.84514303453577 125.09001549759932 56.90760839642076 58.23623204621762 101.52015456585406 85.52428145052816 83.30790629711552 66.30044642620064 113.4915168130429 123.86292615484601 115.41728206375568 149.27671816887087 81.14895699311849 101.28401333514925 136.6220181186911 125.46437219956611 63.91032181756935 104.84122896807895 85.4123798109798 32.96822215836182 112.89949197811613 74.52446072696367 43.850400827504984 107.9209595597638 40.03383232488817 53.83924223160382 84.37237706540495 81.15366850240258 101.53211113843771 132.39895798289518 76.74399938623527 141.94822100552017 84.15923199501415 44.095795832821096 88.65436156663078 64.04982490733558 86.05754739942788 79.281517676069 144.4728622286333 99.35187264371969 147.4466621404897 93.92412437380808 147.97533343995053 118.14186720298308 114.54784795278643 64.80891578227633 133.7138300338567 137.15609629526244 117.75175279553731 146.44399711452968 140.10038605298774 110.71282608314024 116.78826474280667 108.76195717185855 82.24199136410249 126.50886051286294 115.98167117205492 90.417976435611 102.1549558007836 149.2703791780969 143.2789955984985 92.34622519414302 56.42100658320243 147.21810121039266 37.511110519908044 89.73226004684217 59.670677696980704 86.77776077151943 136.15707321288505 39.03555918378308 48.36398011897759 89.37150545432313 61.45126044135236 51.3306153028051 115.02289155338299 105.49200915623028 75.54549063974132 42.634059344857675 96.60927981021696 140.31081031020756 64.12888239225758 113.03948865370961 57.43572967364112 64.01673976634298 49.45421254112763 115.55891234508414 40.1310709146617 53.114399227547075 102.80502168281178 131.32878729710893 62.85675273897355 59.99596411743342 48.69268107835194 76.35304320158096 143.5463257500167 96.26279858897101 59.6854514165825 122.77561164489192 82.34081163442515 90.53891488444819 92.27344678861552 89.00659283059252 139.2877699042882 85.42028303362362 125.52751859270205 117.42885016895389 135.32619968998887 82.01371813619133 89.70053610209362 57.06355676180651 146.6422496567766 43.84410172767801 63.19411792267245 36.70267564985377 84.91835035356331 140.3880592322635 139.08952285665526 45.627266504693985 47.56730006771962 115.1086631492605 104.40498914795897 43.06148479897415 92.23192952509393 62.04756167182105 148.02755619584167 88.89770831196756 85.99634584653984 66.35094036034073 54.146916601848105 145.83054281754156 115.1834438361517 133.0228073280157 102.93894739601231 101.63040124563454 91.70815601118235 91.57109426847833 98.89027535463009 109.27887549748928 144.49300673757048 82.3294861249821 69.39034105658445 143.49568837391305 61.62506511194081 129.81339657638682 86.62869128044267 116.07106731711163 61.462048556939806 112.3103817521407 106.50993264128711 36.521976502785975 134.4467773150102 34.40553265105621 41.93171011925141 147.67656098272442 88.12300958371463 79.41054144645544 98.29684864020959 132.12690180356074 41.89192375625076 124.26112605135073 43.71507424719831 67.63696372360316 106.4944802244543 44.12462523698909 32.1966056793094 45.954428821298094 50.96437567036162 39.089359275661096 70.41138934458327 108.37089070919899 126.27414362504807 105.84691055869587 83.62935094043402 47.41047912708193 100.84801723429672 98.73850199273977 106.05949993044828 117.56308109196546 77.8287914575836 94.67857283695209 40.40604148805848 116.94924560328398 56.39949460482278 145.7733783677391 122.81429372561016 110.38087991271142 55.154382122227396 136.4859619360526 108.19053177515217 127.75510506022873 143.65922410230604 45.79859502536117 134.3022045238635 66.06157890129069 128.95765821403091 35.751816900502206 85.0825700457458 117.26304541438041 147.48627817144273 89.87875510892269 34.94221911630173 127.35460784369698 53.45318438213636 66.80133542934126 77.54935287463752 112.03149248839706 122.64399368403788 74.50982850926863 137.99750995804618 123.06439194652003 99.8458467123417 114.53737687219146 62.14627162391953 107.67335208795208 32.88900497310785 149.23803937745058 96.40743241836144 85.13135941813209 146.07990344198157 148.9784620961353 57.23482298672971 30.834559180405755 82.42111189325512 139.35120970099933 138.0190728351609 67.21272587615039 50.21155277624889 38.01818953198904 146.32467981552833 89.00546822326304 79.86733994115241 94.01350104549444 91.87806314354403 45.26067034094199 139.5130296447834 88.21443523693031 104.21297389115028 30.896535319290038 45.29447271294519 110.66468015570273 41.6356924528082 82.88681341331849 146.16785412505135 72.47364631610404 88.34324848201341 54.61876939542871 74.29749809526379 132.50932671440768 128.4121727970661 43.966419982000374 125.22165443951705 126.78149929160791 109.38052102636811 147.94689003051187 108.75415483513694 88.15895916607543 114.96978747298174 109.92581081176189 83.37762682008028 129.93309930080818 44.07750184770987 42.23022478728994 85.59987707605464 60.02004469209115 71.21748485977696 130.6039622043141 135.2988687974829 121.90945445982477 32.21629288324361 102.60175772198177 107.96251548330038 90.34390850950865 148.73395026002447 39.50413293907329 46.06763297215085 31.00614120998678 110.1157845329141 146.39781229768818 32.39724383699465 98.36238234414084 91.53883583598684 85.5199899312414 52.437222845058145 63.80243305373918 134.74318105979694 86.67643163351518 99.17140312147819 102.99762601073947 63.24836860184518 107.06821387353249 124.11731046105945 69.78797777586527 121.51915439961131 71.72705842777383 59.91951293947868 58.975941860464154 148.68991046346503 143.5172668314168 144.84505697343405 93.72364323958837 99.81168943367312 66.42404196644947 104.48273524946939 35.310196391298476 135.46098037018143 137.77881199412428 61.51220648431223 43.8569330720809 77.87657743350334 69.45448561148243 130.32480064100218 36.22034069880836 120.17306696886581 136.13378429843397 51.96646125874635 73.90481097421701 113.90845086675738 123.22474046574676 134.73131122889623 78.35405930366183 87.79968454785288 42.329999012120396 67.25149740755148 136.08208339800368 57.8700520171672 92.36861550089517 76.70029725286943 90.1691603156081 122.33807760418325 111.47686227884296 46.96657803893898 137.79126947885499 118.2198898931572 144.06611090525274 146.99396276023162 31.30106177095861 39.08263655467847 109.20183753353493 114.98338128979617 81.14632558994919 81.51414391074482 51.42856836169567 111.05783505492215 132.51788980671188 112.00706776484883 69.7301369852582 112.06197795879466 79.48481490747335 59.968558515959046 31.832276449012227 49.43748385383461 144.09699593317248 59.13193468701161 74.43419902140556 130.14884385589033 98.97359182279892 79.00500709616229 37.059222855050706 44.01023939307054 97.03949455208856 113.16663728990575 89.90715465844187 103.46030518336005 67.59597047358142 106.74839403819685 57.12295816788733 83.91221379172195 31.093716496943223 100.941258894134 61.813873978238476 100.7751127890703 137.41072096306866 32.776068083138114 98.7333333148916 118.3244452521727 68.52620886670668 43.77227380924354 101.72031841301809 94.02098830497127 91.90287361418888 102.39206214181063 88.32142719009371 65.27736482395198 86.90745908335452 124.51233984894856 86.78496290983585 51.83203243898088 35.730298270348044 106.91129053070088 33.4838565542733 122.05598135601139 91.86296618118217 75.63543411590155 64.70801849394701 112.85581427989489 78.40079834219827 52.9143362268116 80.6687928436017 97.58091245010789 49.37720738556777 96.09201937921563 147.33404063986322 40.327535597777455 38.048260959705274 113.49548620932737 36.9556582156229 51.1278480559335 139.60576181261524 126.09625885294209 95.72030811548731 35.335052698026374 60.746537466004824 93.65735668880548 102.20936738561457 93.57844295311543 131.06098190888144 95.79281646871485 41.75336698552151 132.39198799711585 96.55302478542454 146.43529110797704 81.82576940317588 81.31541346044784 97.84193451687126 140.39317120454686 46.64569554793411 112.70728106135643 103.93778887294243 68.11757393590126 129.50987499281064 145.94330462425154 109.94275936960032 55.839710967169935 46.96873440491958 68.14394558041401 101.33130511225586 35.460999319591025 143.7619901739166 55.481029330686454 108.90423121555853 98.1633356133287 142.10751250744488 55.21321460442624 120.65797164847957 111.66139173916561 102.80413181425426 148.98190901269413 33.07254079955352 126.72850145571212 83.8922253517532 91.01019696739596 58.45136972001105 69.80295224807979 62.736282069932386 36.87396894059855 60.654531821839946 55.80814405815126 124.07458673779135 30.501669004874238 145.67396570779334 87.56044826796973 143.49791040712273 115.47121624045897 98.57099236021381 87.92198718926713 134.65796982959608 106.83619487577732 124.28166818306208 97.4689546688293 31.03254222123846 112.8367898217155 123.08836484580323 36.336742277064545 115.42004446750954 148.65646797549562 53.76887677789254 45.935734344581995 135.32459195711897 144.275284146866 138.55100063818816 146.29413167545496 95.40949070455035 60.493426491079475 76.97358132624183 93.13160850754043 67.80109245780666 114.24340226185112 145.20511515026612 79.89542330543074 78.07708808155154 102.49995648964247 41.9316539738621 38.1436819556817 129.89082199151227 31.619165423047022 145.55744728194472 97.56313950171833 88.2779418529581 82.18660866943907 118.77128066982567 63.81955291577246 93.20544398166173 75.56683590848023 90.84797618008213
2 |
--------------------------------------------------------------------------------
/suppl_material_problems/I_34_8.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "I-34-8 Feynamn Lectures on Physics\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/I_34.html\n",
10 | "\n",
11 | "w=q v V /p\n",
12 | "\n",
13 | "\n"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 1,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "using DynamicPolynomials\n",
23 | "using JuMP\n",
24 | "using MosekTools\n",
25 | "using LinearAlgebra\n",
26 | "using CSV\n",
27 | "using DataFrames\n",
28 | "import JSON\n",
29 | "using Dates\n",
30 | "using Gurobi\n",
31 | "using SymbolicUtils # for symbolic simplification"
32 | ]
33 | },
34 | {
35 | "cell_type": "markdown",
36 | "metadata": {},
37 | "source": [
38 | "functions for generating monomials"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 2,
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "data": {
48 | "text/plain": [
49 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
50 | ]
51 | },
52 | "execution_count": 2,
53 | "metadata": {},
54 | "output_type": "execute_result"
55 | }
56 | ],
57 | "source": [
58 | "function all_monomials_up_to_max_deg(x, deg)\n",
59 | " if size(x,1) == 0\n",
60 | " [1]\n",
61 | " else\n",
62 | " [ x[1]^k * m for k=0:deg \n",
63 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
64 | " ]\n",
65 | " end\n",
66 | "end\n",
67 | "\n",
68 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
69 | " [m\n",
70 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
71 | " #if all(unit(m) .== u)\n",
72 | " ]\n",
73 | "end\n",
74 | " \n",
75 | "function degree_poly(p)\n",
76 | " maximum(degree.(monomials(p)))\n",
77 | "end\n",
78 | "\n",
79 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
80 | " if size(x,1) == 0\n",
81 | " [1]\n",
82 | " else\n",
83 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
84 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
85 | " ]\n",
86 | " end\n",
87 | "end\n",
88 | "\n",
89 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
90 | " [m\n",
91 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
92 | " #if all(unit(m) .== u)\n",
93 | " ]\n",
94 | "end\n",
95 | "\n",
96 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
97 | " if size(x,1) == 0\n",
98 | " [1]\n",
99 | " else\n",
100 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
101 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
102 | " ]\n",
103 | " end\n",
104 | "end"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 3,
110 | "metadata": {},
111 | "outputs": [
112 | {
113 | "data": {
114 | "text/plain": [
115 | "1×9 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
116 | " omega Dt Dp Dangle F qc v B p"
117 | ]
118 | },
119 | "execution_count": 3,
120 | "metadata": {},
121 | "output_type": "execute_result"
122 | }
123 | ],
124 | "source": [
125 | "@polyvar omega Dt Dp Dangle F qc v B p # \n",
126 | "\n",
127 | "x = [omega Dt Dp Dangle F qc v B p ] #"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": 5,
133 | "metadata": {},
134 | "outputs": [
135 | {
136 | "data": {
137 | "text/plain": [
138 | "4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
139 | " -Dangle + omegaDt\n",
140 | " Dp - DtF\n",
141 | " F - qcvB\n",
142 | " -Dp + Danglep"
143 | ]
144 | },
145 | "execution_count": 5,
146 | "metadata": {},
147 | "output_type": "execute_result"
148 | }
149 | ],
150 | "source": [
151 | "axioms= \n",
152 | "[\n",
153 | " omega * Dt - Dangle, # omega = Dangle/Dt, \n",
154 | " Dp - F * Dt, # Dp = F * Dt, \n",
155 | " F - qc * v * B, # F = q * v * B\n",
156 | " Dangle * p - Dp, # Dangle = Dp/p \n",
157 | "]\n"
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": 6,
163 | "metadata": {},
164 | "outputs": [
165 | {
166 | "ename": "LoadError",
167 | "evalue": "BoundsError: attempt to access 0-element Vector{Int64} at index [1]",
168 | "output_type": "error",
169 | "traceback": [
170 | "BoundsError: attempt to access 0-element Vector{Int64} at index [1]",
171 | "",
172 | "Stacktrace:",
173 | " [1] getindex",
174 | " @ .\\essentials.jl:13 [inlined]",
175 | " [2] all_monomials_up_to_max_deg_overall_and_individual(x::Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Vector{Int64})",
176 | " @ Main .\\In[2]:43",
177 | " [3] (::var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}})(k::Int64)",
178 | " @ Main .\\none:0",
179 | " [4] iterate(::Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}})",
180 | " @ Base .\\generator.jl:47",
181 | " [5] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}}, state::Tuple{})",
182 | " @ Base.Iterators .\\iterators.jl:1195",
183 | " [6] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
184 | " @ Base.Iterators .\\iterators.jl:1191",
185 | " [7] grow_to!(dest::Vector{Any}, itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
186 | " @ Base .\\array.jl:855",
187 | " [8] _collect",
188 | " @ .\\array.jl:759 [inlined]",
189 | " [9] collect(itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
190 | " @ Base .\\array.jl:707",
191 | " [10] all_monomials_up_to_max_deg_overall_and_individual(x::Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Vector{Int64})",
192 | " @ Main .\\In[2]:43",
193 | " [11] (::var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}})(k::Int64)",
194 | " @ Main .\\none:0",
195 | " [12] iterate(::Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}})",
196 | " @ Base .\\generator.jl:47",
197 | " [13] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}}, state::Tuple{})",
198 | " @ Base.Iterators .\\iterators.jl:1195",
199 | " [14] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
200 | " @ Base.Iterators .\\iterators.jl:1191",
201 | " [15] grow_to!(dest::Vector{Any}, itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
202 | " @ Base .\\array.jl:855",
203 | " [16] _collect",
204 | " @ .\\array.jl:759 [inlined]",
205 | " [17] collect(itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
206 | " @ Base .\\array.jl:707",
207 | " [18] all_monomials_up_to_max_deg_overall_and_individual(x::Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Vector{Int64})",
208 | " @ Main .\\In[2]:43",
209 | " [19] (::var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}})(k::Int64)",
210 | " @ Main .\\none:0",
211 | " [20] iterate(::Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}})",
212 | " @ Base .\\generator.jl:47",
213 | " [21] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}}, state::Tuple{})",
214 | " @ Base.Iterators .\\iterators.jl:1195",
215 | " [22] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
216 | " @ Base.Iterators .\\iterators.jl:1191",
217 | " [23] grow_to!(dest::Vector{Any}, itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
218 | " @ Base .\\array.jl:855",
219 | " [24] _collect",
220 | " @ .\\array.jl:759 [inlined]",
221 | " [25] collect(itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
222 | " @ Base .\\array.jl:707",
223 | " [26] all_monomials_up_to_max_deg_overall_and_individual(x::Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Vector{Int64})",
224 | " @ Main .\\In[2]:43",
225 | " [27] (::var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}})(k::Int64)",
226 | " @ Main .\\none:0",
227 | " [28] iterate(::Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}})",
228 | " @ Base .\\generator.jl:47",
229 | " [29] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}}, state::Tuple{})",
230 | " @ Base.Iterators .\\iterators.jl:1195",
231 | " [30] iterate(f::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
232 | " @ Base.Iterators .\\iterators.jl:1191",
233 | " [31] grow_to!(dest::Vector{Any}, itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
234 | " @ Base .\\array.jl:855",
235 | " [32] _collect",
236 | " @ .\\array.jl:759 [inlined]",
237 | " [33] collect(itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Vector{Int64}}}})",
238 | " @ Base .\\array.jl:707",
239 | " [34] all_monomials_up_to_max_deg_overall_and_individual(x::Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Vector{Int64})",
240 | " @ Main .\\In[2]:43",
241 | " [35] (::var\"#12#13\"{Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Matrix{Int64}})(k::Int64)",
242 | " @ Main .\\none:0",
243 | " [36] iterate",
244 | " @ .\\generator.jl:47 [inlined]",
245 | " [37] iterate",
246 | " @ .\\iterators.jl:1195 [inlined]",
247 | " [38] iterate",
248 | " @ .\\iterators.jl:1191 [inlined]",
249 | " [39] grow_to!(dest::Vector{Any}, itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Matrix{Int64}}}})",
250 | " @ Base .\\array.jl:855",
251 | " [40] _collect",
252 | " @ .\\array.jl:759 [inlined]",
253 | " [41] collect(itr::Base.Iterators.Flatten{Base.Generator{UnitRange{Int64}, var\"#12#13\"{Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, Int64, Int64, Matrix{Int64}}}})",
254 | " @ Base .\\array.jl:707",
255 | " [42] all_monomials_up_to_max_deg_overall_and_individual(x::Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}, deg::Int64, deg_overall::Int64, theDegrees::Matrix{Int64})",
256 | " @ Main .\\In[2]:43",
257 | " [43] (::var\"#15#16\")(ai::Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64})",
258 | " @ Main .\\none:0",
259 | " [44] iterate",
260 | " @ .\\generator.jl:47 [inlined]",
261 | " [45] collect(itr::Base.Generator{Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}, var\"#15#16\"})",
262 | " @ Base .\\array.jl:782",
263 | " [46] top-level scope",
264 | " @ In[6]:6"
265 | ]
266 | }
267 | ],
268 | "source": [
269 | "deg = 3\n",
270 | "deg_overall = 10\n",
271 | "theDegrees = [ 2 2 2 2 2 2 2 2 2] \n",
272 | " # omega Dt Dp Dangle F qc v B p \n",
273 | "\n",
274 | "candidate_mons = [\n",
275 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
276 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
277 | " for ai=axioms\n",
278 | "]\n",
279 | "\n",
280 | "@show size.(candidate_mons)\n",
281 | "\n",
282 | "#model = Model(Mosek.Optimizer)\n",
283 | "model = Model(Gurobi.Optimizer)\n",
284 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
285 | "\n",
286 | "mons_q = mons_of_max_degree_and_unit_overall([omega qc v B p ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
287 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
288 | "\n",
289 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
290 | "coeff_αs = [\n",
291 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
292 | " for (i,X)=enumerate(candidate_mons)\n",
293 | " ]\n",
294 | "@show size.(coeff_αs)\n",
295 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
296 | "\n",
297 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
298 | "eqs = coefficients(residual)\n",
299 | "\n",
300 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
301 | "@constraint model sum(coeff_q[degree.(mons_q, [omega]).>0]) == 1.0\n",
302 | "\n",
303 | "@constraint model eqs .== 0\n",
304 | "@objective model Max 0\n",
305 | "\n",
306 | "optimize!(model)\n",
307 | "@show termination_status(model)"
308 | ]
309 | },
310 | {
311 | "cell_type": "code",
312 | "execution_count": 7,
313 | "metadata": {},
314 | "outputs": [
315 | {
316 | "data": {
317 | "text/plain": [
318 | "#43 (generic function with 1 method)"
319 | ]
320 | },
321 | "execution_count": 7,
322 | "metadata": {},
323 | "output_type": "execute_result"
324 | }
325 | ],
326 | "source": [
327 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
328 | ]
329 | },
330 | {
331 | "cell_type": "code",
332 | "execution_count": 8,
333 | "metadata": {},
334 | "outputs": [
335 | {
336 | "data": {
337 | "text/latex": [
338 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
339 | ],
340 | "text/plain": [
341 | "-p³c² + p³v² + m_0pv²c²"
342 | ]
343 | },
344 | "execution_count": 8,
345 | "metadata": {},
346 | "output_type": "execute_result"
347 | }
348 | ],
349 | "source": [
350 | "value_q = value_poly(q)\n",
351 | "value_q"
352 | ]
353 | },
354 | {
355 | "cell_type": "code",
356 | "execution_count": 9,
357 | "metadata": {},
358 | "outputs": [
359 | {
360 | "data": {
361 | "text/latex": [
362 | "$$ -p^{3}c^{2} + p^{3}v^{2} + m_0pv^{2}c^{2} $$"
363 | ],
364 | "text/plain": [
365 | "-p³c² + p³v² + m_0pv²c²"
366 | ]
367 | },
368 | "execution_count": 9,
369 | "metadata": {},
370 | "output_type": "execute_result"
371 | }
372 | ],
373 | "source": [
374 | "q_sim = simplify(value_q)"
375 | ]
376 | },
377 | {
378 | "cell_type": "markdown",
379 | "metadata": {},
380 | "source": [
381 | "which can be reorganized to arrive at the known relation p = m_0 * v /sqrt(1 - v*v/c*c)"
382 | ]
383 | },
384 | {
385 | "cell_type": "code",
386 | "execution_count": 10,
387 | "metadata": {},
388 | "outputs": [
389 | {
390 | "name": "stdout",
391 | "output_type": "stream",
392 | "text": [
393 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[-p²c² + p²v² - mpvc² + mpv³, -pv²]\n"
394 | ]
395 | },
396 | {
397 | "data": {
398 | "text/plain": [
399 | "2-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
400 | " -p²c² + p²v² - mpvc² + mpv³\n",
401 | " -pv²"
402 | ]
403 | },
404 | "execution_count": 10,
405 | "metadata": {},
406 | "output_type": "execute_result"
407 | }
408 | ],
409 | "source": [
410 | "@show value_αs = value_poly.(αs)"
411 | ]
412 | },
413 | {
414 | "cell_type": "markdown",
415 | "metadata": {},
416 | "source": []
417 | }
418 | ],
419 | "metadata": {
420 | "kernelspec": {
421 | "display_name": "Julia 1.10.2",
422 | "language": "julia",
423 | "name": "julia-1.10"
424 | },
425 | "language_info": {
426 | "file_extension": ".jl",
427 | "mimetype": "application/julia",
428 | "name": "julia",
429 | "version": "1.9.4"
430 | }
431 | },
432 | "nbformat": 4,
433 | "nbformat_minor": 2
434 | }
435 |
--------------------------------------------------------------------------------
/suppl_material_problems/light.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Radiation Damping. Light Scattering\n",
8 | "\n",
9 | "https://www.feynmanlectures.caltech.edu/I_32.html\n",
10 | "\n",
11 | "total amount of light scattered in all directions\n"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 1,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "using DynamicPolynomials\n",
21 | "using JuMP\n",
22 | "using MosekTools\n",
23 | "using LinearAlgebra\n",
24 | "using CSV\n",
25 | "using DataFrames\n",
26 | "import JSON\n",
27 | "using Dates\n",
28 | "using Gurobi"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "functions for generating monomials"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": 2,
41 | "metadata": {},
42 | "outputs": [
43 | {
44 | "data": {
45 | "text/plain": [
46 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
47 | ]
48 | },
49 | "execution_count": 2,
50 | "metadata": {},
51 | "output_type": "execute_result"
52 | }
53 | ],
54 | "source": [
55 | "function all_monomials_up_to_max_deg(x, deg)\n",
56 | " if size(x,1) == 0\n",
57 | " [1]\n",
58 | " else\n",
59 | " [ x[1]^k * m for k=0:deg \n",
60 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
61 | " ]\n",
62 | " end\n",
63 | "end\n",
64 | "\n",
65 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
66 | " [m\n",
67 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
68 | " #if all(unit(m) .== u)\n",
69 | " ]\n",
70 | "end\n",
71 | " \n",
72 | "function degree_poly(p)\n",
73 | " maximum(degree.(monomials(p)))\n",
74 | "end\n",
75 | "\n",
76 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
77 | " if size(x,1) == 0\n",
78 | " [1]\n",
79 | " else\n",
80 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
81 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
82 | " ]\n",
83 | " end\n",
84 | "end\n",
85 | "\n",
86 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
87 | " [m\n",
88 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
89 | " #if all(unit(m) .== u)\n",
90 | " ]\n",
91 | "end\n",
92 | "\n",
93 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
94 | " if size(x,1) == 0\n",
95 | " [1]\n",
96 | " else\n",
97 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
98 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
99 | " ]\n",
100 | " end\n",
101 | "end"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": 17,
107 | "metadata": {},
108 | "outputs": [
109 | {
110 | "data": {
111 | "text/plain": [
112 | "1×10 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
113 | " P S r qc ap sin_theta dA dtheta w x_0"
114 | ]
115 | },
116 | "execution_count": 17,
117 | "metadata": {},
118 | "output_type": "execute_result"
119 | }
120 | ],
121 | "source": [
122 | "@polyvar P S r qc ap sin_theta dA dtheta w x_0 # Intg c eps_0 W Q E P q_e x_0 m m_e r_0 a b lambda w e c # the order matters per evaluation # sin_theta, a = sin_theta, b = cos_theta \n",
123 | "\n",
124 | "x =[ P S r qc ap sin_theta dA dtheta w x_0] # Intg sin_theta \n",
125 | "# w_0 natural fequency of atom vibration"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": 18,
131 | "metadata": {},
132 | "outputs": [
133 | {
134 | "data": {
135 | "text/plain": [
136 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
137 | " Sr² - qc²ap²sin_theta²\n",
138 | " dA - 6.283185307179586r²sin_thetadtheta\n",
139 | " P - SdA\n",
140 | " 1.3333333333333333 - sin_theta³dtheta\n",
141 | " ap² - 0.5w⁴x_0²"
142 | ]
143 | },
144 | "execution_count": 18,
145 | "metadata": {},
146 | "output_type": "execute_result"
147 | }
148 | ],
149 | "source": [
150 | "axioms= \n",
151 | "[\n",
152 | " # a^2 + b^2 - 1, # a = sin_theta, b = cos_theta \n",
153 | " # S - eps_0 * c * E^2, #need an expectation over E (I.32.1)\n",
154 | " # S * 16 * pi^2 *eps_0 * r^2 * c^3 - qc^2 * ap^2 * a^2, #sin_theta^2, # rate of radiation of energy (I.32.2)\n",
155 | " S * r^2 - qc^2 * ap^2 * sin_theta^2, ##S * 16 * pi^2 *eps_0 * r^2 * c^3 - qc^2 * ap^2 * sin_theta^2, #sin_theta^2, # rate of radiation of energy (I.32.2)\n",
156 | " dA - 2* pi* r^2 * sin_theta * dtheta, # The area of a spherical segment is 2πrsinθ⋅rdθ\n",
157 | " # Intg * sin_theta^3 * dtheta - 4/3, # a crocked way of defining an integral of sin^3 theta between 0 and pi\n",
158 | " # P - Intg * S * dA,\n",
159 | " P - S * dA, \n",
160 | " #Intg - sin_theta^3 * dtheta,\n",
161 | " #Intg - 4/3,\n",
162 | " 4/3 - sin_theta^3 * dtheta,\n",
163 | " #P * 6 * pi * eps_0 * c^3 - q^2 * ap^2, # (I.32.5)\n",
164 | " ap^2 - 0.5 *w^4 * x_0^2, # (I.32.5b) The average of the acceleration of an ocilating charge over a cycle (squared)\n",
165 | " #P * 12 * pi * eps_0 * c^3 - q^2 * w^4 * x_0^2, # (I.32.6)\n",
166 | " # e^2 * 4 * pi * eps_0 - q_e^2, # electric potenial of an electron (I.32.7)\n",
167 | " # W - 1/2 * m * w^2 * x_0^2, # total energy of an oscillator, on the average half is kinetic and half is potential energy (I.32.9)\n",
168 | " # r_0 * m_e * c^2 - e^2, # radius magnitude\n",
169 | " # Q * 4 * pi * r_0 - 3 * lambda, # total energy content of the oscillator at any time divided by the energy loss per radian\n",
170 | " # lambda * w - 2* pi * c, # wavelength to angualr frequency relation\n",
171 | " ]"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": 20,
177 | "metadata": {},
178 | "outputs": [
179 | {
180 | "name": "stdout",
181 | "output_type": "stream",
182 | "text": [
183 | "size.(candidate_mons) = [(58170,), (58170,), (58170,), (58170,), (58170,)]\n",
184 | "Set parameter Username\n",
185 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
186 | "Set parameter TimeLimit to value 600\n",
187 | "size.(coeff_αs) = [(58170,), (58170,), (58170,), (58170,), (58170,)]\n",
188 | "Set parameter TimeLimit to value 600\n",
189 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
190 | "\n",
191 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
192 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
193 | "\n",
194 | "Optimize a model with 386146 rows, 292603 columns and 584703 nonzeros\n",
195 | "Model fingerprint: 0x0ffd25c9\n",
196 | "Coefficient statistics:\n",
197 | " Matrix range [5e-01, 6e+00]\n",
198 | " Objective range [0e+00, 0e+00]\n",
199 | " Bounds range [0e+00, 0e+00]\n",
200 | " RHS range [4e+00, 4e+00]\n",
201 | "Presolve removed 386146 rows and 292603 columns\n",
202 | "Presolve time: 0.22s\n",
203 | "Presolve: All rows and columns removed\n",
204 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
205 | " 0 -0.0000000e+00 0.000000e+00 1.184700e-02 0s\n",
206 | "\n",
207 | "Solved in 0 iterations and 0.38 seconds (0.31 work units)\n",
208 | "Optimal objective -0.000000000e+00\n",
209 | "\n",
210 | "User-callback calls 62, time in user-callback 0.00 sec\n",
211 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
212 | ]
213 | },
214 | {
215 | "data": {
216 | "text/plain": [
217 | "OPTIMAL::TerminationStatusCode = 1"
218 | ]
219 | },
220 | "execution_count": 20,
221 | "metadata": {},
222 | "output_type": "execute_result"
223 | }
224 | ],
225 | "source": [
226 | "deg = 4\n",
227 | "deg_overall = 10\n",
228 | "theDegrees = [ 2 2 4 2 2 3 2 2 4 2] # 4 2 ] # [2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 ] \n",
229 | " # P S r qc ap sin_theta dA dtheta w x_0] # Intg W Q E S P q q_e x_0 ap m m_e r r_0 lambda a b w e c eps_0 \n",
230 | "#theDegrees = [2 2 2 4 3 4 4 3 2 2 4 2] # [2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 ] \n",
231 | " # Intg S eps_0 r c qc ap sin_theta dA dtheta w x_0 # W Q E S P q q_e x_0 ap m m_e r r_0 lambda a b w e c eps_0 \n",
232 | "\n",
233 | "candidate_mons = [\n",
234 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
235 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
236 | " for ai=axioms\n",
237 | "]\n",
238 | "@show size.(candidate_mons)\n",
239 | "\n",
240 | "# model = Model(Mosek.Optimizer)\n",
241 | "model = Model(Gurobi.Optimizer)\n",
242 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
243 | "\n",
244 | "mons_q = mons_of_max_degree_and_unit_overall([ P qc r w x_0 ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
245 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
246 | "\n",
247 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
248 | "coeff_αs = [\n",
249 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
250 | " for (i,X)=enumerate(candidate_mons)\n",
251 | " ]\n",
252 | "@show size.(coeff_αs)\n",
253 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
254 | "\n",
255 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
256 | "eqs = coefficients(residual)\n",
257 | "\n",
258 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
259 | "@constraint model sum(coeff_q[degree.(mons_q, [P ]).>0]) == 4.0 # insist that some variables will appear\n",
260 | "#@constraint model sum(coeff_q[degree.(mons_q,[E_c]).>0]) == 0.0 # insist that some variables will not appear\n",
261 | "@constraint model eqs .== 0\n",
262 | "@objective model Max 0\n",
263 | "\n",
264 | "optimize!(model)\n",
265 | "@show termination_status(model)"
266 | ]
267 | },
268 | {
269 | "cell_type": "code",
270 | "execution_count": 1,
271 | "metadata": {},
272 | "outputs": [
273 | {
274 | "data": {
275 | "text/plain": [
276 | "#3 (generic function with 1 method)"
277 | ]
278 | },
279 | "execution_count": 1,
280 | "metadata": {},
281 | "output_type": "execute_result"
282 | }
283 | ],
284 | "source": [
285 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))\n"
286 | ]
287 | },
288 | {
289 | "cell_type": "code",
290 | "execution_count": 22,
291 | "metadata": {},
292 | "outputs": [
293 | {
294 | "data": {
295 | "text/latex": [
296 | "$$ 4.0P - 16.755160819145562qc^{2}w^{4}x_0^{2} $$"
297 | ],
298 | "text/plain": [
299 | "4.0P - 16.755160819145562qc²w⁴x_0²"
300 | ]
301 | },
302 | "execution_count": 22,
303 | "metadata": {},
304 | "output_type": "execute_result"
305 | }
306 | ],
307 | "source": [
308 | "value_q = value_poly(q)\n",
309 | "value_q"
310 | ]
311 | },
312 | {
313 | "cell_type": "markdown",
314 | "metadata": {},
315 | "source": [
316 | "dividing by 4, we get as expected P = 4/3*pi q_c^2 x_0^2 w^4"
317 | ]
318 | },
319 | {
320 | "cell_type": "code",
321 | "execution_count": 23,
322 | "metadata": {},
323 | "outputs": [
324 | {
325 | "name": "stdout",
326 | "output_type": "stream",
327 | "text": [
328 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[25.132741228718345sin_thetadtheta, 4.0S, 4.0, -12.566370614359172qc²w⁴x_0², 25.132741228718345qc²sin_theta³dtheta]\n"
329 | ]
330 | },
331 | {
332 | "data": {
333 | "text/plain": [
334 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
335 | " 25.132741228718345sin_thetadtheta\n",
336 | " 4.0S\n",
337 | " 4.0\n",
338 | " -12.566370614359172qc²w⁴x_0²\n",
339 | " 25.132741228718345qc²sin_theta³dtheta"
340 | ]
341 | },
342 | "execution_count": 23,
343 | "metadata": {},
344 | "output_type": "execute_result"
345 | }
346 | ],
347 | "source": [
348 | "@show value_αs = value_poly.(αs)"
349 | ]
350 | },
351 | {
352 | "cell_type": "markdown",
353 | "metadata": {},
354 | "source": [
355 | "______________________________alternative (squares ) formulation _____________________"
356 | ]
357 | },
358 | {
359 | "cell_type": "code",
360 | "execution_count": 5,
361 | "metadata": {},
362 | "outputs": [
363 | {
364 | "data": {
365 | "text/plain": [
366 | "1×10 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
367 | " P S rs qcs aps sin_theta dA dtheta ws x_0s"
368 | ]
369 | },
370 | "execution_count": 5,
371 | "metadata": {},
372 | "output_type": "execute_result"
373 | }
374 | ],
375 | "source": [
376 | "@polyvar P S rs qcs aps sin_theta dA dtheta ws x_0s # Intg c eps_0 W Q E P q_e x_0 m m_e r_0 a b lambda w e c # the order matters per evaluation # sin_theta, a = sin_theta, b = cos_theta \n",
377 | "\n",
378 | "x =[ P S rs qcs aps sin_theta dA dtheta ws x_0s] # Intg sin_theta \n",
379 | "# w_0 natural fequency of atom vibration"
380 | ]
381 | },
382 | {
383 | "cell_type": "code",
384 | "execution_count": 6,
385 | "metadata": {},
386 | "outputs": [
387 | {
388 | "data": {
389 | "text/plain": [
390 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
391 | " Srs - qcsapssin_theta²\n",
392 | " dA - 6.283185307179586rssin_thetadtheta\n",
393 | " -1.3333333333333333 + sin_theta³dtheta\n",
394 | " P - SdA\n",
395 | " aps - 0.5ws²x_0s"
396 | ]
397 | },
398 | "execution_count": 6,
399 | "metadata": {},
400 | "output_type": "execute_result"
401 | }
402 | ],
403 | "source": [
404 | "axioms= \n",
405 | "[\n",
406 | " # a^2 + b^2 - 1, # a = sin_theta, b = cos_theta \n",
407 | " # S - eps_0 * c * E^2, #need an expectation over E (I.32.1)\n",
408 | " # S * 16 * pi^2 *eps_0 * r^2 * c^3 - qc^2 * ap^2 * a^2, #sin_theta^2, # rate of radiation of energy (I.32.2)\n",
409 | " S * rs - qcs * aps * sin_theta^2, ##S * 16 * pi^2 *eps_0 * r^2 * c^3 - qc^2 * ap^2 * sin_theta^2, #sin_theta^2, # rate of radiation of energy (I.32.2)\n",
410 | " dA - 2* pi* rs * sin_theta * dtheta, # \n",
411 | " sin_theta^3 * dtheta - 4/3, # a crocked way of defining an integral of sin^3 theta between 0 and pi\n",
412 | " P - S * dA,\n",
413 | " #P * 6 * pi * eps_0 * c^3 - q^2 * ap^2, # (I.32.5)\n",
414 | " aps - 0.5 *ws^2 * x_0s, # (I.32.5b)\n",
415 | " #P * 12 * pi * eps_0 * c^3 - q^2 * w^4 * x_0^2, # (I.32.6)\n",
416 | " # e^2 * 4 * pi * eps_0 - q_e^2, # electric potenial of an electron (I.32.7)\n",
417 | " # W - 1/2 * m * w^2 * x_0^2, # total energy of an oscillator, on the average half is kinetic and half is potential energy (I.32.9)\n",
418 | " # r_0 * m_e * c^2 - e^2, # radius magnitude\n",
419 | " # Q * 4 * pi * r_0 - 3 * lambda, # total energy content of the oscillator at any time divided by the energy loss per radian\n",
420 | " # lambda * w - 2* pi * c, # wavelength to angualr frequency relation\n",
421 | " ]"
422 | ]
423 | },
424 | {
425 | "cell_type": "code",
426 | "execution_count": 10,
427 | "metadata": {},
428 | "outputs": [
429 | {
430 | "name": "stdout",
431 | "output_type": "stream",
432 | "text": [
433 | "size.(candidate_mons) = [(21539,), (21539,), (21539,), (21539,), (21539,)]\n",
434 | "Set parameter Username\n",
435 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
436 | "Set parameter TimeLimit to value 600\n",
437 | "size.(coeff_αs) = [(21539,), (21539,), (21539,), (21539,), (21539,)]\n",
438 | "Set parameter TimeLimit to value 600\n",
439 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
440 | "\n",
441 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
442 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
443 | "\n",
444 | "Optimize a model with 125796 rows, 108698 columns and 217140 nonzeros\n",
445 | "Model fingerprint: 0xa6f23944\n",
446 | "Coefficient statistics:\n",
447 | " Matrix range [5e-01, 6e+00]\n",
448 | " Objective range [0e+00, 0e+00]\n",
449 | " Bounds range [0e+00, 0e+00]\n",
450 | " RHS range [4e+00, 4e+00]\n",
451 | "Presolve removed 125796 rows and 108698 columns\n",
452 | "Presolve time: 0.10s\n",
453 | "Presolve: All rows and columns removed\n",
454 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
455 | " 0 -0.0000000e+00 0.000000e+00 7.462000e-03 0s\n",
456 | "\n",
457 | "Solved in 0 iterations and 0.19 seconds (0.09 work units)\n",
458 | "Optimal objective -0.000000000e+00\n",
459 | "\n",
460 | "User-callback calls 63, time in user-callback 0.00 sec\n",
461 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
462 | ]
463 | },
464 | {
465 | "data": {
466 | "text/plain": [
467 | "OPTIMAL::TerminationStatusCode = 1"
468 | ]
469 | },
470 | "execution_count": 10,
471 | "metadata": {},
472 | "output_type": "execute_result"
473 | }
474 | ],
475 | "source": [
476 | "deg = 3\n",
477 | "deg_overall = 12\n",
478 | "theDegrees = [1 1 2 2 2 3 1 2 2 2] # 4 2 ] # [2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 ] \n",
479 | " # P S rs qcs aps sin_theta dA dtheta ws x_0s] # W Q E S P q q_e x_0 ap m m_e r r_0 lambda a b w e c eps_0 \n",
480 | "#theDegrees = [2 2 2 4 3 4 4 3 2 2 4 2] # [2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 ] \n",
481 | " # Intg S eps_0 r c qc ap sin_theta dA dtheta w x_0 # W Q E S P q q_e x_0 ap m m_e r r_0 lambda a b w e c eps_0 \n",
482 | "\n",
483 | "candidate_mons = [\n",
484 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
485 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
486 | " for ai=axioms\n",
487 | "]\n",
488 | "@show size.(candidate_mons)\n",
489 | "\n",
490 | "# model = Model(Mosek.Optimizer)\n",
491 | "model = Model(Gurobi.Optimizer)\n",
492 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
493 | "\n",
494 | "mons_q = mons_of_max_degree_and_unit_overall([ P qcs rs ws x_0s ], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
495 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
496 | "\n",
497 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
498 | "coeff_αs = [\n",
499 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
500 | " for (i,X)=enumerate(candidate_mons)\n",
501 | " ]\n",
502 | "@show size.(coeff_αs)\n",
503 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
504 | "\n",
505 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
506 | "eqs = coefficients(residual)\n",
507 | "\n",
508 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
509 | "@constraint model sum(coeff_q[degree.(mons_q, [P ]).>0]) == 4.0 # insist that some variables will appear\n",
510 | "#@constraint model sum(coeff_q[degree.(mons_q,[E_c]).>0]) == 0.0 # insist that some variables will not appear\n",
511 | "@constraint model eqs .== 0\n",
512 | "@objective model Max 0\n",
513 | "\n",
514 | "optimize!(model)\n",
515 | "@show termination_status(model)"
516 | ]
517 | },
518 | {
519 | "cell_type": "code",
520 | "execution_count": 11,
521 | "metadata": {},
522 | "outputs": [
523 | {
524 | "data": {
525 | "text/plain": [
526 | "#71 (generic function with 1 method)"
527 | ]
528 | },
529 | "execution_count": 11,
530 | "metadata": {},
531 | "output_type": "execute_result"
532 | }
533 | ],
534 | "source": [
535 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
536 | ]
537 | },
538 | {
539 | "cell_type": "code",
540 | "execution_count": 12,
541 | "metadata": {},
542 | "outputs": [
543 | {
544 | "data": {
545 | "text/latex": [
546 | "$$ 4.0Prsws - 16.755160819145562rsqcsws^{3}x_0s $$"
547 | ],
548 | "text/plain": [
549 | "4.0Prsws - 16.755160819145562rsqcsws³x_0s"
550 | ]
551 | },
552 | "execution_count": 12,
553 | "metadata": {},
554 | "output_type": "execute_result"
555 | }
556 | ],
557 | "source": [
558 | "value_q = value_poly(q)\n",
559 | "value_q"
560 | ]
561 | },
562 | {
563 | "cell_type": "code",
564 | "execution_count": 14,
565 | "metadata": {},
566 | "outputs": [
567 | {
568 | "name": "stdout",
569 | "output_type": "stream",
570 | "text": [
571 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[3.0sin_theta³dAdthetaws, 4.0qcsapssin_theta²ws, 25.132741228718345rsqcsapsws - 3.0SrsdAws + 3.0qcsapssin_theta²dAws, 4.0rsws, 33.510321638291124rsqcsws]\n"
572 | ]
573 | },
574 | {
575 | "data": {
576 | "text/plain": [
577 | "5-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
578 | " 3.0sin_theta³dAdthetaws\n",
579 | " 4.0qcsapssin_theta²ws\n",
580 | " 25.132741228718345rsqcsapsws - 3.0SrsdAws + 3.0qcsapssin_theta²dAws\n",
581 | " 4.0rsws\n",
582 | " 33.510321638291124rsqcsws"
583 | ]
584 | },
585 | "execution_count": 14,
586 | "metadata": {},
587 | "output_type": "execute_result"
588 | }
589 | ],
590 | "source": [
591 | "@show value_αs = value_poly.(αs)"
592 | ]
593 | }
594 | ],
595 | "metadata": {
596 | "kernelspec": {
597 | "display_name": "Julia 1.10.2",
598 | "language": "julia",
599 | "name": "julia-1.10"
600 | },
601 | "language_info": {
602 | "file_extension": ".jl",
603 | "mimetype": "application/julia",
604 | "name": "julia",
605 | "version": "1.9.4"
606 | }
607 | },
608 | "nbformat": 4,
609 | "nbformat_minor": 2
610 | }
611 |
--------------------------------------------------------------------------------
/suppl_material_problems/hall.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Hall Effect\n",
8 | "\n",
9 | "https://en.wikipedia.org/wiki/Hall_effect#Corbino_effect\n",
10 | "\n",
11 | "The Hall effect is the production of a potential difference (the Hall voltage) across an electrical conductor that is transverse to an electric current in the conductor and to an applied magnetic field perpendicular to the current.\n",
12 | "\n",
13 | "U_H = h L I B / (N q_e)\n",
14 | "\n",
15 | "https://www.youtube.com/watch?v=1OZCWetFCps"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 1,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "using DynamicPolynomials\n",
25 | "using JuMP\n",
26 | "using MosekTools\n",
27 | "using LinearAlgebra\n",
28 | "using CSV\n",
29 | "using DataFrames\n",
30 | "import JSON\n",
31 | "using Dates\n",
32 | "using Gurobi"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "functions for generating monomials"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 2,
45 | "metadata": {},
46 | "outputs": [
47 | {
48 | "data": {
49 | "text/plain": [
50 | "all_monomials_up_to_max_deg_overall_and_individual (generic function with 1 method)"
51 | ]
52 | },
53 | "execution_count": 2,
54 | "metadata": {},
55 | "output_type": "execute_result"
56 | }
57 | ],
58 | "source": [
59 | "function all_monomials_up_to_max_deg(x, deg)\n",
60 | " if size(x,1) == 0\n",
61 | " [1]\n",
62 | " else\n",
63 | " [ x[1]^k * m for k=0:deg \n",
64 | " for m=all_monomials_up_to_max_deg(x[2:end], deg)\n",
65 | " ]\n",
66 | " end\n",
67 | "end\n",
68 | "\n",
69 | "function mons_of_max_degree_and_unit(x, deg, u)\n",
70 | " [m\n",
71 | " for m=all_monomials_up_to_max_deg(x, deg)\n",
72 | " #if all(unit(m) .== u)\n",
73 | " ]\n",
74 | "end\n",
75 | " \n",
76 | "function degree_poly(p)\n",
77 | " maximum(degree.(monomials(p)))\n",
78 | "end\n",
79 | "\n",
80 | "function all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
81 | " if size(x,1) == 0\n",
82 | " [1]\n",
83 | " else\n",
84 | " [ x[1]^k * m for k=0:min(deg, deg_overall) \n",
85 | " for m=all_monomials_up_to_max_deg_overall(x[2:end], deg, deg_overall-k)\n",
86 | " ]\n",
87 | " end\n",
88 | "end\n",
89 | "\n",
90 | "function mons_of_max_degree_and_unit_overall(x, deg, deg_overall, u)\n",
91 | " [m\n",
92 | " for m=all_monomials_up_to_max_deg_overall(x, deg, deg_overall)\n",
93 | " #if all(unit(m) .== u)\n",
94 | " ]\n",
95 | "end\n",
96 | "\n",
97 | "function all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
98 | " if size(x,1) == 0\n",
99 | " [1]\n",
100 | " else\n",
101 | " [ x[1]^k * m for k=0:min(deg, deg_overall, theDegrees[1]) \n",
102 | " for m=all_monomials_up_to_max_deg_overall_and_individual(x[2:end], deg, deg_overall-k, theDegrees[2:end])\n",
103 | " ]\n",
104 | " end\n",
105 | "end"
106 | ]
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": 3,
111 | "metadata": {},
112 | "outputs": [
113 | {
114 | "data": {
115 | "text/plain": [
116 | "1×16 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
117 | " F_m q_e v B F_e E h U_H dt L I Q N n V d"
118 | ]
119 | },
120 | "execution_count": 3,
121 | "metadata": {},
122 | "output_type": "execute_result"
123 | }
124 | ],
125 | "source": [
126 | "@polyvar F_m q_e v B F_e E h U_H dt L I Q N n V d # the order matters per evaluation(?) # a_y a_x dv_x dv_y\n",
127 | "\n",
128 | "x = [F_m q_e v B F_e E h U_H dt L I Q N n V d ] #dv_x dv_y a_y a_x"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": 4,
134 | "metadata": {},
135 | "outputs": [
136 | {
137 | "data": {
138 | "text/plain": [
139 | "9-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
140 | " F_m - q_evB\n",
141 | " F_e - q_eE\n",
142 | " -F_e + F_m\n",
143 | " -U_H + Eh\n",
144 | " -L + vdt\n",
145 | " -Q + dtI\n",
146 | " Q - q_eN\n",
147 | " -N + nV\n",
148 | " V - hLd"
149 | ]
150 | },
151 | "execution_count": 4,
152 | "metadata": {},
153 | "output_type": "execute_result"
154 | }
155 | ],
156 | "source": [
157 | "axioms= \n",
158 | "[\n",
159 | " F_m - q_e * v * B, # Lorentz force\n",
160 | " F_e - q_e * E, # electric force (E homogenous electric feild between the upper and lower metal plate)\n",
161 | " F_m - F_e, # Newton's 3rd Law\n",
162 | " E * h - U_H, # electric potnetial U_H to field E relation per plate width h (the electric field is not known)\n",
163 | " v * dt - L, # velocity (v = L/dt) is not known\n",
164 | " I * dt - Q, # amount of charge Q, is the current I times dt (can be measured by an amp meter)\n",
165 | " Q - N * q_e, # the charge Q is the number of electrons N by the chage of each electron q_e\n",
166 | " n * V - N, # charge density is the number of electrons traveling through the metal plate in a given time over the volume V\n",
167 | " V - L * h * d, # the volume V is the product of the length L by the width h, by the thickness of the plate d\n",
168 | " ]\n",
169 | " "
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": 5,
175 | "metadata": {},
176 | "outputs": [
177 | {
178 | "name": "stdout",
179 | "output_type": "stream",
180 | "text": [
181 | "size.(candidate_mons) = [(104583,), (104583,), (104583,), (104583,), (104583,), (104583,), (104583,), (104583,), (104583,)]\n"
182 | ]
183 | }
184 | ],
185 | "source": [
186 | "deg = 3\n",
187 | "deg_overall = 8\n",
188 | "theDegrees = [ 1 1 2 1 1 1 2 1 2 2 2 1 1 1 1 1] \n",
189 | " # F_m q_e v B F_e E h U_H dt L I Q N n V d\n",
190 | "\n",
191 | "candidate_mons = [\n",
192 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
193 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
194 | " for ai=axioms\n",
195 | "]\n",
196 | "\n",
197 | "@show size.(candidate_mons)\n",
198 | "\n",
199 | "# model = Model(Mosek.Optimizer)\n",
200 | "model = Model(Gurobi.Optimizer)\n",
201 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
202 | "\n",
203 | "mons_q = mons_of_max_degree_and_unit_overall([I n q_e d B h L U_H], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
204 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
205 | "\n",
206 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
207 | "coeff_αs = [\n",
208 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
209 | " for (i,X)=enumerate(candidate_mons)\n",
210 | " ]\n",
211 | "@show size.(coeff_αs)\n",
212 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
213 | "\n",
214 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
215 | "eqs = coefficients(residual)\n",
216 | "\n",
217 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
218 | "@constraint model sum(coeff_q[degree.(mons_q, [U_H ]).>0]) == 1.0\n",
219 | "\n",
220 | "@constraint model eqs .== 0\n",
221 | "@objective model Max 0\n",
222 | "\n",
223 | "optimize!(model)\n",
224 | "@show termination_status(model)"
225 | ]
226 | },
227 | {
228 | "cell_type": "code",
229 | "execution_count": 14,
230 | "metadata": {},
231 | "outputs": [
232 | {
233 | "data": {
234 | "text/plain": [
235 | "#75 (generic function with 1 method)"
236 | ]
237 | },
238 | "execution_count": 14,
239 | "metadata": {},
240 | "output_type": "execute_result"
241 | }
242 | ],
243 | "source": [
244 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
245 | ]
246 | },
247 | {
248 | "cell_type": "code",
249 | "execution_count": 15,
250 | "metadata": {},
251 | "outputs": [
252 | {
253 | "data": {
254 | "text/latex": [
255 | "$$ 2.0mGM + mv_e^{2}r $$"
256 | ],
257 | "text/plain": [
258 | "2.0mGM + mv_e²r"
259 | ]
260 | },
261 | "execution_count": 15,
262 | "metadata": {},
263 | "output_type": "execute_result"
264 | }
265 | ],
266 | "source": [
267 | "value_q = value_poly(q)\n",
268 | "value_q"
269 | ]
270 | },
271 | {
272 | "cell_type": "markdown",
273 | "metadata": {},
274 | "source": []
275 | },
276 | {
277 | "cell_type": "code",
278 | "execution_count": 3,
279 | "metadata": {},
280 | "outputs": [
281 | {
282 | "ename": "LoadError",
283 | "evalue": "UndefVarError: `value_poly` not defined",
284 | "output_type": "error",
285 | "traceback": [
286 | "UndefVarError: `value_poly` not defined",
287 | "",
288 | "Stacktrace:",
289 | " [1] top-level scope",
290 | " @ show.jl:1128"
291 | ]
292 | }
293 | ],
294 | "source": [
295 | "@show value_αs = value_poly.(αs)"
296 | ]
297 | },
298 | {
299 | "cell_type": "markdown",
300 | "metadata": {},
301 | "source": [
302 | "___________________________________________________________________reduced parameters_____________________________________________________________"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": 7,
308 | "metadata": {},
309 | "outputs": [
310 | {
311 | "data": {
312 | "text/plain": [
313 | "1×12 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
314 | " F_m q_e v B F_e E h U_H dt L I N"
315 | ]
316 | },
317 | "execution_count": 7,
318 | "metadata": {},
319 | "output_type": "execute_result"
320 | }
321 | ],
322 | "source": [
323 | "@polyvar F_m q_e v B F_e E h U_H dt L I N # the order matters per evaluation # Q N n V d\n",
324 | "\n",
325 | "x = [F_m q_e v B F_e E h U_H dt L I N ] #dv_x dv_y a_y a_x"
326 | ]
327 | },
328 | {
329 | "cell_type": "code",
330 | "execution_count": 8,
331 | "metadata": {},
332 | "outputs": [
333 | {
334 | "data": {
335 | "text/plain": [
336 | "6-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
337 | " F_m - q_evB\n",
338 | " F_e - q_eE\n",
339 | " -F_e + F_m\n",
340 | " -U_H + Eh\n",
341 | " -L + vdt\n",
342 | " dtI - q_eN"
343 | ]
344 | },
345 | "execution_count": 8,
346 | "metadata": {},
347 | "output_type": "execute_result"
348 | }
349 | ],
350 | "source": [
351 | "axioms= \n",
352 | "[\n",
353 | " F_m - q_e * v * B, # Lorentz force\n",
354 | " F_e - q_e * E, # electric force (E homogenous electric feild between the upper and lower metal plate)\n",
355 | " F_m - F_e, # Newton's 3rd Law\n",
356 | " E * h - U_H, # electric potnetial U_H to field E relation per plate width h (the electric field is not known)\n",
357 | " v * dt - L, # velocity (v = L/dt) is not known\n",
358 | " # I * dt - Q, # amount of charge Q, is the current I times dt (can be measured by an amp meter)\n",
359 | " I * dt - N * q_e, # amount of charge Q, is the current I times dt (can be measured by an amp meter)\n",
360 | " # Q - N * q_e, # the charge Q is the number of electrons N by the chage of each electron q_e\n",
361 | " ## n * L * h * d - N, # charge density is the number of electrons traveling through the metal plate in a given time over the volume V\n",
362 | " # n * V - N, # charge density is the number of electrons traveling through the metal plate in a given time over the volume V\n",
363 | " # V - L * h * d, # the volume V is the product of the length L by the width h, by the thickness of the plate d\n",
364 | " ]\n",
365 | " "
366 | ]
367 | },
368 | {
369 | "cell_type": "code",
370 | "execution_count": 11,
371 | "metadata": {},
372 | "outputs": [
373 | {
374 | "name": "stdout",
375 | "output_type": "stream",
376 | "text": [
377 | "size.(candidate_mons) = [(19438,), (19438,), (19438,), (19438,), (19438,), (19438,)]\n",
378 | "Set parameter Username\n",
379 | "Academic license - for non-commercial use only - expires 2024-12-04\n",
380 | "Set parameter TimeLimit to value 600\n",
381 | "size.(coeff_αs) = [(19438,), (19438,), (19438,), (19438,), (19438,), (19438,)]\n",
382 | "Set parameter TimeLimit to value 600\n",
383 | "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 11+.0 (22631.2))\n",
384 | "\n",
385 | "CPU model: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, instruction set [SSE2|AVX|AVX2]\n",
386 | "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n",
387 | "\n",
388 | "Optimize a model with 114894 rows, 118275 columns and 235899 nonzeros\n",
389 | "Model fingerprint: 0x8063a4d5\n",
390 | "Coefficient statistics:\n",
391 | " Matrix range [1e+00, 1e+00]\n",
392 | " Objective range [0e+00, 0e+00]\n",
393 | " Bounds range [0e+00, 0e+00]\n",
394 | " RHS range [1e+00, 1e+00]\n",
395 | "Presolve removed 114894 rows and 118275 columns\n",
396 | "Presolve time: 0.10s\n",
397 | "Presolve: All rows and columns removed\n",
398 | "Iteration Objective Primal Inf. Dual Inf. Time\n",
399 | " 0 -0.0000000e+00 0.000000e+00 1.840400e-02 0s\n",
400 | "\n",
401 | "Solved in 0 iterations and 0.16 seconds (0.10 work units)\n",
402 | "Optimal objective -0.000000000e+00\n",
403 | "\n",
404 | "User-callback calls 65, time in user-callback 0.00 sec\n",
405 | "termination_status(model) = MathOptInterface.OPTIMAL\n"
406 | ]
407 | },
408 | {
409 | "data": {
410 | "text/plain": [
411 | "OPTIMAL::TerminationStatusCode = 1"
412 | ]
413 | },
414 | "execution_count": 11,
415 | "metadata": {},
416 | "output_type": "execute_result"
417 | }
418 | ],
419 | "source": [
420 | "deg = 2\n",
421 | "deg_overall = 8\n",
422 | "theDegrees = [ 1 2 2 2 1 2 2 2 1 1 1 1] \n",
423 | " # F_m q_e v B F_e E h U_H dt L I N \n",
424 | "\n",
425 | "candidate_mons = [\n",
426 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
427 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
428 | " for ai=axioms\n",
429 | "]\n",
430 | "\n",
431 | "@show size.(candidate_mons)\n",
432 | "\n",
433 | "# model = Model(Mosek.Optimizer)\n",
434 | "model = Model(Gurobi.Optimizer)\n",
435 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
436 | "\n",
437 | "mons_q = mons_of_max_degree_and_unit_overall([I N q_e B h L U_H], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
438 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
439 | "\n",
440 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
441 | "coeff_αs = [\n",
442 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
443 | " for (i,X)=enumerate(candidate_mons)\n",
444 | " ]\n",
445 | "@show size.(coeff_αs)\n",
446 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
447 | "\n",
448 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
449 | "eqs = coefficients(residual)\n",
450 | "\n",
451 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
452 | "@constraint model sum(coeff_q[degree.(mons_q, [U_H ]).>0]) == 1.0\n",
453 | "\n",
454 | "@constraint model eqs .== 0\n",
455 | "@objective model Max 0\n",
456 | "\n",
457 | "optimize!(model)\n",
458 | "@show termination_status(model)"
459 | ]
460 | },
461 | {
462 | "cell_type": "code",
463 | "execution_count": 12,
464 | "metadata": {},
465 | "outputs": [
466 | {
467 | "data": {
468 | "text/plain": [
469 | "#45 (generic function with 1 method)"
470 | ]
471 | },
472 | "execution_count": 12,
473 | "metadata": {},
474 | "output_type": "execute_result"
475 | }
476 | ],
477 | "source": [
478 | "value_poly = p -> sum(value.(coefficients(p)).* monomials(p))"
479 | ]
480 | },
481 | {
482 | "cell_type": "code",
483 | "execution_count": 13,
484 | "metadata": {},
485 | "outputs": [
486 | {
487 | "data": {
488 | "text/latex": [
489 | "$$ q_e^{2}U_HLN^{2} - q_eBhL^{2}IN $$"
490 | ],
491 | "text/plain": [
492 | "q_e²U_HLN² - q_eBhL²IN"
493 | ]
494 | },
495 | "execution_count": 13,
496 | "metadata": {},
497 | "output_type": "execute_result"
498 | }
499 | ],
500 | "source": [
501 | "value_q = value_poly(q)\n",
502 | "value_q"
503 | ]
504 | },
505 | {
506 | "cell_type": "markdown",
507 | "metadata": {},
508 | "source": [
509 | "After rearangment we get U_H = B h L I / (N q_e)"
510 | ]
511 | },
512 | {
513 | "cell_type": "code",
514 | "execution_count": 14,
515 | "metadata": {},
516 | "outputs": [
517 | {
518 | "name": "stdout",
519 | "output_type": "stream",
520 | "text": [
521 | "value_αs = value_poly.(αs) = Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}[hdtLIN, -hdtLIN, -hdtLIN, -q_edtLIN, q_eBhLIN, -q_eU_HLN]\n"
522 | ]
523 | },
524 | {
525 | "data": {
526 | "text/plain": [
527 | "6-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Float64}}:\n",
528 | " hdtLIN\n",
529 | " -hdtLIN\n",
530 | " -hdtLIN\n",
531 | " -q_edtLIN\n",
532 | " q_eBhLIN\n",
533 | " -q_eU_HLN"
534 | ]
535 | },
536 | "execution_count": 14,
537 | "metadata": {},
538 | "output_type": "execute_result"
539 | },
540 | {
541 | "name": "stderr",
542 | "output_type": "stream",
543 | "text": [
544 | "WARNING: both JuMP and DynamicPolynomials export \"name\"; uses of it in module Main must be qualified\n"
545 | ]
546 | }
547 | ],
548 | "source": [
549 | "@show value_αs = value_poly.(αs)"
550 | ]
551 | },
552 | {
553 | "cell_type": "markdown",
554 | "metadata": {},
555 | "source": [
556 | "______________________________________________________________ eliminate q ____________________________________________________________________________________"
557 | ]
558 | },
559 | {
560 | "cell_type": "code",
561 | "execution_count": 15,
562 | "metadata": {},
563 | "outputs": [
564 | {
565 | "data": {
566 | "text/plain": [
567 | "1×15 Matrix{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}:\n",
568 | " F_m q_e v B F_e E h U_H dt L I N n Q d"
569 | ]
570 | },
571 | "execution_count": 15,
572 | "metadata": {},
573 | "output_type": "execute_result"
574 | }
575 | ],
576 | "source": [
577 | "@polyvar F_m q_e v B F_e E h U_H dt L I N n Q d # the order matters per evaluation # Q N n V d\n",
578 | "\n",
579 | "x = [F_m q_e v B F_e E h U_H dt L I N n Q d] #dv_x dv_y a_y a_x"
580 | ]
581 | },
582 | {
583 | "cell_type": "code",
584 | "execution_count": 16,
585 | "metadata": {},
586 | "outputs": [
587 | {
588 | "data": {
589 | "text/plain": [
590 | "7-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:\n",
591 | " F_m - q_evB\n",
592 | " F_e - q_eE\n",
593 | " -F_e + F_m\n",
594 | " -U_H + Eh\n",
595 | " -L + vdt\n",
596 | " dtI - q_eN\n",
597 | " -N + hLnd"
598 | ]
599 | },
600 | "execution_count": 16,
601 | "metadata": {},
602 | "output_type": "execute_result"
603 | }
604 | ],
605 | "source": [
606 | "axioms= \n",
607 | "[\n",
608 | " F_m - q_e * v * B, # Lorentz force\n",
609 | " F_e - q_e * E, # electric force (E homogenous electric feild between the upper and lower metal plate)\n",
610 | " F_m - F_e, # Newton's 3rd Law\n",
611 | " E * h - U_H, # electric potnetial U_H to field E relation per plate width h (the electric field is not known)\n",
612 | " v * dt - L, # velocity (v = L/dt) is not known\n",
613 | " # I * dt - Q, # amount of charge Q, is the current I times dt (can be measured by an amp meter)\n",
614 | " I * dt - N * q_e, # amount of charge Q, is the current I times dt (can be measured by an amp meter)\n",
615 | " # Q - N * q_e, # the charge Q is the number of electrons N by the chage of each electron q_e\n",
616 | " n * L * h * d - N, # charge density is the number of electrons traveling through the metal plate in a given time over the volume V\n",
617 | " # n * V - N, # charge density is the number of electrons traveling through the metal plate in a given time over the volume V\n",
618 | " # V - L * h * d, # the volume V is the product of the length L by the width h, by the thickness of the plate d\n",
619 | " ]"
620 | ]
621 | },
622 | {
623 | "cell_type": "code",
624 | "execution_count": 17,
625 | "metadata": {},
626 | "outputs": [
627 | {
628 | "name": "stdout",
629 | "output_type": "stream",
630 | "text": [
631 | "size.(candidate_mons) = [(79665,), (79665,), (79665,), (79665,), (79665,), (79665,), (79665,)]\n"
632 | ]
633 | }
634 | ],
635 | "source": [
636 | "deg = 2\n",
637 | "deg_overall = 8\n",
638 | "theDegrees = [ 1 2 2 2 1 2 2 2 1 1 1 1 1 1 1] \n",
639 | " # F_m q_e v B F_e E h U_H dt L I N n Q d \n",
640 | "\n",
641 | "candidate_mons = [\n",
642 | " #mons_of_max_degree_and_unit_overall(params, deg, deg_overall, [])\n",
643 | " all_monomials_up_to_max_deg_overall_and_individual(x, deg, deg_overall, theDegrees)\n",
644 | " for ai=axioms\n",
645 | "]\n",
646 | "\n",
647 | "@show size.(candidate_mons)\n",
648 | "\n",
649 | "# model = Model(Mosek.Optimizer)\n",
650 | "model = Model(Gurobi.Optimizer)\n",
651 | "set_optimizer_attribute(model, \"TimeLimit\", 600.0)\n",
652 | "\n",
653 | "mons_q = mons_of_max_degree_and_unit_overall([I n q_e B h d U_H], deg, deg_overall, []) # only include variables expected to appear in the final theorem \n",
654 | "coeff_q = @variable(model, [1:size(mons_q,1)], base_name=\"q\")\n",
655 | "\n",
656 | "q = sum(ci .* mi for (ci, mi)=zip(coeff_q, mons_q)) # Zip pairs things without needing a ref index, e.g., zip([1, 2, 3], [4,5,6])=((1,4), (2,5), (3,6))\n",
657 | "coeff_αs = [\n",
658 | " @variable(model, [1:size(X,1)], base_name=\"α$i\")\n",
659 | " for (i,X)=enumerate(candidate_mons)\n",
660 | " ]\n",
661 | "@show size.(coeff_αs)\n",
662 | "αs = [sum(ci .* mi) for (ci, mi)=zip(coeff_αs, candidate_mons)]\n",
663 | "\n",
664 | "residual = q - sum(αᵢ * aᵢ for (αᵢ, aᵢ)=zip(αs,axioms));\n",
665 | "eqs = coefficients(residual)\n",
666 | "\n",
667 | "# Ensure that the sum of the coefficients on the terms involving m isn't zero, in order that m is part of expression\n",
668 | "@constraint model sum(coeff_q[degree.(mons_q, [U_H ]).>0]) == 1.0\n",
669 | "\n",
670 | "@constraint model eqs .== 0\n",
671 | "@objective model Max 0\n",
672 | "\n",
673 | "optimize!(model)\n",
674 | "@show termination_status(model)"
675 | ]
676 | }
677 | ],
678 | "metadata": {
679 | "kernelspec": {
680 | "display_name": "Julia 1.10.2",
681 | "language": "julia",
682 | "name": "julia-1.10"
683 | },
684 | "language_info": {
685 | "file_extension": ".jl",
686 | "mimetype": "application/julia",
687 | "name": "julia",
688 | "version": "1.9.4"
689 | }
690 | },
691 | "nbformat": 4,
692 | "nbformat_minor": 2
693 | }
694 |
--------------------------------------------------------------------------------