Average Error: 4.8 → 1.5
Time: 5.6s
Precision: binary64
\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\mathsf{fma}\left(z, y \cdot \tanh \left(\frac{t}{y}\right) - y \cdot \tanh \left(\frac{x}{y}\right), x\right) \]
(FPCore (x y z t)
 :precision binary64
 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
 :precision binary64
 (fma z (- (* y (tanh (/ t y))) (* y (tanh (/ x y)))) x))
double code(double x, double y, double z, double t) {
	return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
double code(double x, double y, double z, double t) {
	return fma(z, ((y * tanh((t / y))) - (y * tanh((x / y)))), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))
end
function code(x, y, z, t)
	return fma(z, Float64(Float64(y * tanh(Float64(t / y))) - Float64(y * tanh(Float64(x / y)))), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(z * N[(N[(y * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(y * N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\mathsf{fma}\left(z, y \cdot \tanh \left(\frac{t}{y}\right) - y \cdot \tanh \left(\frac{x}{y}\right), x\right)

Error

Target

Original4.8
Target2.1
Herbie1.5
\[x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) \]

Derivation

  1. Initial program 4.8

    \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
  2. Simplified1.5

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
  3. Applied egg-rr1.5

    \[\leadsto \mathsf{fma}\left(z, \color{blue}{\tanh \left(\frac{t}{y}\right) \cdot y + \left(-\tanh \left(\frac{x}{y}\right)\right) \cdot y}, x\right) \]
  4. Final simplification1.5

    \[\leadsto \mathsf{fma}\left(z, y \cdot \tanh \left(\frac{t}{y}\right) - y \cdot \tanh \left(\frac{x}{y}\right), x\right) \]

Reproduce

herbie shell --seed 2022186 
(FPCore (x y z t)
  :name "SynthBasics:moogVCF from YampaSynth-0.2"
  :precision binary64

  :herbie-target
  (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))

  (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))