
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - 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 * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - 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 * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+285) (fma (- (* z z) t) (* y -4.0) (* x x)) (* (* (* y -4.0) z) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+285) {
tmp = fma(((z * z) - t), (y * -4.0), (x * x));
} else {
tmp = ((y * -4.0) * z) * z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+285) tmp = fma(Float64(Float64(z * z) - t), Float64(y * -4.0), Float64(x * x)); else tmp = Float64(Float64(Float64(y * -4.0) * z) * z); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+285], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * -4.0), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+285}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y \cdot -4\right) \cdot z\right) \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 5.00000000000000016e285Initial program 96.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval98.4
Applied rewrites98.4%
if 5.00000000000000016e285 < (*.f64 z z) Initial program 62.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.2
Applied rewrites73.2%
Applied rewrites89.1%
Final simplification96.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* z z) t)))
(if (<= t_1 -5e+237)
(* (* 4.0 y) t)
(if (<= t_1 2e+235) (* x x) (* (* (* y -4.0) z) z)))))
double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -5e+237) {
tmp = (4.0 * y) * t;
} else if (t_1 <= 2e+235) {
tmp = x * x;
} else {
tmp = ((y * -4.0) * z) * z;
}
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) :: tmp
t_1 = (z * z) - t
if (t_1 <= (-5d+237)) then
tmp = (4.0d0 * y) * t
else if (t_1 <= 2d+235) then
tmp = x * x
else
tmp = ((y * (-4.0d0)) * z) * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -5e+237) {
tmp = (4.0 * y) * t;
} else if (t_1 <= 2e+235) {
tmp = x * x;
} else {
tmp = ((y * -4.0) * z) * z;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * z) - t tmp = 0 if t_1 <= -5e+237: tmp = (4.0 * y) * t elif t_1 <= 2e+235: tmp = x * x else: tmp = ((y * -4.0) * z) * z return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * z) - t) tmp = 0.0 if (t_1 <= -5e+237) tmp = Float64(Float64(4.0 * y) * t); elseif (t_1 <= 2e+235) tmp = Float64(x * x); else tmp = Float64(Float64(Float64(y * -4.0) * z) * z); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * z) - t; tmp = 0.0; if (t_1 <= -5e+237) tmp = (4.0 * y) * t; elseif (t_1 <= 2e+235) tmp = x * x; else tmp = ((y * -4.0) * z) * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+237], N[(N[(4.0 * y), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[t$95$1, 2e+235], N[(x * x), $MachinePrecision], N[(N[(N[(y * -4.0), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot z - t\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+237}:\\
\;\;\;\;\left(4 \cdot y\right) \cdot t\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y \cdot -4\right) \cdot z\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 (*.f64 z z) t) < -5.0000000000000002e237Initial program 93.3%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6481.9
Applied rewrites81.9%
Applied rewrites81.9%
if -5.0000000000000002e237 < (-.f64 (*.f64 z z) t) < 2.0000000000000001e235Initial program 97.4%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6497.1
Applied rewrites97.1%
Taylor expanded in t around inf
+-commutativeN/A
distribute-lft-inN/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.6
Applied rewrites90.6%
Applied rewrites87.6%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6461.8
Applied rewrites61.8%
if 2.0000000000000001e235 < (-.f64 (*.f64 z z) t) Initial program 70.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6464.2
Applied rewrites64.2%
Applied rewrites76.1%
Final simplification67.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+29) (fma (* 4.0 t) y (* x x)) (fma (* (* y -4.0) z) z (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+29) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = fma(((y * -4.0) * z), z, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+29) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = fma(Float64(Float64(y * -4.0) * z), z, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+29], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * -4.0), $MachinePrecision] * z), $MachinePrecision] * z + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+29}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot -4\right) \cdot z, z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.99999999999999914e28Initial program 97.9%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.3
Applied rewrites92.3%
Applied rewrites93.7%
if 9.99999999999999914e28 < (*.f64 z z) Initial program 75.3%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.8
Applied rewrites70.8%
Applied rewrites86.4%
Final simplification90.5%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+230) (fma (* 4.0 t) y (* x x)) (* (* (* y -4.0) z) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+230) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = ((y * -4.0) * z) * z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+230) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = Float64(Float64(Float64(y * -4.0) * z) * z); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+230], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * -4.0), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+230}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y \cdot -4\right) \cdot z\right) \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e230Initial program 97.2%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6486.9
Applied rewrites86.9%
Applied rewrites88.6%
if 1.0000000000000001e230 < (*.f64 z z) Initial program 66.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.0
Applied rewrites73.0%
Applied rewrites86.8%
Final simplification88.0%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 3600000.0) (* (* 4.0 y) t) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 3600000.0) {
tmp = (4.0 * y) * t;
} else {
tmp = x * x;
}
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 ((x * x) <= 3600000.0d0) then
tmp = (4.0d0 * y) * t
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 3600000.0) {
tmp = (4.0 * y) * t;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 3600000.0: tmp = (4.0 * y) * t else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 3600000.0) tmp = Float64(Float64(4.0 * y) * t); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 3600000.0) tmp = (4.0 * y) * t; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 3600000.0], N[(N[(4.0 * y), $MachinePrecision] * t), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3600000:\\
\;\;\;\;\left(4 \cdot y\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.6e6Initial program 90.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6449.0
Applied rewrites49.0%
Applied rewrites49.8%
if 3.6e6 < (*.f64 x x) Initial program 85.6%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6485.6
Applied rewrites85.6%
Taylor expanded in t around inf
+-commutativeN/A
distribute-lft-inN/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.3
Applied rewrites80.3%
Applied rewrites79.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6476.2
Applied rewrites76.2%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 88.2%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6488.0
Applied rewrites88.0%
Taylor expanded in t around inf
+-commutativeN/A
distribute-lft-inN/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6484.3
Applied rewrites84.3%
Applied rewrites79.6%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6445.5
Applied rewrites45.5%
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - 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 * x) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t): return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t)))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (4.0 * (y * ((z * z) - t))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}
herbie shell --seed 2024285
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))