Average Error: 4.8 → 1.6
Time: 16.8s
Precision: binary64
Cost: 13764
\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+216}:\\ \;\;\;\;x + \left(t - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -1e+216)
   (+ x (* (- t x) z))
   (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))))
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) {
	double tmp;
	if (y <= -1e+216) {
		tmp = x + ((t - x) * z);
	} else {
		tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (y <= (-1d+216)) then
        tmp = x + ((t - x) * z)
    else
        tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -1e+216) {
		tmp = x + ((t - x) * z);
	} else {
		tmp = x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
	}
	return tmp;
}
def code(x, y, z, t):
	return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
def code(x, y, z, t):
	tmp = 0
	if y <= -1e+216:
		tmp = x + ((t - x) * z)
	else:
		tmp = x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
	return tmp
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)
	tmp = 0.0
	if (y <= -1e+216)
		tmp = Float64(x + Float64(Float64(t - x) * z));
	else
		tmp = Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (y <= -1e+216)
		tmp = x + ((t - x) * z);
	else
		tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
	end
	tmp_2 = tmp;
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_] := If[LessEqual[y, -1e+216], N[(x + N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+216}:\\
\;\;\;\;x + \left(t - x\right) \cdot z\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if y < -1e216

    1. Initial program 19.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)} \]
      Proof
      (fma.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x)): 1 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around inf 3.1

      \[\leadsto \color{blue}{\left(t - x\right) \cdot z + x} \]

    if -1e216 < y

    1. Initial program 3.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)} \]
      Proof
      (fma.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x)): 1 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr1.5

      \[\leadsto \color{blue}{y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+216}:\\ \;\;\;\;x + \left(t - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error12.7
Cost7760
\[\begin{array}{l} t_1 := x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right)\\ t_2 := x + \left(t - x\right) \cdot z\\ \mathbf{if}\;y \leq -1 \cdot 10^{+220}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.7217356634547555 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.568400605208612 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 10^{+200}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error21.1
Cost980
\[\begin{array}{l} t_1 := x - x \cdot z\\ t_2 := x + t \cdot z\\ \mathbf{if}\;t \leq -9.944675515646138 \cdot 10^{+90}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -9.967599457640238 \cdot 10^{-254}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.7890899811072983 \cdot 10^{-187}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.136316401738445 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.217061905812988 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.1
Cost848
\[\begin{array}{l} t_1 := x + t \cdot z\\ \mathbf{if}\;y \leq -3.7217356634547555 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.263458881980802 \cdot 10^{+43}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.953885966503502 \cdot 10^{+86}:\\ \;\;\;\;\left(t - x\right) \cdot z\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+133}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error15.8
Cost712
\[\begin{array}{l} t_1 := x + \left(t - x\right) \cdot z\\ \mathbf{if}\;y \leq -3.7217356634547555 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.6769396687784952 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error15.8
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -3.7217356634547555 \cdot 10^{-38}:\\ \;\;\;\;x + \left(t \cdot z - x \cdot z\right)\\ \mathbf{elif}\;y \leq 1.6769396687784952 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + \left(t - x\right) \cdot z\\ \end{array} \]
Alternative 6
Error18.0
Cost584
\[\begin{array}{l} t_1 := x + t \cdot z\\ \mathbf{if}\;y \leq -3.7217356634547555 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.916940385450448 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error22.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0695222474838717 \cdot 10^{-193}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.65298824970966 \cdot 10^{-263}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error22.8
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022294 
(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))))))