I was wondering what defines horsepower in an airplane piston engine and how can it be changed?, is horsepower changing during flight?
Horsepower in airplane piston engine is defined as in any other piston engine. A piston engine realizes a certain moment at certain RPM. When you multiply that (actually M[Nm] * ω[s-1] = P [W] ---> P [W] * 1.341 = HP). That's why in a 150 HP engine, you don't realize 150 HP at all RPMs, only at certain RPMs (usually near max RPM).
Furthermore, if an airplane flies 300KTAS (~160m/s) at max power, 250HP (~185kW), you will get thrust:
T = P/v = 185/160 = 1.156 kN
For the same velocity, a 150 HP (~110 kW) engine will give you:
T = P/v = 110/160 = 1.156 kN = 0.687 kN
See the figure below, it's a sample that shows drag that you need to overcome with your thrust at different velocities. It's for an example 700 kg airplane at 100 m ASL (above sea level) with 150HP or 250HP engines. Of course, the 250HP one will weigh more, but I've ignored that for this example. Max throttle assumed, though you can change it during flight. One throttle (power) setting will give you max range, another will give you max endurance, while max throttle will often give you best manoeuvring performance.
Hope that answers your question. Have a nice day!
Horsepower is torque x RPM so it changes with throttle and RPM.
The published value is the maximum horsepower rating, and is the rating of particular engine at wide open throttle at sea level, and redline RPM, on a standard day (59F, 29.92" of mercury).
They have large cylinder volumes to produce torque at low RPMs to accommodate direct drive propellers. Normally aspirated aircraft engines are, roughly, 1/2 HP per cubic inch, which varies somewhat depending on compression ratio. A higher compression ratio, requiring 100 octane fuel, will be a bit more than .5 hp/cu in. For example, an 80 octane Lycoming O-320 is 150HP maximum with 320 cubic inches, or .46 hp/cu in. The newer 100 octane O-320s have 160 hp due to a higher compression ratio and so are at .5. A 100 octane Lyc O-360 with 360 cubic inches is 180 hp or .5 hp/cu in, and the 200 HP version is .55 hp/cu in (due to different valves plus a higher compression ratio).
So, as a rough rule of thumb, the engine's horsepower rating tells you, mainly, that the displacement in cubic inches is approximately the rating x2, give or take say, 5-10%, for a normally aspirated direct drive engine.
To get significantly above that requires reduction gearboxes to allow the engine to spin (pump air) faster and if you look at a geared engine like the Rotax 912, you are getting about double the power per displacement, or 1 HP per cu in (80 hp from 79 cu in).