
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
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 * 2.0d0) / ((y * z) - (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
function code(x, y, z, t) return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x * 2.0) / ((y * z) - (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
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 * 2.0d0) / ((y * z) - (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
function code(x, y, z, t) return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x * 2.0) / ((y * z) - (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* y z) (* t z))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e+293)))
(* (/ x (- y t)) (/ 2.0 z))
(/ (+ x x) (* (- y t) z)))))
double code(double x, double y, double z, double t) {
double t_1 = (y * z) - (t * z);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 1e+293)) {
tmp = (x / (y - t)) * (2.0 / z);
} else {
tmp = (x + x) / ((y - t) * z);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (y * z) - (t * z);
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 1e+293)) {
tmp = (x / (y - t)) * (2.0 / z);
} else {
tmp = (x + x) / ((y - t) * z);
}
return tmp;
}
def code(x, y, z, t): t_1 = (y * z) - (t * z) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 1e+293): tmp = (x / (y - t)) * (2.0 / z) else: tmp = (x + x) / ((y - t) * z) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(y * z) - Float64(t * z)) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 1e+293)) tmp = Float64(Float64(x / Float64(y - t)) * Float64(2.0 / z)); else tmp = Float64(Float64(x + x) / Float64(Float64(y - t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (y * z) - (t * z); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 1e+293))) tmp = (x / (y - t)) * (2.0 / z); else tmp = (x + x) / ((y - t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 1e+293]], $MachinePrecision]], N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision], N[(N[(x + x), $MachinePrecision] / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot z - t \cdot z\\
\mathbf{if}\;t\_1 \leq -\infty \lor \neg \left(t\_1 \leq 10^{+293}\right):\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + x}{\left(y - t\right) \cdot z}\\
\end{array}
\end{array}
if (-.f64 (*.f64 y z) (*.f64 t z)) < -inf.0 or 9.9999999999999992e292 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 68.1%
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
if -inf.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 9.9999999999999992e292Initial program 98.2%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.3
Applied rewrites98.3%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6498.3
Applied rewrites98.3%
Final simplification98.6%
(FPCore (x y z t) :precision binary64 (if (<= z 1.9e-107) (/ (+ x x) (* (- y t) z)) (/ (* (/ x z) 2.0) (- y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.9e-107) {
tmp = (x + x) / ((y - t) * z);
} else {
tmp = ((x / z) * 2.0) / (y - 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 (z <= 1.9d-107) then
tmp = (x + x) / ((y - t) * z)
else
tmp = ((x / z) * 2.0d0) / (y - t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.9e-107) {
tmp = (x + x) / ((y - t) * z);
} else {
tmp = ((x / z) * 2.0) / (y - t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.9e-107: tmp = (x + x) / ((y - t) * z) else: tmp = ((x / z) * 2.0) / (y - t) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.9e-107) tmp = Float64(Float64(x + x) / Float64(Float64(y - t) * z)); else tmp = Float64(Float64(Float64(x / z) * 2.0) / Float64(y - t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.9e-107) tmp = (x + x) / ((y - t) * z); else tmp = ((x / z) * 2.0) / (y - t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.9e-107], N[(N[(x + x), $MachinePrecision] / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / z), $MachinePrecision] * 2.0), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.9 \cdot 10^{-107}:\\
\;\;\;\;\frac{x + x}{\left(y - t\right) \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\
\end{array}
\end{array}
if z < 1.9000000000000001e-107Initial program 91.8%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6494.2
Applied rewrites94.2%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6494.2
Applied rewrites94.2%
if 1.9000000000000001e-107 < z Initial program 90.4%
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
times-fracN/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6498.7
Applied rewrites98.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.45e-25) (not (<= y 1.18e+76))) (* (/ x (* z y)) 2.0) (* (/ x (* t z)) -2.0)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.45e-25) || !(y <= 1.18e+76)) {
tmp = (x / (z * y)) * 2.0;
} else {
tmp = (x / (t * z)) * -2.0;
}
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 ((y <= (-1.45d-25)) .or. (.not. (y <= 1.18d+76))) then
tmp = (x / (z * y)) * 2.0d0
else
tmp = (x / (t * z)) * (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.45e-25) || !(y <= 1.18e+76)) {
tmp = (x / (z * y)) * 2.0;
} else {
tmp = (x / (t * z)) * -2.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.45e-25) or not (y <= 1.18e+76): tmp = (x / (z * y)) * 2.0 else: tmp = (x / (t * z)) * -2.0 return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.45e-25) || !(y <= 1.18e+76)) tmp = Float64(Float64(x / Float64(z * y)) * 2.0); else tmp = Float64(Float64(x / Float64(t * z)) * -2.0); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.45e-25) || ~((y <= 1.18e+76))) tmp = (x / (z * y)) * 2.0; else tmp = (x / (t * z)) * -2.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.45e-25], N[Not[LessEqual[y, 1.18e+76]], $MachinePrecision]], N[(N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(x / N[(t * z), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-25} \lor \neg \left(y \leq 1.18 \cdot 10^{+76}\right):\\
\;\;\;\;\frac{x}{z \cdot y} \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t \cdot z} \cdot -2\\
\end{array}
\end{array}
if y < -1.45e-25 or 1.17999999999999997e76 < y Initial program 89.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.7
Applied rewrites78.7%
if -1.45e-25 < y < 1.17999999999999997e76Initial program 92.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6480.1
Applied rewrites80.1%
Final simplification79.5%
(FPCore (x y z t) :precision binary64 (/ (+ x x) (* (- y t) z)))
double code(double x, double y, double z, double t) {
return (x + x) / ((y - t) * z);
}
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 + x) / ((y - t) * z)
end function
public static double code(double x, double y, double z, double t) {
return (x + x) / ((y - t) * z);
}
def code(x, y, z, t): return (x + x) / ((y - t) * z)
function code(x, y, z, t) return Float64(Float64(x + x) / Float64(Float64(y - t) * z)) end
function tmp = code(x, y, z, t) tmp = (x + x) / ((y - t) * z); end
code[x_, y_, z_, t_] := N[(N[(x + x), $MachinePrecision] / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + x}{\left(y - t\right) \cdot z}
\end{array}
Initial program 91.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6493.3
Applied rewrites93.3%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6493.3
Applied rewrites93.3%
(FPCore (x y z t) :precision binary64 (* (/ x (* t z)) -2.0))
double code(double x, double y, double z, double t) {
return (x / (t * z)) * -2.0;
}
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 * z)) * (-2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x / (t * z)) * -2.0;
}
def code(x, y, z, t): return (x / (t * z)) * -2.0
function code(x, y, z, t) return Float64(Float64(x / Float64(t * z)) * -2.0) end
function tmp = code(x, y, z, t) tmp = (x / (t * z)) * -2.0; end
code[x_, y_, z_, t_] := N[(N[(x / N[(t * z), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{t \cdot z} \cdot -2
\end{array}
Initial program 91.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6460.2
Applied rewrites60.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (/ x (* (- y t) z)) 2.0))
(t_2 (/ (* x 2.0) (- (* y z) (* t z)))))
(if (< t_2 -2.559141628295061e-13)
t_1
(if (< t_2 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (x / ((y - t) * z)) * 2.0;
double t_2 = (x * 2.0) / ((y * z) - (t * z));
double tmp;
if (t_2 < -2.559141628295061e-13) {
tmp = t_1;
} else if (t_2 < 1.045027827330126e-269) {
tmp = ((x / z) * 2.0) / (y - t);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (x / ((y - t) * z)) * 2.0d0
t_2 = (x * 2.0d0) / ((y * z) - (t * z))
if (t_2 < (-2.559141628295061d-13)) then
tmp = t_1
else if (t_2 < 1.045027827330126d-269) then
tmp = ((x / z) * 2.0d0) / (y - t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (x / ((y - t) * z)) * 2.0;
double t_2 = (x * 2.0) / ((y * z) - (t * z));
double tmp;
if (t_2 < -2.559141628295061e-13) {
tmp = t_1;
} else if (t_2 < 1.045027827330126e-269) {
tmp = ((x / z) * 2.0) / (y - t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (x / ((y - t) * z)) * 2.0 t_2 = (x * 2.0) / ((y * z) - (t * z)) tmp = 0 if t_2 < -2.559141628295061e-13: tmp = t_1 elif t_2 < 1.045027827330126e-269: tmp = ((x / z) * 2.0) / (y - t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x / Float64(Float64(y - t) * z)) * 2.0) t_2 = Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) tmp = 0.0 if (t_2 < -2.559141628295061e-13) tmp = t_1; elseif (t_2 < 1.045027827330126e-269) tmp = Float64(Float64(Float64(x / z) * 2.0) / Float64(y - t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x / ((y - t) * z)) * 2.0; t_2 = (x * 2.0) / ((y * z) - (t * z)); tmp = 0.0; if (t_2 < -2.559141628295061e-13) tmp = t_1; elseif (t_2 < 1.045027827330126e-269) tmp = ((x / z) * 2.0) / (y - t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$2, -2.559141628295061e-13], t$95$1, If[Less[t$95$2, 1.045027827330126e-269], N[(N[(N[(x / z), $MachinePrecision] * 2.0), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x}{\left(y - t\right) \cdot z} \cdot 2\\
t_2 := \frac{x \cdot 2}{y \cdot z - t \cdot z}\\
\mathbf{if}\;t\_2 < -2.559141628295061 \cdot 10^{-13}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 < 1.045027827330126 \cdot 10^{-269}:\\
\;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024338
(FPCore (x y z t)
:name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
:precision binary64
:alt
(! :herbie-platform default (if (< (/ (* x 2) (- (* y z) (* t z))) -2559141628295061/10000000000000000000000000000) (* (/ x (* (- y t) z)) 2) (if (< (/ (* x 2) (- (* y z) (* t z))) 522513913665063/50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (* (/ x z) 2) (- y t)) (* (/ x (* (- y t) z)) 2))))
(/ (* x 2.0) (- (* y z) (* t z))))