| Alternative 1 | |
|---|---|
| Error | 1.4 |
| Cost | 19904 |
\[\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\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
(let* ((t_1 (tanh (/ t y))))
(if (<= y -1.16e+136)
(+ x (- (* z (* y t_1)) (* z x)))
(if (<= y 8.5e+170)
(+ x (* (- t_1 (tanh (/ x y))) (* z y)))
(+ x (* z (- t 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) {
double t_1 = tanh((t / y));
double tmp;
if (y <= -1.16e+136) {
tmp = x + ((z * (y * t_1)) - (z * x));
} else if (y <= 8.5e+170) {
tmp = x + ((t_1 - tanh((x / y))) * (z * y));
} else {
tmp = x + (z * (t - x));
}
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) :: t_1
real(8) :: tmp
t_1 = tanh((t / y))
if (y <= (-1.16d+136)) then
tmp = x + ((z * (y * t_1)) - (z * x))
else if (y <= 8.5d+170) then
tmp = x + ((t_1 - tanh((x / y))) * (z * y))
else
tmp = x + (z * (t - x))
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 t_1 = Math.tanh((t / y));
double tmp;
if (y <= -1.16e+136) {
tmp = x + ((z * (y * t_1)) - (z * x));
} else if (y <= 8.5e+170) {
tmp = x + ((t_1 - Math.tanh((x / y))) * (z * y));
} else {
tmp = x + (z * (t - x));
}
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): t_1 = math.tanh((t / y)) tmp = 0 if y <= -1.16e+136: tmp = x + ((z * (y * t_1)) - (z * x)) elif y <= 8.5e+170: tmp = x + ((t_1 - math.tanh((x / y))) * (z * y)) else: tmp = x + (z * (t - x)) 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) t_1 = tanh(Float64(t / y)) tmp = 0.0 if (y <= -1.16e+136) tmp = Float64(x + Float64(Float64(z * Float64(y * t_1)) - Float64(z * x))); elseif (y <= 8.5e+170) tmp = Float64(x + Float64(Float64(t_1 - tanh(Float64(x / y))) * Float64(z * y))); else tmp = Float64(x + Float64(z * Float64(t - x))); 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) t_1 = tanh((t / y)); tmp = 0.0; if (y <= -1.16e+136) tmp = x + ((z * (y * t_1)) - (z * x)); elseif (y <= 8.5e+170) tmp = x + ((t_1 - tanh((x / y))) * (z * y)); else tmp = x + (z * (t - x)); 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_] := Block[{t$95$1 = N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -1.16e+136], N[(x + N[(N[(z * N[(y * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.5e+170], N[(x + N[(N[(t$95$1 - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t - x), $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}
t_1 := \tanh \left(\frac{t}{y}\right)\\
\mathbf{if}\;y \leq -1.16 \cdot 10^{+136}:\\
\;\;\;\;x + \left(z \cdot \left(y \cdot t_1\right) - z \cdot x\right)\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+170}:\\
\;\;\;\;x + \left(t_1 - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
Results
| Original | 4.5 |
|---|---|
| Target | 2.0 |
| Herbie | 2.0 |
if y < -1.1599999999999999e136Initial program 14.9
Applied egg-rr15.0
Applied egg-rr7.4
Taylor expanded in x around 0 26.9
Simplified5.0
[Start]26.9 | \[ x + \left(y \cdot \left(\left(\frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}} - \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right) \cdot z\right) + -1 \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]26.9 | \[ x + \left(y \cdot \left(\left(\frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}} - \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right) \cdot z\right) + \color{blue}{\left(-z \cdot x\right)}\right)
\] |
unsub-neg [=>]26.9 | \[ x + \color{blue}{\left(y \cdot \left(\left(\frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}} - \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right) \cdot z\right) - z \cdot x\right)}
\] |
if -1.1599999999999999e136 < y < 8.5000000000000004e170Initial program 1.3
if 8.5000000000000004e170 < y Initial program 17.6
Simplified6.1
[Start]17.6 | \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\] |
|---|---|
+-commutative [=>]17.6 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x}
\] |
*-commutative [=>]17.6 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x
\] |
associate-*l* [=>]6.1 | \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x
\] |
fma-def [=>]6.1 | \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)}
\] |
Taylor expanded in y around inf 4.5
Final simplification2.0
| Alternative 1 | |
|---|---|
| Error | 1.4 |
| Cost | 19904 |
| Alternative 2 | |
|---|---|
| Error | 2.0 |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Error | 8.4 |
| Cost | 7760 |
| Alternative 4 | |
|---|---|
| Error | 9.5 |
| Cost | 7504 |
| Alternative 5 | |
|---|---|
| Error | 10.5 |
| Cost | 7372 |
| Alternative 6 | |
|---|---|
| Error | 9.5 |
| Cost | 7241 |
| Alternative 7 | |
|---|---|
| Error | 18.4 |
| Cost | 849 |
| Alternative 8 | |
|---|---|
| Error | 15.3 |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 15.3 |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Error | 23.7 |
| Cost | 653 |
| Alternative 11 | |
|---|---|
| Error | 18.2 |
| Cost | 585 |
| Alternative 12 | |
|---|---|
| Error | 24.4 |
| Cost | 456 |
| Alternative 13 | |
|---|---|
| Error | 22.5 |
| Cost | 452 |
| Alternative 14 | |
|---|---|
| Error | 22.8 |
| Cost | 64 |
herbie shell --seed 2023187
(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))))))