
(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 6 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 1.1e+82) (* y (* t (- x z))) (* t (* y (- x z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1.1e+82) {
tmp = y * (t * (x - z));
} 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 (t <= 1.1d+82) then
tmp = y * (t * (x - z))
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 (t <= 1.1e+82) {
tmp = y * (t * (x - z));
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if t <= 1.1e+82: tmp = y * (t * (x - z)) else: tmp = t * (y * (x - z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (t <= 1.1e+82) tmp = Float64(y * Float64(t * Float64(x - z))); 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 (t <= 1.1e+82)
tmp = y * (t * (x - z));
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[t, 1.1e+82], N[(y * N[(t * N[(x - z), $MachinePrecision]), $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}\;t \leq 1.1 \cdot 10^{+82}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\end{array}
if t < 1.1000000000000001e82Initial program 88.7%
distribute-rgt-out--90.2%
associate-*l*95.2%
Simplified95.2%
if 1.1000000000000001e82 < t Initial program 93.6%
distribute-rgt-out--97.7%
Simplified97.7%
Final simplification95.7%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= x -1.5e+24) (* t (* y x)) (if (<= x 6.4e+68) (* y (* t (- z))) (* x (* t y)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.5e+24) {
tmp = t * (y * x);
} else if (x <= 6.4e+68) {
tmp = y * (t * -z);
} else {
tmp = x * (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 (x <= (-1.5d+24)) then
tmp = t * (y * x)
else if (x <= 6.4d+68) then
tmp = y * (t * -z)
else
tmp = x * (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 (x <= -1.5e+24) {
tmp = t * (y * x);
} else if (x <= 6.4e+68) {
tmp = y * (t * -z);
} else {
tmp = x * (t * y);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if x <= -1.5e+24: tmp = t * (y * x) elif x <= 6.4e+68: tmp = y * (t * -z) else: tmp = x * (t * y) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (x <= -1.5e+24) tmp = Float64(t * Float64(y * x)); elseif (x <= 6.4e+68) tmp = Float64(y * Float64(t * Float64(-z))); else tmp = Float64(x * 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 (x <= -1.5e+24)
tmp = t * (y * x);
elseif (x <= 6.4e+68)
tmp = y * (t * -z);
else
tmp = x * (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[x, -1.5e+24], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.4e+68], N[(y * N[(t * (-z)), $MachinePrecision]), $MachinePrecision], N[(x * N[(t * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+24}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;x \leq 6.4 \cdot 10^{+68}:\\
\;\;\;\;y \cdot \left(t \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if x < -1.49999999999999997e24Initial program 90.2%
distribute-rgt-out--93.5%
Simplified93.5%
Taylor expanded in x around inf 71.8%
if -1.49999999999999997e24 < x < 6.39999999999999989e68Initial program 90.9%
distribute-rgt-out--91.6%
associate-*l*94.7%
Simplified94.7%
Taylor expanded in x around 0 80.5%
mul-1-neg80.5%
*-commutative80.5%
distribute-rgt-neg-in80.5%
Simplified80.5%
if 6.39999999999999989e68 < x Initial program 84.8%
distribute-rgt-out--89.3%
associate-*l*89.5%
Simplified89.5%
Taylor expanded in x around inf 73.5%
add-cube-cbrt72.8%
pow372.9%
*-commutative72.9%
Applied egg-rr72.9%
rem-cube-cbrt73.5%
*-commutative73.5%
associate-*r*78.0%
Applied egg-rr78.0%
Final simplification78.0%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= x -1.3e+24) (* t (* y x)) (if (<= x 2.4e+68) (* t (* y (- z))) (* x (* t y)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.3e+24) {
tmp = t * (y * x);
} else if (x <= 2.4e+68) {
tmp = t * (y * -z);
} else {
tmp = x * (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 (x <= (-1.3d+24)) then
tmp = t * (y * x)
else if (x <= 2.4d+68) then
tmp = t * (y * -z)
else
tmp = x * (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 (x <= -1.3e+24) {
tmp = t * (y * x);
} else if (x <= 2.4e+68) {
tmp = t * (y * -z);
} else {
tmp = x * (t * y);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if x <= -1.3e+24: tmp = t * (y * x) elif x <= 2.4e+68: tmp = t * (y * -z) else: tmp = x * (t * y) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (x <= -1.3e+24) tmp = Float64(t * Float64(y * x)); elseif (x <= 2.4e+68) tmp = Float64(t * Float64(y * Float64(-z))); else tmp = Float64(x * 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 (x <= -1.3e+24)
tmp = t * (y * x);
elseif (x <= 2.4e+68)
tmp = t * (y * -z);
else
tmp = x * (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[x, -1.3e+24], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.4e+68], N[(t * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], N[(x * N[(t * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+24}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+68}:\\
\;\;\;\;t \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if x < -1.2999999999999999e24Initial program 90.2%
distribute-rgt-out--93.5%
Simplified93.5%
Taylor expanded in x around inf 71.8%
if -1.2999999999999999e24 < x < 2.40000000000000008e68Initial program 90.9%
distribute-rgt-out--91.6%
Simplified91.6%
Taylor expanded in x around 0 77.4%
mul-1-neg77.4%
distribute-rgt-neg-out77.4%
Simplified77.4%
if 2.40000000000000008e68 < x Initial program 84.8%
distribute-rgt-out--89.3%
associate-*l*89.5%
Simplified89.5%
Taylor expanded in x around inf 73.5%
add-cube-cbrt72.8%
pow372.9%
*-commutative72.9%
Applied egg-rr72.9%
rem-cube-cbrt73.5%
*-commutative73.5%
associate-*r*78.0%
Applied egg-rr78.0%
Final simplification76.2%
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.6%
distribute-rgt-out--91.6%
associate-*l*91.7%
Simplified91.7%
Final simplification91.7%
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.6%
distribute-rgt-out--91.6%
associate-*l*91.7%
Simplified91.7%
Taylor expanded in x around inf 46.5%
Final simplification46.5%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* x (* t y)))
assert(y < t);
double code(double x, double y, double z, double t) {
return x * (t * y);
}
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 = x * (t * y)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return x * (t * y);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return x * (t * y)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(x * Float64(t * y)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = x * (t * y);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(x * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
x \cdot \left(t \cdot y\right)
\end{array}
Initial program 89.6%
distribute-rgt-out--91.6%
associate-*l*91.7%
Simplified91.7%
Taylor expanded in x around inf 46.5%
add-cube-cbrt46.0%
pow346.0%
*-commutative46.0%
Applied egg-rr46.0%
rem-cube-cbrt46.5%
*-commutative46.5%
associate-*r*50.5%
Applied egg-rr50.5%
Final simplification50.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 2023192
(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))