
(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 5 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 (<= t 3.4e-54) (* y (* t (- x z))) (* (- x z) (* t y))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 3.4e-54) {
tmp = y * (t * (x - z));
} else {
tmp = (x - z) * (t * y);
}
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.4d-54) then
tmp = y * (t * (x - z))
else
tmp = (x - z) * (t * y)
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.4e-54) {
tmp = y * (t * (x - z));
} else {
tmp = (x - z) * (t * y);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if t <= 3.4e-54: tmp = y * (t * (x - z)) else: tmp = (x - z) * (t * y) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (t <= 3.4e-54) tmp = Float64(y * Float64(t * Float64(x - z))); else tmp = Float64(Float64(x - z) * Float64(t * y)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (t <= 3.4e-54)
tmp = y * (t * (x - z));
else
tmp = (x - z) * (t * y);
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.4e-54], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - z), $MachinePrecision] * N[(t * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 3.4 \cdot 10^{-54}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if t < 3.39999999999999987e-54Initial program 88.2%
distribute-rgt-out--90.5%
associate-*l*91.0%
*-commutative91.0%
Simplified91.0%
if 3.39999999999999987e-54 < t Initial program 92.7%
*-commutative92.7%
distribute-rgt-out--94.2%
associate-*r*98.2%
*-commutative98.2%
Simplified98.2%
Final simplification92.9%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -7.8e-31) (not (<= z 2.05e-22))) (* y (* z (- t))) (* y (* t x))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7.8e-31) || !(z <= 2.05e-22)) {
tmp = y * (z * -t);
} else {
tmp = y * (t * x);
}
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 <= (-7.8d-31)) .or. (.not. (z <= 2.05d-22))) then
tmp = y * (z * -t)
else
tmp = y * (t * x)
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 <= -7.8e-31) || !(z <= 2.05e-22)) {
tmp = y * (z * -t);
} else {
tmp = y * (t * x);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -7.8e-31) or not (z <= 2.05e-22): tmp = y * (z * -t) else: tmp = y * (t * x) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -7.8e-31) || !(z <= 2.05e-22)) tmp = Float64(y * Float64(z * Float64(-t))); else tmp = Float64(y * Float64(t * x)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -7.8e-31) || ~((z <= 2.05e-22)))
tmp = y * (z * -t);
else
tmp = y * (t * x);
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, -7.8e-31], N[Not[LessEqual[z, 2.05e-22]], $MachinePrecision]], N[(y * N[(z * (-t)), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-31} \lor \neg \left(z \leq 2.05 \cdot 10^{-22}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\
\end{array}
\end{array}
if z < -7.8000000000000003e-31 or 2.05e-22 < z Initial program 86.8%
distribute-rgt-out--90.9%
associate-*l*92.3%
*-commutative92.3%
Simplified92.3%
Taylor expanded in x around 0 72.4%
mul-1-neg72.4%
distribute-rgt-neg-out72.4%
Simplified72.4%
if -7.8000000000000003e-31 < z < 2.05e-22Initial program 91.9%
distribute-rgt-out--91.9%
associate-*l*91.5%
*-commutative91.5%
Simplified91.5%
Taylor expanded in x around inf 78.2%
associate-*r*79.4%
*-commutative79.4%
Simplified79.4%
Final simplification76.0%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -6.6e-32) (not (<= z 4.5e-13))) (* z (* t (- y))) (* y (* t x))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.6e-32) || !(z <= 4.5e-13)) {
tmp = z * (t * -y);
} else {
tmp = y * (t * x);
}
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 <= (-6.6d-32)) .or. (.not. (z <= 4.5d-13))) then
tmp = z * (t * -y)
else
tmp = y * (t * x)
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 <= -6.6e-32) || !(z <= 4.5e-13)) {
tmp = z * (t * -y);
} else {
tmp = y * (t * x);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -6.6e-32) or not (z <= 4.5e-13): tmp = z * (t * -y) else: tmp = y * (t * x) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -6.6e-32) || !(z <= 4.5e-13)) tmp = Float64(z * Float64(t * Float64(-y))); else tmp = Float64(y * Float64(t * x)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -6.6e-32) || ~((z <= 4.5e-13)))
tmp = z * (t * -y);
else
tmp = y * (t * x);
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, -6.6e-32], N[Not[LessEqual[z, 4.5e-13]], $MachinePrecision]], N[(z * N[(t * (-y)), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-32} \lor \neg \left(z \leq 4.5 \cdot 10^{-13}\right):\\
\;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\
\end{array}
\end{array}
if z < -6.60000000000000051e-32 or 4.5e-13 < z Initial program 86.8%
distribute-rgt-out--90.9%
associate-*l*92.3%
*-commutative92.3%
Simplified92.3%
Taylor expanded in x around 0 72.0%
mul-1-neg72.0%
distribute-rgt-neg-in72.0%
distribute-rgt-neg-out72.0%
associate-*l*74.7%
Simplified74.7%
if -6.60000000000000051e-32 < z < 4.5e-13Initial program 91.9%
distribute-rgt-out--91.9%
associate-*l*91.5%
*-commutative91.5%
Simplified91.5%
Taylor expanded in x around inf 78.2%
associate-*r*79.4%
*-commutative79.4%
Simplified79.4%
Final simplification77.1%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* t (- x z))))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (t * (x - z));
}
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 * (t * (x - z))
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (t * (x - z));
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (t * (x - z))
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(t * Float64(x - z))) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (t * (x - z));
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot \left(x - z\right)\right)
\end{array}
Initial program 89.4%
distribute-rgt-out--91.4%
associate-*l*91.9%
*-commutative91.9%
Simplified91.9%
Final simplification91.9%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* t x)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (t * x);
}
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 * (t * x)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (t * x);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (t * x)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(t * x)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (t * x);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot x\right)
\end{array}
Initial program 89.4%
distribute-rgt-out--91.4%
associate-*l*91.9%
*-commutative91.9%
Simplified91.9%
Taylor expanded in x around inf 52.8%
associate-*r*54.5%
*-commutative54.5%
Simplified54.5%
Final simplification54.5%
(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 2023320
(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))