
(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}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (fma d2 d1 (* (- (- d4 d1) d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
return fma(d2, d1, (((d4 - d1) - d3) * d1));
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) return fma(d2, d1, Float64(Float64(Float64(d4 - d1) - d3) * d1)) end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := N[(d2 * d1 + N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\mathsf{fma}\left(d2, d1, \left(\left(d4 - d1\right) - d3\right) \cdot d1\right)
\end{array}
Initial program 87.1%
lift--.f64N/A
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
associate--l-N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64N/A
associate-+l-N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6497.6
Applied rewrites97.6%
Final simplification97.6%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= (- (+ (* d4 d1) (- (* d1 d2) (* d3 d1))) (* d1 d1)) INFINITY) (fma (- d2 d3) d1 (* (- d4 d1) d1)) (* (- (- d4 d3) d1) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((((d4 * d1) + ((d1 * d2) - (d3 * d1))) - (d1 * d1)) <= ((double) INFINITY)) {
tmp = fma((d2 - d3), d1, ((d4 - d1) * d1));
} else {
tmp = ((d4 - d3) - d1) * d1;
}
return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (Float64(Float64(Float64(d4 * d1) + Float64(Float64(d1 * d2) - Float64(d3 * d1))) - Float64(d1 * d1)) <= Inf) tmp = fma(Float64(d2 - d3), d1, Float64(Float64(d4 - d1) * d1)); else tmp = Float64(Float64(Float64(d4 - d3) - d1) * d1); end return tmp end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[N[(N[(N[(d4 * d1), $MachinePrecision] + N[(N[(d1 * d2), $MachinePrecision] - N[(d3 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(d4 \cdot d1 + \left(d1 \cdot d2 - d3 \cdot d1\right)\right) - d1 \cdot d1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(d2 - d3, d1, \left(d4 - d1\right) \cdot d1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\
\end{array}
\end{array}
if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0Initial program 100.0%
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--.f64100.0
Applied rewrites100.0%
if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) Initial program 0.0%
Taylor expanded in d2 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--.f6481.8
Applied rewrites81.8%
Final simplification97.6%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* (- (- d3) d1) d1)))
(if (<= d1 -1.3e+140)
t_0
(if (<= d1 4.4e+145) (* (- (+ d4 d2) d3) d1) t_0))))assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double t_0 = (-d3 - d1) * d1;
double tmp;
if (d1 <= -1.3e+140) {
tmp = t_0;
} else if (d1 <= 4.4e+145) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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) * d1
if (d1 <= (-1.3d+140)) then
tmp = t_0
else if (d1 <= 4.4d+145) then
tmp = ((d4 + d2) - d3) * d1
else
tmp = t_0
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = (-d3 - d1) * d1;
double tmp;
if (d1 <= -1.3e+140) {
tmp = t_0;
} else if (d1 <= 4.4e+145) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = t_0;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): t_0 = (-d3 - d1) * d1 tmp = 0 if d1 <= -1.3e+140: tmp = t_0 elif d1 <= 4.4e+145: tmp = ((d4 + d2) - d3) * d1 else: tmp = t_0 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) t_0 = Float64(Float64(Float64(-d3) - d1) * d1) tmp = 0.0 if (d1 <= -1.3e+140) tmp = t_0; elseif (d1 <= 4.4e+145) tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); else tmp = t_0; end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
t_0 = (-d3 - d1) * d1;
tmp = 0.0;
if (d1 <= -1.3e+140)
tmp = t_0;
elseif (d1 <= 4.4e+145)
tmp = ((d4 + d2) - d3) * d1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -1.3e+140], t$95$0, If[LessEqual[d1, 4.4e+145], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(\left(-d3\right) - d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -1.3 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d1 \leq 4.4 \cdot 10^{+145}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d1 < -1.3000000000000001e140 or 4.40000000000000017e145 < d1 Initial program 52.2%
Taylor expanded in d2 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.5
Applied rewrites92.5%
Taylor expanded in d4 around 0
Applied rewrites88.1%
if -1.3000000000000001e140 < d1 < 4.40000000000000017e145Initial program 99.4%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6493.2
Applied rewrites93.2%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -6e+50) (* (- d2 d3) d1) (if (<= d2 -4.6e-299) (* (- (- d3) d1) d1) (* (- d4 d3) d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6e+50) {
tmp = (d2 - d3) * d1;
} else if (d2 <= -4.6e-299) {
tmp = (-d3 - d1) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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 <= (-6d+50)) then
tmp = (d2 - d3) * d1
else if (d2 <= (-4.6d-299)) then
tmp = (-d3 - d1) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6e+50) {
tmp = (d2 - d3) * d1;
} else if (d2 <= -4.6e-299) {
tmp = (-d3 - d1) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -6e+50: tmp = (d2 - d3) * d1 elif d2 <= -4.6e-299: tmp = (-d3 - d1) * d1 else: tmp = (d4 - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -6e+50) tmp = Float64(Float64(d2 - d3) * d1); elseif (d2 <= -4.6e-299) tmp = Float64(Float64(Float64(-d3) - d1) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -6e+50)
tmp = (d2 - d3) * d1;
elseif (d2 <= -4.6e-299)
tmp = (-d3 - d1) * d1;
else
tmp = (d4 - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6e+50], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -4.6e-299], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -6 \cdot 10^{+50}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d2 \leq -4.6 \cdot 10^{-299}:\\
\;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -5.9999999999999996e50Initial program 82.8%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6487.5
Applied rewrites87.5%
Taylor expanded in d4 around 0
Applied rewrites77.2%
if -5.9999999999999996e50 < d2 < -4.6000000000000001e-299Initial program 95.3%
Taylor expanded in d2 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--.f6497.1
Applied rewrites97.1%
Taylor expanded in d4 around 0
Applied rewrites69.2%
if -4.6000000000000001e-299 < d2 Initial program 85.1%
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 rewrites57.7%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (let* ((t_0 (* (- d2 d3) d1))) (if (<= d3 -5e+86) t_0 (if (<= d3 6.8e+187) (* (+ d4 d2) d1) t_0))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -5e+86) {
tmp = t_0;
} else if (d3 <= 6.8e+187) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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 - d3) * d1
if (d3 <= (-5d+86)) then
tmp = t_0
else if (d3 <= 6.8d+187) then
tmp = (d4 + d2) * d1
else
tmp = t_0
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -5e+86) {
tmp = t_0;
} else if (d3 <= 6.8e+187) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): t_0 = (d2 - d3) * d1 tmp = 0 if d3 <= -5e+86: tmp = t_0 elif d3 <= 6.8e+187: tmp = (d4 + d2) * d1 else: tmp = t_0 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) t_0 = Float64(Float64(d2 - d3) * d1) tmp = 0.0 if (d3 <= -5e+86) tmp = t_0; elseif (d3 <= 6.8e+187) tmp = Float64(Float64(d4 + d2) * d1); else tmp = t_0; end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
t_0 = (d2 - d3) * d1;
tmp = 0.0;
if (d3 <= -5e+86)
tmp = t_0;
elseif (d3 <= 6.8e+187)
tmp = (d4 + d2) * d1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -5e+86], t$95$0, If[LessEqual[d3, 6.8e+187], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(d2 - d3\right) \cdot d1\\
\mathbf{if}\;d3 \leq -5 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d3 \leq 6.8 \cdot 10^{+187}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d3 < -4.9999999999999998e86 or 6.7999999999999999e187 < d3 Initial program 89.4%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6497.3
Applied rewrites97.3%
Taylor expanded in d4 around 0
Applied rewrites88.4%
if -4.9999999999999998e86 < d3 < 6.7999999999999999e187Initial program 86.1%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6474.5
Applied rewrites74.5%
Taylor expanded in d3 around 0
Applied rewrites65.9%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (let* ((t_0 (* (- d1) d3))) (if (<= d3 -5.2e+125) t_0 (if (<= d3 6.8e+187) (* (+ d4 d2) d1) t_0))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double t_0 = -d1 * d3;
double tmp;
if (d3 <= -5.2e+125) {
tmp = t_0;
} else if (d3 <= 6.8e+187) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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 = -d1 * d3
if (d3 <= (-5.2d+125)) then
tmp = t_0
else if (d3 <= 6.8d+187) then
tmp = (d4 + d2) * d1
else
tmp = t_0
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = -d1 * d3;
double tmp;
if (d3 <= -5.2e+125) {
tmp = t_0;
} else if (d3 <= 6.8e+187) {
tmp = (d4 + d2) * d1;
} else {
tmp = t_0;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): t_0 = -d1 * d3 tmp = 0 if d3 <= -5.2e+125: tmp = t_0 elif d3 <= 6.8e+187: tmp = (d4 + d2) * d1 else: tmp = t_0 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) t_0 = Float64(Float64(-d1) * d3) tmp = 0.0 if (d3 <= -5.2e+125) tmp = t_0; elseif (d3 <= 6.8e+187) tmp = Float64(Float64(d4 + d2) * d1); else tmp = t_0; end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
t_0 = -d1 * d3;
tmp = 0.0;
if (d3 <= -5.2e+125)
tmp = t_0;
elseif (d3 <= 6.8e+187)
tmp = (d4 + d2) * d1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d3), $MachinePrecision]}, If[LessEqual[d3, -5.2e+125], t$95$0, If[LessEqual[d3, 6.8e+187], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(-d1\right) \cdot d3\\
\mathbf{if}\;d3 \leq -5.2 \cdot 10^{+125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d3 \leq 6.8 \cdot 10^{+187}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d3 < -5.20000000000000006e125 or 6.7999999999999999e187 < d3 Initial program 89.3%
Taylor expanded in d3 around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6480.9
Applied rewrites80.9%
if -5.20000000000000006e125 < d3 < 6.7999999999999999e187Initial program 86.2%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6474.6
Applied rewrites74.6%
Taylor expanded in d3 around 0
Applied rewrites66.0%
Final simplification70.3%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.1e+53) (* d1 d2) (if (<= d2 1.05e-167) (* (- d1) d3) (* d4 d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.1e+53) {
tmp = d1 * d2;
} else if (d2 <= 1.05e-167) {
tmp = -d1 * d3;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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+53)) then
tmp = d1 * d2
else if (d2 <= 1.05d-167) then
tmp = -d1 * d3
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.1e+53) {
tmp = d1 * d2;
} else if (d2 <= 1.05e-167) {
tmp = -d1 * d3;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.1e+53: tmp = d1 * d2 elif d2 <= 1.05e-167: tmp = -d1 * d3 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.1e+53) tmp = Float64(d1 * d2); elseif (d2 <= 1.05e-167) tmp = Float64(Float64(-d1) * d3); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.1e+53)
tmp = d1 * d2;
elseif (d2 <= 1.05e-167)
tmp = -d1 * d3;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.1e+53], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, 1.05e-167], N[((-d1) * d3), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.1 \cdot 10^{+53}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq 1.05 \cdot 10^{-167}:\\
\;\;\;\;\left(-d1\right) \cdot d3\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -1.09999999999999999e53Initial program 82.8%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6460.4
Applied rewrites60.4%
if -1.09999999999999999e53 < d2 < 1.05000000000000009e-167Initial program 95.6%
Taylor expanded in d3 around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6445.2
Applied rewrites45.2%
if 1.05000000000000009e-167 < d2 Initial program 82.1%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6427.1
Applied rewrites27.1%
Final simplification41.9%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.7e+40) (* d1 d2) (if (<= d2 -4.6e-299) (* (- d1) d1) (* d4 d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.7e+40) {
tmp = d1 * d2;
} else if (d2 <= -4.6e-299) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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.7d+40)) then
tmp = d1 * d2
else if (d2 <= (-4.6d-299)) then
tmp = -d1 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.7e+40) {
tmp = d1 * d2;
} else if (d2 <= -4.6e-299) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.7e+40: tmp = d1 * d2 elif d2 <= -4.6e-299: tmp = -d1 * d1 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.7e+40) tmp = Float64(d1 * d2); elseif (d2 <= -4.6e-299) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.7e+40)
tmp = d1 * d2;
elseif (d2 <= -4.6e-299)
tmp = -d1 * d1;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.7e+40], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -4.6e-299], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.7 \cdot 10^{+40}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -4.6 \cdot 10^{-299}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -1.69999999999999994e40Initial program 83.0%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6459.5
Applied rewrites59.5%
if -1.69999999999999994e40 < d2 < -4.6000000000000001e-299Initial program 95.2%
Taylor expanded in d1 around inf
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6432.8
Applied rewrites32.8%
if -4.6000000000000001e-299 < d2 Initial program 85.1%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6428.5
Applied rewrites28.5%
Final simplification37.4%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.8e+55) (* (- (+ d4 d2) d3) d1) (* (- (- d4 d3) d1) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e+55) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = ((d4 - d3) - d1) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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.8d+55)) then
tmp = ((d4 + d2) - d3) * d1
else
tmp = ((d4 - d3) - d1) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e+55) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = ((d4 - d3) - d1) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.8e+55: tmp = ((d4 + d2) - d3) * d1 else: tmp = ((d4 - d3) - d1) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.8e+55) tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); else tmp = Float64(Float64(Float64(d4 - d3) - d1) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.8e+55)
tmp = ((d4 + d2) - d3) * d1;
else
tmp = ((d4 - d3) - d1) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e+55], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.8 \cdot 10^{+55}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.79999999999999994e55Initial program 83.8%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6488.7
Applied rewrites88.7%
if -1.79999999999999994e55 < d2 Initial program 88.1%
Taylor expanded in d2 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--.f6484.3
Applied rewrites84.3%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -6.6e+36) (* (- d2 d3) d1) (* (- d4 d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6.6e+36) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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 <= (-6.6d+36)) then
tmp = (d2 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6.6e+36) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -6.6e+36: tmp = (d2 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -6.6e+36) tmp = Float64(Float64(d2 - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -6.6e+36)
tmp = (d2 - d3) * d1;
else
tmp = (d4 - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6.6e+36], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -6.6 \cdot 10^{+36}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -6.5999999999999997e36Initial program 83.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6486.5
Applied rewrites86.5%
Taylor expanded in d4 around 0
Applied rewrites76.5%
if -6.5999999999999997e36 < d2 Initial program 88.4%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6479.4
Applied rewrites79.4%
Taylor expanded in d2 around 0
Applied rewrites62.7%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.6e+34) (* d1 d2) (* d4 d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e+34) {
tmp = d1 * d2;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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+34)) then
tmp = d1 * d2
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e+34) {
tmp = d1 * d2;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.6e+34: tmp = d1 * d2 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.6e+34) tmp = Float64(d1 * d2); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -5.6e+34)
tmp = d1 * d2;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.6e+34], N[(d1 * d2), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.6 \cdot 10^{+34}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -5.60000000000000016e34Initial program 83.8%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6457.2
Applied rewrites57.2%
if -5.60000000000000016e34 < d2 Initial program 88.3%
Taylor expanded in d4 around inf
*-commutativeN/A
lower-*.f6430.3
Applied rewrites30.3%
Final simplification37.4%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d2))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): return d1 * d2
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) return Float64(d1 * d2) end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp = code(d1, d2, d3, d4)
tmp = d1 * d2;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := N[(d1 * d2), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
d1 \cdot d2
\end{array}
Initial program 87.1%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6431.6
Applied rewrites31.6%
Final simplification31.6%
(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 2024255
(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)))