Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3

?

Percentage Accurate: 90.2% → 96.4%
Time: 9.2s
Precision: binary64
Cost: 1737

?

\[ \begin{array}{c}[y, t] = \mathsf{sort}([y, t])\\ \end{array} \]
\[\left(x \cdot y - z \cdot y\right) \cdot t \]
\[\begin{array}{l} t_1 := \left(x \cdot y - y \cdot z\right) \cdot t\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+59} \lor \neg \left(t_1 \leq 2 \cdot 10^{-114}\right):\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (- (* x y) (* y z)) t)))
   (if (or (<= t_1 -5e+59) (not (<= t_1 2e-114)))
     (* (- x z) (* y t))
     (* y (* t (- x z))))))
double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) - (y * z)) * t;
	double tmp;
	if ((t_1 <= -5e+59) || !(t_1 <= 2e-114)) {
		tmp = (x - z) * (y * t);
	} else {
		tmp = y * (t * (x - 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
    code = ((x * y) - (z * y)) * t
end 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) :: t_1
    real(8) :: tmp
    t_1 = ((x * y) - (y * z)) * t
    if ((t_1 <= (-5d+59)) .or. (.not. (t_1 <= 2d-114))) then
        tmp = (x - z) * (y * t)
    else
        tmp = y * (t * (x - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
public static double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) - (y * z)) * t;
	double tmp;
	if ((t_1 <= -5e+59) || !(t_1 <= 2e-114)) {
		tmp = (x - z) * (y * t);
	} else {
		tmp = y * (t * (x - z));
	}
	return tmp;
}
def code(x, y, z, t):
	return ((x * y) - (z * y)) * t
def code(x, y, z, t):
	t_1 = ((x * y) - (y * z)) * t
	tmp = 0
	if (t_1 <= -5e+59) or not (t_1 <= 2e-114):
		tmp = (x - z) * (y * t)
	else:
		tmp = y * (t * (x - z))
	return tmp
function code(x, y, z, t)
	return Float64(Float64(Float64(x * y) - Float64(z * y)) * t)
end
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(x * y) - Float64(y * z)) * t)
	tmp = 0.0
	if ((t_1 <= -5e+59) || !(t_1 <= 2e-114))
		tmp = Float64(Float64(x - z) * Float64(y * t));
	else
		tmp = Float64(y * Float64(t * Float64(x - z)));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = ((x * y) - (z * y)) * t;
end
function tmp_2 = code(x, y, z, t)
	t_1 = ((x * y) - (y * z)) * t;
	tmp = 0.0;
	if ((t_1 <= -5e+59) || ~((t_1 <= 2e-114)))
		tmp = (x - z) * (y * t);
	else
		tmp = y * (t * (x - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+59], N[Not[LessEqual[t$95$1, 2e-114]], $MachinePrecision]], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := \left(x \cdot y - y \cdot z\right) \cdot t\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+59} \lor \neg \left(t_1 \leq 2 \cdot 10^{-114}\right):\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\


\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original90.2%
Target96.0%
Herbie96.4%
\[\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} \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 (*.f64 x y) (*.f64 z y)) t) < -4.9999999999999997e59 or 2.0000000000000001e-114 < (*.f64 (-.f64 (*.f64 x y) (*.f64 z y)) t)

    1. Initial program 91.4%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Taylor expanded in x around 0 83.2%

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    3. Simplified99.1%

      \[\leadsto \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)} \]
      Step-by-step derivation

      [Start]83.2

      \[ y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right) \]

      associate-*r* [=>]88.8

      \[ \color{blue}{\left(y \cdot t\right) \cdot x} + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right) \]

      *-commutative [<=]88.8

      \[ \color{blue}{\left(t \cdot y\right)} \cdot x + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right) \]

      mul-1-neg [=>]88.8

      \[ \left(t \cdot y\right) \cdot x + \color{blue}{\left(-y \cdot \left(t \cdot z\right)\right)} \]

      associate-*r* [=>]90.1

      \[ \left(t \cdot y\right) \cdot x + \left(-\color{blue}{\left(y \cdot t\right) \cdot z}\right) \]

      *-commutative [<=]90.1

      \[ \left(t \cdot y\right) \cdot x + \left(-\color{blue}{\left(t \cdot y\right)} \cdot z\right) \]

      distribute-rgt-neg-in [=>]90.1

      \[ \left(t \cdot y\right) \cdot x + \color{blue}{\left(t \cdot y\right) \cdot \left(-z\right)} \]

      distribute-lft-in [<=]99.1

      \[ \color{blue}{\left(t \cdot y\right) \cdot \left(x + \left(-z\right)\right)} \]

      sub-neg [<=]99.1

      \[ \left(t \cdot y\right) \cdot \color{blue}{\left(x - z\right)} \]

      *-commutative [=>]99.1

      \[ \color{blue}{\left(x - z\right) \cdot \left(t \cdot y\right)} \]

      *-commutative [=>]99.1

      \[ \left(x - z\right) \cdot \color{blue}{\left(y \cdot t\right)} \]

    if -4.9999999999999997e59 < (*.f64 (-.f64 (*.f64 x y) (*.f64 z y)) t) < 2.0000000000000001e-114

    1. Initial program 95.4%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified94.7%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
      Step-by-step derivation

      [Start]95.4

      \[ \left(x \cdot y - z \cdot y\right) \cdot t \]

      distribute-rgt-out-- [=>]95.4

      \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t \]

      associate-*l* [=>]94.7

      \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot y - y \cdot z\right) \cdot t \leq -5 \cdot 10^{+59} \lor \neg \left(\left(x \cdot y - y \cdot z\right) \cdot t \leq 2 \cdot 10^{-114}\right):\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy92.1%
Cost845
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+247}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{elif}\;z \leq -1.04 \cdot 10^{-258} \lor \neg \left(z \leq 3.8 \cdot 10^{-256}\right):\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 2
Accuracy73.3%
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+35} \lor \neg \left(z \leq 1.75 \cdot 10^{-57}\right):\\ \;\;\;\;z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 3
Accuracy73.2%
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -5.1 \cdot 10^{+39}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-58}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\ \end{array} \]
Alternative 4
Accuracy73.0%
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+45}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-57}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-t\right)\\ \end{array} \]
Alternative 5
Accuracy96.9%
Cost580
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-54}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \]
Alternative 6
Accuracy56.1%
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 10^{+21}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 7
Accuracy52.7%
Cost320
\[y \cdot \left(x \cdot t\right) \]

Reproduce?

herbie shell --seed 2023160 
(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))