more formulas

This commit is contained in:
Álvaro González 2026-02-24 10:21:07 +01:00
parent f7a678d7dd
commit 1bcf829525
16 changed files with 527 additions and 770 deletions

View file

@ -32,4 +32,8 @@
- [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies(). - [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies().
- [X] Replace flutter-markdown with flutter-markdown-plus - [X] Replace flutter-markdown with flutter-markdown-plus
- [X] Heron's formula: investigate why a=3, b=40, c=5 yields NaN. Root cause: input values don't form a valid triangle (violate triangle inequality: 3+5=8 is not > 40). Added documentation note to the formula description. - [X] Heron's formula: investigate why a=3, b=40, c=5 yields NaN. Root cause: input values don't form a valid triangle (violate triangle inequality: 3+5=8 is not > 40). Added documentation note to the formula description.
- [R] Refactor ./assets/formulas d4rt files:
- [R] Pretty print files as dart literals (like JSON, but allow raw strings r"""like this""")
- [R] Ensure there is no formula duplicates. If necesary, move or delete the formula in file formulas.d4rt
- [R] defaultCorpus must load all formula files
- [ ] Investigate starup time when there is no previous database and corpus is loaded from assets. - [ ] Investigate starup time when there is no previous database and corpus is loaded from assets.

View file

@ -1,5 +1,8 @@
[ [
{"name":"Temperature converter","description":r""" // Temperature Converter
{
"name": "Temperature converter",
"description": r"""
Simple temperature converter example that returns the input value (Kelvin) as output. Simple temperature converter example that returns the input value (Kelvin) as output.
Formula: $$T_{out} = T_{in}$$ Formula: $$T_{out} = T_{in}$$
@ -7,6 +10,12 @@ Formula: $$T_{out} = T_{in}$$
Inputs: `Input` in kelvin (K). Inputs: `Input` in kelvin (K).
Output: `Output` in kelvin (K). Output: `Output` in kelvin (K).
![Temperature scales (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Temperature_scales.svg/800px-Temperature_scales.svg.png) ![Temperature scales (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/Comparison_of_temperature_scales.svg/960px-Comparison_of_temperature_scales.svg.png)""",
""","input":[{"name":"Input","unit":"Kelvin"}],"output":{"name":"Output","unit":"Kelvin"},"d4rtCode":"Output = Input;","tags":["converter","temperature"]} "input": [
{"name": "Input", "unit": "Kelvin"}
],
"output": {"name": "Output", "unit": "Kelvin"},
"d4rtCode": "Output = Input;",
"tags": ["converter", "temperature"]
}
] ]

View file

@ -1,20 +1,59 @@
[ [
{"name":"Coulomb's Law","input":[{"name":"q1","unit":"coulomb"},{"name":"q2","unit":"coulomb"},{"name":"r","unit":"meter"}],"output":{"name":"F","unit":"newton"},"d4rtCode":"F = (8.9875517923e9 * q1 * q2) / pow(r, 2);","description":r""" // Coulomb's Law
{
"name": "Coulomb's Law",
"description": r"""
Calculates the magnitude of the electrostatic force between two point charges. Calculates the magnitude of the electrostatic force between two point charges.
Formula: $F = k \dfrac{q_1 q_2}{r^2}$ where $k = 8.9875517923\times10^9\ \mathrm{N\,m^2/C^2}$. Formula: $F = k \dfrac{q_1 q_2}{r^2}$ where $k = 8.9875517923\times10^9\ \mathrm{N\,m^2/C^2}$.
Inputs: `q1`, `q2` in coulombs; `r` in meters. Inputs: `q1`, `q2` in coulombs; `r` in meters.
Output: Force `F` in newtons (N). Output: Force `F` in newtons (N).""",
""","tags":["physics","electricity","electrostatics"]}, "input": [
{"name":"Ohm's Law","input":[{"name":"I","unit":"ampere"},{"name":"R","unit":"ohm"}],"output":{"name":"V","unit":"volt"},"d4rtCode":"V = I * R;","description":r""" {"name": "q1", "unit": "coulomb"},
{"name": "q2", "unit": "coulomb"},
{"name": "r", "unit": "meter"}
],
"output": {"name": "F", "unit": "newton"},
"d4rtCode": "F = (8.9875517923e9 * q1 * q2) / pow(r, 2);",
"tags": ["physics", "electricity", "electrostatics"]
},
// Ohm's Law
{
"name": "Ohm's Law",
"description": r"""
Relates voltage, current and resistance for a linear resistor. Relates voltage, current and resistance for a linear resistor.
Formula: $V = I\,R$. Formula: $V = I\,R$.
Inputs: current `I` in amperes (A), resistance `R` in ohms (Ω). Inputs: current `I` in amperes (A), resistance `R` in ohms (Ω).
Output: voltage `V` in volts (V). Output: voltage `V` in volts (V).""",
""","tags":["physics","electricity","electronics"]}, "input": [
{"name":"Electric Power","input":[{"name":"V","unit":"volt"},{"name":"I","unit":"ampere"}],"output":{"name":"P","unit":"watt"},"d4rtCode":"P = V * I;","description":r""" {"name": "I", "unit": "ampere"},
{"name": "R", "unit": "ohm"}
],
"output": {"name": "V", "unit": "volt"},
"d4rtCode": "V = I * R;",
"tags": ["physics", "electricity", "electronics"]
},
// Electric Power
{
"name": "Electric Power",
"description": r"""
Calculates electrical power delivered to a load. Calculates electrical power delivered to a load.
Formula: $P = V\,I$ (also $P = I^2 R$ or $P = V^2 / R$ when substituting Ohm's law). Formula: $P = V\,I$ (also $P = I^2 R$ or $P = V^2 / R$ when substituting Ohm's law).
Inputs: voltage `V` in volts (V), current `I` in amperes (A). Inputs: voltage `V` in volts (V), current `I` in amperes (A).
Output: power `P` in watts (W). Output: power `P` in watts (W).""",
""","tags":["physics","electricity","electronics"]} "input": [
{"name": "V", "unit": "volt"},
{"name": "I", "unit": "ampere"}
],
"output": {"name": "P", "unit": "watt"},
"d4rtCode": "P = V * I;",
"tags": ["physics", "electricity", "electronics"]
}
] ]

View file

@ -1,5 +1,8 @@
[ [
{"name":"Kinetic Energy","description":r""" // Kinetic Energy
{
"name": "Kinetic Energy",
"description": r"""
Energy possessed by a moving object. Energy possessed by a moving object.
$$KE = \frac{1}{2}mv^2$$ $$KE = \frac{1}{2}mv^2$$
@ -8,9 +11,20 @@ Where:
- $m$: Mass (kg) - $m$: Mass (kg)
- $v$: Velocity (m/s) - $v$: Velocity (m/s)
![Kinetic energy (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Kinetic_energy.svg/1200px-Kinetic_energy.svg.png) ![Kinetic energy (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Kinetic_energy.svg/1200px-Kinetic_energy.svg.png)""",
""","input":[{"name":"m","unit":"kilogram"},{"name":"v","unit":"meters per second"}],"output":{"name":"KE","unit":"joule"},"d4rtCode":"KE = 0.5 * m * pow(v, 2);","tags":["physics","energy","mechanics"]}, "input": [
{"name":"Work","description":r""" {"name": "m", "unit": "kilogram"},
{"name": "v", "unit": "meters per second"}
],
"output": {"name": "KE", "unit": "joule"},
"d4rtCode": "KE = 0.5 * m * pow(v, 2);",
"tags": ["physics", "energy", "mechanics"]
},
// Work
{
"name": "Work",
"description": r"""
Energy transferred when a force moves an object. Energy transferred when a force moves an object.
$$W = F d \cos(\theta)$$ $$W = F d \cos(\theta)$$
@ -21,9 +35,24 @@ Where:
- $d$: Displacement (meters) - $d$: Displacement (meters)
- $\theta$: Angle between force and displacement - $\theta$: Angle between force and displacement
![Work (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Work.svg/800px-Work.svg.png) ![Work (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Work.svg/800px-Work.svg.png)""",
""","input":[{"name":"F","unit":"newton"},{"name":"d","unit":"meter"},{"name":"theta","unit":"degree"}],"output":{"name":"W","unit":"joule"},"d4rtCode":"var thetaRad = theta * (pi / 180); W = F * d * cos(thetaRad);","tags":["physics","energy","mechanics"]}, "input": [
{"name":"Power","description":r""" {"name": "F", "unit": "newton"},
{"name": "d", "unit": "meter"},
{"name": "theta", "unit": "degree"}
],
"output": {"name": "W", "unit": "joule"},
"d4rtCode": """
var thetaRad = theta * (pi / 180);
W = F * d * cos(thetaRad);
""",
"tags": ["physics", "energy", "mechanics"]
},
// Power
{
"name": "Power",
"description": r"""
Rate at which work is done or energy is transferred. Rate at which work is done or energy is transferred.
$$P = \frac{W}{t}$$ $$P = \frac{W}{t}$$
@ -33,9 +62,20 @@ Where:
- $W$: Work or energy (Joules) - $W$: Work or energy (Joules)
- $t$: Time (seconds) - $t$: Time (seconds)
![Power (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Power_equation.svg/800px-Power_equation.svg.png) ![Power (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Power_equation.svg/800px-Power_equation.svg.png)""",
""","input":[{"name":"W","unit":"joule"},{"name":"t","unit":"second"}],"output":{"name":"P","unit":"watt"},"d4rtCode":"P = W / t;","tags":["physics","energy","mechanics"]}, "input": [
{"name":"Mass-Energy Equivalence","description":r""" {"name": "W", "unit": "joule"},
{"name": "t", "unit": "second"}
],
"output": {"name": "P", "unit": "watt"},
"d4rtCode": "P = W / t;",
"tags": ["physics", "energy", "mechanics"]
},
// Mass-Energy Equivalence
{
"name": "Mass-Energy Equivalence",
"description": r"""
Einstein's mass-energy equivalence relation. Einstein's mass-energy equivalence relation.
$$E = mc^2$$ $$E = mc^2$$
@ -47,6 +87,12 @@ Where:
This shows mass can be converted to energy and vice versa. This shows mass can be converted to energy and vice versa.
![Einstein formula (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Einstein_light_beam.svg/800px-Einstein_light_beam.svg.png) ![Einstein formula (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Einstein_light_beam.svg/800px-Einstein_light_beam.svg.png)""",
""","input":[{"name":"m","unit":"kilogram"}],"output":{"name":"E","unit":"joule"},"d4rtCode":"E = m * pow(299792458, 2);","tags":["physics","relativity","energy"]} "input": [
{"name": "m", "unit": "kilogram"}
],
"output": {"name": "E", "unit": "joule"},
"d4rtCode": "E = m * pow(299792458, 2);",
"tags": ["physics", "relativity", "energy"]
}
] ]

View file

@ -1,5 +1,8 @@
[ [
{"name":"Density","description":r""" // Density
{
"name": "Density",
"description": r"""
Mass per unit volume of a substance. Mass per unit volume of a substance.
$$\rho = \frac{m}{V}$$ $$\rho = \frac{m}{V}$$
@ -11,9 +14,20 @@ Where:
Density is an intrinsic property of materials. Density is an intrinsic property of materials.
![Density illustration (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2d/Density_of_solids.svg/800px-Density_of_solids.svg.png) ![Density illustration (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2d/Density_of_solids.svg/800px-Density_of_solids.svg.png)""",
""","input":[{"name":"m","unit":"kilogram"},{"name":"V","unit":"cubic meter"}],"output":{"name":"rho","unit":"kilogram per cubic meter"},"d4rtCode":"rho = m / V;","tags":["physics","mechanics","material"]}, "input": [
{"name":"Pressure","description":r""" {"name": "m", "unit": "kilogram"},
{"name": "V", "unit": "cubic meter"}
],
"output": {"name": "rho", "unit": "kilogram per cubic meter"},
"d4rtCode": "rho = m / V;",
"tags": ["physics", "mechanics", "material"]
},
// Pressure
{
"name": "Pressure",
"description": r"""
Force applied perpendicular to a surface per unit area. Force applied perpendicular to a surface per unit area.
$$P = \frac{F}{A}$$ $$P = \frac{F}{A}$$
@ -25,9 +39,20 @@ Where:
Pressure is transmitted equally in all directions in fluids. Pressure is transmitted equally in all directions in fluids.
![Pressure (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Pressure_in_fluid.svg/800px-Pressure_in_fluid.svg.png) ![Pressure (diagram) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Pressure_in_fluid.svg/800px-Pressure_in_fluid.svg.png)""",
""","input":[{"name":"F","unit":"newton"},{"name":"A","unit":"square meter"}],"output":{"name":"P","unit":"pascal"},"d4rtCode":"P = F / A;","tags":["physics","mechanics","fluid"]}, "input": [
{"name":"Buoyant Force","description":r""" {"name": "F", "unit": "newton"},
{"name": "A", "unit": "square meter"}
],
"output": {"name": "P", "unit": "pascal"},
"d4rtCode": "P = F / A;",
"tags": ["physics", "mechanics", "fluid"]
},
// Buoyant Force
{
"name": "Buoyant Force",
"description": r"""
Upward force exerted on an object immersed in a fluid (Archimedes' principle). Upward force exerted on an object immersed in a fluid (Archimedes' principle).
$$F_b = \rho g V$$ $$F_b = \rho g V$$
@ -40,7 +65,14 @@ Where:
An object floats when buoyant force equals its weight. An object floats when buoyant force equals its weight.
![Archimedes principle (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Archimedes-principle.svg/960px-Archimedes-principle.svg.png) ![Archimedes principle (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Archimedes-principle.svg/960px-Archimedes-principle.svg.png)""",
"input": [
""","input":[{"name":"rho","unit":"kilogram per cubic meter"},{"name":"g","unit":"meters per square second"},{"name":"V","unit":"cubic meter"}],"output":{"name":"Fb","unit":"newton"},"d4rtCode":"Fb = rho * g * V;","tags":["physics","fluid","mechanics"]} {"name": "rho", "unit": "kilogram per cubic meter"},
{"name": "g", "unit": "meters per square second"},
{"name": "V", "unit": "cubic meter"}
],
"output": {"name": "Fb", "unit": "newton"},
"d4rtCode": "Fb = rho * g * V;",
"tags": ["physics", "fluid", "mechanics"]
}
] ]

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,22 @@
[ [
// Geometry formulas extracted from formulas.d4rt
// Area of Circle // Area of Circle
{ {
"name": "Area of Circle", "name": "Area of Circle",
"description": r'''\nArea enclosed by a circle\n\n$$A = \pi r^2$$\n\nWhere:\n- $A$: Area (square meters)\n- $r$: Radius (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThe area is proportional to the square of the radius.''', "description": r"""
Area enclosed by a circle
$$A = \pi r^2$$
Where:
- $A$: Area (square meters)
- $r$: Radius (meters)
- $\pi$: Pi ($\approx 3.14159$)
The area is proportional to the square of the radius.""",
"input": [ "input": [
{"name": "r", "unit": "meter"} // Radius {"name": "r", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": "A = pi * pow(r, 2);", "d4rtCode": "A = pi * pow(r, 2);",
"tags": ["geometry", "circle", "area"] "tags": ["geometry", "circle", "area"]
}, },
@ -15,11 +24,21 @@
// Circumference of Circle // Circumference of Circle
{ {
"name": "Circumference of Circle", "name": "Circumference of Circle",
"description": r'''\nPerimeter (distance around) a circle\n\n$$C = 2\pi r$$\n\nWhere:\n- $C$: Circumference (meters)\n- $r$: Radius (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThe circumference is proportional to the radius.''', "description": r"""
Perimeter (distance around) a circle
$$C = 2\pi r$$
Where:
- $C$: Circumference (meters)
- $r$: Radius (meters)
- $\pi$: Pi ($\approx 3.14159$)
The circumference is proportional to the radius.""",
"input": [ "input": [
{"name": "r", "unit": "meter"} // Radius {"name": "r", "unit": "meter"}
], ],
"output": {"name": "C", "unit": "meter"}, // Circumference "output": {"name": "C", "unit": "meter"},
"d4rtCode": "C = 2 * pi * r;", "d4rtCode": "C = 2 * pi * r;",
"tags": ["geometry", "circle", "perimeter"] "tags": ["geometry", "circle", "perimeter"]
}, },
@ -27,12 +46,22 @@
// Area of Triangle // Area of Triangle
{ {
"name": "Area of Triangle", "name": "Area of Triangle",
"description": r'''\nArea enclosed by a triangle\n\n$$A = \frac{1}{2}bh$$\n\nWhere:\n- $A$: Area (square meters)\n- $b$: Base length (meters)\n- $h$: Height perpendicular to base (meters)\n\nThis formula works for any triangle.''', "description": r"""
Area enclosed by a triangle
$$A = \frac{1}{2}bh$$
Where:
- $A$: Area (square meters)
- $b$: Base length (meters)
- $h$: Height perpendicular to base (meters)
This formula works for any triangle.""",
"input": [ "input": [
{"name": "b", "unit": "meter"}, // Base {"name": "b", "unit": "meter"},
{"name": "h", "unit": "meter"} // Height {"name": "h", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": "A = 0.5 * b * h;", "d4rtCode": "A = 0.5 * b * h;",
"tags": ["geometry", "triangle", "area"] "tags": ["geometry", "triangle", "area"]
}, },
@ -40,12 +69,22 @@
// Area of Rectangle // Area of Rectangle
{ {
"name": "Area of Rectangle", "name": "Area of Rectangle",
"description": r'''\nArea enclosed by a rectangle\n\n$$A = lw$$\n\nWhere:\n- $A$: Area (square meters)\n- $l$: Length (meters)\n- $w$: Width (meters)\n\nThe area is the product of length and width.''', "description": r"""
Area enclosed by a rectangle
$$A = lw$$
Where:
- $A$: Area (square meters)
- $l$: Length (meters)
- $w$: Width (meters)
The area is the product of length and width.""",
"input": [ "input": [
{"name": "l", "unit": "meter"}, // Length {"name": "l", "unit": "meter"},
{"name": "w", "unit": "meter"} // Width {"name": "w", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": "A = l * w;", "d4rtCode": "A = l * w;",
"tags": ["geometry", "rectangle", "area"] "tags": ["geometry", "rectangle", "area"]
}, },
@ -53,13 +92,23 @@
// Area of Trapezoid // Area of Trapezoid
{ {
"name": "Area of Trapezoid", "name": "Area of Trapezoid",
"description": r'''\nArea enclosed by a trapezoid\n\n$$A = \frac{1}{2}(a+b)h$$\n\nWhere:\n- $A$: Area (square meters)\n- $a, b$: Lengths of parallel sides (meters)\n- $h$: Height (perpendicular distance between parallel sides, meters)\n\nThe area is the average of parallel sides times height.''', "description": r"""
Area enclosed by a trapezoid
$$A = \frac{1}{2}(a+b)h$$
Where:
- $A$: Area (square meters)
- $a, b$: Lengths of parallel sides (meters)
- $h$: Height (perpendicular distance between parallel sides, meters)
The area is the average of parallel sides times height.""",
"input": [ "input": [
{"name": "a", "unit": "meter"}, // Parallel side 1 {"name": "a", "unit": "meter"},
{"name": "b", "unit": "meter"}, // Parallel side 2 {"name": "b", "unit": "meter"},
{"name": "h", "unit": "meter"} // Height {"name": "h", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": "A = 0.5 * (a + b) * h;", "d4rtCode": "A = 0.5 * (a + b) * h;",
"tags": ["geometry", "trapezoid", "area"] "tags": ["geometry", "trapezoid", "area"]
}, },
@ -67,12 +116,23 @@
// Area of Regular Polygon // Area of Regular Polygon
{ {
"name": "Area of Regular Polygon", "name": "Area of Regular Polygon",
"description": r'''\nArea of a regular polygon with n sides\n\n$$A = \frac{1}{4}ns^2\cot(\frac{\pi}{n})$$\n\nWhere:\n- $A$: Area (square meters)\n- $n$: Number of sides\n- $s$: Side length (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThis formula works for any regular polygon (equal sides and angles).''', "description": r"""
Area of a regular polygon with n sides
$$A = \frac{1}{4}ns^2\cot(\frac{\pi}{n})$$
Where:
- $A$: Area (square meters)
- $n$: Number of sides
- $s$: Side length (meters)
- $\pi$: Pi ($\approx 3.14159$)
This formula works for any regular polygon (equal sides and angles).""",
"input": [ "input": [
{"name": "n", "unit": "scalar"}, // Number of sides {"name": "n", "unit": "scalar"},
{"name": "s", "unit": "meter"} // Side length {"name": "s", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": "A = 0.25 * n * pow(s, 2) * (cos(pi/n) / sin(pi/n));", "d4rtCode": "A = 0.25 * n * pow(s, 2) * (cos(pi/n) / sin(pi/n));",
"tags": ["geometry", "polygon", "area"] "tags": ["geometry", "polygon", "area"]
}, },
@ -80,11 +140,20 @@
// Sum of Interior Angles of Polygon // Sum of Interior Angles of Polygon
{ {
"name": "Sum of Interior Angles", "name": "Sum of Interior Angles",
"description": r'''\nSum of interior angles of a polygon\n\n$$S = (n - 2) \times 180°$$\n\nWhere:\n- $S$: Sum of interior angles (degrees)\n- $n$: Number of sides\n\nThis formula works for any simple polygon.''', "description": r"""
Sum of interior angles of a polygon
$$S = (n - 2) \times 180°$$
Where:
- $S$: Sum of interior angles (degrees)
- $n$: Number of sides
This formula works for any simple polygon.""",
"input": [ "input": [
{"name": "n", "unit": "scalar"} // Number of sides {"name": "n", "unit": "scalar"}
], ],
"output": {"name": "S", "unit": "degree"}, // Sum of angles "output": {"name": "S", "unit": "degree"},
"d4rtCode": "S = (n - 2) * 180;", "d4rtCode": "S = (n - 2) * 180;",
"tags": ["geometry", "polygon", "angles"] "tags": ["geometry", "polygon", "angles"]
}, },
@ -92,13 +161,25 @@
// Heron's Formula (Area of Triangle) // Heron's Formula (Area of Triangle)
{ {
"name": "Heron's Formula", "name": "Heron's Formula",
"description": r'''\nArea of a triangle using only side lengths\n\n$$A = \sqrt{s(s-a)(s-b)(s-c)}$$\n\nWhere:\n- $A$: Area (square meters)\n- $a, b, c$: Side lengths (meters)\n- $s$: Semi-perimeter $= \frac{a+b+c}{2}$\n\nThis formula is useful when height is unknown.\n\n**Note:** The side lengths must satisfy the triangle inequality: the sum of any two sides must be greater than the third side (a+b>c, a+c>b, b+c>a). If this condition is not met, the formula returns NaN.''', "description": r"""
Area of a triangle using only side lengths
$$A = \sqrt{s(s-a)(s-b)(s-c)}$$
Where:
- $A$: Area (square meters)
- $a, b, c$: Side lengths (meters)
- $s$: Semi-perimeter $= \frac{a+b+c}{2}$
This formula is useful when height is unknown.
**Note:** The side lengths must satisfy the triangle inequality: the sum of any two sides must be greater than the third side (a+b>c, a+c>b, b+c>a). If this condition is not met, the formula returns NaN.""",
"input": [ "input": [
{"name": "a", "unit": "meter"}, // Side 1 {"name": "a", "unit": "meter"},
{"name": "b", "unit": "meter"}, // Side 2 {"name": "b", "unit": "meter"},
{"name": "c", "unit": "meter"} // Side 3 {"name": "c", "unit": "meter"}
], ],
"output": {"name": "A", "unit": "square meter"}, // Area "output": {"name": "A", "unit": "square meter"},
"d4rtCode": """ "d4rtCode": """
if( a + b < c || a+c < b || b+c < a ){ if( a + b < c || a+c < b || b+c < a ){
signal( "There is not a valid triangle with those longitudes" ); signal( "There is not a valid triangle with those longitudes" );

View file

@ -1,6 +1,9 @@
[ [
{"name":"Hooke's Law","description":r""" // Hooke's Law
Force exerted by a spring is proportional to its displacement (linear region). {
"name": "Hooke's Law",
"description": r"""
Force exerted by a spring is proportional to its displacement.
$$F = -kx$$ $$F = -kx$$
@ -9,8 +12,13 @@ Where:
- $k$: Spring constant (N/m) - $k$: Spring constant (N/m)
- $x$: Displacement from equilibrium (meters) - $x$: Displacement from equilibrium (meters)
The negative sign indicates the force opposes displacement. The negative sign indicates the force opposes the displacement.""",
"input": [
![Hooke's law (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/HookesLaw.svg/800px-HookesLaw.svg.png) {"name": "k", "unit": "newton per meter"},
""","input":[{"name":"k","unit":"newton per meter"},{"name":"x","unit":"meter"}],"output":{"name":"F","unit":"newton"},"d4rtCode":"F = -k * x;","tags":["physics","elasticity","oscillations"]} {"name": "x", "unit": "meter"}
],
"output": {"name": "F", "unit": "newton"},
"d4rtCode": "F = -k * x;",
"tags": ["physics", "elasticity", "oscillations"]
}
] ]

View file

@ -1,5 +1,8 @@
[ [
{"name":"Apgar Score","description":r""" // Apgar Score
{
"name": "Apgar Score",
"description": r"""
Newborn health assessment scoring system performed at 1 and 5 minutes after birth. Newborn health assessment scoring system performed at 1 and 5 minutes after birth.
The Apgar score sums five categories (02 points each): The Apgar score sums five categories (02 points each):
@ -11,6 +14,29 @@ The Apgar score sums five categories (02 points each):
Total score ranges from 0 to 10. Higher scores indicate better newborn condition. Total score ranges from 0 to 10. Higher scores indicate better newborn condition.
![Apgar score (illustration) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Apgar_scale.svg/800px-Apgar_scale.svg.png) ![Apgar score (illustration) (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Apgar_scale.svg/800px-Apgar_scale.svg.png)""",
""","input":[{"name":"HeartRate","values":["Absent","< 100 bpm>","> 100 bpm"]},{"name":"Breathing","values":["Absent","Weak, irregular","Strong, robust cry"]},{"name":"MuscleTone","values":["None","Some","Flexed arms/leg, resists extension"]},{"name":"Reflexes","values":["No response","Grimace on aggressive stimulation","Cry on stimulation"]},{"name":"SkinColor","values":["Blue or pale","Blue extremities, pink body","Pink"]}],"output":{"name":"Result","unit":"string"},"d4rtCode":"var total = indexOf(\"HeartRate\") + indexOf(\"Breathing\") + indexOf(\"MuscleTone\") + indexOf(\"Reflexes\") + indexOf(\"SkinColor\"); late var interpretation; if( total < 4 ) { interpretation = 'Critical condition'; } else if( total < 7 ){ interpretation = 'Needs assistance'; } else { interpretation = 'Normal'; } Result = 'Score: \$total - \$interpretation';","tags":["medical","pediatrics","assessment"]} "input": [
{"name": "HeartRate", "values": ["Absent", "< 100 bpm>", "> 100 bpm"]},
{"name": "Breathing", "values": ["Absent", "Weak, irregular", "Strong, robust cry"]},
{"name": "MuscleTone", "values": ["None", "Some", "Flexed arms/leg, resists extension"]},
{"name": "Reflexes", "values": ["No response", "Grimace on aggressive stimulation", "Cry on stimulation"]},
{"name": "SkinColor", "values": ["Blue or pale", "Blue extremities, pink body", "Pink"]}
],
"output": {"name": "Result", "unit": "string"},
"d4rtCode": """
var total = indexOf("HeartRate") + indexOf("Breathing") + indexOf("MuscleTone") + indexOf("Reflexes") + indexOf("SkinColor");
late var interpretation;
if( total < 4 ) {
interpretation = 'Critical condition';
}
else if( total < 7 ){
interpretation = 'Needs assistance';
}
else {
interpretation = 'Normal';
}
Result = 'Score: \$total - \$interpretation';
""",
"tags": ["medical", "pediatrics", "assessment"]
}
] ]

View file

@ -1,3 +1,26 @@
[ [
{"name":"Compare price per mass","description":"Compares two products by their price per mass and returns which is cheaper, including price per kg for each product.","input":[{"name":"price1","unit":"currency"},{"name":"mass1","unit":"kilogram"},{"name":"price2","unit":"currency"},{"name":"mass2","unit":"kilogram"}],"output":{"name":"Result","unit":"string"},"d4rtCode":"var p1 = price1 / mass1; var p2 = price2 / mass2; if (p1 < p2) { Result = 'first product is cheaper at \$\{p1.toStringAsFixed(2)\} currency/kg vs \$\{p2.toStringAsFixed(2)\} currency/kg'; } else if (p2 < p1) { Result = 'second product is cheaper at \$\{p2.toStringAsFixed(2)\} currency/kg vs \$\{p1.toStringAsFixed(2)\} currency/kg'; } else { Result = 'both products have the same price per mass at \$\{p1.toStringAsFixed(2)\} currency/kg'; }","tags":["comparison","shopping","economics"]} // Compare Price per Mass
{
"name": "Compare price per mass",
"description": "Compares two products by their price per mass and returns which is cheaper, including price per kg for each product.",
"input": [
{"name": "price1", "unit": "currency"},
{"name": "mass1", "unit": "kilogram"},
{"name": "price2", "unit": "currency"},
{"name": "mass2", "unit": "kilogram"}
],
"output": {"name": "Result", "unit": "string"},
"d4rtCode": """
var p1 = price1 / mass1;
var p2 = price2 / mass2;
if (p1 < p2) {
Result = 'first product is cheaper at \${p1.toStringAsFixed(2)} currency/kg vs \${p2.toStringAsFixed(2)} currency/kg';
} else if (p2 < p1) {
Result = 'second product is cheaper at \${p2.toStringAsFixed(2)} currency/kg vs \${p1.toStringAsFixed(2)} currency/kg';
} else {
Result = 'both products have the same price per mass at \${p1.toStringAsFixed(2)} currency/kg';
}
""",
"tags": ["comparison", "shopping", "economics"]
}
] ]

View file

@ -1,16 +1,29 @@
[ [
{"name":"Snell's Law","description":r""" // Snell's Law
Law describing refraction of light at an interface between two media. {
"name": "Snell's Law",
"description": r"""
Law describing refraction of light at interface between media.
$$n_1\sin(\theta_1) = n_2\sin(\theta_2)$$ $$n_1\sin(\theta_1) = n_2\sin(\theta_2)$$
Where: Where:
- $n_1, n_2$: Refractive indices - $n_1, n_2$: Refractive indices of the two media
- $\theta_1$: Angle of incidence - $\theta_1$: Angle of incidence
- $\theta_2$: Angle of refraction - $\theta_2$: Angle of refraction
This law explains how light bends when passing between materials. This law explains how light bends when passing between materials.""",
"input": [
![Refraction diagram (Wikipedia)](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Refraction_en.svg/800px-Refraction_en.svg.png) {"name": "n1", "unit": "scalar"},
""","input":[{"name":"n1","unit":"scalar"},{"name":"n2","unit":"scalar"},{"name":"theta1","unit":"degree"}],"output":{"name":"theta2","unit":"degree"},"d4rtCode":"var theta1Rad = theta1 * (pi / 180); var sinTheta2 = (n1 * sin(theta1Rad)) / n2; theta2 = asin(sinTheta2) * (180 / pi);","tags":["physics","optics","light"]} {"name": "n2", "unit": "scalar"},
{"name": "theta1", "unit": "degree"}
],
"output": {"name": "theta2", "unit": "degree"},
"d4rtCode": """
var theta1Rad = theta1 * (pi / 180);
var sinTheta2 = (n1 * sin(theta1Rad)) / n2;
theta2 = asin(sinTheta2) * (180 / pi);
""",
"tags": ["physics", "optics", "light"]
}
] ]

View file

@ -1,5 +1,8 @@
[ [
{"name":"Ideal Gas Law","description":r""" // Ideal Gas Law
{
"name": "Ideal Gas Law",
"description": r"""
Equation of state for an ideal gas. Equation of state for an ideal gas.
$$PV = nRT$$ $$PV = nRT$$
@ -13,6 +16,14 @@ Where:
This law combines Boyle's, Charles's and Avogadro's laws. This law combines Boyle's, Charles's and Avogadro's laws.
![Ideal Gas](https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Ideal_gas_sphere.svg/800px-Ideal_gas_sphere.svg.png) ![Ideal Gas](https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Ideal_gas_sphere.svg/800px-Ideal_gas_sphere.svg.png)""",
""","input":[{"name":"n","unit":"mole"},{"name":"T","unit":"kelvin"},{"name":"V","unit":"cubic meter"}],"output":{"name":"P","unit":"pascal"},"d4rtCode":"P = (n * 8.314462618 * T) / V;","tags":["physics","thermodynamics","gas"]} "input": [
{"name": "n", "unit": "mole"},
{"name": "T", "unit": "kelvin"},
{"name": "V", "unit": "cubic meter"}
],
"output": {"name": "P", "unit": "pascal"},
"d4rtCode": "P = (n * 8.314462618 * T) / V;",
"tags": ["physics", "thermodynamics", "gas"]
}
] ]

View file

@ -52,10 +52,16 @@ Future<Corpus> createDefaultCorpus() async{
Future<void> loadFormulas() async { Future<void> loadFormulas() async {
final formulaResources = [ final formulaResources = [
"assets/formulas/formulas.d4rt", "assets/formulas/formulas.d4rt",
"assets/formulas/geometry.d4rt",
"assets/formulas/energy_and_power.d4rt",
"assets/formulas/electromagnetism.d4rt", "assets/formulas/electromagnetism.d4rt",
"assets/formulas/thermodynamics.d4rt", "assets/formulas/thermodynamics.d4rt",
"assets/formulas/fluids_and_pressure.d4rt", "assets/formulas/fluids_and_pressure.d4rt",
"assets/formulas/optics.d4rt",
"assets/formulas/materials_elasticity.d4rt",
"assets/formulas/medical_and_bio.d4rt",
"assets/formulas/conversions_and_constants.d4rt",
"assets/formulas/misc_math.d4rt",
]; ];
for (final formRes in formulaResources) { for (final formRes in formulaResources) {

View file

@ -468,26 +468,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker name: leak_tracker
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "11.0.2" version: "10.0.9"
leak_tracker_flutter_testing: leak_tracker_flutter_testing:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker_flutter_testing name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.10" version: "3.0.9"
leak_tracker_testing: leak_tracker_testing:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker_testing name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.2" version: "3.0.1"
linked_scroll_controller: linked_scroll_controller:
dependency: transitive dependency: transitive
description: description:
@ -540,10 +540,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.17.0" version: "1.16.0"
mime: mime:
dependency: transitive dependency: transitive
description: description:
@ -881,26 +881,26 @@ packages:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: test name: test
sha256: "75906bf273541b676716d1ca7627a17e4c4070a3a16272b7a3dc7da3b9f3f6b7" sha256: "301b213cd241ca982e9ba50266bd3f5bd1ea33f1455554c5abb85d1be0e2d87e"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.26.3" version: "1.25.15"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.7" version: "0.7.4"
test_core: test_core:
dependency: transitive dependency: transitive
description: description:
name: test_core name: test_core
sha256: "0cc24b5ff94b38d2ae73e1eb43cc302b77964fbf67abad1e296025b78deb53d0" sha256: "84d17c3486c8dfdbe5e12a50c8ae176d15e2a771b96909a9442b40173649ccaa"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.12" version: "0.6.8"
timing: timing:
dependency: transitive dependency: transitive
description: description:
@ -1025,10 +1025,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.2.0" version: "2.1.4"
vm_service: vm_service:
dependency: transitive dependency: transitive
description: description: