text:
Talk:Euphoria (programming language)

I'm sure this is a worthy subject, but claims like "easier to learn than BASIC" and "fastest interpreted language" are just advertising mumbo-jumbo. Sure, you want to have who designed it and what their goals were, but if I'm looking at an enecylopedia article about a programming language, I want to know who uses it and for what, what it looks like (maybe some sample code?), what actual features it has in plain English, and a link to their website if any.

Actually not just ad mumbo-jumbo, I believe those were specific design goals of the language...I'm having a bit of difficulty wording them objectively though. There are benchmarks and such, but I didn't want to get into technicalities. There's a link to the website at the bottom. If you want sample code, I can accomodate. :) Is it a bit better now?

Euphoria IS an excellent language that is relatively easy to learn, very flexable and seriously powerful. You can combine it's strongly type-checked high level features with any amount of embedded 32-bit machine code and API/Dll calls to make genuine applications in a fraction of the time required to write them in any other language that I am familiar with. The very simple data types that it was designed around can be polymorphed into any object or structure available elsewhere with ease, and the finished product will usually execute faster than anything short of pure ASM or very well written C. The main problem that Euphoria has always had is public relations one. The official website still bears the catch-cry of "Just say no to complicated programming languages". This is a philosophy that I applaude, but an advertizing blunder of biblical proportions that has relegated what is undoubtedly one of the best languages ever devised to the realms of the closet hobbiest. As a result it has barely been used for anything apart from pet hobby projects, and its own internal development. This is a real shame as virtually any commercial application on the market could have been developed in Euphoria in a fracton of the time and therefore a fraction of the cost of doing it in C++, delphi, python, PHP or whatever. It is also extremely reliable and unless you go messing around embedded or external ML will always trap it's own errors and clean up it's own mess. All this being said, until we can give it a face lift, Euphoria is mainly used by 2nd rate backyard programmers to write custom apps that keep track of the humidity in their dog's kennel.

Looks better to me anyway. We can also soon put this under euphoria (programming language) or perhaps euphoria (prog. language), because CliffordAdams has just come out with the latest version of UseMod. --LMS

However
This is actually a language goal. I also can guarantee you that it's easier to learn than basic.

I have used and participated in the development of this language (and external freeware libraries) for 10 years now, in this time I have never heard anyone say BASIC was easier to learn.

It may also be said that the language construct is simple, yes. But it's impossible to say write a core windows program without using pointers, so yes you use them all the time, and no, the language does not protect you from this. It's an impossibility.

That's a problem with the windows API really, because when I make a windows program in Euphoria, it's subject to exactly the same memory faults and errors as if I had made it in C, it just happens to be about 10 times faster to actually code.

"Not using pointers" etc is not actually a language construct is what I mean, intrinsically it doesn't matter if the language supports pointers or not, the reality is you use them regardless of the support. And just because the language doesn't support them, doesn't mean you get pointer errors because you allocated the memory with the Windows GlobalAlloc command.

A pointer is really more NOT a language reference. It's just (usually) a 32-bit integer which points to a memory offset. Any language is capable of using this really, and no language can ever protect you from undesired results. HoCkster

I have to agree that Euphoria is easier to learn than BASIC, provided you intend to learn the entire language in each case (not just a subset).

More importantly, Euphoria has fewer built-in limitations (which you also have to learn about, but which are seldom documented :)

As far as speed is concerned, it's easy to prove for yourself that Euphoria is faster than most other interpreted languages in most instances. Of course it's often possible to craft a test which will show that any language X is the fastest for some task, if you choose that task carefully.

But what matters to me is that Euphoria is fast enough to use commercially, and no one asks me if I can "speed up" their applications. If I had to write everything in C (or C++, Delphi, COBOL, Fortran...) I would get 1/3 as much work done, and therefore be making 1/3 as much per hour.

Everyone says everything is easier to learn than BASIC, and then I look at the first line of a sample program and run. I have used FirstBasic and find it fast enough for anything I will ever do but unless the ad is BS the same company has beefed up their PowerBasic Console model to almost the best C compiler speeds. This looks interesting but so doesn't Forth - but as above, the first line of code seems almost mystical ( requires a baseline of knowledge I suppose that makes any language seem easy to the possessor of said knowledge ). BASIC is for us linear thinking dopes ( non ++ anything people ).

EUPHORIA's "Hello, World!"
puts(1, "Hello, World!\n")

memory
sure if you're doing a single function program then you will not need to explicitly allocate or deallocate memory. to develop and full application in linux gui's or windows, you have to allocate memory period and be subject to the pitfalls of doing this. who said in euphoria you don't need to allocate or free memory? it supports this explicitly, and thus allows you to use linux .so and windows .dll files and hence have access to the relative api. by saying that euphoria does not need to allocate memory could be interpreted as in a way saying it is less powerful than C, which is a dubious speculation. euphoria supports direct memory allocation in a far more sophisticated manner than c.

If you are interfacing with a decent library then the library will be doing most of the allocating for you, otherwise in Euphoria it will do it for you automatically if you are just dealing with loading bitmaps, reading files and manipulating memory etc. This needs no memory allocation. Where you have to allocate memory is for the smaller things like passing a "string" to a C function. You have to convert it first to a Unicode, Ascii and most often null terminate it to make it "C compatable".

Its not entirely possible in a GUI environment to make a program which does not explicitly allocate memory, maybe your library does all of it for you however, and the code *you* write involves no memory allocation at all.

I've made some Euphoria programs in windows in which the memory allocation amounted to nothing other than the (48 byte) WndClassEx structure, and convering text via SetWindowText to control functions, calling the function then immediately freeing the memory block allocated - on a sliding scale the amount you *have* to allocate is really not what you'd call problematic, or likely to lead to any major pitfalls.

The way *most* people use euphoria, developing programs/utilities etc with an overhead library involve no direct memory manipulation at all, which is why the claim euphoria does not need to allocate memory is so often stated. The Reality is Euphoria only ever *has* to allocate memory when it calls a compiled function in another language, which in turns requires memory to manipulate whatever data it is you are passing to it, as it is presumed you both have read/write access to this same memory block. Which is the simplest way to overcome the many different ways many different languages use memory.

Euphoria can manipulate memory just like C can, just if you don't call C libraries I'd say its a *lot* quicker just to do it in native Euphoria. HoCkster

Note on integer size
Euphoria uses 31-bit values for integers NOT 32 and this fact is stated repeatedly throughout the official documentation. The 32nd bit designates it as an integer instead of an atom. This is NOT a typo so don't correct this. - DNewhall

Euphoria can, of course, handle 32+bit integers in its atom data type.

- 32+bit isn't entirely accurate. Euphoria can only support 31bit integers, and 64-bit double precision floats. The mantissa is 52-bits. OpenEuphoria probably inherits this limitation. — Preceding unsigned comment added by 108.90.2.142 (talk) 05:44, 4 November 2011 (UTC)

There seems to be some confusion over terminology. Euphoria can store (arithmetical) integers from -9,007,199,254,740,992 to +9,007,199,254,740,992 without loss of precision. When a value is in the range -1,073,741,824 to +1,073,741,823 it is stored in the Euphoria data type known as an integer otherwise they are stored in the data type known as an atom. The integer data type is a more efficient entity and ought to be used for (arithmetical) integers in the subset range mentioned above. When using integers outside that range, such as 32-bit addresses, the atom data type must be used. Furthermore, the 64-bit version of OpenEuphoria is being readied for release, which will significantly extend the range of integers able to be used. DerekP (talk) 00:07, 5 November 2011 (UTC)

Integer Size: further clarification
Integers are 30 bits in a signed or unsigned direction. Hence integers overload at 2^30 plus or minus, and atoms at 2^40 something plus or minus. Hence the above post is correct that an integer is really 31 bits, but it is forced as a signed variable (you don't get to choose). You can't declare an integer (be it 31 bits) as signed or unsigned so the 31 remaining bits fall into the category as a signed variable. One bit designates the sign, and the remaining 30 bits the actual value of the integer. HoCkster

Integers Overload, Atoms Approximate
As a further note, Integers Overload, Atoms Approximate. Integers handle exact integer values NOT up until 32 btis, it's been well documented not to use integers for 32 bit numbers (use atoms).... they start to approximate at 2^48 onwards.

What's the big deal?
Am I missing something here? The article seems to be written by someone who is unaware that programming language development continued after the creation of C. There's a lot of bragging that Euphoria doesn't require pointer or array management and doesn't have static typing, and that's great, but that applies to a wide variety of languages used today.

I see that despite using the term "object" rather liberally, there seem to be no OO facilities at all. I also can't find anything on built-in hash/dictionary support, besides using an enum to index an array. Comparing a scripting language to C is all well and good, but what makes Euphoria better than, say, Python or another dynamic language? —Preceding unsigned comment added by 96.240.116.103 (talk) 16:15, 18 May 2009 (UTC)

euphoria syntax highlighting lost
Since the switch from Geshi to Pygments for syntax highlighting (T85794), support for 'euphoria' was unfortunately dropped, which was used only once on this page. The highlighting on this page is manually added. If you want specialised 'euphoria' syntax highlight support again, it will need to be added to Pygments. Alternatively, if there is another language which has similar syntax, we can add that as a fallback. John Vandenberg (chat) 21:11, 18 July 2015 (UTC)

External links modified
Hello fellow Wikipedians,

I have just modified 4 external links on Euphoria (programming language). Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
 * Added archive https://web.archive.org/web/20110716180721/http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=9&fromYear=7&toMonth=9&toYear=7&keywords=atari to http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=9&fromYear=7&toMonth=9&toYear=7&keywords=atari
 * Added archive https://web.archive.org/web/20110716180705/http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=A&fromYear=B&toMonth=A&toYear=B&keywords=oct+18+1%3A19 to http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=A&fromYear=B&toMonth=A&toYear=B&keywords=oct+18+1%3A19
 * Added archive https://web.archive.org/web/20110716180757/http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=3&fromYear=3&toMonth=3&toYear=3&keywords=13%3A04 to http://www.rapideuphoria.com/cgi-bin/esearch.exu?fromMonth=3&fromYear=3&toMonth=3&toYear=3&keywords=13%3A04
 * Added archive https://web.archive.org/web/20080509094445/http://www.usingeuphoria.com/ to http://www.usingeuphoria.com/

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

Cheers.— InternetArchiveBot  (Report bug) 17:46, 24 September 2017 (UTC)

title: Talk:Euphoria (programming language)


text:
Energy

In physics, energy is the quantitative property that is transferred to a body or to a physical system, recognizable in the performance of work and in the form of heat and light. Energy is a conserved quantity—the law of conservation of energy states that energy can be converted in form, but not created or destroyed; matter and energy may also be converted to one another. The unit of measurement for energy in the International System of Units (SI) is the joule (J).

Common forms of energy include the kinetic energy of a moving object, the potential energy stored by an object (for instance due to its position in a field), the elastic energy stored in a solid object, chemical energy associated with chemical reactions, the radiant energy carried by electromagnetic radiation, and the internal energy contained within a thermodynamic system. All living organisms constantly take in and release energy.

Due to mass–energy equivalence, any object that has mass when stationary (called rest mass) also has an equivalent amount of energy whose form is called rest energy, and any additional energy (of any form) acquired by the object above that rest energy will increase the object's total mass just as it increases its total energy.

Human civilization requires energy to function, which it gets from energy resources such as fossil fuels, nuclear fuel, or renewable energy. The Earth's climate and ecosystems processes are driven by the energy the planet receives from the Sun (although a small amount is also contributed by geothermal energy).

Forms

The total energy of a system can be subdivided and classified into potential energy, kinetic energy, or combinations of the two in various ways. Kinetic energy is determined by the movement of an object – or the composite motion of the object's components – while potential energy reflects the potential of an object to have motion, generally being based upon the object's position within a field or what is stored within the field itself.

While these two categories are sufficient to describe all forms of energy, it is often convenient to refer to particular combinations of potential and kinetic energy as its own form. For example, the sum of translational and rotational kinetic and potential energy within a system is referred to as mechanical energy, whereas nuclear energy refers to the combined potentials within an atomic nucleus from either the nuclear force or the weak force, among other examples.

History
The word energy derives from the ἐνέργεια, which possibly appears for the first time in the work of Aristotle in the 4th century BC. In contrast to the modern definition, energeia was a qualitative philosophical concept, broad enough to include ideas such as happiness and pleasure.

In the late 17th century, Gottfried Leibniz proposed the idea of the, or living force, which defined as the product of the mass of an object and its velocity squared; he believed that total vis viva was conserved. To account for slowing due to friction, Leibniz theorized that thermal energy consisted of the motions of the constituent parts of matter, although it would be more than a century until this was generally accepted. The modern analog of this property, kinetic energy, differs from vis viva only by a factor of two. Writing in the early 18th century, Émilie du Châtelet proposed the concept of conservation of energy in the marginalia of her French language translation of Newton's Principia Mathematica, which represented the first formulation of a conserved measurable quantity that was distinct from momentum, and which would later be called "energy".

In 1807, Thomas Young was possibly the first to use the term "energy" instead of vis viva, in its modern sense. Gustave-Gaspard Coriolis described "kinetic energy" in 1829 in its modern sense, and in 1853, William Rankine coined the term "potential energy". The law of conservation of energy was also first postulated in the early 19th century, and applies to any isolated system. It was argued for some years whether heat was a physical substance, dubbed the caloric, or merely a physical quantity, such as momentum. In 1845 James Prescott Joule discovered the link between mechanical work and the generation of heat.

These developments led to the theory of conservation of energy, formalized largely by William Thomson (Lord Kelvin) as the field of thermodynamics. Thermodynamics aided the rapid development of explanations of chemical processes by Rudolf Clausius, Josiah Willard Gibbs, and Walther Nernst. It also led to a mathematical formulation of the concept of entropy by Clausius and to the introduction of laws of radiant energy by Jožef Stefan. According to Noether's theorem, the conservation of energy is a consequence of the fact that the laws of physics do not change over time. Thus, since 1918, theorists have understood that the law of conservation of energy is the direct mathematical consequence of the translational symmetry of the quantity conjugate to energy, namely time.

Units of measure

In 1843, James Prescott Joule independently discovered the mechanical equivalent in a series of experiments. The most famous of them used the "Joule apparatus": a descending weight, attached to a string, caused rotation of a paddle immersed in water, practically insulated from heat transfer. It showed that the gravitational potential energy lost by the weight in descending was equal to the internal energy gained by the water through friction with the paddle.

In the International System of Units (SI), the unit of energy is the joule, named after Joule. It is a derived unit that is equal to the energy expended (or work done) in applying a force of one newton through a distance of one metre. However energy is also expressed in many other units not part of the SI, such as ergs, calories, British thermal units, kilowatt-hours and kilocalories, which require a conversion factor when expressed in SI units.

The SI unit of energy rate (energy per unit time) is the watt, which is a joule per second. Thus, one joule is one watt-second, and 3600 joules equal one watt-hour. The CGS energy unit is the erg and the imperial and US customary unit is the foot pound. Other energy units such as the electronvolt, food calorie or thermodynamic kcal (based on the temperature change of water in a heating process), and BTU are used in specific areas of science and commerce.

Classical mechanics
In classical mechanics, energy is a conceptually and mathematically useful property, as it is a conserved quantity. Several formulations of mechanics have been developed using energy as a core concept.

Work, a function of energy, is force times distance.

 * $$ W = \int_C \mathbf{F} \cdot \mathrm{d} \mathbf{s}$$

This says that the work ($$W$$) is equal to the line integral of the force F along a path C; for details see the mechanical work article. Work and thus energy is frame dependent. For example, consider a ball being hit by a bat. In the center-of-mass reference frame, the bat does no work on the ball. But, in the reference frame of the person swinging the bat, considerable work is done on the ball.

The total energy of a system is sometimes called the Hamiltonian, after William Rowan Hamilton. The classical equations of motion can be written in terms of the Hamiltonian, even for highly complex or abstract systems. These classical equations have direct analogs in nonrelativistic quantum mechanics.

Another energy-related concept is called the Lagrangian, after Joseph-Louis Lagrange. This formalism is as fundamental as the Hamiltonian, and both can be used to derive the equations of motion or be derived from them. It was invented in the context of classical mechanics, but is generally useful in modern physics. The Lagrangian is defined as the kinetic energy minus the potential energy. Usually, the Lagrange formalism is mathematically more convenient than the Hamiltonian for non-conservative systems (such as systems with friction).

Noether's theorem (1918) states that any differentiable symmetry of the action of a physical system has a corresponding conservation law. Noether's theorem has become a fundamental tool of modern theoretical physics and the calculus of variations. A generalisation of the seminal formulations on constants of motion in Lagrangian and Hamiltonian mechanics (1788 and 1833, respectively), it does not apply to systems that cannot be modeled with a Lagrangian; for example, dissipative systems with continuous symmetries need not have a corresponding conservation law.

Chemistry
In the context of chemistry, energy is an attribute of a substance as a consequence of its atomic, molecular, or aggregate structure. Since a chemical transformation is accompanied by a change in one or more of these kinds of structure, it is usually accompanied by a decrease, and sometimes an increase, of the total energy of the substances involved. Some energy may be transferred between the surroundings and the reactants in the form of heat or light; thus the products of a reaction have sometimes more but usually less energy than the reactants. A reaction is said to be exothermic or exergonic if the final state is lower on the energy scale than the initial state; in the less common case of endothermic reactions the situation is the reverse. Chemical reactions are usually not possible unless the reactants surmount an energy barrier known as the activation energy. The speed of a chemical reaction (at a given temperature T) is related to the activation energy E by the Boltzmann's population factor e−E/kT; that is, the probability of a molecule to have energy greater than or equal to E at a given temperature T. This exponential dependence of a reaction rate on temperature is known as the Arrhenius equation. The activation energy necessary for a chemical reaction can be provided in the form of thermal energy.

Biology
In biology, energy is an attribute of all biological systems, from the biosphere to the smallest living organism. Within an organism it is responsible for growth and development of a biological cell or organelle of a biological organism. Energy used in respiration is stored in substances such as carbohydrates (including sugars), lipids, and proteins stored by cells. In human terms, the human equivalent (H-e) (Human energy conversion) indicates, for a given amount of energy expenditure, the relative quantity of energy needed for human metabolism, using as a standard an average human energy expenditure of 12,500 kJ per day and a basal metabolic rate of 80 watts. For example, if our bodies run (on average) at 80 watts, then a light bulb running at 100 watts is running at 1.25 human equivalents (100 ÷ 80) i.e. 1.25 H-e. For a difficult task of only a few seconds' duration, a person can put out thousands of watts, many times the 746 watts in one official horsepower. For tasks lasting a few minutes, a fit human can generate perhaps 1,000 watts. For an activity that must be sustained for an hour, output drops to around 300; for an activity kept up all day, 150 watts is about the maximum. The human equivalent assists understanding of energy flows in physical and biological systems by expressing energy units in human terms: it provides a "feel" for the use of a given amount of energy.

Sunlight's radiant energy is also captured by plants as chemical potential energy in photosynthesis, when carbon dioxide and water (two low-energy compounds) are converted into carbohydrates, lipids, proteins and oxygen. Release of the energy stored during photosynthesis as heat or light may be triggered suddenly by a spark in a forest fire, or it may be made available more slowly for animal or human metabolism when organic molecules are ingested and catabolism is triggered by enzyme action.

All living creatures rely on an external source of energy to be able to grow and reproduce – radiant energy from the Sun in the case of green plants and chemical energy (in some form) in the case of animals. The daily 1500–2000 Calories (6–8 MJ) recommended for a human adult are taken as food molecules, mostly carbohydrates and fats, of which glucose (C6H12O6) and stearin (C57H110O6) are convenient examples. The food molecules are oxidized to carbon dioxide and water in the mitochondria

and some of the energy is used to convert ADP into ATP:

The rest of the chemical energy of the carbohydrate or fat are converted into heat: the ATP is used as a sort of "energy currency", and some of the chemical energy it contains is used for other metabolism when ATP reacts with OH groups and eventually splits into ADP and phosphate (at each stage of a metabolic pathway, some chemical energy is converted into heat). Only a tiny fraction of the original chemical energy is used for work:
 * gain in kinetic energy of a sprinter during a 100 m race: 4 kJ
 * gain in gravitational potential energy of a 150 kg weight lifted through 2 metres: 3 kJ
 * Daily food intake of a normal adult: 6–8 MJ

It would appear that living organisms are remarkably inefficient (in the physical sense) in their use of the energy they receive (chemical or radiant energy); most machines manage higher efficiencies. In growing organisms the energy that is converted to heat serves a vital purpose, as it allows the organism tissue to be highly ordered with regard to the molecules it is built from. The second law of thermodynamics states that energy (and matter) tends to become more evenly spread out across the universe: to concentrate energy (or matter) in one specific place, it is necessary to spread out a greater amount of energy (as heat) across the remainder of the universe ("the surroundings"). Simpler organisms can achieve higher energy efficiencies than more complex ones, but the complex organisms can occupy ecological niches that are not available to their simpler brethren. The conversion of a portion of the chemical energy to heat at each step in a metabolic pathway is the physical reason behind the pyramid of biomass observed in ecology. As an example, to take just the first step in the food chain: of the estimated 124.7 Pg/a of carbon that is fixed by photosynthesis, 64.3 Pg/a (52%) are used for the metabolism of green plants, i.e. reconverted into carbon dioxide and heat.

Earth sciences
In geology, continental drift, mountain ranges, volcanoes, and earthquakes are phenomena that can be explained in terms of energy transformations in the Earth's interior, while meteorological phenomena like wind, rain, hail, snow, lightning, tornadoes and hurricanes are all a result of energy transformations in our atmosphere brought about by solar energy.

Sunlight is the main input to Earth's energy budget which accounts for its temperature and climate stability. Sunlight may be stored as gravitational potential energy after it strikes the Earth, as (for example when) water evaporates from oceans and is deposited upon mountains (where, after being released at a hydroelectric dam, it can be used to drive turbines or generators to produce electricity). Sunlight also drives most weather phenomena, save a few exceptions, like those generated by volcanic events for example. An example of a solar-mediated weather event is a hurricane, which occurs when large unstable areas of warm ocean, heated over months, suddenly give up some of their thermal energy to power a few days of violent air movement.

In a slower process, radioactive decay of atoms in the core of the Earth releases heat. This thermal energy drives plate tectonics and may lift mountains, via orogenesis. This slow lifting represents a kind of gravitational potential energy storage of the thermal energy, which may later be transformed into active kinetic energy during landslides, after a triggering event. Earthquakes also release stored elastic potential energy in rocks, a store that has been produced ultimately from the same radioactive heat sources. Thus, according to present understanding, familiar events such as landslides and earthquakes release energy that has been stored as potential energy in the Earth's gravitational field or elastic strain (mechanical potential energy) in rocks. Prior to this, they represent release of energy that has been stored in heavy atoms since the collapse of long-destroyed supernova stars (which created these atoms).

Cosmology
In cosmology and astronomy the phenomena of stars, nova, supernova, quasars and gamma-ray bursts are the universe's highest-output energy transformations of matter. All stellar phenomena (including solar activity) are driven by various kinds of energy transformations. Energy in such transformations is either from gravitational collapse of matter (usually molecular hydrogen) into various classes of astronomical objects (stars, black holes, etc.), or from nuclear fusion (of lighter elements, primarily hydrogen). The nuclear fusion of hydrogen in the Sun also releases another store of potential energy which was created at the time of the Big Bang. At that time, according to theory, space expanded and the universe cooled too rapidly for hydrogen to completely fuse into heavier elements. This meant that hydrogen represents a store of potential energy that can be released by fusion. Such a fusion process is triggered by heat and pressure generated from gravitational collapse of hydrogen clouds when they produce stars, and some of the fusion energy is then transformed into sunlight.

Quantum mechanics
In quantum mechanics, energy is defined in terms of the energy operator (Hamiltonian) as a time derivative of the wave function. The Schrödinger equation equates the energy operator to the full energy of a particle or a system. Its results can be considered as a definition of measurement of energy in quantum mechanics. The Schrödinger equation describes the space- and time-dependence of a slowly changing (non-relativistic) wave function of quantum systems. The solution of this equation for a bound system is discrete (a set of permitted states, each characterized by an energy level) which results in the concept of quanta. In the solution of the Schrödinger equation for any oscillator (vibrator) and for electromagnetic waves in a vacuum, the resulting energy states are related to the frequency by Planck's relation: $$E = h\nu$$ (where $$h$$ is the Planck constant and $$\nu$$ the frequency). In the case of an electromagnetic wave these energy states are called quanta of light or photons.

Relativity
When calculating kinetic energy (work to accelerate a massive body from zero speed to some finite speed) relativistically – using Lorentz transformations instead of Newtonian mechanics – Einstein discovered an unexpected by-product of these calculations to be an energy term which does not vanish at zero speed. He called it rest energy: energy which every massive body must possess even when being at rest. The amount of energy is directly proportional to the mass of the body:

$$ E_0 = m_0 c^2 ,$$ where
 * m0 is the rest mass of the body,
 * c is the speed of light in vacuum,
 * $$E_0$$ is the rest energy.

For example, consider electron–positron annihilation, in which the rest energy of these two individual particles (equivalent to their rest mass) is converted to the radiant energy of the photons produced in the process. In this system the matter and antimatter (electrons and positrons) are destroyed and changed to non-matter (the photons). However, the total mass and total energy do not change during this interaction. The photons each have no rest mass but nonetheless have radiant energy which exhibits the same inertia as did the two original particles. This is a reversible process – the inverse process is called pair creation – in which the rest mass of particles is created from the radiant energy of two (or more) annihilating photons.

In general relativity, the stress–energy tensor serves as the source term for the gravitational field, in rough analogy to the way mass serves as the source term in the non-relativistic Newtonian approximation.

Energy and mass are manifestations of one and the same underlying physical property of a system. This property is responsible for the inertia and strength of gravitational interaction of the system ("mass manifestations"), and is also responsible for the potential ability of the system to perform work or heating ("energy manifestations"), subject to the limitations of other physical laws.

In classical physics, energy is a scalar quantity, the canonical conjugate to time. In special relativity energy is also a scalar (although not a Lorentz scalar but a time component of the energy–momentum 4-vector). In other words, energy is invariant with respect to rotations of space, but not invariant with respect to rotations of spacetime (= boosts).

Transformation
Energy may be transformed between different forms at various efficiencies. Items that transform between these forms are called transducers. Examples of transducers include a battery (from chemical energy to electric energy), a dam (from gravitational potential energy to kinetic energy of moving water (and the blades of a turbine) and ultimately to electric energy through an electric generator), and a heat engine (from heat to work).

Examples of energy transformation include generating electric energy from heat energy via a steam turbine, or lifting an object against gravity using electrical energy driving a crane motor. Lifting against gravity performs mechanical work on the object and stores gravitational potential energy in the object. If the object falls to the ground, gravity does mechanical work on the object which transforms the potential energy in the gravitational field to the kinetic energy released as heat on impact with the ground. The Sun transforms nuclear potential energy to other forms of energy; its total mass does not decrease due to that itself (since it still contains the same total energy even in different forms) but its mass does decrease when the energy escapes out to its surroundings, largely as radiant energy.

There are strict limits to how efficiently heat can be converted into work in a cyclic process, e.g. in a heat engine, as described by Carnot's theorem and the second law of thermodynamics. However, some energy transformations can be quite efficient. The direction of transformations in energy (what kind of energy is transformed to what other kind) is often determined by entropy (equal energy spread among all available degrees of freedom) considerations. In practice all energy transformations are permitted on a small scale, but certain larger transformations are not permitted because it is statistically unlikely that energy or matter will randomly move into more concentrated forms or smaller spaces.

Energy transformations in the universe over time are characterized by various kinds of potential energy, that has been available since the Big Bang, being "released" (transformed to more active types of energy such as kinetic or radiant energy) when a triggering mechanism is available. Familiar examples of such processes include nucleosynthesis, a process ultimately using the gravitational potential energy released from the gravitational collapse of supernovae to "store" energy in the creation of heavy isotopes (such as uranium and thorium), and nuclear decay, a process in which energy is released that was originally stored in these heavy elements, before they were incorporated into the Solar System and the Earth. This energy is triggered and released in nuclear fission bombs or in civil nuclear power generation. Similarly, in the case of a chemical explosion, chemical potential energy is transformed to kinetic and thermal energy in a very short time.

Yet another example is that of a pendulum. At its highest points the kinetic energy is zero and the gravitational potential energy is at its maximum. At its lowest point the kinetic energy is at its maximum and is equal to the decrease in potential energy. If one (unrealistically) assumes that there is no friction or other losses, the conversion of energy between these processes would be perfect, and the pendulum would continue swinging forever.

Energy is also transferred from potential energy ($$E_p$$) to kinetic energy ($$E_k$$) and then back to potential energy constantly. This is referred to as conservation of energy. In this isolated system, energy cannot be created or destroyed; therefore, the initial energy and the final energy will be equal to each other. This can be demonstrated by the following:

The equation can then be simplified further since $$E_p = mgh$$ (mass times acceleration due to gravity times the height) and $E_k = \frac{1}{2} mv^2$ (half mass times velocity squared). Then the total amount of energy can be found by adding $$E_p + E_k = E_\text{total}$$.

Conservation of energy and mass in transformation
Energy gives rise to weight when it is trapped in a system with zero momentum, where it can be weighed. It is also equivalent to mass, and this mass is always associated with it. Mass is also equivalent to a certain amount of energy, and likewise always appears associated with it, as described in mass–energy equivalence. The formula E = mc², derived by Albert Einstein (1905) quantifies the relationship between relativistic mass and energy within the concept of special relativity. In different theoretical frameworks, similar formulas were derived by J.J. Thomson (1881), Henri Poincaré (1900), Friedrich Hasenöhrl (1904) and others (see Mass–energy equivalence for further information).

Part of the rest energy (equivalent to rest mass) of matter may be converted to other forms of energy (still exhibiting mass), but neither energy nor mass can be destroyed; rather, both remain constant during any process. However, since $$c^2$$ is extremely large relative to ordinary human scales, the conversion of an everyday amount of rest mass (for example, 1 kg) from rest energy to other forms of energy (such as kinetic energy, thermal energy, or the radiant energy carried by light and other radiation) can liberate tremendous amounts of energy (~$$9\times 10^{16}$$ joules = 21 megatons of TNT), as can be seen in nuclear reactors and nuclear weapons. Conversely, the mass equivalent of an everyday amount energy is minuscule, which is why a loss of energy (loss of mass) from most systems is difficult to measure on a weighing scale, unless the energy loss is very large. Examples of large transformations between rest energy (of matter) and other forms of energy (e.g., kinetic energy into particles with rest mass) are found in nuclear physics and particle physics. Often, however, the complete conversion of matter (such as atoms) to non-matter (such as photons) is forbidden by conservation laws.

Reversible and non-reversible transformations
Thermodynamics divides energy transformation into two kinds: reversible processes and irreversible processes. An irreversible process is one in which energy is dissipated (spread) into empty energy states available in a volume, from which it cannot be recovered into more concentrated forms (fewer quantum states), without degradation of even more energy. A reversible process is one in which this sort of dissipation does not happen. For example, conversion of energy from one type of potential field to another is reversible, as in the pendulum system described above. In processes where heat is generated, quantum states of lower energy, present as possible excitations in fields between atoms, act as a reservoir for part of the energy, from which it cannot be recovered, in order to be converted with 100% efficiency into other forms of energy. In this case, the energy must partly stay as thermal energy and cannot be completely recovered as usable energy, except at the price of an increase in some other kind of heat-like increase in disorder in quantum states, in the universe (such as an expansion of matter, or a randomization in a crystal).

As the universe evolves with time, more and more of its energy becomes trapped in irreversible states (i.e., as heat or as other kinds of increases in disorder). This has led to the hypothesis of the inevitable thermodynamic heat death of the universe. In this heat death the energy of the universe does not change, but the fraction of energy which is available to do work through a heat engine, or be transformed to other usable forms of energy (through the use of generators attached to heat engines), continues to decrease.

Conservation of energy
The fact that energy can be neither created nor destroyed is called the law of conservation of energy. In the form of the first law of thermodynamics, this states that a closed system's energy is constant unless energy is transferred in or out as work or heat, and that no energy is lost in transfer. The total inflow of energy into a system must equal the total outflow of energy from the system, plus the change in the energy contained within the system. Whenever one measures (or calculates) the total energy of a system of particles whose interactions do not depend explicitly on time, it is found that the total energy of the system always remains constant.

While heat can always be fully converted into work in a reversible isothermal expansion of an ideal gas, for cyclic processes of practical interest in heat engines the second law of thermodynamics states that the system doing work always loses some energy as waste heat. This creates a limit to the amount of heat energy that can do work in a cyclic process, a limit called the available energy. Mechanical and other forms of energy can be transformed in the other direction into thermal energy without such limitations. The total energy of a system can be calculated by adding up all forms of energy in the system.

Richard Feynman said during a 1961 lecture: "There is a fact, or if you wish, a law, governing all natural phenomena that are known to date. There is no known exception to this law – it is exact so far as we know. The law is called the conservation of energy. It states that there is a certain quantity, which we call energy, that does not change in manifold changes which nature undergoes. That is a most abstract idea, because it is a mathematical principle; it says that there is a numerical quantity which does not change when something happens. It is not a description of a mechanism, or anything concrete; it is just a strange fact that we can calculate some number and when we finish watching nature go through her tricks and calculate the number again, it is the same."

Most kinds of energy (with gravitational energy being a notable exception) are subject to strict local conservation laws as well. In this case, energy can only be exchanged between adjacent regions of space, and all observers agree as to the volumetric density of energy in any given space. There is also a global law of conservation of energy, stating that the total energy of the universe cannot change; this is a corollary of the local law, but not vice versa.

This law is a fundamental principle of physics. As shown rigorously by Noether's theorem, the conservation of energy is a mathematical consequence of translational symmetry of time, a property of most phenomena below the cosmic scale that makes them independent of their locations on the time coordinate. Put differently, yesterday, today, and tomorrow are physically indistinguishable. This is because energy is the quantity which is canonical conjugate to time. This mathematical entanglement of energy and time also results in the uncertainty principle – it is impossible to define the exact amount of energy during any definite time interval (though this is practically significant only for very short time intervals). The uncertainty principle should not be confused with energy conservation – rather it provides mathematical limits to which energy can in principle be defined and measured.

Each of the basic forces of nature is associated with a different type of potential energy, and all types of potential energy (like all other types of energy) appear as system mass, whenever present. For example, a compressed spring will be slightly more massive than before it was compressed. Likewise, whenever energy is transferred between systems by any mechanism, an associated mass is transferred with it.

In quantum mechanics energy is expressed using the Hamiltonian operator. On any time scales, the uncertainty in the energy is by

 * $$\Delta E \Delta t \ge \frac { \hbar } {2 } $$

which is similar in form to the Heisenberg Uncertainty Principle (but not really mathematically equivalent thereto, since H and t are not dynamically conjugate variables, neither in classical nor in quantum mechanics).

In particle physics, this inequality permits a qualitative understanding of virtual particles, which carry momentum. The exchange of virtual particles with real particles is responsible for the creation of all known fundamental forces (more accurately known as fundamental interactions). Virtual photons are also responsible for the electrostatic interaction between electric charges (which results in Coulomb's law), for spontaneous radiative decay of excited atomic and nuclear states, for the Casimir force, for the Van der Waals force and some other observable phenomena.

Closed systems
Energy transfer can be considered for the special case of systems which are closed to transfers of matter. The portion of the energy which is transferred by conservative forces over a distance is measured as the work the source system does on the receiving system. The portion of the energy which does not do work during the transfer is called heat. Energy can be transferred between systems in a variety of ways. Examples include the transmission of electromagnetic energy via photons, physical collisions which transfer kinetic energy, tidal interactions, and the conductive transfer of thermal energy.

Energy is strictly conserved and is also locally conserved wherever it can be defined. In thermodynamics, for closed systems, the process of energy transfer is described by the first law:

where $$E$$ is the amount of energy transferred, $$W$$ represents the work done on or by the system, and $$Q$$ represents the heat flow into or out of the system. As a simplification, the heat term, $$Q$$, can sometimes be ignored, especially for fast processes involving gases, which are poor conductors of heat, or when the thermal efficiency of the transfer is high. For such adiabatic processes,

This simplified equation is the one used to define the joule, for example.

Open systems
Beyond the constraints of closed systems, open systems can gain or lose energy in association with matter transfer (this process is illustrated by injection of an air-fuel mixture into a car engine, a system which gains in energy thereby, without addition of either work or heat). Denoting this energy by $$E_\text{matter}$$, one may write

Internal energy
Internal energy is the sum of all microscopic forms of energy of a system. It is the energy needed to create the system. It is related to the potential energy, e.g., molecular structure, crystal structure, and other geometric aspects, as well as the motion of the particles, in form of kinetic energy. Thermodynamics is chiefly concerned with changes in internal energy and not its absolute value, which is impossible to determine with thermodynamics alone.

First law of thermodynamics
The first law of thermodynamics asserts that the total energy of a system and its surroundings (but not necessarily thermodynamic free energy) is always conserved and that heat flow is a form of energy transfer. For homogeneous systems, with a well-defined temperature and pressure, a commonly used corollary of the first law is that, for a system subject only to pressure forces and heat transfer (e.g., a cylinder-full of gas) without chemical changes, the differential change in the internal energy of the system (with a gain in energy signified by a positive quantity) is given as

 * $$\mathrm{d}E = T\mathrm{d}S - P\mathrm{d}V\,$$,

where the first term on the right is the heat transferred into the system, expressed in terms of temperature T and entropy S (in which entropy increases and its change dS is positive when heat is added to the system), and the last term on the right hand side is identified as work done on the system, where pressure is P and volume V (the negative sign results since compression of the system requires work to be done on it and so the volume change, dV, is negative when work is done on the system).

This equation is highly specific, ignoring all chemical, electrical, nuclear, and gravitational forces, effects such as advection of any form of energy other than heat and PV-work. The general formulation of the first law (i.e., conservation of energy) is valid even in situations in which the system is not homogeneous. For these cases the change in internal energy of a closed system is expressed in a general form by

 * $$\mathrm{d}E=\delta Q+\delta W$$

where $$\delta Q$$ is the heat supplied to the system and $$\delta W$$ is the work applied to the system.

Equipartition of energy
The energy of a mechanical harmonic oscillator (a mass on a spring) is alternately kinetic and potential energy. At two points in the oscillation cycle it is entirely kinetic, and at two points it is entirely potential. Over a whole cycle, or over many cycles, average energy is equally split between kinetic and potential. This is an example of the equipartition principle: the total energy of a system with many degrees of freedom is equally split among all available degrees of freedom, on average.

This principle is vitally important to understanding the behavior of a quantity closely related to energy, called entropy. Entropy is a measure of evenness of a distribution of energy between parts of a system. When an isolated system is given more degrees of freedom (i.e., given new available energy states that are the same as existing states), then total energy spreads over all available degrees equally without distinction between "new" and "old" degrees. This mathematical result is part of the second law of thermodynamics. The second law of thermodynamics is simple only for systems which are near or in a physical equilibrium state. For non-equilibrium systems, the laws governing the systems' behavior are still debatable. One of the guiding principles for these systems is the principle of maximum entropy production. It states that nonequilibrium systems behave in such a way as to maximize their entropy production.

Journals

 * The Journal of Energy History / Revue d'histoire de l'énergie (JEHRHE), 2018–

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: Energy