
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
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 * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
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 * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -5e+31) (* y (* (- x z) t)) (* t (- (* y x) (* y z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5e+31) {
tmp = y * ((x - z) * t);
} else {
tmp = t * ((y * x) - (y * z));
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-5d+31)) then
tmp = y * ((x - z) * t)
else
tmp = t * ((y * x) - (y * z))
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5e+31) {
tmp = y * ((x - z) * t);
} else {
tmp = t * ((y * x) - (y * z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -5e+31: tmp = y * ((x - z) * t) else: tmp = t * ((y * x) - (y * z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -5e+31) tmp = Float64(y * Float64(Float64(x - z) * t)); else tmp = Float64(t * Float64(Float64(y * x) - Float64(y * z))); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -5e+31)
tmp = y * ((x - z) * t);
else
tmp = t * ((y * x) - (y * z));
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[y, -5e+31], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(t * N[(N[(y * x), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+31}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -5.00000000000000027e31Initial program 82.8%
distribute-rgt-out--88.7%
associate-*l*97.8%
Simplified97.8%
if -5.00000000000000027e31 < y Initial program 95.6%
Final simplification96.2%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -2.3e-87) (not (<= z 1.56e-76))) (* y (* z (- t))) (* y (* x t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e-87) || !(z <= 1.56e-76)) {
tmp = y * (z * -t);
} else {
tmp = y * (x * t);
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-2.3d-87)) .or. (.not. (z <= 1.56d-76))) then
tmp = y * (z * -t)
else
tmp = y * (x * t)
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e-87) || !(z <= 1.56e-76)) {
tmp = y * (z * -t);
} else {
tmp = y * (x * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -2.3e-87) or not (z <= 1.56e-76): tmp = y * (z * -t) else: tmp = y * (x * t) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -2.3e-87) || !(z <= 1.56e-76)) tmp = Float64(y * Float64(z * Float64(-t))); else tmp = Float64(y * Float64(x * t)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -2.3e-87) || ~((z <= 1.56e-76)))
tmp = y * (z * -t);
else
tmp = y * (x * t);
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.3e-87], N[Not[LessEqual[z, 1.56e-76]], $MachinePrecision]], N[(y * N[(z * (-t)), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-87} \lor \neg \left(z \leq 1.56 \cdot 10^{-76}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot t\right)\\
\end{array}
\end{array}
if z < -2.3000000000000001e-87 or 1.55999999999999992e-76 < z Initial program 91.6%
distribute-rgt-out--94.2%
associate-*l*93.1%
Simplified93.1%
Taylor expanded in x around 0 74.1%
associate-*r*74.1%
neg-mul-174.1%
Simplified74.1%
if -2.3000000000000001e-87 < z < 1.55999999999999992e-76Initial program 93.2%
distribute-rgt-out--93.2%
associate-*l*93.7%
Simplified93.7%
Taylor expanded in x around inf 87.6%
Final simplification79.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -1.46e-87) (not (<= z 3e-74))) (* t (* z (- y))) (* y (* x t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.46e-87) || !(z <= 3e-74)) {
tmp = t * (z * -y);
} else {
tmp = y * (x * t);
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-1.46d-87)) .or. (.not. (z <= 3d-74))) then
tmp = t * (z * -y)
else
tmp = y * (x * t)
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.46e-87) || !(z <= 3e-74)) {
tmp = t * (z * -y);
} else {
tmp = y * (x * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -1.46e-87) or not (z <= 3e-74): tmp = t * (z * -y) else: tmp = y * (x * t) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -1.46e-87) || !(z <= 3e-74)) tmp = Float64(t * Float64(z * Float64(-y))); else tmp = Float64(y * Float64(x * t)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -1.46e-87) || ~((z <= 3e-74)))
tmp = t * (z * -y);
else
tmp = y * (x * t);
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.46e-87], N[Not[LessEqual[z, 3e-74]], $MachinePrecision]], N[(t * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.46 \cdot 10^{-87} \lor \neg \left(z \leq 3 \cdot 10^{-74}\right):\\
\;\;\;\;t \cdot \left(z \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot t\right)\\
\end{array}
\end{array}
if z < -1.4599999999999999e-87 or 3.00000000000000007e-74 < z Initial program 91.7%
distribute-rgt-out--94.2%
Simplified94.2%
Taylor expanded in x around 0 74.8%
neg-mul-174.8%
distribute-lft-neg-in74.8%
Simplified74.8%
if -1.4599999999999999e-87 < z < 3.00000000000000007e-74Initial program 93.1%
distribute-rgt-out--93.2%
associate-*l*94.6%
Simplified94.6%
Taylor expanded in x around inf 88.3%
Final simplification80.1%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= t 3.5e-9) (* y (* (- x z) t)) (* (- x z) (* y t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 3.5e-9) {
tmp = y * ((x - z) * t);
} else {
tmp = (x - z) * (y * t);
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= 3.5d-9) then
tmp = y * ((x - z) * t)
else
tmp = (x - z) * (y * t)
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 3.5e-9) {
tmp = y * ((x - z) * t);
} else {
tmp = (x - z) * (y * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if t <= 3.5e-9: tmp = y * ((x - z) * t) else: tmp = (x - z) * (y * t) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (t <= 3.5e-9) tmp = Float64(y * Float64(Float64(x - z) * t)); else tmp = Float64(Float64(x - z) * Float64(y * t)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (t <= 3.5e-9)
tmp = y * ((x - z) * t);
else
tmp = (x - z) * (y * t);
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[t, 3.5e-9], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 3.5 \cdot 10^{-9}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\end{array}
\end{array}
if t < 3.4999999999999999e-9Initial program 92.2%
distribute-rgt-out--93.2%
associate-*l*95.1%
Simplified95.1%
if 3.4999999999999999e-9 < t Initial program 92.5%
distribute-rgt-out--95.5%
associate-*l*88.3%
Simplified88.3%
*-commutative88.3%
flip--76.6%
associate-*r/75.1%
Applied egg-rr75.1%
associate-/l*76.6%
difference-of-squares79.6%
associate-/r*88.3%
*-inverses88.3%
Simplified88.3%
Taylor expanded in y around 0 88.3%
Simplified95.6%
Final simplification95.2%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -7e+28) (* y (* (- x z) t)) (* t (* y (- x z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -7e+28) {
tmp = y * ((x - z) * t);
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-7d+28)) then
tmp = y * ((x - z) * t)
else
tmp = t * (y * (x - z))
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -7e+28) {
tmp = y * ((x - z) * t);
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -7e+28: tmp = y * ((x - z) * t) else: tmp = t * (y * (x - z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -7e+28) tmp = Float64(y * Float64(Float64(x - z) * t)); else tmp = Float64(t * Float64(y * Float64(x - z))); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -7e+28)
tmp = y * ((x - z) * t);
else
tmp = t * (y * (x - z));
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[y, -7e+28], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+28}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\end{array}
if y < -6.9999999999999999e28Initial program 82.8%
distribute-rgt-out--88.7%
associate-*l*97.8%
Simplified97.8%
if -6.9999999999999999e28 < y Initial program 95.6%
distribute-rgt-out--95.6%
Simplified95.6%
Final simplification96.2%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* (- x z) t)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * ((x - z) * t);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y * ((x - z) * t)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * ((x - z) * t);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * ((x - z) * t)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(Float64(x - z) * t)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * ((x - z) * t);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(\left(x - z\right) \cdot t\right)
\end{array}
Initial program 92.2%
distribute-rgt-out--93.8%
associate-*l*93.3%
Simplified93.3%
Final simplification93.3%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* x t)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (x * t);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y * (x * t)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (x * t);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (x * t)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(x * t)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (x * t);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(x * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(x \cdot t\right)
\end{array}
Initial program 92.2%
distribute-rgt-out--93.8%
associate-*l*93.3%
Simplified93.3%
Taylor expanded in x around inf 56.4%
Final simplification56.4%
(FPCore (x y z t) :precision binary64 (if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (t < -9.231879582886777e-80) {
tmp = (y * t) * (x - z);
} else if (t < 2.543067051564877e+83) {
tmp = y * (t * (x - z));
} else {
tmp = (y * (x - z)) * t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t < (-9.231879582886777d-80)) then
tmp = (y * t) * (x - z)
else if (t < 2.543067051564877d+83) then
tmp = y * (t * (x - z))
else
tmp = (y * (x - z)) * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t < -9.231879582886777e-80) {
tmp = (y * t) * (x - z);
} else if (t < 2.543067051564877e+83) {
tmp = y * (t * (x - z));
} else {
tmp = (y * (x - z)) * t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t < -9.231879582886777e-80: tmp = (y * t) * (x - z) elif t < 2.543067051564877e+83: tmp = y * (t * (x - z)) else: tmp = (y * (x - z)) * t return tmp
function code(x, y, z, t) tmp = 0.0 if (t < -9.231879582886777e-80) tmp = Float64(Float64(y * t) * Float64(x - z)); elseif (t < 2.543067051564877e+83) tmp = Float64(y * Float64(t * Float64(x - z))); else tmp = Float64(Float64(y * Float64(x - z)) * t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t < -9.231879582886777e-80) tmp = (y * t) * (x - z); elseif (t < 2.543067051564877e+83) tmp = y * (t * (x - z)); else tmp = (y * (x - z)) * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Less[t, -9.231879582886777e-80], N[(N[(y * t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision], If[Less[t, 2.543067051564877e+83], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t < -9.231879582886777 \cdot 10^{-80}:\\
\;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\
\mathbf{elif}\;t < 2.543067051564877 \cdot 10^{+83}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot \left(x - z\right)\right) \cdot t\\
\end{array}
\end{array}
herbie shell --seed 2023224
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))
(* (- (* x y) (* z y)) t))