
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
(FPCore (d1 d2 d3 d4) :precision binary64 (fma (- d2 d3) d1 (* (- d4 d1) d1)))
double code(double d1, double d2, double d3, double d4) {
return fma((d2 - d3), d1, ((d4 - d1) * d1));
}
function code(d1, d2, d3, d4) return fma(Float64(d2 - d3), d1, Float64(Float64(d4 - d1) * d1)) end
code[d1_, d2_, d3_, d4_] := N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(d2 - d3, d1, \left(d4 - d1\right) \cdot d1\right)
\end{array}
Initial program 90.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower--.f6499.2
Applied rewrites99.2%
Final simplification99.2%
(FPCore (d1 d2 d3 d4)
:precision binary64
(if (<= d4 -1.95e-283)
(* (- d2 d1) d1)
(if (<= d4 7e-53)
(* (- (- d3) d1) d1)
(if (<= d4 6.5e+100) (* (- d2 d3) d1) (* (- d4 d3) d1)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= -1.95e-283) {
tmp = (d2 - d1) * d1;
} else if (d4 <= 7e-53) {
tmp = (-d3 - d1) * d1;
} else if (d4 <= 6.5e+100) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d4 <= (-1.95d-283)) then
tmp = (d2 - d1) * d1
else if (d4 <= 7d-53) then
tmp = (-d3 - d1) * d1
else if (d4 <= 6.5d+100) then
tmp = (d2 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= -1.95e-283) {
tmp = (d2 - d1) * d1;
} else if (d4 <= 7e-53) {
tmp = (-d3 - d1) * d1;
} else if (d4 <= 6.5e+100) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d4 <= -1.95e-283: tmp = (d2 - d1) * d1 elif d4 <= 7e-53: tmp = (-d3 - d1) * d1 elif d4 <= 6.5e+100: tmp = (d2 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d4 <= -1.95e-283) tmp = Float64(Float64(d2 - d1) * d1); elseif (d4 <= 7e-53) tmp = Float64(Float64(Float64(-d3) - d1) * d1); elseif (d4 <= 6.5e+100) tmp = Float64(Float64(d2 - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d4 <= -1.95e-283) tmp = (d2 - d1) * d1; elseif (d4 <= 7e-53) tmp = (-d3 - d1) * d1; elseif (d4 <= 6.5e+100) tmp = (d2 - d3) * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -1.95e-283], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 7e-53], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 6.5e+100], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq -1.95 \cdot 10^{-283}:\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\
\mathbf{elif}\;d4 \leq 7 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
\mathbf{elif}\;d4 \leq 6.5 \cdot 10^{+100}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d4 < -1.9500000000000001e-283Initial program 87.2%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in d3 around 0
Applied rewrites55.8%
if -1.9500000000000001e-283 < d4 < 6.99999999999999987e-53Initial program 98.2%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6498.3
Applied rewrites98.3%
Taylor expanded in d2 around 0
Applied rewrites73.6%
if 6.99999999999999987e-53 < d4 < 6.50000000000000001e100Initial program 99.9%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6480.5
Applied rewrites80.5%
Taylor expanded in d1 around 0
Applied rewrites77.0%
if 6.50000000000000001e100 < d4 Initial program 84.6%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6487.4
Applied rewrites87.4%
Taylor expanded in d2 around 0
Applied rewrites66.5%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* (- d2 d1) d1)))
(if (<= d1 -1.6e+124)
t_0
(if (<= d1 3.2e+142) (* (- (+ d4 d2) d3) d1) t_0))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d1) * d1;
double tmp;
if (d1 <= -1.6e+124) {
tmp = t_0;
} else if (d1 <= 3.2e+142) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = (d2 - d1) * d1
if (d1 <= (-1.6d+124)) then
tmp = t_0
else if (d1 <= 3.2d+142) then
tmp = ((d4 + d2) - d3) * d1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d1) * d1;
double tmp;
if (d1 <= -1.6e+124) {
tmp = t_0;
} else if (d1 <= 3.2e+142) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = (d2 - d1) * d1 tmp = 0 if d1 <= -1.6e+124: tmp = t_0 elif d1 <= 3.2e+142: tmp = ((d4 + d2) - d3) * d1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(Float64(d2 - d1) * d1) tmp = 0.0 if (d1 <= -1.6e+124) tmp = t_0; elseif (d1 <= 3.2e+142) tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = (d2 - d1) * d1; tmp = 0.0; if (d1 <= -1.6e+124) tmp = t_0; elseif (d1 <= 3.2e+142) tmp = ((d4 + d2) - d3) * d1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -1.6e+124], t$95$0, If[LessEqual[d1, 3.2e+142], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(d2 - d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -1.6 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d1 \leq 3.2 \cdot 10^{+142}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d1 < -1.59999999999999996e124 or 3.20000000000000005e142 < d1 Initial program 64.7%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6492.8
Applied rewrites92.8%
Taylor expanded in d3 around 0
Applied rewrites92.8%
if -1.59999999999999996e124 < d1 < 3.20000000000000005e142Initial program 99.9%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6494.4
Applied rewrites94.4%
(FPCore (d1 d2 d3 d4) :precision binary64 (let* ((t_0 (* (- d3) d1))) (if (<= d3 -1.02e+113) t_0 (if (<= d3 4.1e+52) (* (+ d4 d2) d1) t_0))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = -d3 * d1;
double tmp;
if (d3 <= -1.02e+113) {
tmp = t_0;
} else if (d3 <= 4.1e+52) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = -d3 * d1
if (d3 <= (-1.02d+113)) then
tmp = t_0
else if (d3 <= 4.1d+52) then
tmp = (d4 + d2) * d1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = -d3 * d1;
double tmp;
if (d3 <= -1.02e+113) {
tmp = t_0;
} else if (d3 <= 4.1e+52) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = -d3 * d1 tmp = 0 if d3 <= -1.02e+113: tmp = t_0 elif d3 <= 4.1e+52: tmp = (d4 + d2) * d1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(Float64(-d3) * d1) tmp = 0.0 if (d3 <= -1.02e+113) tmp = t_0; elseif (d3 <= 4.1e+52) tmp = Float64(Float64(d4 + d2) * d1); else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = -d3 * d1; tmp = 0.0; if (d3 <= -1.02e+113) tmp = t_0; elseif (d3 <= 4.1e+52) tmp = (d4 + d2) * d1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d3) * d1), $MachinePrecision]}, If[LessEqual[d3, -1.02e+113], t$95$0, If[LessEqual[d3, 4.1e+52], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-d3\right) \cdot d1\\
\mathbf{if}\;d3 \leq -1.02 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d3 \leq 4.1 \cdot 10^{+52}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d3 < -1.02000000000000002e113 or 4.1e52 < d3 Initial program 86.8%
Taylor expanded in d3 around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6470.8
Applied rewrites70.8%
if -1.02000000000000002e113 < d3 < 4.1e52Initial program 93.0%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6478.0
Applied rewrites78.0%
Taylor expanded in d3 around 0
Applied rewrites72.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d4 -1.95e-283) (* d1 d2) (if (<= d4 9.5e+28) (* (- d3) d1) (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= -1.95e-283) {
tmp = d1 * d2;
} else if (d4 <= 9.5e+28) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d4 <= (-1.95d-283)) then
tmp = d1 * d2
else if (d4 <= 9.5d+28) then
tmp = -d3 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= -1.95e-283) {
tmp = d1 * d2;
} else if (d4 <= 9.5e+28) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d4 <= -1.95e-283: tmp = d1 * d2 elif d4 <= 9.5e+28: tmp = -d3 * d1 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d4 <= -1.95e-283) tmp = Float64(d1 * d2); elseif (d4 <= 9.5e+28) tmp = Float64(Float64(-d3) * d1); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d4 <= -1.95e-283) tmp = d1 * d2; elseif (d4 <= 9.5e+28) tmp = -d3 * d1; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -1.95e-283], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 9.5e+28], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq -1.95 \cdot 10^{-283}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d4 \leq 9.5 \cdot 10^{+28}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d4 < -1.9500000000000001e-283Initial program 87.2%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6430.8
Applied rewrites30.8%
if -1.9500000000000001e-283 < d4 < 9.49999999999999927e28Initial program 98.5%
Taylor expanded in d3 around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6455.7
Applied rewrites55.7%
if 9.49999999999999927e28 < d4 Initial program 88.9%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6459.6
Applied rewrites59.6%
Final simplification43.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.5e+77) (* d1 d2) (if (<= d2 -7.5e-277) (* (- d1) d1) (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.5e+77) {
tmp = d1 * d2;
} else if (d2 <= -7.5e-277) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-5.5d+77)) then
tmp = d1 * d2
else if (d2 <= (-7.5d-277)) then
tmp = -d1 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.5e+77) {
tmp = d1 * d2;
} else if (d2 <= -7.5e-277) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.5e+77: tmp = d1 * d2 elif d2 <= -7.5e-277: tmp = -d1 * d1 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.5e+77) tmp = Float64(d1 * d2); elseif (d2 <= -7.5e-277) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.5e+77) tmp = d1 * d2; elseif (d2 <= -7.5e-277) tmp = -d1 * d1; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.5e+77], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -7.5e-277], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.5 \cdot 10^{+77}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -7.5 \cdot 10^{-277}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -5.50000000000000036e77Initial program 85.0%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6469.3
Applied rewrites69.3%
if -5.50000000000000036e77 < d2 < -7.49999999999999971e-277Initial program 91.7%
Taylor expanded in d1 around inf
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6436.4
Applied rewrites36.4%
if -7.49999999999999971e-277 < d2 Initial program 91.9%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6433.0
Applied rewrites33.0%
Final simplification40.8%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d4 5.2e+26) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= 5.2e+26) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d4 <= 5.2d+26) then
tmp = ((d2 - d3) - d1) * d1
else
tmp = ((d4 + d2) - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= 5.2e+26) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d4 <= 5.2e+26: tmp = ((d2 - d3) - d1) * d1 else: tmp = ((d4 + d2) - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d4 <= 5.2e+26) tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1); else tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d4 <= 5.2e+26) tmp = ((d2 - d3) - d1) * d1; else tmp = ((d4 + d2) - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 5.2e+26], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 5.2 \cdot 10^{+26}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if d4 < 5.20000000000000004e26Initial program 91.0%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6483.7
Applied rewrites83.7%
if 5.20000000000000004e26 < d4 Initial program 89.1%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6491.0
Applied rewrites91.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.6e-6) (* (- d2 d3) d1) (* (- d4 d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e-6) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-5.6d-6)) then
tmp = (d2 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e-6) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.6e-6: tmp = (d2 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.6e-6) tmp = Float64(Float64(d2 - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.6e-6) tmp = (d2 - d3) * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.6e-6], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.6 \cdot 10^{-6}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -5.59999999999999975e-6Initial program 89.3%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6489.4
Applied rewrites89.4%
Taylor expanded in d1 around 0
Applied rewrites74.4%
if -5.59999999999999975e-6 < d2 Initial program 91.0%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6481.8
Applied rewrites81.8%
Taylor expanded in d2 around 0
Applied rewrites66.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.1e-7) (* (- d2 d1) d1) (* (- d4 d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.1e-7) {
tmp = (d2 - d1) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.1d-7)) then
tmp = (d2 - d1) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.1e-7) {
tmp = (d2 - d1) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.1e-7: tmp = (d2 - d1) * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.1e-7) tmp = Float64(Float64(d2 - d1) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -1.1e-7) tmp = (d2 - d1) * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.1e-7], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.1 \cdot 10^{-7}:\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.1000000000000001e-7Initial program 89.3%
Taylor expanded in d4 around 0
associate--r+N/A
distribute-lft-out--N/A
unpow2N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6489.4
Applied rewrites89.4%
Taylor expanded in d3 around 0
Applied rewrites69.3%
if -1.1000000000000001e-7 < d2 Initial program 91.0%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6481.8
Applied rewrites81.8%
Taylor expanded in d2 around 0
Applied rewrites66.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.8e+78) (* (+ d4 d2) d1) (* (- d4 d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.8e+78) {
tmp = (d4 + d2) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-5.8d+78)) then
tmp = (d4 + d2) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.8e+78) {
tmp = (d4 + d2) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.8e+78: tmp = (d4 + d2) * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.8e+78) tmp = Float64(Float64(d4 + d2) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.8e+78) tmp = (d4 + d2) * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.8e+78], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.8 \cdot 10^{+78}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -5.80000000000000034e78Initial program 85.0%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6489.4
Applied rewrites89.4%
Taylor expanded in d3 around 0
Applied rewrites81.4%
if -5.80000000000000034e78 < d2 Initial program 91.8%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6481.1
Applied rewrites81.1%
Taylor expanded in d2 around 0
Applied rewrites64.6%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -8.2e-13) (* d1 d2) (* d4 d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -8.2e-13) {
tmp = d1 * d2;
} else {
tmp = d4 * d1;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-8.2d-13)) then
tmp = d1 * d2
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -8.2e-13) {
tmp = d1 * d2;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -8.2e-13: tmp = d1 * d2 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -8.2e-13) tmp = Float64(d1 * d2); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -8.2e-13) tmp = d1 * d2; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -8.2e-13], N[(d1 * d2), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -8.2000000000000004e-13Initial program 88.5%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6452.9
Applied rewrites52.9%
if -8.2000000000000004e-13 < d2 Initial program 91.4%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6436.2
Applied rewrites36.2%
Final simplification40.8%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d2))
double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * d2
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
def code(d1, d2, d3, d4): return d1 * d2
function code(d1, d2, d3, d4) return Float64(d1 * d2) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * d2; end
code[d1_, d2_, d3_, d4_] := N[(d1 * d2), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot d2
\end{array}
Initial program 90.6%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6431.3
Applied rewrites31.3%
Final simplification31.3%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * (((d2 - d3) + d4) - d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
def code(d1, d2, d3, d4): return d1 * (((d2 - d3) + d4) - d1)
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1)) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * (((d2 - d3) + d4) - d1); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
\end{array}
herbie shell --seed 2024288
(FPCore (d1 d2 d3 d4)
:name "FastMath dist4"
:precision binary64
:alt
(! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
(- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))