d4t_formulas/assets/formulas/formulas.d4rt
2026-02-07 16:16:00 +01:00

391 lines
12 KiB
Text

[
{
"name": "Temperature converter",
"description": "Example of simple formula, just unit conversion",
"input": [
{"name": "Input", "unit": "Kelvin" }
],
"output": {"name": "Output", "unit": "Kelvin" },
"d4rtCode": "Output = Input;",
"tags": ["converter", "temperature" ]
},
// Free fall distance (vertical)
{
"name": "Free Fall Distance",
"description": r"""
Calculates vertical displacement under constant gravity
$$h = \frac{1}{2}gt^2$$
Where:
- $g$: Gravitational acceleration $9.81\ \mathrm{m/s^2}$ on Earth
- $t$: Time in free fall (seconds)
![Free Fall Diagram](https://altcalculator.com/wp-content/uploads/2023/08/Free-Fall.png)""",
"input": [
{"name": "t", "unit": "second"}, // Time in seconds
{"name": "g", "unit": "meters per second"} // Gravitational acceleration
],
"output": {"name": "h", "unit": "meter"}, // Height in meters
"d4rtCode": "h = 0.5 * g * pow(t, 2);",
"tags": ["physics", "kinematics"]
},
// Newton's Law of Universal Gravitation
{
"name": "Gravitational Force",
"description": r'''
Newton's law of universal gravitation
\(F = G\frac{m_1m_2}{r^2}\)
Where:
- $G$: Gravitational constant ($6.674\times 10^{-11}\ \mathrm{N\cdot m^2/kg^2}$)
- $m_1, m_2$: Masses of two objects
- $r$: Distance between centers of masses
![Gravitation](https://upload.wikimedia.org/wikipedia/commons/thumb/3/33/NewtonsLawOfUniversalGravitation.svg/1200px-NewtonsLawOfUniversalGravitation.svg.png)''',
"input": [
{"name": "m1", "unit": "kilogram"}, // Mass 1
{"name": "m2", "unit": "kilogram"}, // Mass 2
{"name": "r", "unit": "meter"} // Distance between masses
],
"output": {"name": "F", "unit": "newton"}, // Force in newtons
"d4rtCode": "F = (6.67430e-11 * m1 * m2) / pow(r, 2);",
"tags": ["physics", "astronomy", "gravity"]
},
// Kinetic Energy
{
"name": "Kinetic Energy",
"description": r'''
Energy possessed by a moving object
$$KE = \frac{1}{2}mv^2$$
Where:
- $m$: Mass of object
- $v$: Velocity of object
![Kinetic Energy](https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Kinetic_energy.svg/1200px-Kinetic_energy.svg.png)''',
"input": [
{"name": "m", "unit": "kilogram"}, // Mass
{"name": "v", "unit": "meters per second"} // Velocity
],
"output": {"name": "KE", "unit": "joule"}, // Energy in joules
"d4rtCode": "KE = 0.5 * m * pow(v, 2);",
"tags": ["physics", "energy", "mechanics"]
},
// Projectile Motion Range
{
"name": "Projectile Range",
"description": r"""Calculates horizontal distance of projectile motion
$$R = \frac{v^2 \sin(2\theta)}{g}$$
Where:
- $v$: Initial velocity
- $\theta$: Launch angle
- $g$: Gravitational acceleration
![Projectile Motion](https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Projectile_motion_diagram.png/800px-Projectile_motion_diagram.png)""",
"input": [
{"name": "v", "unit": "meters per second"}, // Initial velocity
{"name": "a", "unit": "degree"} // Launch angle
],
"output": {"name": "R", "unit": "meter"}, // Horizontal distance
"d4rtCode": """
var radians = a * (pi / 180);
R = (pow(v, 2) * sin(2 * radians)) / 9.80665;
""",
"tags": ["physics", "kinematics", "projectile"]
},
{
"name": "Newton's Second Law",
"description": r'''
Force equals mass times acceleration
$$F = m \cdot a$$
Where:
- $m$: Mass of object ($\mathrm{kg}$)
- $a$: Acceleration ($\mathrm{m/s^2}$)
![Newton's Second Law](https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Newtonslawsofmotion.jpg/800px-Newtonslawsofmotion.jpg)''',
"input": [
{"name": "m", "unit": "kilogram"}, // Mass
{"name": "a", "unit": "meters per square second"} // Acceleration
],
"output": {"name": "F", "unit": "newton"}, // Force in newtons
"d4rtCode": "F = m * a;",
"tags": ["physics", "mechanics", "newton"]
},
// Apgar Score
{
"name": "Apgar Score",
"description": "Newborn health assessment scoring system\n\nScores 0-2 for:\n1. Heart rate\n2. Breathing\n3. Muscle tone\n4. Reflexes\n5. Skin color\nTotal score 0-10",
"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"]
}
,
{
"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"]
}
,
// Einstein's Mass-Energy Equivalence
{
"name": "Mass-Energy Equivalence",
"description": r'''
Einstein's famous equation showing the relationship between mass and energy
$$E = mc^2$$
Where:
- $E$: Energy (Joules)
- $m$: Mass (kilograms)
- $c$: Speed of light $299,792,458$ $\mathrm{m/s}$
This equation shows that mass can be converted to energy and vice versa.''',
"input": [
{"name": "m", "unit": "kilogram"} // Mass
],
"output": {"name": "E", "unit": "joule"}, // Energy
"d4rtCode": "E = m * pow(299792458, 2);",
"tags": ["physics", "relativity", "energy"]
},
// Ohm's Law
{
"name": "Ohm's Law",
"description": r'''
Relationship between voltage, current, and resistance in electrical circuits
$$V = IR$$
Where:
- $V$: Voltage (Volts)
- $I$: Current (Amperes)
- $R$: Resistance (Ohms)
This fundamental law describes how current flows through resistive materials.''',
"input": [
{"name": "I", "unit": "ampere"}, // Current
{"name": "R", "unit": "ohm"} // Resistance
],
"output": {"name": "V", "unit": "volt"}, // Voltage
"d4rtCode": "V = I * R;",
"tags": ["physics", "electricity", "electronics"]
},
// Hooke's Law
{
"name": "Hooke's Law",
"description": r'''
Force exerted by a spring is proportional to its displacement
$$F = -kx$$
Where:
- $F$: Restoring force (Newtons)
- $k$: Spring constant (N/m)
- $x$: Displacement from equilibrium (meters)
The negative sign indicates the force opposes the displacement.''',
"input": [
{"name": "k", "unit": "newton per meter"}, // Spring constant
{"name": "x", "unit": "meter"} // Displacement
],
"output": {"name": "F", "unit": "newton"}, // Force
"d4rtCode": "F = -k * x;",
"tags": ["physics", "elasticity", "oscillations"]
},
// Centripetal Force
{
"name": "Centripetal Force",
"description": r'''
Force required to keep an object moving in circular motion
$$F = \frac{mv^2}{r}$$
Where:
- $F$: Centripetal force (Newtons)
- $m$: Mass of object (kilograms)
- $v$: Velocity (m/s)
- $r$: Radius of circular path (meters)
This force acts toward the center of the circle.''',
"input": [
{"name": "m", "unit": "kilogram"}, // Mass
{"name": "v", "unit": "meters per second"}, // Velocity
{"name": "r", "unit": "meter"} // Radius
],
"output": {"name": "F", "unit": "newton"}, // Force
"d4rtCode": "F = (m * pow(v, 2)) / r;",
"tags": ["physics", "circular motion", "centripetal"]
},
// Wave Equation
{
"name": "Wave Equation",
"description": r'''
Relationship between wave speed, frequency, and wavelength
$$v = f\lambda$$
Where:
- $v$: Wave speed (m/s)
- $f$: Frequency (Hertz)
- $\lambda$: Wavelength (meters)
This applies to all types of waves including sound and light.''',
"input": [
{"name": "f", "unit": "hertz"}, // Frequency
{"name": "lambda", "unit": "meter"} // Wavelength
],
"output": {"name": "v", "unit": "meters per second"}, // Wave speed
"d4rtCode": "v = f * lambda;",
"tags": ["physics", "waves", "frequency"]
},
// Pythagorean Theorem
{
"name": "Pythagorean Theorem",
"description": r'''
Fundamental relation in Euclidean geometry among the three sides of a right triangle
$$a^2 + b^2 = c^2$$
Where:
- $a$, $b$: Legs of the right triangle
- $c$: Hypotenuse of the right triangle
The square of the hypotenuse is equal to the sum of squares of the other two sides.''',
"input": [
{"name": "a", "unit": "meter"}, // First leg
{"name": "b", "unit": "meter"} // Second leg
],
"output": {"name": "c", "unit": "meter"}, // Hypotenuse
"d4rtCode": "c = sqrt(pow(a, 2) + pow(b, 2));",
"tags": ["trigonometry", "geometry", "pythagorean"]
},
// Sine Rule
{
"name": "Sine Rule",
"description": r'''
Relationship between the sides and angles of any triangle
$$\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}$$
Where:
- $a$, $b$, $c$: Sides of the triangle
- $A$, $B$, $C$: Angles opposite to sides $a$, $b$, $c$ respectively
This rule is useful for solving triangles when certain combinations of angles and sides are known.''',
"input": [
{"name": "a", "unit": "meter"}, // Side a
{"name": "A", "unit": "degree"}, // Angle A in degrees
{"name": "B", "unit": "degree"} // Angle B in degrees
],
"output": {"name": "b", "unit": "meter"}, // Side b
"d4rtCode": """
var angleARad = A * (pi / 180);
var angleBRad = B * (pi / 180);
b = (a * sin(angleBRad)) / sin(angleARad);
""",
"tags": ["trigonometry", "triangle", "sine"]
},
// Cosine Rule
{
"name": "Cosine Rule",
"description": r'''
Generalization of the Pythagorean theorem for any triangle
$$c^2 = a^2 + b^2 - 2ab\cos(C)$$
Where:
- $a$, $b$, $c$: Sides of the triangle
- $C$: Angle opposite to side $c$
This rule relates all three sides of a triangle to one of its angles.''',
"input": [
{"name": "a", "unit": "meter"}, // Side a
{"name": "b", "unit": "meter"}, // Side b
{"name": "C", "unit": "degree"} // Angle C in degrees
],
"output": {"name": "c", "unit": "meter"}, // Side c
"d4rtCode": """
var angleCRad = C * (pi / 180);
c = sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(angleCRad));
""",
"tags": ["trigonometry", "triangle", "cosine"]
},
// Trigonometric Identity
{
"name": "Trigonometric Identity",
"description": r'''
Fundamental Pythagorean identity in trigonometry
$$\sin^2(\theta) + \cos^2(\theta) = 1$$
Where:
- $\theta$: Any angle in radians or degrees
This identity is derived from the Pythagorean theorem applied to the unit circle.''',
"input": [
{"name": "theta", "unit": "degree"} // Angle in degrees
],
"output": {"name": "result", "unit": "scalar"}, // Result (should be 1)
"d4rtCode": """
var thetaRad = theta * (pi / 180);
result = pow(sin(thetaRad), 2) + pow(cos(thetaRad), 2);
""",
"tags": ["trigonometry", "identity", "sine", "cosine"]
}
]