
(FPCore (c_p c_n t s)
:precision binary64
(let* ((t_1 (/ 1.0 (+ 1.0 (exp (- t))))) (t_2 (/ 1.0 (+ 1.0 (exp (- s))))))
(/
(* (pow t_2 c_p) (pow (- 1.0 t_2) c_n))
(* (pow t_1 c_p) (pow (- 1.0 t_1) c_n)))))
double code(double c_p, double c_n, double t, double s) {
double t_1 = 1.0 / (1.0 + exp(-t));
double t_2 = 1.0 / (1.0 + exp(-s));
return (pow(t_2, c_p) * pow((1.0 - t_2), c_n)) / (pow(t_1, c_p) * pow((1.0 - t_1), c_n));
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
real(8) :: t_1
real(8) :: t_2
t_1 = 1.0d0 / (1.0d0 + exp(-t))
t_2 = 1.0d0 / (1.0d0 + exp(-s))
code = ((t_2 ** c_p) * ((1.0d0 - t_2) ** c_n)) / ((t_1 ** c_p) * ((1.0d0 - t_1) ** c_n))
end function
public static double code(double c_p, double c_n, double t, double s) {
double t_1 = 1.0 / (1.0 + Math.exp(-t));
double t_2 = 1.0 / (1.0 + Math.exp(-s));
return (Math.pow(t_2, c_p) * Math.pow((1.0 - t_2), c_n)) / (Math.pow(t_1, c_p) * Math.pow((1.0 - t_1), c_n));
}
def code(c_p, c_n, t, s): t_1 = 1.0 / (1.0 + math.exp(-t)) t_2 = 1.0 / (1.0 + math.exp(-s)) return (math.pow(t_2, c_p) * math.pow((1.0 - t_2), c_n)) / (math.pow(t_1, c_p) * math.pow((1.0 - t_1), c_n))
function code(c_p, c_n, t, s) t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-t)))) t_2 = Float64(1.0 / Float64(1.0 + exp(Float64(-s)))) return Float64(Float64((t_2 ^ c_p) * (Float64(1.0 - t_2) ^ c_n)) / Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n))) end
function tmp = code(c_p, c_n, t, s) t_1 = 1.0 / (1.0 + exp(-t)); t_2 = 1.0 / (1.0 + exp(-s)); tmp = ((t_2 ^ c_p) * ((1.0 - t_2) ^ c_n)) / ((t_1 ^ c_p) * ((1.0 - t_1) ^ c_n)); end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[t$95$2, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$2), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{1}{1 + e^{-t}}\\
t_2 := \frac{1}{1 + e^{-s}}\\
\frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c_p c_n t s)
:precision binary64
(let* ((t_1 (/ 1.0 (+ 1.0 (exp (- t))))) (t_2 (/ 1.0 (+ 1.0 (exp (- s))))))
(/
(* (pow t_2 c_p) (pow (- 1.0 t_2) c_n))
(* (pow t_1 c_p) (pow (- 1.0 t_1) c_n)))))
double code(double c_p, double c_n, double t, double s) {
double t_1 = 1.0 / (1.0 + exp(-t));
double t_2 = 1.0 / (1.0 + exp(-s));
return (pow(t_2, c_p) * pow((1.0 - t_2), c_n)) / (pow(t_1, c_p) * pow((1.0 - t_1), c_n));
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
real(8) :: t_1
real(8) :: t_2
t_1 = 1.0d0 / (1.0d0 + exp(-t))
t_2 = 1.0d0 / (1.0d0 + exp(-s))
code = ((t_2 ** c_p) * ((1.0d0 - t_2) ** c_n)) / ((t_1 ** c_p) * ((1.0d0 - t_1) ** c_n))
end function
public static double code(double c_p, double c_n, double t, double s) {
double t_1 = 1.0 / (1.0 + Math.exp(-t));
double t_2 = 1.0 / (1.0 + Math.exp(-s));
return (Math.pow(t_2, c_p) * Math.pow((1.0 - t_2), c_n)) / (Math.pow(t_1, c_p) * Math.pow((1.0 - t_1), c_n));
}
def code(c_p, c_n, t, s): t_1 = 1.0 / (1.0 + math.exp(-t)) t_2 = 1.0 / (1.0 + math.exp(-s)) return (math.pow(t_2, c_p) * math.pow((1.0 - t_2), c_n)) / (math.pow(t_1, c_p) * math.pow((1.0 - t_1), c_n))
function code(c_p, c_n, t, s) t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-t)))) t_2 = Float64(1.0 / Float64(1.0 + exp(Float64(-s)))) return Float64(Float64((t_2 ^ c_p) * (Float64(1.0 - t_2) ^ c_n)) / Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n))) end
function tmp = code(c_p, c_n, t, s) t_1 = 1.0 / (1.0 + exp(-t)); t_2 = 1.0 / (1.0 + exp(-s)); tmp = ((t_2 ^ c_p) * ((1.0 - t_2) ^ c_n)) / ((t_1 ^ c_p) * ((1.0 - t_1) ^ c_n)); end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[t$95$2, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$2), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{1}{1 + e^{-t}}\\
t_2 := \frac{1}{1 + e^{-s}}\\
\frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}
\end{array}
\end{array}
(FPCore (c_p c_n t s) :precision binary64 (pow (* (+ 1.0 (/ -1.0 (+ 1.0 (exp (- 0.0 s))))) 2.0) c_n))
double code(double c_p, double c_n, double t, double s) {
return pow(((1.0 + (-1.0 / (1.0 + exp((0.0 - s))))) * 2.0), c_n);
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
code = ((1.0d0 + ((-1.0d0) / (1.0d0 + exp((0.0d0 - s))))) * 2.0d0) ** c_n
end function
public static double code(double c_p, double c_n, double t, double s) {
return Math.pow(((1.0 + (-1.0 / (1.0 + Math.exp((0.0 - s))))) * 2.0), c_n);
}
def code(c_p, c_n, t, s): return math.pow(((1.0 + (-1.0 / (1.0 + math.exp((0.0 - s))))) * 2.0), c_n)
function code(c_p, c_n, t, s) return Float64(Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(0.0 - s))))) * 2.0) ^ c_n end
function tmp = code(c_p, c_n, t, s) tmp = ((1.0 + (-1.0 / (1.0 + exp((0.0 - s))))) * 2.0) ^ c_n; end
code[c$95$p_, c$95$n_, t_, s_] := N[Power[N[(N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(0.0 - s), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], c$95$n], $MachinePrecision]
\begin{array}{l}
\\
{\left(\left(1 + \frac{-1}{1 + e^{0 - s}}\right) \cdot 2\right)}^{c\_n}
\end{array}
Initial program 90.7%
Taylor expanded in c_p around 0
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
neg-sub0N/A
--lowering--.f64N/A
pow-lowering-pow.f64N/A
Simplified93.8%
Taylor expanded in t around 0
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
neg-mul-1N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
neg-mul-1N/A
neg-sub0N/A
--lowering--.f64N/A
pow-lowering-pow.f6493.8
Simplified93.8%
div-invN/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
--lowering--.f64N/A
pow-flipN/A
neg-mul-1N/A
pow-unpowN/A
metadata-evalN/A
pow-lowering-pow.f6493.7
Applied egg-rr93.7%
pow-prod-downN/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
--lowering--.f6497.7
Applied egg-rr97.7%
(FPCore (c_p c_n t s)
:precision binary64
(let* ((t_1 (+ (fma (- 0.0 t) (* 0.5 c_p) 1.0) (* t (* c_n -0.5)))))
(if (<= (- 0.0 s) -5e-12)
(pow 0.5 c_n)
(* (* (fma (- 0.0 t) (fma c_p 0.5 (* c_n -0.5)) 1.0) t_1) (/ 1.0 t_1)))))
double code(double c_p, double c_n, double t, double s) {
double t_1 = fma((0.0 - t), (0.5 * c_p), 1.0) + (t * (c_n * -0.5));
double tmp;
if ((0.0 - s) <= -5e-12) {
tmp = pow(0.5, c_n);
} else {
tmp = (fma((0.0 - t), fma(c_p, 0.5, (c_n * -0.5)), 1.0) * t_1) * (1.0 / t_1);
}
return tmp;
}
function code(c_p, c_n, t, s) t_1 = Float64(fma(Float64(0.0 - t), Float64(0.5 * c_p), 1.0) + Float64(t * Float64(c_n * -0.5))) tmp = 0.0 if (Float64(0.0 - s) <= -5e-12) tmp = 0.5 ^ c_n; else tmp = Float64(Float64(fma(Float64(0.0 - t), fma(c_p, 0.5, Float64(c_n * -0.5)), 1.0) * t_1) * Float64(1.0 / t_1)); end return tmp end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(N[(N[(0.0 - t), $MachinePrecision] * N[(0.5 * c$95$p), $MachinePrecision] + 1.0), $MachinePrecision] + N[(t * N[(c$95$n * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(0.0 - s), $MachinePrecision], -5e-12], N[Power[0.5, c$95$n], $MachinePrecision], N[(N[(N[(N[(0.0 - t), $MachinePrecision] * N[(c$95$p * 0.5 + N[(c$95$n * -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$1), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(0 - t, 0.5 \cdot c\_p, 1\right) + t \cdot \left(c\_n \cdot -0.5\right)\\
\mathbf{if}\;0 - s \leq -5 \cdot 10^{-12}:\\
\;\;\;\;{0.5}^{c\_n}\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0 - t, \mathsf{fma}\left(c\_p, 0.5, c\_n \cdot -0.5\right), 1\right) \cdot t\_1\right) \cdot \frac{1}{t\_1}\\
\end{array}
\end{array}
if (neg.f64 s) < -4.9999999999999997e-12Initial program 47.2%
Taylor expanded in c_n around 0
Simplified82.5%
Taylor expanded in c_p around 0
pow-lowering-pow.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
neg-mul-1N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
neg-mul-1N/A
neg-sub0N/A
--lowering--.f6494.2
Simplified94.2%
Taylor expanded in s around 0
pow-lowering-pow.f6494.3
Simplified94.3%
if -4.9999999999999997e-12 < (neg.f64 s) Initial program 93.8%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f6494.7
Simplified94.7%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.5
Simplified97.5%
+-commutativeN/A
distribute-rgt-inN/A
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
*-commutativeN/A
sub0-negN/A
distribute-lft-neg-outN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6497.5
Applied egg-rr97.5%
flip-+N/A
div-invN/A
*-lowering-*.f64N/A
Applied egg-rr97.5%
Final simplification97.3%
(FPCore (c_p c_n t s)
:precision binary64
(let* ((t_1 (+ (fma (- 0.0 t) (* 0.5 c_p) 1.0) (* t (* c_n -0.5)))))
(if (<= (- 0.0 s) -1e+38)
(* t (* c_p -0.5))
(* (* (fma (- 0.0 t) (fma c_p 0.5 (* c_n -0.5)) 1.0) t_1) (/ 1.0 t_1)))))
double code(double c_p, double c_n, double t, double s) {
double t_1 = fma((0.0 - t), (0.5 * c_p), 1.0) + (t * (c_n * -0.5));
double tmp;
if ((0.0 - s) <= -1e+38) {
tmp = t * (c_p * -0.5);
} else {
tmp = (fma((0.0 - t), fma(c_p, 0.5, (c_n * -0.5)), 1.0) * t_1) * (1.0 / t_1);
}
return tmp;
}
function code(c_p, c_n, t, s) t_1 = Float64(fma(Float64(0.0 - t), Float64(0.5 * c_p), 1.0) + Float64(t * Float64(c_n * -0.5))) tmp = 0.0 if (Float64(0.0 - s) <= -1e+38) tmp = Float64(t * Float64(c_p * -0.5)); else tmp = Float64(Float64(fma(Float64(0.0 - t), fma(c_p, 0.5, Float64(c_n * -0.5)), 1.0) * t_1) * Float64(1.0 / t_1)); end return tmp end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(N[(N[(0.0 - t), $MachinePrecision] * N[(0.5 * c$95$p), $MachinePrecision] + 1.0), $MachinePrecision] + N[(t * N[(c$95$n * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(0.0 - s), $MachinePrecision], -1e+38], N[(t * N[(c$95$p * -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.0 - t), $MachinePrecision] * N[(c$95$p * 0.5 + N[(c$95$n * -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$1), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(0 - t, 0.5 \cdot c\_p, 1\right) + t \cdot \left(c\_n \cdot -0.5\right)\\
\mathbf{if}\;0 - s \leq -1 \cdot 10^{+38}:\\
\;\;\;\;t \cdot \left(c\_p \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0 - t, \mathsf{fma}\left(c\_p, 0.5, c\_n \cdot -0.5\right), 1\right) \cdot t\_1\right) \cdot \frac{1}{t\_1}\\
\end{array}
\end{array}
if (neg.f64 s) < -9.99999999999999977e37Initial program 0.0%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f640.0
Simplified0.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f643.1
Simplified3.1%
Taylor expanded in c_p around inf
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6473.1
Simplified73.1%
if -9.99999999999999977e37 < (neg.f64 s) Initial program 93.3%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f6494.1
Simplified94.1%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.2
Simplified97.2%
+-commutativeN/A
distribute-rgt-inN/A
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
*-commutativeN/A
sub0-negN/A
distribute-lft-neg-outN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6497.2
Applied egg-rr97.2%
flip-+N/A
div-invN/A
*-lowering-*.f64N/A
Applied egg-rr97.2%
Final simplification96.6%
(FPCore (c_p c_n t s) :precision binary64 (if (<= s 5600.0) (fma (* c_n t) 0.5 (fma (- 0.0 t) (* 0.5 c_p) 1.0)) (* t (* c_p -0.5))))
double code(double c_p, double c_n, double t, double s) {
double tmp;
if (s <= 5600.0) {
tmp = fma((c_n * t), 0.5, fma((0.0 - t), (0.5 * c_p), 1.0));
} else {
tmp = t * (c_p * -0.5);
}
return tmp;
}
function code(c_p, c_n, t, s) tmp = 0.0 if (s <= 5600.0) tmp = fma(Float64(c_n * t), 0.5, fma(Float64(0.0 - t), Float64(0.5 * c_p), 1.0)); else tmp = Float64(t * Float64(c_p * -0.5)); end return tmp end
code[c$95$p_, c$95$n_, t_, s_] := If[LessEqual[s, 5600.0], N[(N[(c$95$n * t), $MachinePrecision] * 0.5 + N[(N[(0.0 - t), $MachinePrecision] * N[(0.5 * c$95$p), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(t * N[(c$95$p * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 5600:\\
\;\;\;\;\mathsf{fma}\left(c\_n \cdot t, 0.5, \mathsf{fma}\left(0 - t, 0.5 \cdot c\_p, 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(c\_p \cdot -0.5\right)\\
\end{array}
\end{array}
if s < 5600Initial program 93.3%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f6494.1
Simplified94.1%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.2
Simplified97.2%
+-commutativeN/A
distribute-rgt-inN/A
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
*-commutativeN/A
sub0-negN/A
distribute-lft-neg-outN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6497.2
Applied egg-rr97.2%
+-commutativeN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-*l*N/A
metadata-evalN/A
div-invN/A
accelerator-lowering-fma.f64N/A
--lowering--.f64N/A
div-invN/A
metadata-evalN/A
*-lowering-*.f6497.2
Applied egg-rr97.2%
if 5600 < s Initial program 0.0%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f640.0
Simplified0.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f643.1
Simplified3.1%
Taylor expanded in c_p around inf
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6473.1
Simplified73.1%
Final simplification96.6%
(FPCore (c_p c_n t s) :precision binary64 (if (<= s 5600.0) (fma t (* -0.5 (- c_p c_n)) 1.0) (* t (* c_p -0.5))))
double code(double c_p, double c_n, double t, double s) {
double tmp;
if (s <= 5600.0) {
tmp = fma(t, (-0.5 * (c_p - c_n)), 1.0);
} else {
tmp = t * (c_p * -0.5);
}
return tmp;
}
function code(c_p, c_n, t, s) tmp = 0.0 if (s <= 5600.0) tmp = fma(t, Float64(-0.5 * Float64(c_p - c_n)), 1.0); else tmp = Float64(t * Float64(c_p * -0.5)); end return tmp end
code[c$95$p_, c$95$n_, t_, s_] := If[LessEqual[s, 5600.0], N[(t * N[(-0.5 * N[(c$95$p - c$95$n), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(t * N[(c$95$p * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 5600:\\
\;\;\;\;\mathsf{fma}\left(t, -0.5 \cdot \left(c\_p - c\_n\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(c\_p \cdot -0.5\right)\\
\end{array}
\end{array}
if s < 5600Initial program 93.3%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f6494.1
Simplified94.1%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.2
Simplified97.2%
Taylor expanded in t around 0
+-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.2
Simplified97.2%
Taylor expanded in c_p around 0
metadata-evalN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f6497.2
Simplified97.2%
if 5600 < s Initial program 0.0%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f640.0
Simplified0.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f643.1
Simplified3.1%
Taylor expanded in c_p around inf
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6473.1
Simplified73.1%
Final simplification96.6%
(FPCore (c_p c_n t s) :precision binary64 (if (<= s 1000.0) (fma t (* c_p -0.5) 1.0) (* t (* c_p -0.5))))
double code(double c_p, double c_n, double t, double s) {
double tmp;
if (s <= 1000.0) {
tmp = fma(t, (c_p * -0.5), 1.0);
} else {
tmp = t * (c_p * -0.5);
}
return tmp;
}
function code(c_p, c_n, t, s) tmp = 0.0 if (s <= 1000.0) tmp = fma(t, Float64(c_p * -0.5), 1.0); else tmp = Float64(t * Float64(c_p * -0.5)); end return tmp end
code[c$95$p_, c$95$n_, t_, s_] := If[LessEqual[s, 1000.0], N[(t * N[(c$95$p * -0.5), $MachinePrecision] + 1.0), $MachinePrecision], N[(t * N[(c$95$p * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 1000:\\
\;\;\;\;\mathsf{fma}\left(t, c\_p \cdot -0.5, 1\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(c\_p \cdot -0.5\right)\\
\end{array}
\end{array}
if s < 1e3Initial program 93.3%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f6494.1
Simplified94.1%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.2
Simplified97.2%
Taylor expanded in c_n around 0
+-commutativeN/A
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6497.1
Simplified97.1%
if 1e3 < s Initial program 0.0%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f640.0
Simplified0.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f643.1
Simplified3.1%
Taylor expanded in c_p around inf
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6473.1
Simplified73.1%
Final simplification96.5%
(FPCore (c_p c_n t s) :precision binary64 (if (<= s 5600.0) 1.0 (* t (* c_p -0.5))))
double code(double c_p, double c_n, double t, double s) {
double tmp;
if (s <= 5600.0) {
tmp = 1.0;
} else {
tmp = t * (c_p * -0.5);
}
return tmp;
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
real(8) :: tmp
if (s <= 5600.0d0) then
tmp = 1.0d0
else
tmp = t * (c_p * (-0.5d0))
end if
code = tmp
end function
public static double code(double c_p, double c_n, double t, double s) {
double tmp;
if (s <= 5600.0) {
tmp = 1.0;
} else {
tmp = t * (c_p * -0.5);
}
return tmp;
}
def code(c_p, c_n, t, s): tmp = 0 if s <= 5600.0: tmp = 1.0 else: tmp = t * (c_p * -0.5) return tmp
function code(c_p, c_n, t, s) tmp = 0.0 if (s <= 5600.0) tmp = 1.0; else tmp = Float64(t * Float64(c_p * -0.5)); end return tmp end
function tmp_2 = code(c_p, c_n, t, s) tmp = 0.0; if (s <= 5600.0) tmp = 1.0; else tmp = t * (c_p * -0.5); end tmp_2 = tmp; end
code[c$95$p_, c$95$n_, t_, s_] := If[LessEqual[s, 5600.0], 1.0, N[(t * N[(c$95$p * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 5600:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(c\_p \cdot -0.5\right)\\
\end{array}
\end{array}
if s < 5600Initial program 93.3%
Taylor expanded in c_p around 0
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
neg-sub0N/A
--lowering--.f64N/A
pow-lowering-pow.f64N/A
Simplified96.0%
Taylor expanded in c_n around 0
Simplified97.0%
if 5600 < s Initial program 0.0%
Taylor expanded in s around 0
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f640.0
Simplified0.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f643.1
Simplified3.1%
Taylor expanded in c_p around inf
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f6473.1
Simplified73.1%
Final simplification96.3%
(FPCore (c_p c_n t s) :precision binary64 1.0)
double code(double c_p, double c_n, double t, double s) {
return 1.0;
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
code = 1.0d0
end function
public static double code(double c_p, double c_n, double t, double s) {
return 1.0;
}
def code(c_p, c_n, t, s): return 1.0
function code(c_p, c_n, t, s) return 1.0 end
function tmp = code(c_p, c_n, t, s) tmp = 1.0; end
code[c$95$p_, c$95$n_, t_, s_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 90.7%
Taylor expanded in c_p around 0
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
sub-negN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
neg-sub0N/A
--lowering--.f64N/A
pow-lowering-pow.f64N/A
Simplified93.8%
Taylor expanded in c_n around 0
Simplified94.4%
(FPCore (c_p c_n t s) :precision binary64 (* (pow (/ (+ 1.0 (exp (- t))) (+ 1.0 (exp (- s)))) c_p) (pow (/ (+ 1.0 (exp t)) (+ 1.0 (exp s))) c_n)))
double code(double c_p, double c_n, double t, double s) {
return pow(((1.0 + exp(-t)) / (1.0 + exp(-s))), c_p) * pow(((1.0 + exp(t)) / (1.0 + exp(s))), c_n);
}
real(8) function code(c_p, c_n, t, s)
real(8), intent (in) :: c_p
real(8), intent (in) :: c_n
real(8), intent (in) :: t
real(8), intent (in) :: s
code = (((1.0d0 + exp(-t)) / (1.0d0 + exp(-s))) ** c_p) * (((1.0d0 + exp(t)) / (1.0d0 + exp(s))) ** c_n)
end function
public static double code(double c_p, double c_n, double t, double s) {
return Math.pow(((1.0 + Math.exp(-t)) / (1.0 + Math.exp(-s))), c_p) * Math.pow(((1.0 + Math.exp(t)) / (1.0 + Math.exp(s))), c_n);
}
def code(c_p, c_n, t, s): return math.pow(((1.0 + math.exp(-t)) / (1.0 + math.exp(-s))), c_p) * math.pow(((1.0 + math.exp(t)) / (1.0 + math.exp(s))), c_n)
function code(c_p, c_n, t, s) return Float64((Float64(Float64(1.0 + exp(Float64(-t))) / Float64(1.0 + exp(Float64(-s)))) ^ c_p) * (Float64(Float64(1.0 + exp(t)) / Float64(1.0 + exp(s))) ^ c_n)) end
function tmp = code(c_p, c_n, t, s) tmp = (((1.0 + exp(-t)) / (1.0 + exp(-s))) ^ c_p) * (((1.0 + exp(t)) / (1.0 + exp(s))) ^ c_n); end
code[c$95$p_, c$95$n_, t_, s_] := N[(N[Power[N[(N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], c$95$p], $MachinePrecision] * N[Power[N[(N[(1.0 + N[Exp[t], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Exp[s], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{1 + e^{-t}}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(\frac{1 + e^{t}}{1 + e^{s}}\right)}^{c\_n}
\end{array}
herbie shell --seed 2024199
(FPCore (c_p c_n t s)
:name "Harley's example"
:precision binary64
:pre (and (< 0.0 c_p) (< 0.0 c_n))
:alt
(! :herbie-platform default (* (pow (/ (+ 1 (exp (- t))) (+ 1 (exp (- s)))) c_p) (pow (/ (+ 1 (exp t)) (+ 1 (exp s))) c_n)))
(/ (* (pow (/ 1.0 (+ 1.0 (exp (- s)))) c_p) (pow (- 1.0 (/ 1.0 (+ 1.0 (exp (- s))))) c_n)) (* (pow (/ 1.0 (+ 1.0 (exp (- t)))) c_p) (pow (- 1.0 (/ 1.0 (+ 1.0 (exp (- t))))) c_n))))