
(FPCore (x y z t) :precision binary64 (+ 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))));
}
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
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ 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))));
}
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
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 4.5e+176) (fma (* (- (tanh (/ t y_m)) (tanh (/ x y_m))) y_m) z x) (fma (- t x) z x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 4.5e+176) {
tmp = fma(((tanh((t / y_m)) - tanh((x / y_m))) * y_m), z, x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 4.5e+176) tmp = fma(Float64(Float64(tanh(Float64(t / y_m)) - tanh(Float64(x / y_m))) * y_m), z, x); else tmp = fma(Float64(t - x), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 4.5e+176], N[(N[(N[(N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * y$95$m), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 4.5 \cdot 10^{+176}:\\
\;\;\;\;\mathsf{fma}\left(\left(\tanh \left(\frac{t}{y\_m}\right) - \tanh \left(\frac{x}{y\_m}\right)\right) \cdot y\_m, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 4.50000000000000003e176Initial program 95.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.1
Applied rewrites99.1%
if 4.50000000000000003e176 < y Initial program 69.3%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1
(+
(*
(/ 1.0 (/ (+ (/ (fma y_m x (/ (* (* x x) y_m) t)) t) y_m) t))
(* z y_m))
x))
(t_2 (tanh (/ t y_m)))
(t_3 (- x (* (- (tanh (/ x y_m)) t_2) (* z y_m)))))
(if (<= t_3 -5e+298)
(fma (- t x) z x)
(if (<= t_3 -5e+173)
t_1
(if (<= t_3 2e+83)
(- (fma (* z y_m) t_2 x) (* z x))
(if (<= t_3 5e+304) t_1 (fma z t (* (- x) z))))))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = ((1.0 / (((fma(y_m, x, (((x * x) * y_m) / t)) / t) + y_m) / t)) * (z * y_m)) + x;
double t_2 = tanh((t / y_m));
double t_3 = x - ((tanh((x / y_m)) - t_2) * (z * y_m));
double tmp;
if (t_3 <= -5e+298) {
tmp = fma((t - x), z, x);
} else if (t_3 <= -5e+173) {
tmp = t_1;
} else if (t_3 <= 2e+83) {
tmp = fma((z * y_m), t_2, x) - (z * x);
} else if (t_3 <= 5e+304) {
tmp = t_1;
} else {
tmp = fma(z, t, (-x * z));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(y_m, x, Float64(Float64(Float64(x * x) * y_m) / t)) / t) + y_m) / t)) * Float64(z * y_m)) + x) t_2 = tanh(Float64(t / y_m)) t_3 = Float64(x - Float64(Float64(tanh(Float64(x / y_m)) - t_2) * Float64(z * y_m))) tmp = 0.0 if (t_3 <= -5e+298) tmp = fma(Float64(t - x), z, x); elseif (t_3 <= -5e+173) tmp = t_1; elseif (t_3 <= 2e+83) tmp = Float64(fma(Float64(z * y_m), t_2, x) - Float64(z * x)); elseif (t_3 <= 5e+304) tmp = t_1; else tmp = fma(z, t, Float64(Float64(-x) * z)); end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(N[(1.0 / N[(N[(N[(N[(y$95$m * x + N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(x - N[(N[(N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision] - t$95$2), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -5e+298], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[t$95$3, -5e+173], t$95$1, If[LessEqual[t$95$3, 2e+83], N[(N[(N[(z * y$95$m), $MachinePrecision] * t$95$2 + x), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 5e+304], t$95$1, N[(z * t + N[((-x) * z), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \frac{1}{\frac{\frac{\mathsf{fma}\left(y\_m, x, \frac{\left(x \cdot x\right) \cdot y\_m}{t}\right)}{t} + y\_m}{t}} \cdot \left(z \cdot y\_m\right) + x\\
t_2 := \tanh \left(\frac{t}{y\_m}\right)\\
t_3 := x - \left(\tanh \left(\frac{x}{y\_m}\right) - t\_2\right) \cdot \left(z \cdot y\_m\right)\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\mathbf{elif}\;t\_3 \leq -5 \cdot 10^{+173}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y\_m, t\_2, x\right) - z \cdot x\\
\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t, \left(-x\right) \cdot z\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -5.0000000000000003e298Initial program 70.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6490.7
Applied rewrites90.7%
if -5.0000000000000003e298 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -5.00000000000000034e173 or 2.00000000000000006e83 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.9999999999999997e304Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6443.8
Applied rewrites43.8%
Applied rewrites43.8%
Taylor expanded in t around -inf
Applied rewrites86.6%
if -5.00000000000000034e173 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 2.00000000000000006e83Initial program 98.4%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
lower-neg.f64N/A
lower-*.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6484.5
Applied rewrites84.5%
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f6484.5
Applied rewrites84.5%
if 4.9999999999999997e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 51.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites99.9%
Applied rewrites100.0%
Final simplification87.0%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (tanh (/ x y_m)))
(t_2 (tanh (/ t y_m)))
(t_3 (- x (* (- t_1 t_2) (* z y_m)))))
(if (<= t_3 -1e+113)
(fma (* (- (/ t y_m) t_1) y_m) z x)
(if (<= t_3 2e+83)
(- (fma (* z y_m) t_2 x) (* z x))
(if (<= t_3 5e+304)
(+
(*
(/ 1.0 (/ (+ (/ (fma y_m x (/ (* (* x x) y_m) t)) t) y_m) t))
(* z y_m))
x)
(fma z t (* (- x) z)))))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = tanh((x / y_m));
double t_2 = tanh((t / y_m));
double t_3 = x - ((t_1 - t_2) * (z * y_m));
double tmp;
if (t_3 <= -1e+113) {
tmp = fma((((t / y_m) - t_1) * y_m), z, x);
} else if (t_3 <= 2e+83) {
tmp = fma((z * y_m), t_2, x) - (z * x);
} else if (t_3 <= 5e+304) {
tmp = ((1.0 / (((fma(y_m, x, (((x * x) * y_m) / t)) / t) + y_m) / t)) * (z * y_m)) + x;
} else {
tmp = fma(z, t, (-x * z));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = tanh(Float64(x / y_m)) t_2 = tanh(Float64(t / y_m)) t_3 = Float64(x - Float64(Float64(t_1 - t_2) * Float64(z * y_m))) tmp = 0.0 if (t_3 <= -1e+113) tmp = fma(Float64(Float64(Float64(t / y_m) - t_1) * y_m), z, x); elseif (t_3 <= 2e+83) tmp = Float64(fma(Float64(z * y_m), t_2, x) - Float64(z * x)); elseif (t_3 <= 5e+304) tmp = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(y_m, x, Float64(Float64(Float64(x * x) * y_m) / t)) / t) + y_m) / t)) * Float64(z * y_m)) + x); else tmp = fma(z, t, Float64(Float64(-x) * z)); end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(x - N[(N[(t$95$1 - t$95$2), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1e+113], N[(N[(N[(N[(t / y$95$m), $MachinePrecision] - t$95$1), $MachinePrecision] * y$95$m), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[t$95$3, 2e+83], N[(N[(N[(z * y$95$m), $MachinePrecision] * t$95$2 + x), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 5e+304], N[(N[(N[(1.0 / N[(N[(N[(N[(y$95$m * x + N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(z * t + N[((-x) * z), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{x}{y\_m}\right)\\
t_2 := \tanh \left(\frac{t}{y\_m}\right)\\
t_3 := x - \left(t\_1 - t\_2\right) \cdot \left(z \cdot y\_m\right)\\
\mathbf{if}\;t\_3 \leq -1 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{t}{y\_m} - t\_1\right) \cdot y\_m, z, x\right)\\
\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y\_m, t\_2, x\right) - z \cdot x\\
\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\frac{1}{\frac{\frac{\mathsf{fma}\left(y\_m, x, \frac{\left(x \cdot x\right) \cdot y\_m}{t}\right)}{t} + y\_m}{t}} \cdot \left(z \cdot y\_m\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t, \left(-x\right) \cdot z\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -1e113Initial program 91.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in t around 0
lower-/.f6483.2
Applied rewrites83.2%
if -1e113 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 2.00000000000000006e83Initial program 98.3%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
lower-neg.f64N/A
lower-*.f6498.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.3
Applied rewrites98.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6486.5
Applied rewrites86.5%
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f6486.5
Applied rewrites86.5%
if 2.00000000000000006e83 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.9999999999999997e304Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6440.1
Applied rewrites40.1%
Applied rewrites40.1%
Taylor expanded in t around -inf
Applied rewrites84.8%
if 4.9999999999999997e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 51.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites99.9%
Applied rewrites100.0%
Final simplification86.5%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (fma (* (- (/ t y_m) (tanh (/ x y_m))) y_m) z x)))
(if (<= x -3.2e+72)
t_1
(if (<= x 1.7e+83)
(fma (* (- (tanh (/ t y_m)) (/ x y_m)) z) y_m x)
(if (<= x 1.85e+151)
t_1
(+
(*
(/ 1.0 (/ (+ (/ (fma y_m x (/ (* (* x x) y_m) t)) t) y_m) t))
(* z y_m))
x))))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = fma((((t / y_m) - tanh((x / y_m))) * y_m), z, x);
double tmp;
if (x <= -3.2e+72) {
tmp = t_1;
} else if (x <= 1.7e+83) {
tmp = fma(((tanh((t / y_m)) - (x / y_m)) * z), y_m, x);
} else if (x <= 1.85e+151) {
tmp = t_1;
} else {
tmp = ((1.0 / (((fma(y_m, x, (((x * x) * y_m) / t)) / t) + y_m) / t)) * (z * y_m)) + x;
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = fma(Float64(Float64(Float64(t / y_m) - tanh(Float64(x / y_m))) * y_m), z, x) tmp = 0.0 if (x <= -3.2e+72) tmp = t_1; elseif (x <= 1.7e+83) tmp = fma(Float64(Float64(tanh(Float64(t / y_m)) - Float64(x / y_m)) * z), y_m, x); elseif (x <= 1.85e+151) tmp = t_1; else tmp = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(y_m, x, Float64(Float64(Float64(x * x) * y_m) / t)) / t) + y_m) / t)) * Float64(z * y_m)) + x); end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[(t / y$95$m), $MachinePrecision] - N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * y$95$m), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[x, -3.2e+72], t$95$1, If[LessEqual[x, 1.7e+83], N[(N[(N[(N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision] - N[(x / y$95$m), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision] * y$95$m + x), $MachinePrecision], If[LessEqual[x, 1.85e+151], t$95$1, N[(N[(N[(1.0 / N[(N[(N[(N[(y$95$m * x + N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\left(\frac{t}{y\_m} - \tanh \left(\frac{x}{y\_m}\right)\right) \cdot y\_m, z, x\right)\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{+72}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(\left(\tanh \left(\frac{t}{y\_m}\right) - \frac{x}{y\_m}\right) \cdot z, y\_m, x\right)\\
\mathbf{elif}\;x \leq 1.85 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{\mathsf{fma}\left(y\_m, x, \frac{\left(x \cdot x\right) \cdot y\_m}{t}\right)}{t} + y\_m}{t}} \cdot \left(z \cdot y\_m\right) + x\\
\end{array}
\end{array}
if x < -3.2000000000000001e72 or 1.6999999999999999e83 < x < 1.8499999999999999e151Initial program 97.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in t around 0
lower-/.f6487.8
Applied rewrites87.8%
if -3.2000000000000001e72 < x < 1.6999999999999999e83Initial program 89.3%
Taylor expanded in y around inf
lower-/.f6480.8
Applied rewrites80.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.8
Applied rewrites85.8%
if 1.8499999999999999e151 < x Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6445.9
Applied rewrites45.9%
Applied rewrites45.9%
Taylor expanded in t around -inf
Applied rewrites94.3%
Final simplification87.5%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(if (<= y_m 2.05e-58)
(+
(* (/ 1.0 (/ (+ (/ (fma y_m x (/ (* (* x x) y_m) t)) t) y_m) t)) (* z y_m))
x)
(if (<= y_m 2e-9)
(+
(*
(/ 1.0 (/ (- (/ (fma (* t t) (/ y_m x) (* t y_m)) (- x)) y_m) x))
(* z y_m))
x)
(fma (- t x) z x))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 2.05e-58) {
tmp = ((1.0 / (((fma(y_m, x, (((x * x) * y_m) / t)) / t) + y_m) / t)) * (z * y_m)) + x;
} else if (y_m <= 2e-9) {
tmp = ((1.0 / (((fma((t * t), (y_m / x), (t * y_m)) / -x) - y_m) / x)) * (z * y_m)) + x;
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 2.05e-58) tmp = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(y_m, x, Float64(Float64(Float64(x * x) * y_m) / t)) / t) + y_m) / t)) * Float64(z * y_m)) + x); elseif (y_m <= 2e-9) tmp = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(Float64(t * t), Float64(y_m / x), Float64(t * y_m)) / Float64(-x)) - y_m) / x)) * Float64(z * y_m)) + x); else tmp = fma(Float64(t - x), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 2.05e-58], N[(N[(N[(1.0 / N[(N[(N[(N[(y$95$m * x + N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y$95$m, 2e-9], N[(N[(N[(1.0 / N[(N[(N[(N[(N[(t * t), $MachinePrecision] * N[(y$95$m / x), $MachinePrecision] + N[(t * y$95$m), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision] - y$95$m), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 2.05 \cdot 10^{-58}:\\
\;\;\;\;\frac{1}{\frac{\frac{\mathsf{fma}\left(y\_m, x, \frac{\left(x \cdot x\right) \cdot y\_m}{t}\right)}{t} + y\_m}{t}} \cdot \left(z \cdot y\_m\right) + x\\
\mathbf{elif}\;y\_m \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{\frac{\frac{\mathsf{fma}\left(t \cdot t, \frac{y\_m}{x}, t \cdot y\_m\right)}{-x} - y\_m}{x}} \cdot \left(z \cdot y\_m\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 2.05000000000000014e-58Initial program 96.7%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6444.2
Applied rewrites44.2%
Applied rewrites44.2%
Taylor expanded in t around -inf
Applied rewrites65.3%
if 2.05000000000000014e-58 < y < 2.00000000000000012e-9Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6444.1
Applied rewrites44.1%
Applied rewrites43.9%
Taylor expanded in x around -inf
Applied rewrites78.2%
if 2.00000000000000012e-9 < y Initial program 82.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6483.4
Applied rewrites83.4%
Final simplification70.6%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(if (<= y_m 4.2e-12)
(+
(* (/ 1.0 (/ (+ (/ (fma y_m x (/ (* (* x x) y_m) t)) t) y_m) t)) (* z y_m))
x)
(fma (- t x) z x)))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 4.2e-12) {
tmp = ((1.0 / (((fma(y_m, x, (((x * x) * y_m) / t)) / t) + y_m) / t)) * (z * y_m)) + x;
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 4.2e-12) tmp = Float64(Float64(Float64(1.0 / Float64(Float64(Float64(fma(y_m, x, Float64(Float64(Float64(x * x) * y_m) / t)) / t) + y_m) / t)) * Float64(z * y_m)) + x); else tmp = fma(Float64(t - x), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 4.2e-12], N[(N[(N[(1.0 / N[(N[(N[(N[(y$95$m * x + N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + y$95$m), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 4.2 \cdot 10^{-12}:\\
\;\;\;\;\frac{1}{\frac{\frac{\mathsf{fma}\left(y\_m, x, \frac{\left(x \cdot x\right) \cdot y\_m}{t}\right)}{t} + y\_m}{t}} \cdot \left(z \cdot y\_m\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 4.19999999999999988e-12Initial program 96.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6444.4
Applied rewrites44.4%
Applied rewrites44.4%
Taylor expanded in t around -inf
Applied rewrites64.5%
if 4.19999999999999988e-12 < y Initial program 82.3%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6482.3
Applied rewrites82.3%
Final simplification69.4%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 7.2e-60) (fma (* (/ t x) x) z x) (fma (- t x) z x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 7.2e-60) {
tmp = fma(((t / x) * x), z, x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 7.2e-60) tmp = fma(Float64(Float64(t / x) * x), z, x); else tmp = fma(Float64(t - x), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 7.2e-60], N[(N[(N[(t / x), $MachinePrecision] * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 7.2 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{x} \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 7.2e-60Initial program 96.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6456.1
Applied rewrites56.1%
Taylor expanded in x around inf
Applied rewrites55.5%
Taylor expanded in t around inf
Applied rewrites62.4%
if 7.2e-60 < y Initial program 84.3%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6477.9
Applied rewrites77.9%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (let* ((t_1 (* (- t x) z))) (if (<= z -1.55e+25) t_1 (if (<= z 0.052) (fma (- x) z x) t_1))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = (t - x) * z;
double tmp;
if (z <= -1.55e+25) {
tmp = t_1;
} else if (z <= 0.052) {
tmp = fma(-x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(t - x) * z) tmp = 0.0 if (z <= -1.55e+25) tmp = t_1; elseif (z <= 0.052) tmp = fma(Float64(-x), z, x); else tmp = t_1; end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.55e+25], t$95$1, If[LessEqual[z, 0.052], N[((-x) * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot z\\
\mathbf{if}\;z \leq -1.55 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 0.052:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.5499999999999999e25 or 0.0519999999999999976 < z Initial program 86.1%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6446.0
Applied rewrites46.0%
Taylor expanded in z around inf
Applied rewrites45.9%
if -1.5499999999999999e25 < z < 0.0519999999999999976Initial program 98.6%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6477.0
Applied rewrites77.0%
Taylor expanded in t around 0
Applied rewrites82.5%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= t -2.35e-119) (* z t) (if (<= t 4.2e-113) (* (- x) z) (* z t))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (t <= -2.35e-119) {
tmp = z * t;
} else if (t <= 4.2e-113) {
tmp = -x * z;
} else {
tmp = z * t;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-2.35d-119)) then
tmp = z * t
else if (t <= 4.2d-113) then
tmp = -x * z
else
tmp = z * t
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
double tmp;
if (t <= -2.35e-119) {
tmp = z * t;
} else if (t <= 4.2e-113) {
tmp = -x * z;
} else {
tmp = z * t;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z, t): tmp = 0 if t <= -2.35e-119: tmp = z * t elif t <= 4.2e-113: tmp = -x * z else: tmp = z * t return tmp
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (t <= -2.35e-119) tmp = Float64(z * t); elseif (t <= 4.2e-113) tmp = Float64(Float64(-x) * z); else tmp = Float64(z * t); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z, t) tmp = 0.0; if (t <= -2.35e-119) tmp = z * t; elseif (t <= 4.2e-113) tmp = -x * z; else tmp = z * t; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[t, -2.35e-119], N[(z * t), $MachinePrecision], If[LessEqual[t, 4.2e-113], N[((-x) * z), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.35 \cdot 10^{-119}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;t \leq 4.2 \cdot 10^{-113}:\\
\;\;\;\;\left(-x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if t < -2.35000000000000001e-119 or 4.2e-113 < t Initial program 93.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6459.8
Applied rewrites59.8%
Taylor expanded in t around inf
Applied rewrites23.1%
if -2.35000000000000001e-119 < t < 4.2e-113Initial program 91.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6470.1
Applied rewrites70.1%
Taylor expanded in z around inf
Applied rewrites28.2%
Taylor expanded in t around 0
Applied rewrites24.3%
Final simplification23.5%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 1.05e-10) (fma (- x) z x) (fma (- t x) z x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 1.05e-10) {
tmp = fma(-x, z, x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 1.05e-10) tmp = fma(Float64(-x), z, x); else tmp = fma(Float64(t - x), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 1.05e-10], N[((-x) * z + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 1.05 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 1.05e-10Initial program 96.9%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.2
Applied rewrites55.2%
Taylor expanded in t around 0
Applied rewrites53.1%
if 1.05e-10 < y Initial program 82.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6483.4
Applied rewrites83.4%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (* (- t x) z))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return (t - x) * z;
}
y_m = abs(y)
real(8) function code(x, y_m, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (t - x) * z
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
return (t - x) * z;
}
y_m = math.fabs(y) def code(x, y_m, z, t): return (t - x) * z
y_m = abs(y) function code(x, y_m, z, t) return Float64(Float64(t - x) * z) end
y_m = abs(y); function tmp = code(x, y_m, z, t) tmp = (t - x) * z; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\left(t - x\right) \cdot z
\end{array}
Initial program 92.9%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6462.8
Applied rewrites62.8%
Taylor expanded in z around inf
Applied rewrites27.1%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (* z t))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return z * t;
}
y_m = abs(y)
real(8) function code(x, y_m, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t
code = z * t
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
return z * t;
}
y_m = math.fabs(y) def code(x, y_m, z, t): return z * t
y_m = abs(y) function code(x, y_m, z, t) return Float64(z * t) end
y_m = abs(y); function tmp = code(x, y_m, z, t) tmp = z * t; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := N[(z * t), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
z \cdot t
\end{array}
Initial program 92.9%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6462.8
Applied rewrites62.8%
Taylor expanded in t around inf
Applied rewrites18.4%
Final simplification18.4%
(FPCore (x y z t) :precision binary64 (+ 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)))));
}
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
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := 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]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2024270
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))